Migrate TriState usages to TriStateFilter enum

This commit is contained in:
arkon
2023-02-24 16:09:47 -05:00
parent a0e76d2fd9
commit 7ec87e76db
9 changed files with 108 additions and 85 deletions

View File

@@ -1,34 +1,13 @@
package eu.kanade.tachiyomi.widget
import eu.kanade.tachiyomi.source.model.Filter
import tachiyomi.domain.manga.model.TriStateFilter
// TODO: replace this with TriStateFilter entirely
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 {
return when (this) {
TriState.DISABLED.value -> TriStateFilter.DISABLED
TriState.ENABLED_IS.value -> TriStateFilter.ENABLED_IS
TriState.ENABLED_NOT.value -> TriStateFilter.ENABLED_NOT
else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
Filter.TriState.STATE_IGNORE -> TriStateFilter.DISABLED
Filter.TriState.STATE_INCLUDE -> TriStateFilter.ENABLED_IS
Filter.TriState.STATE_EXCLUDE -> TriStateFilter.ENABLED_NOT
else -> throw IllegalStateException("Unknown TriState state: $this")
}
}