|
@@ -1,7 +1,6 @@
|
|
|
package eu.kanade.tachiyomi.ui.library
|
|
|
|
|
|
-import androidx.compose.runtime.Immutable
|
|
|
-import cafe.adriel.voyager.core.model.StateScreenModel
|
|
|
+import cafe.adriel.voyager.core.model.ScreenModel
|
|
|
import cafe.adriel.voyager.core.model.coroutineScope
|
|
|
import eu.kanade.domain.base.BasePreferences
|
|
|
import eu.kanade.domain.category.interactor.SetDisplayModeForCategory
|
|
@@ -10,12 +9,9 @@ import eu.kanade.domain.library.service.LibraryPreferences
|
|
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
|
|
import eu.kanade.tachiyomi.util.preference.toggle
|
|
|
import eu.kanade.tachiyomi.widget.TriState
|
|
|
-import kotlinx.coroutines.flow.collectLatest
|
|
|
-import kotlinx.coroutines.flow.update
|
|
|
import tachiyomi.core.preference.Preference
|
|
|
import tachiyomi.core.preference.getAndSet
|
|
|
import tachiyomi.core.util.lang.launchIO
|
|
|
-import tachiyomi.domain.category.interactor.GetCategories
|
|
|
import tachiyomi.domain.category.model.Category
|
|
|
import tachiyomi.domain.library.model.LibraryDisplayMode
|
|
|
import tachiyomi.domain.library.model.LibrarySort
|
|
@@ -25,39 +21,20 @@ import uy.kohesive.injekt.api.get
|
|
|
class LibrarySettingsScreenModel(
|
|
|
val preferences: BasePreferences = Injekt.get(),
|
|
|
val libraryPreferences: LibraryPreferences = Injekt.get(),
|
|
|
- private val getCategories: GetCategories = Injekt.get(),
|
|
|
private val setDisplayModeForCategory: SetDisplayModeForCategory = Injekt.get(),
|
|
|
private val setSortModeForCategory: SetSortModeForCategory = Injekt.get(),
|
|
|
trackManager: TrackManager = Injekt.get(),
|
|
|
-) : StateScreenModel<LibrarySettingsScreenModel.State>(State()) {
|
|
|
+) : ScreenModel {
|
|
|
|
|
|
val trackServices = trackManager.services.filter { service -> service.isLogged }
|
|
|
|
|
|
- init {
|
|
|
- coroutineScope.launchIO {
|
|
|
- getCategories.subscribe()
|
|
|
- .collectLatest {
|
|
|
- mutableState.update { state ->
|
|
|
- state.copy(
|
|
|
- categories = it,
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
fun togglePreference(preference: (LibraryPreferences) -> Preference<Boolean>) {
|
|
|
preference(libraryPreferences).toggle()
|
|
|
}
|
|
|
|
|
|
fun toggleFilter(preference: (LibraryPreferences) -> Preference<Int>) {
|
|
|
preference(libraryPreferences).getAndSet {
|
|
|
- when (it) {
|
|
|
- TriState.DISABLED.value -> TriState.ENABLED_IS.value
|
|
|
- TriState.ENABLED_IS.value -> TriState.ENABLED_NOT.value
|
|
|
- TriState.ENABLED_NOT.value -> TriState.DISABLED.value
|
|
|
- else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
|
|
|
- }
|
|
|
+ TriState.valueOf(it).next().value
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -76,9 +53,4 @@ class LibrarySettingsScreenModel(
|
|
|
setSortModeForCategory.await(category, mode, direction)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Immutable
|
|
|
- data class State(
|
|
|
- val categories: List<Category> = emptyList(),
|
|
|
- )
|
|
|
}
|