Replace StateViewModel with explicit backing fields (#3763)
Assisted-by: Claude:claude-opus-5
This commit is contained in:
@@ -18,14 +18,16 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.util.fastForEach
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import eu.kanade.domain.manga.model.hasCustomCover
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import mihon.core.viewmodel.StateViewModel
|
||||
import mihon.domain.migration.models.MigrationFlag
|
||||
import mihon.domain.migration.usecases.MigrateMangaUseCase
|
||||
import mihon.feature.common.utils.getLabel
|
||||
@@ -128,7 +130,10 @@ class MigrateDialogViewModel(
|
||||
private val coverCache: CoverCache = Injekt.get(),
|
||||
private val downloadManager: DownloadManager = Injekt.get(),
|
||||
private val migrateManga: MigrateMangaUseCase = Injekt.get(),
|
||||
) : StateViewModel<MigrateDialogViewModel.State>(State()) {
|
||||
) : ViewModel() {
|
||||
|
||||
val state: StateFlow<MigrateDialogViewModel.State>
|
||||
field = MutableStateFlow<MigrateDialogViewModel.State>(State())
|
||||
|
||||
fun init(current: Manga, target: Manga) {
|
||||
val applicableFlags = buildList {
|
||||
@@ -144,7 +149,7 @@ class MigrateDialogViewModel(
|
||||
}
|
||||
}
|
||||
val selectedFlags = sourcePreference.migrationFlags.get()
|
||||
mutableState.update {
|
||||
state.update {
|
||||
State(
|
||||
current = current,
|
||||
target = target,
|
||||
@@ -155,7 +160,7 @@ class MigrateDialogViewModel(
|
||||
}
|
||||
|
||||
fun toggleSelection(flag: MigrationFlag) {
|
||||
mutableState.update {
|
||||
state.update {
|
||||
val selectedFlags = it.selectedFlags.toMutableSet()
|
||||
.apply { if (contains(flag)) remove(flag) else add(flag) }
|
||||
.toSet()
|
||||
@@ -164,13 +169,13 @@ class MigrateDialogViewModel(
|
||||
}
|
||||
|
||||
suspend fun migrateManga(replace: Boolean) {
|
||||
val state = state.value
|
||||
val current = state.current ?: return
|
||||
val target = state.target ?: return
|
||||
sourcePreference.migrationFlags.set(state.selectedFlags)
|
||||
mutableState.update { it.copy(isMigrating = true) }
|
||||
val currentState = state.value
|
||||
val current = currentState.current ?: return
|
||||
val target = currentState.target ?: return
|
||||
sourcePreference.migrationFlags.set(currentState.selectedFlags)
|
||||
state.update { it.copy(isMigrating = true) }
|
||||
migrateManga(current, target, replace)
|
||||
mutableState.update { it.copy(isMigrating = false, isMigrated = true) }
|
||||
state.update { it.copy(isMigrating = false, isMigrated = true) }
|
||||
}
|
||||
|
||||
data class State(
|
||||
|
||||
Reference in New Issue
Block a user