crossfade cover art and show the thumbnail under the full image

This commit is contained in:
austinried
2026-10-04 00:29:53 +00:00
parent c14ade1bcb
commit 6ef1a105b8
3 changed files with 27 additions and 7 deletions
@@ -4,6 +4,7 @@ import android.app.Application
import coil3.ImageLoader import coil3.ImageLoader
import coil3.SingletonImageLoader import coil3.SingletonImageLoader
import coil3.network.okhttp.OkHttpNetworkFetcherFactory import coil3.network.okhttp.OkHttpNetworkFetcherFactory
import coil3.request.crossfade
import com.subtracks.di.appModule import com.subtracks.di.appModule
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.koin.core.context.startKoin import org.koin.core.context.startKoin
@@ -22,6 +23,7 @@ class SubtracksApp : Application() {
ImageLoader ImageLoader
.Builder(context) .Builder(context)
.components { add(OkHttpNetworkFetcherFactory(callFactory = { http })) } .components { add(OkHttpNetworkFetcherFactory(callFactory = { http })) }
.crossfade(150)
.build() .build()
} }
} }
@@ -1,5 +1,6 @@
package com.subtracks.ui.components package com.subtracks.ui.components
import android.content.Context
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -8,6 +9,7 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
@@ -23,7 +25,9 @@ fun CoverArt(
ref: CoverArtRef?, ref: CoverArtRef?,
name: String, name: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
thumbnailRef: CoverArtRef? = null,
) { ) {
val context = LocalPlatformContext.current
Box(modifier = modifier.background(MaterialTheme.colorScheme.surfaceVariant)) { Box(modifier = modifier.background(MaterialTheme.colorScheme.surfaceVariant)) {
Text( Text(
text = name.trim().take(1).uppercase(), text = name.trim().take(1).uppercase(),
@@ -31,15 +35,17 @@ fun CoverArt(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.align(Alignment.Center), modifier = Modifier.align(Alignment.Center),
) )
if (thumbnailRef != null && thumbnailRef != ref) {
AsyncImage(
model = remember(thumbnailRef) { imageRequest(context, thumbnailRef) },
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(),
)
}
if (ref != null) { if (ref != null) {
AsyncImage( AsyncImage(
model = model = remember(ref) { imageRequest(context, ref) },
ImageRequest
.Builder(LocalPlatformContext.current)
.data(ref.url)
.memoryCacheKey(ref.cacheKey)
.diskCacheKey(ref.cacheKey)
.build(),
contentDescription = null, contentDescription = null,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@@ -48,6 +54,17 @@ fun CoverArt(
} }
} }
private fun imageRequest(
context: Context,
ref: CoverArtRef,
): ImageRequest =
ImageRequest
.Builder(context)
.data(ref.url)
.memoryCacheKey(ref.cacheKey)
.diskCacheKey(ref.cacheKey)
.build()
@Composable @Composable
fun LoadingState(modifier: Modifier = Modifier) { fun LoadingState(modifier: Modifier = Modifier) {
Box(modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@@ -282,6 +282,7 @@ private fun AlbumHeader(
CoverArt( CoverArt(
ref = coverArt(album?.coverArt, false), ref = coverArt(album?.coverArt, false),
name = album?.name.orEmpty(), name = album?.name.orEmpty(),
thumbnailRef = coverArt(album?.coverArt, true),
modifier = modifier =
Modifier Modifier
.fillMaxWidth(0.86f) .fillMaxWidth(0.86f)