From 3c3b09209c7ea5729c29b9c3ad414c09b2bb9636 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 11 Nov 2023 18:31:27 -0500 Subject: [PATCH] Use immutable collections in presentation-widget module --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 4 ++-- gradle/kotlinx.versions.toml | 2 ++ presentation-widget/build.gradle.kts | 2 ++ .../presentation/widget/BaseUpdatesGridGlanceWidget.kt | 5 ++++- .../widget/{TachiyomiWidgetManager.kt => WidgetManager.kt} | 2 +- .../presentation/widget/components/UpdatesWidget.kt | 3 ++- 6 files changed, 13 insertions(+), 5 deletions(-) rename presentation-widget/src/main/java/tachiyomi/presentation/widget/{TachiyomiWidgetManager.kt => WidgetManager.kt} (97%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index bc0e4aa472..2619a073b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -56,7 +56,7 @@ import org.acra.ktx.initAcra import org.acra.sender.HttpSender import org.conscrypt.Conscrypt import tachiyomi.core.util.system.logcat -import tachiyomi.presentation.widget.TachiyomiWidgetManager +import tachiyomi.presentation.widget.WidgetManager import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy @@ -127,7 +127,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { setAppCompatDelegateThemeMode(Injekt.get().themeMode().get()) // Updates widget update - with(TachiyomiWidgetManager(Injekt.get(), Injekt.get())) { + with(WidgetManager(Injekt.get(), Injekt.get())) { init(ProcessLifecycleOwner.get().lifecycleScope) } diff --git a/gradle/kotlinx.versions.toml b/gradle/kotlinx.versions.toml index fb63cc85ec..5212c2fd01 100644 --- a/gradle/kotlinx.versions.toml +++ b/gradle/kotlinx.versions.toml @@ -7,6 +7,8 @@ xml_serialization_version = "0.86.2" reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin_version" } gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin_version" } +immutables = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version = "0.3.6" } + coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version = "1.7.3" } coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core" } coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android" } diff --git a/presentation-widget/build.gradle.kts b/presentation-widget/build.gradle.kts index 95777e4a47..e41d7be3d4 100644 --- a/presentation-widget/build.gradle.kts +++ b/presentation-widget/build.gradle.kts @@ -28,6 +28,8 @@ dependencies { implementation(compose.glance) lintChecks(compose.lintchecks) + implementation(kotlinx.immutables) + implementation(platform(libs.coil.bom)) implementation(libs.coil.core) diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt index c28f818a62..1b2e83cae8 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt @@ -30,6 +30,8 @@ import coil.size.Scale import coil.transform.RoundedCornersTransformation import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.util.system.dpToPx +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.map import tachiyomi.core.util.lang.withIOContext import tachiyomi.domain.manga.model.MangaCover @@ -106,7 +108,7 @@ abstract class BaseUpdatesGridGlanceWidget( private suspend fun List.prepareData( rowCount: Int, columnCount: Int, - ): List> { + ): ImmutableList> { // Resize to cover size val widthPx = CoverWidth.value.toInt().dpToPx val heightPx = CoverHeight.value.toInt().dpToPx @@ -140,6 +142,7 @@ abstract class BaseUpdatesGridGlanceWidget( .build() Pair(updatesView.mangaId, context.imageLoader.executeBlocking(request).drawable?.toBitmap()) } + .toImmutableList() } } diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/TachiyomiWidgetManager.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt similarity index 97% rename from presentation-widget/src/main/java/tachiyomi/presentation/widget/TachiyomiWidgetManager.kt rename to presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt index 8227c6c518..2ddcbcc386 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/TachiyomiWidgetManager.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/WidgetManager.kt @@ -12,7 +12,7 @@ import logcat.LogPriority import tachiyomi.core.util.system.logcat import tachiyomi.domain.updates.interactor.GetUpdates -class TachiyomiWidgetManager( +class WidgetManager( private val getUpdates: GetUpdates, private val securityPreferences: SecurityPreferences, ) { diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt index 53ebadfa96..95beae7867 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt @@ -21,6 +21,7 @@ import androidx.glance.layout.padding import androidx.glance.text.Text import androidx.glance.text.TextStyle import androidx.glance.unit.ColorProvider +import kotlinx.collections.immutable.ImmutableList import tachiyomi.core.Constants import tachiyomi.presentation.widget.R import tachiyomi.presentation.widget.util.calculateRowAndColumnCount @@ -28,7 +29,7 @@ import tachiyomi.presentation.widget.util.stringResource @Composable fun UpdatesWidget( - data: List>?, + data: ImmutableList>?, contentColor: ColorProvider, topPadding: Dp, bottomPadding: Dp,