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

Update dependency io.github.qdsfdhvh:image-loader to v1.7.0 #1625

Merged
merged 2 commits into from
Nov 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package app.tivi.common.imageloading

import androidx.compose.ui.unit.Density
import app.tivi.data.episodes.SeasonsEpisodesRepository
import app.tivi.data.imagemodels.EpisodeImageModel
import app.tivi.data.util.inPast
Expand All @@ -19,7 +18,6 @@ import me.tatarka.inject.annotations.Inject
class EpisodeImageModelInterceptor(
private val tmdbImageUrlProvider: Lazy<TmdbImageUrlProvider>,
private val repository: SeasonsEpisodesRepository,
private val density: () -> Density,
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val request = when (val data = chain.request.data) {
Expand All @@ -35,10 +33,9 @@ class EpisodeImageModelInterceptor(
}

return repository.getEpisode(model.id)?.tmdbBackdropPath?.let { backdropPath ->
val size = chain.options.sizeResolver.run { density().size() }
val url = tmdbImageUrlProvider.value.getBackdropUrl(
path = backdropPath,
imageWidth = size.width.roundToInt(),
imageWidth = chain.options.size.width.roundToInt(),
)

ImageRequest(chain.request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class HideArtworkInterceptor(
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult = when {
preferences.developerHideArtwork && isArtwork(chain.request.data) -> {
ImageResult.Error(
Exception("Developer setting: hide artwork enabled"),
)
ImageResult.OfError(Exception("Developer setting: hide artwork enabled"))
}
else -> chain.proceed(chain.request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package app.tivi.common.imageloading

import androidx.compose.ui.unit.Density
import app.tivi.data.episodes.SeasonsEpisodesRepository
import app.tivi.data.imagemodels.SeasonImageModel
import app.tivi.data.util.inPast
Expand All @@ -19,7 +18,6 @@ import me.tatarka.inject.annotations.Inject
class SeasonImageModelInterceptor(
private val tmdbImageUrlProvider: Lazy<TmdbImageUrlProvider>,
private val repository: SeasonsEpisodesRepository,
private val density: () -> Density,
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val request = when (val data = chain.request.data) {
Expand All @@ -36,10 +34,9 @@ class SeasonImageModelInterceptor(

val season = repository.getSeason(model.id)
return season?.tmdbPosterPath?.let { posterPath ->
val size = chain.options.sizeResolver.run { density().size() }
val url = tmdbImageUrlProvider.value.getPosterUrl(
path = posterPath,
imageWidth = size.width.roundToInt(),
imageWidth = chain.options.size.width.roundToInt(),
)

ImageRequest(chain.request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package app.tivi.common.imageloading

import androidx.compose.ui.unit.Density
import app.tivi.data.imagemodels.ShowImageModel
import app.tivi.data.models.ImageType
import app.tivi.data.models.TmdbImageEntity
Expand All @@ -23,7 +22,6 @@ class ShowImageModelInterceptor(
private val tmdbImageUrlProvider: Lazy<TmdbImageUrlProvider>,
private val showImagesStore: ShowImagesStore,
private val powerController: PowerController,
private val density: () -> Density,
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val request = when (val data = chain.request.data) {
Expand All @@ -42,12 +40,11 @@ class ShowImageModelInterceptor(
}.getOrNull()

return if (entity != null) {
val size = chain.options.sizeResolver.run { density().size() }

val size = chain.options.size
val width = when (powerController.shouldSaveData()) {
is SaveData.Disabled -> size.width.roundToInt()
// If we can't download hi-res images, we load half-width images (so ~1/4 in size)
is SaveData.Enabled -> size.width.roundToInt() / 2
is SaveData.Enabled -> chain.options.size.width.roundToInt() / 2
}

ImageRequest(chain.request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package app.tivi.common.imageloading

import androidx.compose.ui.geometry.Size
import androidx.compose.ui.unit.Density
import app.tivi.data.models.TmdbImageEntity
import app.tivi.tmdb.TmdbImageUrlProvider
import app.tivi.util.PowerController
Expand All @@ -19,15 +18,12 @@ import me.tatarka.inject.annotations.Inject
class TmdbImageEntityCoilInterceptor(
private val tmdbImageUrlProvider: Lazy<TmdbImageUrlProvider>,
private val powerController: PowerController,
private val density: () -> Density,
) : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val size = chain.options.sizeResolver.run { density().size() }

val request = when (val data = chain.request.data) {
is TmdbImageEntity -> {
ImageRequest(chain.request) {
data(map(data, size))
data(map(data, chain.options.size))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
Expand Down Expand Up @@ -153,15 +152,15 @@ private fun ResultImage(
Image(
painter = remember(result) {
when (result) {
is ImageResult.Bitmap -> {
is ImageResult.OfBitmap -> {
BitmapPainter(
image = result.bitmap.asImageBitmap(),
filterQuality = filterQuality,
)
}

is ImageResult.Image -> result.image.toPainter()
is ImageResult.Painter -> result.painter
is ImageResult.OfImage -> result.image.toPainter()
is ImageResult.OfPainter -> result.painter
else -> EmptyPainter
}
},
Expand All @@ -184,7 +183,7 @@ internal class ConstraintsSizeResolver : SizeResolver, LayoutModifier {

private val constraints = MutableStateFlow(Constraints())

override suspend fun Density.size(): Size {
override suspend fun size(): Size {
return constraints.mapNotNull(Constraints::toSizeOrNull).first()
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ google-firebase-analytics = "com.google.firebase:firebase-analytics:21.5.0"
google-firebase-crashlytics = "com.google.firebase:firebase-crashlytics-ktx:18.5.1"
google-firebase-perf = "com.google.firebase:firebase-perf:20.5.0"

imageloader = "io.github.qdsfdhvh:image-loader:1.6.8"
imageloader = "io.github.qdsfdhvh:image-loader:1.7.0"

junit = "junit:junit:4.13.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package app.tivi.inject

import android.app.Application
import android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE
import androidx.compose.ui.unit.Density
import app.tivi.app.ApplicationInfo
import app.tivi.app.Flavor
import java.io.File
Expand Down Expand Up @@ -61,7 +60,4 @@ actual interface SharedPlatformApplicationComponent {
.readTimeout(20, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.build()

@Provides
fun provideDensity(application: Application): Density = Density(application)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@

package app.tivi.inject

import androidx.compose.ui.unit.Density
import app.tivi.app.ApplicationInfo
import app.tivi.app.Flavor
import kotlin.experimental.ExperimentalNativeApi
import me.tatarka.inject.annotations.Provides
import platform.Foundation.NSBundle
import platform.Foundation.NSUserDefaults
import platform.UIKit.UIScreen

actual interface SharedPlatformApplicationComponent {
@Provides
fun provideNsUserDefaults(): NSUserDefaults = NSUserDefaults.standardUserDefaults

@Provides
fun provideDensity(): Density = Density(density = UIScreen.mainScreen.scale.toFloat())

@OptIn(ExperimentalNativeApi::class)
@ApplicationScope
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package app.tivi.inject

import androidx.compose.ui.unit.Density
import app.tivi.app.ApplicationInfo
import app.tivi.app.Flavor
import java.util.concurrent.TimeUnit
Expand All @@ -30,15 +29,9 @@ actual interface SharedPlatformApplicationComponent {
@Provides
fun providePreferences(): Preferences = Preferences.userRoot().node("app.tivi")

@Provides
fun provideDensity(): Density = Density(density = 1f) // FIXME

@ApplicationScope
@Provides
fun provideOkHttpClient(
// interceptors: Set<Interceptor>,
): OkHttpClient = OkHttpClient.Builder()
// .apply { interceptors.forEach(::addInterceptor) }
fun provideOkHttpClient(): OkHttpClient = OkHttpClient.Builder()
// Adjust the Connection pool to account for historical use of 3 separate clients
// but reduce the keepAlive to 2 minutes to avoid keeping radio open.
.connectionPool(ConnectionPool(10, 2, TimeUnit.MINUTES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private fun NextEpisodeToWatch(
AsyncImage(
model = model,
onAction = { state ->
if (state is ImageResult.Error && model is EpisodeImageModel) {
if (state is ImageResult.OfError && model is EpisodeImageModel) {
// If the episode backdrop request failed, fallback to the show backdrop
model = show.asImageModel(ImageType.BACKDROP)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private fun UpNextItem(
AsyncImage(
model = model,
onAction = { state ->
if (state is ImageResult.Error && model is EpisodeImageModel) {
if (state is ImageResult.OfError && model is EpisodeImageModel) {
// If the episode backdrop request failed, fallback to the show backdrop
model = show.asImageModel(ImageType.BACKDROP)
}
Expand Down