mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 06:21:48 +01:00
Migrate TriState usages to TriStateFilter enum
This commit is contained in:
parent
a0e76d2fd9
commit
7ec87e76db
@ -22,7 +22,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "eu.kanade.tachiyomi"
|
applicationId = "eu.kanade.tachiyomi"
|
||||||
versionCode = 98
|
versionCode = 99
|
||||||
versionName = "0.14.5"
|
versionName = "0.14.5"
|
||||||
|
|
||||||
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
||||||
|
@ -4,11 +4,12 @@ import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
|
|||||||
import eu.kanade.tachiyomi.data.preference.MANGA_HAS_UNREAD
|
import eu.kanade.tachiyomi.data.preference.MANGA_HAS_UNREAD
|
||||||
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
|
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
|
||||||
import eu.kanade.tachiyomi.data.preference.MANGA_NON_READ
|
import eu.kanade.tachiyomi.data.preference.MANGA_NON_READ
|
||||||
import eu.kanade.tachiyomi.widget.TriState
|
|
||||||
import tachiyomi.core.preference.PreferenceStore
|
import tachiyomi.core.preference.PreferenceStore
|
||||||
|
import tachiyomi.core.preference.getEnum
|
||||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||||
import tachiyomi.domain.library.model.LibrarySort
|
import tachiyomi.domain.library.model.LibrarySort
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
|
import tachiyomi.domain.manga.model.TriStateFilter
|
||||||
|
|
||||||
class LibraryPreferences(
|
class LibraryPreferences(
|
||||||
private val preferenceStore: PreferenceStore,
|
private val preferenceStore: PreferenceStore,
|
||||||
@ -36,17 +37,17 @@ class LibraryPreferences(
|
|||||||
|
|
||||||
// region Filter
|
// region Filter
|
||||||
|
|
||||||
fun filterDownloaded() = preferenceStore.getInt("pref_filter_library_downloaded", TriState.DISABLED.value)
|
fun filterDownloaded() = preferenceStore.getEnum("pref_filter_library_downloaded_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
fun filterUnread() = preferenceStore.getInt("pref_filter_library_unread", TriState.DISABLED.value)
|
fun filterUnread() = preferenceStore.getEnum("pref_filter_library_unread_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
fun filterStarted() = preferenceStore.getInt("pref_filter_library_started", TriState.DISABLED.value)
|
fun filterStarted() = preferenceStore.getEnum("pref_filter_library_started_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
fun filterBookmarked() = preferenceStore.getInt("pref_filter_library_bookmarked", TriState.DISABLED.value)
|
fun filterBookmarked() = preferenceStore.getEnum("pref_filter_library_bookmarked_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
fun filterCompleted() = preferenceStore.getInt("pref_filter_library_completed", TriState.DISABLED.value)
|
fun filterCompleted() = preferenceStore.getEnum("pref_filter_library_completed_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
fun filterTracking(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", TriState.DISABLED.value)
|
fun filterTracking(id: Int) = preferenceStore.getEnum("pref_filter_library_tracked_${id}_v2", TriStateFilter.DISABLED)
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import eu.kanade.presentation.components.TriStateItem
|
|||||||
import eu.kanade.presentation.util.collectAsState
|
import eu.kanade.presentation.util.collectAsState
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
|
import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
|
||||||
import eu.kanade.tachiyomi.widget.toTriStateFilter
|
|
||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||||
import tachiyomi.domain.library.model.LibrarySort
|
import tachiyomi.domain.library.model.LibrarySort
|
||||||
@ -76,7 +75,7 @@ private fun ColumnScope.FilterPage(
|
|||||||
state = if (downloadedOnly) {
|
state = if (downloadedOnly) {
|
||||||
TriStateFilter.ENABLED_IS
|
TriStateFilter.ENABLED_IS
|
||||||
} else {
|
} else {
|
||||||
filterDownloaded.toTriStateFilter()
|
filterDownloaded
|
||||||
},
|
},
|
||||||
enabled = !downloadedOnly,
|
enabled = !downloadedOnly,
|
||||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterDownloaded) },
|
onClick = { screenModel.toggleFilter(LibraryPreferences::filterDownloaded) },
|
||||||
@ -84,25 +83,25 @@ private fun ColumnScope.FilterPage(
|
|||||||
val filterUnread by screenModel.libraryPreferences.filterUnread().collectAsState()
|
val filterUnread by screenModel.libraryPreferences.filterUnread().collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(R.string.action_filter_unread),
|
label = stringResource(R.string.action_filter_unread),
|
||||||
state = filterUnread.toTriStateFilter(),
|
state = filterUnread,
|
||||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterUnread) },
|
onClick = { screenModel.toggleFilter(LibraryPreferences::filterUnread) },
|
||||||
)
|
)
|
||||||
val filterStarted by screenModel.libraryPreferences.filterStarted().collectAsState()
|
val filterStarted by screenModel.libraryPreferences.filterStarted().collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(R.string.label_started),
|
label = stringResource(R.string.label_started),
|
||||||
state = filterStarted.toTriStateFilter(),
|
state = filterStarted,
|
||||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterStarted) },
|
onClick = { screenModel.toggleFilter(LibraryPreferences::filterStarted) },
|
||||||
)
|
)
|
||||||
val filterBookmarked by screenModel.libraryPreferences.filterBookmarked().collectAsState()
|
val filterBookmarked by screenModel.libraryPreferences.filterBookmarked().collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(R.string.action_filter_bookmarked),
|
label = stringResource(R.string.action_filter_bookmarked),
|
||||||
state = filterBookmarked.toTriStateFilter(),
|
state = filterBookmarked,
|
||||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterBookmarked) },
|
onClick = { screenModel.toggleFilter(LibraryPreferences::filterBookmarked) },
|
||||||
)
|
)
|
||||||
val filterCompleted by screenModel.libraryPreferences.filterCompleted().collectAsState()
|
val filterCompleted by screenModel.libraryPreferences.filterCompleted().collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(R.string.completed),
|
label = stringResource(R.string.completed),
|
||||||
state = filterCompleted.toTriStateFilter(),
|
state = filterCompleted,
|
||||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompleted) },
|
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompleted) },
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ private fun ColumnScope.FilterPage(
|
|||||||
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(R.string.action_filter_tracked),
|
label = stringResource(R.string.action_filter_tracked),
|
||||||
state = filterTracker.toTriStateFilter(),
|
state = filterTracker,
|
||||||
onClick = { screenModel.toggleTracker(service.id.toInt()) },
|
onClick = { screenModel.toggleTracker(service.id.toInt()) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -125,7 +124,7 @@ private fun ColumnScope.FilterPage(
|
|||||||
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
||||||
TriStateItem(
|
TriStateItem(
|
||||||
label = stringResource(service.nameRes()),
|
label = stringResource(service.nameRes()),
|
||||||
state = filterTracker.toTriStateFilter(),
|
state = filterTracker,
|
||||||
onClick = { screenModel.toggleTracker(service.id.toInt()) },
|
onClick = { screenModel.toggleTracker(service.id.toInt()) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,9 @@ import eu.kanade.tachiyomi.util.preference.minusAssign
|
|||||||
import eu.kanade.tachiyomi.util.preference.plusAssign
|
import eu.kanade.tachiyomi.util.preference.plusAssign
|
||||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.widget.TriState
|
|
||||||
import tachiyomi.core.preference.PreferenceStore
|
import tachiyomi.core.preference.PreferenceStore
|
||||||
|
import tachiyomi.core.preference.getEnum
|
||||||
|
import tachiyomi.domain.manga.model.TriStateFilter
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -47,6 +48,7 @@ object Migrations {
|
|||||||
libraryPreferences: LibraryPreferences,
|
libraryPreferences: LibraryPreferences,
|
||||||
readerPreferences: ReaderPreferences,
|
readerPreferences: ReaderPreferences,
|
||||||
backupPreferences: BackupPreferences,
|
backupPreferences: BackupPreferences,
|
||||||
|
trackManager: TrackManager,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val lastVersionCode = preferenceStore.getInt("last_version_code", 0)
|
val lastVersionCode = preferenceStore.getInt("last_version_code", 0)
|
||||||
val oldVersion = lastVersionCode.get()
|
val oldVersion = lastVersionCode.get()
|
||||||
@ -114,9 +116,9 @@ object Migrations {
|
|||||||
fun convertBooleanPrefToTriState(key: String): Int {
|
fun convertBooleanPrefToTriState(key: String): Int {
|
||||||
val oldPrefValue = prefs.getBoolean(key, false)
|
val oldPrefValue = prefs.getBoolean(key, false)
|
||||||
return if (oldPrefValue) {
|
return if (oldPrefValue) {
|
||||||
TriState.ENABLED_IS.value
|
1
|
||||||
} else {
|
} else {
|
||||||
TriState.DISABLED.value
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prefs.edit {
|
prefs.edit {
|
||||||
@ -335,6 +337,30 @@ object Migrations {
|
|||||||
remove("automatic_ext_updates")
|
remove("automatic_ext_updates")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 99) {
|
||||||
|
val prefKeys = listOf(
|
||||||
|
"pref_filter_library_downloaded",
|
||||||
|
"pref_filter_library_unread",
|
||||||
|
"pref_filter_library_started",
|
||||||
|
"pref_filter_library_bookmarked",
|
||||||
|
"pref_filter_library_completed",
|
||||||
|
) + trackManager.services.map { "pref_filter_library_tracked_${it.id}" }
|
||||||
|
|
||||||
|
prefKeys.forEach { key ->
|
||||||
|
val pref = preferenceStore.getInt(key, 0)
|
||||||
|
prefs.edit {
|
||||||
|
remove(key)
|
||||||
|
|
||||||
|
val newValue = when (pref.get()) {
|
||||||
|
1 -> TriStateFilter.ENABLED_IS
|
||||||
|
2 -> TriStateFilter.ENABLED_NOT
|
||||||
|
else -> TriStateFilter.DISABLED
|
||||||
|
}
|
||||||
|
|
||||||
|
preferenceStore.getEnum("${key}_v2", TriStateFilter.DISABLED).set(newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@ import eu.kanade.presentation.components.TriStateItem
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.source.model.Filter
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.widget.TriState
|
import tachiyomi.domain.manga.model.TriStateFilter
|
||||||
import eu.kanade.tachiyomi.widget.toTriStateFilter
|
|
||||||
import tachiyomi.presentation.core.components.CheckboxItem
|
import tachiyomi.presentation.core.components.CheckboxItem
|
||||||
import tachiyomi.presentation.core.components.CollapsibleBox
|
import tachiyomi.presentation.core.components.CollapsibleBox
|
||||||
import tachiyomi.presentation.core.components.HeadingItem
|
import tachiyomi.presentation.core.components.HeadingItem
|
||||||
@ -101,7 +100,7 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit) {
|
|||||||
label = filter.name,
|
label = filter.name,
|
||||||
state = filter.state.toTriStateFilter(),
|
state = filter.state.toTriStateFilter(),
|
||||||
) {
|
) {
|
||||||
filter.state = TriState.valueOf(filter.state).next().value
|
filter.state = filter.state.toTriStateFilter().next().toTriStateInt()
|
||||||
onUpdate()
|
onUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,3 +162,21 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Int.toTriStateFilter(): TriStateFilter {
|
||||||
|
return when (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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TriStateFilter.toTriStateInt(): Int {
|
||||||
|
return when (this) {
|
||||||
|
TriStateFilter.DISABLED -> Filter.TriState.STATE_IGNORE
|
||||||
|
TriStateFilter.ENABLED_IS -> Filter.TriState.STATE_INCLUDE
|
||||||
|
TriStateFilter.ENABLED_NOT -> Filter.TriState.STATE_EXCLUDE
|
||||||
|
else -> throw IllegalStateException("Unknown TriStateFilter state: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,7 +32,6 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.util.chapter.getNextUnread
|
import eu.kanade.tachiyomi.util.chapter.getNextUnread
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
import eu.kanade.tachiyomi.widget.TriState
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@ -59,6 +58,7 @@ import tachiyomi.domain.library.model.sort
|
|||||||
import tachiyomi.domain.manga.interactor.GetLibraryManga
|
import tachiyomi.domain.manga.interactor.GetLibraryManga
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.domain.manga.model.MangaUpdate
|
import tachiyomi.domain.manga.model.MangaUpdate
|
||||||
|
import tachiyomi.domain.manga.model.TriStateFilter
|
||||||
import tachiyomi.domain.track.interactor.GetTracksPerManga
|
import tachiyomi.domain.track.interactor.GetTracksPerManga
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -143,15 +143,15 @@ class LibraryScreenModel(
|
|||||||
getLibraryItemPreferencesFlow(),
|
getLibraryItemPreferencesFlow(),
|
||||||
getTrackingFilterFlow(),
|
getTrackingFilterFlow(),
|
||||||
) { prefs, trackFilter ->
|
) { prefs, trackFilter ->
|
||||||
val a = (
|
(
|
||||||
prefs.filterDownloaded or
|
listOf(
|
||||||
prefs.filterUnread or
|
prefs.filterDownloaded,
|
||||||
prefs.filterStarted or
|
prefs.filterUnread,
|
||||||
prefs.filterBookmarked or
|
prefs.filterStarted,
|
||||||
prefs.filterCompleted
|
prefs.filterBookmarked,
|
||||||
) != TriState.DISABLED.value
|
prefs.filterCompleted,
|
||||||
val b = trackFilter.values.any { it != TriState.DISABLED.value }
|
) + trackFilter.values
|
||||||
a || b
|
).any { it != TriStateFilter.DISABLED }
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.onEach {
|
.onEach {
|
||||||
@ -167,7 +167,7 @@ class LibraryScreenModel(
|
|||||||
*/
|
*/
|
||||||
private suspend fun LibraryMap.applyFilters(
|
private suspend fun LibraryMap.applyFilters(
|
||||||
trackMap: Map<Long, List<Long>>,
|
trackMap: Map<Long, List<Long>>,
|
||||||
loggedInTrackServices: Map<Long, Int>,
|
loggedInTrackServices: Map<Long, TriStateFilter>,
|
||||||
): LibraryMap {
|
): LibraryMap {
|
||||||
val prefs = getLibraryItemPreferencesFlow().first()
|
val prefs = getLibraryItemPreferencesFlow().first()
|
||||||
val downloadedOnly = prefs.globalFilterDownloaded
|
val downloadedOnly = prefs.globalFilterDownloaded
|
||||||
@ -179,17 +179,17 @@ class LibraryScreenModel(
|
|||||||
|
|
||||||
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
|
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
|
||||||
|
|
||||||
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_NOT.value) it.key else null }
|
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateFilter.ENABLED_NOT) it.key else null }
|
||||||
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_IS.value) it.key else null }
|
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateFilter.ENABLED_IS) it.key else null }
|
||||||
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
||||||
|
|
||||||
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{
|
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{
|
||||||
if (!downloadedOnly && filterDownloaded == TriState.DISABLED.value) return@downloaded true
|
if (!downloadedOnly && filterDownloaded == TriStateFilter.DISABLED) return@downloaded true
|
||||||
|
|
||||||
val isDownloaded = it.libraryManga.manga.isLocal() ||
|
val isDownloaded = it.libraryManga.manga.isLocal() ||
|
||||||
it.downloadCount > 0 ||
|
it.downloadCount > 0 ||
|
||||||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
|
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
|
||||||
return@downloaded if (downloadedOnly || filterDownloaded == TriState.ENABLED_IS.value) {
|
return@downloaded if (downloadedOnly || filterDownloaded == TriStateFilter.ENABLED_IS) {
|
||||||
isDownloaded
|
isDownloaded
|
||||||
} else {
|
} else {
|
||||||
!isDownloaded
|
!isDownloaded
|
||||||
@ -197,10 +197,10 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{
|
val filterFnUnread: (LibraryItem) -> Boolean = unread@{
|
||||||
if (filterUnread == TriState.DISABLED.value) return@unread true
|
if (filterUnread == TriStateFilter.DISABLED) return@unread true
|
||||||
|
|
||||||
val isUnread = it.libraryManga.unreadCount > 0
|
val isUnread = it.libraryManga.unreadCount > 0
|
||||||
return@unread if (filterUnread == TriState.ENABLED_IS.value) {
|
return@unread if (filterUnread == TriStateFilter.ENABLED_IS) {
|
||||||
isUnread
|
isUnread
|
||||||
} else {
|
} else {
|
||||||
!isUnread
|
!isUnread
|
||||||
@ -208,10 +208,10 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val filterFnStarted: (LibraryItem) -> Boolean = started@{
|
val filterFnStarted: (LibraryItem) -> Boolean = started@{
|
||||||
if (filterStarted == TriState.DISABLED.value) return@started true
|
if (filterStarted == TriStateFilter.DISABLED) return@started true
|
||||||
|
|
||||||
val hasStarted = it.libraryManga.hasStarted
|
val hasStarted = it.libraryManga.hasStarted
|
||||||
return@started if (filterStarted == TriState.ENABLED_IS.value) {
|
return@started if (filterStarted == TriStateFilter.ENABLED_IS) {
|
||||||
hasStarted
|
hasStarted
|
||||||
} else {
|
} else {
|
||||||
!hasStarted
|
!hasStarted
|
||||||
@ -219,10 +219,10 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{
|
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{
|
||||||
if (filterBookmarked == TriState.DISABLED.value) return@bookmarked true
|
if (filterBookmarked == TriStateFilter.DISABLED) return@bookmarked true
|
||||||
|
|
||||||
val hasBookmarks = it.libraryManga.hasBookmarks
|
val hasBookmarks = it.libraryManga.hasBookmarks
|
||||||
return@bookmarked if (filterBookmarked == TriState.ENABLED_IS.value) {
|
return@bookmarked if (filterBookmarked == TriStateFilter.ENABLED_IS) {
|
||||||
hasBookmarks
|
hasBookmarks
|
||||||
} else {
|
} else {
|
||||||
!hasBookmarks
|
!hasBookmarks
|
||||||
@ -230,10 +230,10 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{
|
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{
|
||||||
if (filterCompleted == TriState.DISABLED.value) return@completed true
|
if (filterCompleted == TriStateFilter.DISABLED) return@completed true
|
||||||
|
|
||||||
val isCompleted = it.libraryManga.manga.status.toInt() == SManga.COMPLETED
|
val isCompleted = it.libraryManga.manga.status.toInt() == SManga.COMPLETED
|
||||||
return@completed if (filterCompleted == TriState.ENABLED_IS.value) {
|
return@completed if (filterCompleted == TriStateFilter.ENABLED_IS) {
|
||||||
isCompleted
|
isCompleted
|
||||||
} else {
|
} else {
|
||||||
!isCompleted
|
!isCompleted
|
||||||
@ -349,11 +349,11 @@ class LibraryScreenModel(
|
|||||||
localBadge = it[1] as Boolean,
|
localBadge = it[1] as Boolean,
|
||||||
languageBadge = it[2] as Boolean,
|
languageBadge = it[2] as Boolean,
|
||||||
globalFilterDownloaded = it[3] as Boolean,
|
globalFilterDownloaded = it[3] as Boolean,
|
||||||
filterDownloaded = it[4] as Int,
|
filterDownloaded = it[4] as TriStateFilter,
|
||||||
filterUnread = it[5] as Int,
|
filterUnread = it[5] as TriStateFilter,
|
||||||
filterStarted = it[6] as Int,
|
filterStarted = it[6] as TriStateFilter,
|
||||||
filterBookmarked = it[7] as Int,
|
filterBookmarked = it[7] as TriStateFilter,
|
||||||
filterCompleted = it[8] as Int,
|
filterCompleted = it[8] as TriStateFilter,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -406,7 +406,7 @@ class LibraryScreenModel(
|
|||||||
*
|
*
|
||||||
* @return map of track id with the filter value
|
* @return map of track id with the filter value
|
||||||
*/
|
*/
|
||||||
private fun getTrackingFilterFlow(): Flow<Map<Long, Int>> {
|
private fun getTrackingFilterFlow(): Flow<Map<Long, TriStateFilter>> {
|
||||||
val loggedServices = trackManager.services.filter { it.isLogged }
|
val loggedServices = trackManager.services.filter { it.isLogged }
|
||||||
return if (loggedServices.isNotEmpty()) {
|
return if (loggedServices.isNotEmpty()) {
|
||||||
val prefFlows = loggedServices
|
val prefFlows = loggedServices
|
||||||
@ -706,11 +706,11 @@ class LibraryScreenModel(
|
|||||||
val languageBadge: Boolean,
|
val languageBadge: Boolean,
|
||||||
|
|
||||||
val globalFilterDownloaded: Boolean,
|
val globalFilterDownloaded: Boolean,
|
||||||
val filterDownloaded: Int,
|
val filterDownloaded: TriStateFilter,
|
||||||
val filterUnread: Int,
|
val filterUnread: TriStateFilter,
|
||||||
val filterStarted: Int,
|
val filterStarted: TriStateFilter,
|
||||||
val filterBookmarked: Int,
|
val filterBookmarked: TriStateFilter,
|
||||||
val filterCompleted: Int,
|
val filterCompleted: TriStateFilter,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
|
@ -8,13 +8,13 @@ import eu.kanade.domain.category.interactor.SetSortModeForCategory
|
|||||||
import eu.kanade.domain.library.service.LibraryPreferences
|
import eu.kanade.domain.library.service.LibraryPreferences
|
||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
import eu.kanade.tachiyomi.util.preference.toggle
|
import eu.kanade.tachiyomi.util.preference.toggle
|
||||||
import eu.kanade.tachiyomi.widget.TriState
|
|
||||||
import tachiyomi.core.preference.Preference
|
import tachiyomi.core.preference.Preference
|
||||||
import tachiyomi.core.preference.getAndSet
|
import tachiyomi.core.preference.getAndSet
|
||||||
import tachiyomi.core.util.lang.launchIO
|
import tachiyomi.core.util.lang.launchIO
|
||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||||
import tachiyomi.domain.library.model.LibrarySort
|
import tachiyomi.domain.library.model.LibrarySort
|
||||||
|
import tachiyomi.domain.manga.model.TriStateFilter
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ class LibrarySettingsScreenModel(
|
|||||||
preference(libraryPreferences).toggle()
|
preference(libraryPreferences).toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleFilter(preference: (LibraryPreferences) -> Preference<Int>) {
|
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriStateFilter>) {
|
||||||
preference(libraryPreferences).getAndSet {
|
preference(libraryPreferences).getAndSet {
|
||||||
TriState.valueOf(it).next().value
|
it.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +137,7 @@ class MainActivity : BaseActivity() {
|
|||||||
libraryPreferences = libraryPreferences,
|
libraryPreferences = libraryPreferences,
|
||||||
readerPreferences = Injekt.get(),
|
readerPreferences = Injekt.get(),
|
||||||
backupPreferences = Injekt.get(),
|
backupPreferences = Injekt.get(),
|
||||||
|
trackManager = Injekt.get(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -1,34 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.widget
|
package eu.kanade.tachiyomi.widget
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
import tachiyomi.domain.manga.model.TriStateFilter
|
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 {
|
fun Int.toTriStateFilter(): TriStateFilter {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
TriState.DISABLED.value -> TriStateFilter.DISABLED
|
Filter.TriState.STATE_IGNORE -> TriStateFilter.DISABLED
|
||||||
TriState.ENABLED_IS.value -> TriStateFilter.ENABLED_IS
|
Filter.TriState.STATE_INCLUDE -> TriStateFilter.ENABLED_IS
|
||||||
TriState.ENABLED_NOT.value -> TriStateFilter.ENABLED_NOT
|
Filter.TriState.STATE_EXCLUDE -> TriStateFilter.ENABLED_NOT
|
||||||
else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
|
else -> throw IllegalStateException("Unknown TriState state: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user