mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Use immutable collections in presentation-widget module
This commit is contained in:
parent
4a6571d310
commit
3c3b09209c
6 changed files with 13 additions and 5 deletions
|
@ -56,7 +56,7 @@ import org.acra.ktx.initAcra
|
||||||
import org.acra.sender.HttpSender
|
import org.acra.sender.HttpSender
|
||||||
import org.conscrypt.Conscrypt
|
import org.conscrypt.Conscrypt
|
||||||
import tachiyomi.core.util.system.logcat
|
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.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
@ -127,7 +127,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
||||||
setAppCompatDelegateThemeMode(Injekt.get<UiPreferences>().themeMode().get())
|
setAppCompatDelegateThemeMode(Injekt.get<UiPreferences>().themeMode().get())
|
||||||
|
|
||||||
// Updates widget update
|
// Updates widget update
|
||||||
with(TachiyomiWidgetManager(Injekt.get(), Injekt.get())) {
|
with(WidgetManager(Injekt.get(), Injekt.get())) {
|
||||||
init(ProcessLifecycleOwner.get().lifecycleScope)
|
init(ProcessLifecycleOwner.get().lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ xml_serialization_version = "0.86.2"
|
||||||
reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin_version" }
|
reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin_version" }
|
||||||
gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", 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-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version = "1.7.3" }
|
||||||
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core" }
|
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core" }
|
||||||
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android" }
|
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android" }
|
||||||
|
|
|
@ -28,6 +28,8 @@ dependencies {
|
||||||
implementation(compose.glance)
|
implementation(compose.glance)
|
||||||
lintChecks(compose.lintchecks)
|
lintChecks(compose.lintchecks)
|
||||||
|
|
||||||
|
implementation(kotlinx.immutables)
|
||||||
|
|
||||||
implementation(platform(libs.coil.bom))
|
implementation(platform(libs.coil.bom))
|
||||||
implementation(libs.coil.core)
|
implementation(libs.coil.core)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ import coil.size.Scale
|
||||||
import coil.transform.RoundedCornersTransformation
|
import coil.transform.RoundedCornersTransformation
|
||||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import tachiyomi.core.util.lang.withIOContext
|
import tachiyomi.core.util.lang.withIOContext
|
||||||
import tachiyomi.domain.manga.model.MangaCover
|
import tachiyomi.domain.manga.model.MangaCover
|
||||||
|
@ -106,7 +108,7 @@ abstract class BaseUpdatesGridGlanceWidget(
|
||||||
private suspend fun List<UpdatesWithRelations>.prepareData(
|
private suspend fun List<UpdatesWithRelations>.prepareData(
|
||||||
rowCount: Int,
|
rowCount: Int,
|
||||||
columnCount: Int,
|
columnCount: Int,
|
||||||
): List<Pair<Long, Bitmap?>> {
|
): ImmutableList<Pair<Long, Bitmap?>> {
|
||||||
// Resize to cover size
|
// Resize to cover size
|
||||||
val widthPx = CoverWidth.value.toInt().dpToPx
|
val widthPx = CoverWidth.value.toInt().dpToPx
|
||||||
val heightPx = CoverHeight.value.toInt().dpToPx
|
val heightPx = CoverHeight.value.toInt().dpToPx
|
||||||
|
@ -140,6 +142,7 @@ abstract class BaseUpdatesGridGlanceWidget(
|
||||||
.build()
|
.build()
|
||||||
Pair(updatesView.mangaId, context.imageLoader.executeBlocking(request).drawable?.toBitmap())
|
Pair(updatesView.mangaId, context.imageLoader.executeBlocking(request).drawable?.toBitmap())
|
||||||
}
|
}
|
||||||
|
.toImmutableList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import logcat.LogPriority
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.updates.interactor.GetUpdates
|
import tachiyomi.domain.updates.interactor.GetUpdates
|
||||||
|
|
||||||
class TachiyomiWidgetManager(
|
class WidgetManager(
|
||||||
private val getUpdates: GetUpdates,
|
private val getUpdates: GetUpdates,
|
||||||
private val securityPreferences: SecurityPreferences,
|
private val securityPreferences: SecurityPreferences,
|
||||||
) {
|
) {
|
|
@ -21,6 +21,7 @@ import androidx.glance.layout.padding
|
||||||
import androidx.glance.text.Text
|
import androidx.glance.text.Text
|
||||||
import androidx.glance.text.TextStyle
|
import androidx.glance.text.TextStyle
|
||||||
import androidx.glance.unit.ColorProvider
|
import androidx.glance.unit.ColorProvider
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import tachiyomi.core.Constants
|
import tachiyomi.core.Constants
|
||||||
import tachiyomi.presentation.widget.R
|
import tachiyomi.presentation.widget.R
|
||||||
import tachiyomi.presentation.widget.util.calculateRowAndColumnCount
|
import tachiyomi.presentation.widget.util.calculateRowAndColumnCount
|
||||||
|
@ -28,7 +29,7 @@ import tachiyomi.presentation.widget.util.stringResource
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UpdatesWidget(
|
fun UpdatesWidget(
|
||||||
data: List<Pair<Long, Bitmap?>>?,
|
data: ImmutableList<Pair<Long, Bitmap?>>?,
|
||||||
contentColor: ColorProvider,
|
contentColor: ColorProvider,
|
||||||
topPadding: Dp,
|
topPadding: Dp,
|
||||||
bottomPadding: Dp,
|
bottomPadding: Dp,
|
||||||
|
|
Loading…
Reference in a new issue