mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-23 13:23:28 +03:00
Fix per-category sort/display affecting the wrong category
This commit is contained in:
parent
9432d2d06a
commit
bd47eafeec
6 changed files with 37 additions and 42 deletions
|
@ -31,9 +31,16 @@ import tachiyomi.presentation.core.theme.header
|
|||
@Composable
|
||||
fun HeadingItem(
|
||||
@StringRes labelRes: Int,
|
||||
) {
|
||||
HeadingItem(stringResource(labelRes))
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HeadingItem(
|
||||
text: String,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(labelRes),
|
||||
text = text,
|
||||
style = MaterialTheme.typography.header,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
|
|
@ -6,10 +6,7 @@ import androidx.compose.foundation.layout.padding
|
|||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import eu.kanade.domain.library.service.LibraryPreferences
|
||||
|
@ -35,13 +32,8 @@ import tachiyomi.domain.manga.model.TriStateFilter
|
|||
fun LibrarySettingsDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
screenModel: LibrarySettingsScreenModel,
|
||||
activeCategoryIndex: Int,
|
||||
category: Category,
|
||||
) {
|
||||
val state by screenModel.state.collectAsState()
|
||||
val category by remember(activeCategoryIndex) {
|
||||
derivedStateOf { state.categories[activeCategoryIndex] }
|
||||
}
|
||||
|
||||
TabbedDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
tabTitles = listOf(
|
||||
|
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ object LibraryTab : Tab {
|
|||
is LibraryScreenModel.Dialog.SettingsSheet -> LibrarySettingsDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
screenModel = settingsScreenModel,
|
||||
activeCategoryIndex = screenModel.activeCategoryIndex,
|
||||
category = state.categories[screenModel.activeCategoryIndex],
|
||||
)
|
||||
is LibraryScreenModel.Dialog.ChangeCategory -> {
|
||||
ChangeCategoryDialog(
|
||||
|
|
|
@ -7,6 +7,21 @@ enum class TriState(val value: Int) {
|
|||
DISABLED(0),
|
||||
ENABLED_IS(1),
|
||||
ENABLED_NOT(2),
|
||||
;
|
||||
|
||||
fun next(): TriState {
|
||||
return when (this) {
|
||||
DISABLED -> ENABLED_IS
|
||||
ENABLED_IS -> ENABLED_NOT
|
||||
ENABLED_NOT -> DISABLED
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun valueOf(value: Int): TriState {
|
||||
return TriState.values().first { it.value == value }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.toTriStateFilter(): TriStateFilter {
|
||||
|
|
|
@ -4,4 +4,13 @@ enum class TriStateFilter {
|
|||
DISABLED, // Disable filter
|
||||
ENABLED_IS, // Enabled with "is" filter
|
||||
ENABLED_NOT, // Enabled with "not" filter
|
||||
;
|
||||
|
||||
fun next(): TriStateFilter {
|
||||
return when (this) {
|
||||
DISABLED -> ENABLED_IS
|
||||
ENABLED_IS -> ENABLED_NOT
|
||||
ENABLED_NOT -> DISABLED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue