mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: 优化图片显示
This commit is contained in:
parent
6039f8cea5
commit
bb8fbacec3
|
@ -31,15 +31,17 @@ import com.ramcosta.composedestinations.annotation.Destination
|
|||
import com.ramcosta.composedestinations.annotation.RootNavGraph
|
||||
import li.songe.gkd.data.RawSubscription
|
||||
import li.songe.gkd.util.LocalNavController
|
||||
import li.songe.gkd.util.ProfileTransitions
|
||||
import li.songe.gkd.util.appInfoCacheFlow
|
||||
import li.songe.gkd.util.imageLoader
|
||||
import li.songe.gkd.util.subsIdToRawFlow
|
||||
|
||||
|
||||
@RootNavGraph
|
||||
@Destination
|
||||
@Destination(style = ProfileTransitions::class)
|
||||
@Composable
|
||||
fun GroupItemPage(subsInt: Long, groupKey: Int, appId: String? = null) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val subsIdToRaw by subsIdToRawFlow.collectAsState()
|
||||
val rawSubs = subsIdToRaw[subsInt]
|
||||
|
@ -72,8 +74,9 @@ fun GroupItemPage(subsInt: Long, groupKey: Int, appId: String? = null) {
|
|||
is RawSubscription.RawAppGroup -> {
|
||||
Text(
|
||||
text = ((rawSubs?.name
|
||||
?: subsInt.toString()) + (appInfoCache[appId]?.name ?: rawApp?.name
|
||||
?: appId) + "/" + (group.name))
|
||||
?: subsInt.toString()) + "/" + (appInfoCache[appId]?.name
|
||||
?: rawApp?.name
|
||||
?: appId) + "/" + (group.name))
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,7 @@ fun GroupItemPage(subsInt: Long, groupKey: Int, appId: String? = null) {
|
|||
val url = allExampleUrls.getOrNull(p)
|
||||
if (url != null) {
|
||||
SubcomposeAsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current).data(url)
|
||||
model = ImageRequest.Builder(context).data(url)
|
||||
.crossfade(DefaultDurationMillis).build(),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
|
|
@ -14,6 +14,8 @@ import io.ktor.serialization.kotlinx.json.json
|
|||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import li.songe.gkd.app
|
||||
import okhttp3.OkHttpClient
|
||||
import java.time.Duration
|
||||
|
||||
|
||||
val kv by lazy { MMKV.mmkvWithID("kv")!! }
|
||||
|
@ -48,14 +50,22 @@ val client by lazy {
|
|||
}
|
||||
|
||||
val imageLoader by lazy {
|
||||
ImageLoader.Builder(app).components {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
add(ImageDecoderDecoder.Factory())
|
||||
} else {
|
||||
add(GifDecoder.Factory())
|
||||
}
|
||||
}.diskCache {
|
||||
DiskCache.Builder().directory(imageCacheDir).build()
|
||||
}.build()
|
||||
ImageLoader.Builder(app)
|
||||
.okHttpClient(
|
||||
OkHttpClient.Builder()
|
||||
.connectTimeout(Duration.ofSeconds(30))
|
||||
.readTimeout(Duration.ofSeconds(30))
|
||||
.writeTimeout(Duration.ofSeconds(30))
|
||||
.build()
|
||||
)
|
||||
.components {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
add(ImageDecoderDecoder.Factory())
|
||||
} else {
|
||||
add(GifDecoder.Factory())
|
||||
}
|
||||
}.diskCache {
|
||||
DiskCache.Builder().directory(imageCacheDir).build()
|
||||
}.build()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user