Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Update to Compose SNAPSHOT 6765009 #683

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ dependencies {
implementation Libs.AndroidX.Navigation.fragment
implementation Libs.AndroidX.Navigation.ui

implementation Libs.Google.material
implementation Libs.Mdc.material

implementation Libs.Insetter.ktx

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/app/tivi/home/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package app.tivi.home
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.observe
import androidx.navigation.NavController
import app.tivi.AppNavigator
import app.tivi.R
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import app.tivi.buildsrc.Versions

buildscript {
ext.buildConfig = [
'compileSdk': 29,
'compileSdk': 30,
'minSdk' : 23,
'targetSdk' : 29,
'targetSdk' : 30,
]

repositories {
Expand Down Expand Up @@ -114,6 +114,8 @@ subprojects {

freeCompilerArgs += "-Xallow-jvm-ir-dependencies"

freeCompilerArgs += "-Xjvm-default=all"

// Set JVM target to 1.8
jvmTarget = "1.8"
}
Expand Down
23 changes: 13 additions & 10 deletions buildSrc/src/main/java/app/tivi/buildsrc/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ object Libs {

const val leakCanary = "com.squareup.leakcanary:leakcanary-android:2.4"

// Move back to Store when alpha07 is out
const val store = "com.dropbox.mobile.store:store4:4.0.0-SNAPSHOT"
const val store = "com.dropbox.mobile.store:store4:4.0.0-alpha07"

object Insetter {
private const val version = "0.3.1"
Expand All @@ -54,13 +53,17 @@ object Libs {
}

object Accompanist {
private const val version = "0.1.8.ui-${AndroidX.Compose.snapshot}-SNAPSHOT"
private const val version = "0.1.10.ui-${AndroidX.Compose.snapshot}-SNAPSHOT"
const val mdcTheme = "dev.chrisbanes.accompanist:accompanist-mdc-theme:$version"
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
}

object Google {
object Mdc {
const val material = "com.google.android.material:material:1.1.0"
const val composeThemeAdapter = "com.google.android.material:compose-theme-adapter:0.1.0-dev17"
}

object Google {
const val firebaseCore = "com.google.firebase:firebase-core:17.4.3"

const val crashlytics = "com.google.firebase:firebase-crashlytics:17.0.1"
Expand All @@ -73,14 +76,14 @@ object Libs {
}

object Kotlin {
private const val version = "1.4.0-rc"
private const val version = "1.4.0"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
const val extensions = "org.jetbrains.kotlin:kotlin-android-extensions:$version"
}

object Coroutines {
private const val version = "1.3.8-1.4.0-rc"
private const val version = "1.3.9"
const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$version"
Expand Down Expand Up @@ -133,7 +136,7 @@ object Libs {

const val constraintlayout = "androidx.constraintlayout:constraintlayout:2.0.0-rc1"

const val coreKtx = "androidx.core:core-ktx:1.3.1"
const val coreKtx = "androidx.core:core-ktx:1.5.0-alpha02"

object Lifecycle {
private const val version = "2.3.0-alpha06"
Expand All @@ -157,8 +160,8 @@ object Libs {
}

object Compose {
const val snapshot = "6752477"
const val version = "0.1.0-SNAPSHOT"
const val snapshot = "6765009"
const val version = "1.0.0-SNAPSHOT"

@get:JvmStatic
val snapshotUrl: String
Expand Down Expand Up @@ -223,7 +226,7 @@ object Libs {
}

object Coil {
private const val version = "0.11.0"
private const val version = "1.0.0-rc1"
const val coil = "io.coil-kt:coil:$version"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DefaultItemAnimator
import app.tivi.FragmentWithBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,36 @@ import android.content.Context
import app.tivi.appinitializers.AppInitializer
import coil.Coil
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.annotation.ExperimentalCoilApi
import coil.util.CoilUtils
import dagger.hilt.android.qualifiers.ApplicationContext
import okhttp3.OkHttpClient
import javax.inject.Inject

class CoilAppInitializer @Inject constructor(
private val tmdbImageEntityMapper: TmdbImageEntityCoilMapper,
private val episodeEntityMapper: EpisodeCoilMapper,
class CoilAppInitializer @OptIn(ExperimentalCoilApi::class)
@Inject constructor(
private val tmdbImageEntityInterceptor: TmdbImageEntityCoilInterceptor,
private val episodeEntityInterceptor: EpisodeEntityCoilInterceptor,
private val okHttpClient: OkHttpClient,
@ApplicationContext private val context: Context
) : AppInitializer {
override fun init(application: Application) {
val coilOkHttpClient = okHttpClient.newBuilder()
.cache(CoilUtils.createDefaultCache(context))
.build()
Coil.setImageLoader(object : ImageLoaderFactory {
override fun newImageLoader(): ImageLoader = ImageLoader.Builder(application)
Coil.setImageLoader {
ImageLoader.Builder(application)
// Hardware bitmaps break with our transitions, disable them for now
.allowHardware(false)
// Since we don't use hardware bitmaps, we can pool bitmaps and use a higher
// ratio of memory
.bitmapPoolPercentage(0.5)
.componentRegistry {
add(tmdbImageEntityMapper)
add(episodeEntityMapper)
add(tmdbImageEntityInterceptor)
add(episodeEntityInterceptor)
}
.okHttpClient(coilOkHttpClient)
.build()
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,36 @@ package app.tivi.common.imageloading

import app.tivi.data.entities.Episode
import app.tivi.tmdb.TmdbImageUrlProvider
import coil.map.MeasuredMapper
import coil.annotation.ExperimentalCoilApi
import coil.intercept.Interceptor
import coil.request.ImageResult
import coil.size.PixelSize
import coil.size.Size
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import javax.inject.Inject
import javax.inject.Provider

class EpisodeCoilMapper @Inject constructor(
@ExperimentalCoilApi
class EpisodeEntityCoilInterceptor @Inject constructor(
private val tmdbImageUrlProvider: Provider<TmdbImageUrlProvider>
) : MeasuredMapper<Episode, HttpUrl> {
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val data = chain.request.data
val request = when {
data is Episode && handles(data) -> {
chain.request.newBuilder()
.data(map(data, chain.size))
.build()
}
else -> chain.request
}
return chain.proceed(request)
}

override fun handles(data: Episode): Boolean = data.tmdbBackdropPath != null
private fun handles(data: Episode): Boolean = data.tmdbBackdropPath != null

override fun map(data: Episode, size: Size): HttpUrl {
private fun map(data: Episode, size: Size): HttpUrl {
val width = if (size is PixelSize) size.width else 0
val urlProvider = tmdbImageUrlProvider.get()
return urlProvider.getBackdropUrl(data.tmdbBackdropPath!!, width).toHttpUrl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import app.tivi.data.entities.ImageType
import app.tivi.data.entities.ShowTmdbImage
import app.tivi.data.entities.TmdbImageEntity
import coil.annotation.ExperimentalCoilApi
import coil.api.loadAny
import coil.loadAny
import coil.transform.RoundedCornersTransformation
import coil.transform.Transformation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import android.content.Context
import android.view.MenuItem
import app.tivi.extensions.resolveThemeDimensionPixelSize
import coil.Coil
import coil.request.LoadRequest
import coil.request.ImageRequest
import coil.size.PixelSize
import coil.size.Size
import coil.size.SizeResolver
import coil.transform.CircleCropTransformation

fun MenuItem.loadImageUrl(context: Context, url: String, circleCrop: Boolean = true) {
val request = LoadRequest.Builder(context)
val request = ImageRequest.Builder(context)
.data(url)
.size(object : SizeResolver {
override suspend fun size(): Size {
Expand All @@ -42,5 +42,6 @@ fun MenuItem.loadImageUrl(context: Context, url: String, circleCrop: Boolean = t
}
}
.build()
Coil.execute(request)

Coil.enqueue(request)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import app.tivi.ui.animations.saturateDrawableAnimator
import coil.annotation.ExperimentalCoilApi
import coil.decode.DataSource
import coil.request.ErrorResult
import coil.request.RequestResult
import coil.request.ImageResult
import coil.request.SuccessResult
import coil.transition.Transition
import coil.transition.TransitionTarget
Expand All @@ -38,11 +38,11 @@ class SaturatingTransformation(
}

override suspend fun transition(
target: TransitionTarget<*>,
result: RequestResult
target: TransitionTarget,
result: ImageResult
) {
// Don't animate if the request was fulfilled by the memory cache.
if (result is SuccessResult && result.source == DataSource.MEMORY_CACHE) {
if (result is SuccessResult && result.metadata.dataSource == DataSource.MEMORY_CACHE) {
target.onSuccess(result.drawable)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,34 @@ import app.tivi.data.entities.TmdbImageEntity
import app.tivi.tmdb.TmdbImageUrlProvider
import app.tivi.util.PowerController
import app.tivi.util.SaveData
import coil.map.MeasuredMapper
import coil.annotation.ExperimentalCoilApi
import coil.intercept.Interceptor
import coil.request.ImageResult
import coil.size.PixelSize
import coil.size.Size
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import javax.inject.Inject
import javax.inject.Provider

class TmdbImageEntityCoilMapper @Inject constructor(
@ExperimentalCoilApi
class TmdbImageEntityCoilInterceptor @Inject constructor(
private val tmdbImageUrlProvider: Provider<TmdbImageUrlProvider>,
private val powerController: PowerController
) : MeasuredMapper<TmdbImageEntity, HttpUrl> {

override fun handles(data: TmdbImageEntity): Boolean = true
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val request = when (val data = chain.request.data) {
is TmdbImageEntity -> {
chain.request.newBuilder()
.data(map(data, chain.size))
.build()
}
else -> chain.request
}
return chain.proceed(request)
}

override fun map(data: TmdbImageEntity, size: Size): HttpUrl {
private fun map(data: TmdbImageEntity, size: Size): HttpUrl {
val width = if (size is PixelSize) {
when (powerController.shouldSaveData()) {
is SaveData.Disabled -> size.width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Rect
import androidx.core.graphics.alpha
import coil.bitmappool.BitmapPool
import coil.bitmap.BitmapPool
import coil.size.Size
import coil.transform.Transformation

Expand Down
4 changes: 1 addition & 3 deletions common-ui-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ dependencies {
implementation Libs.AndroidX.Compose.tooling
implementation Libs.AndroidX.Compose.livedata

implementation Libs.Google.material
implementation Libs.Mdc.material

implementation Libs.Kotlin.stdlib


}
Loading