Migrate TriState usages to TriStateFilter enum
(cherry picked from commit 7ec87e76db55766e02c28eb732cf18ba4c413b18) # Conflicts: # app/build.gradle.kts # app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt # app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt
This commit is contained in:
parent
8e1c68ee5c
commit
51f655e9d5
@ -6,12 +6,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_NON_COMPLETED
|
||||
import eu.kanade.tachiyomi.data.preference.MANGA_NON_READ
|
||||
import eu.kanade.tachiyomi.widget.TriState
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import tachiyomi.core.preference.getEnum
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.model.LibrarySort
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
|
||||
class LibraryPreferences(
|
||||
private val preferenceStore: PreferenceStore,
|
||||
@ -39,21 +39,21 @@ class LibraryPreferences(
|
||||
|
||||
// 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)
|
||||
|
||||
// SY -->
|
||||
fun filterLewd() = preferenceStore.getInt("pref_filter_library_lewd", TriState.DISABLED.value)
|
||||
fun filterLewd() = preferenceStore.getEnum("pref_filter_library_lewd_v2", TriStateFilter.DISABLED)
|
||||
// SY <--
|
||||
|
||||
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
|
||||
|
||||
|
@ -21,7 +21,6 @@ import eu.kanade.presentation.components.TriStateItem
|
||||
import eu.kanade.presentation.util.collectAsState
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
|
||||
import eu.kanade.tachiyomi.widget.toTriStateFilter
|
||||
import kotlinx.coroutines.flow.map
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
@ -95,7 +94,7 @@ private fun ColumnScope.FilterPage(
|
||||
state = if (downloadedOnly) {
|
||||
TriStateFilter.ENABLED_IS
|
||||
} else {
|
||||
filterDownloaded.toTriStateFilter()
|
||||
filterDownloaded
|
||||
},
|
||||
enabled = !downloadedOnly,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterDownloaded) },
|
||||
@ -103,32 +102,32 @@ private fun ColumnScope.FilterPage(
|
||||
val filterUnread by screenModel.libraryPreferences.filterUnread().collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_unread),
|
||||
state = filterUnread.toTriStateFilter(),
|
||||
state = filterUnread,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterUnread) },
|
||||
)
|
||||
val filterStarted by screenModel.libraryPreferences.filterStarted().collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.label_started),
|
||||
state = filterStarted.toTriStateFilter(),
|
||||
state = filterStarted,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterStarted) },
|
||||
)
|
||||
val filterBookmarked by screenModel.libraryPreferences.filterBookmarked().collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_bookmarked),
|
||||
state = filterBookmarked.toTriStateFilter(),
|
||||
state = filterBookmarked,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterBookmarked) },
|
||||
)
|
||||
val filterCompleted by screenModel.libraryPreferences.filterCompleted().collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.completed),
|
||||
state = filterCompleted.toTriStateFilter(),
|
||||
state = filterCompleted,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompleted) },
|
||||
)
|
||||
// SY -->
|
||||
val filterLewd by screenModel.libraryPreferences.filterLewd().collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.lewd),
|
||||
state = filterLewd.toTriStateFilter(),
|
||||
state = filterLewd,
|
||||
onClick = { screenModel.toggleFilter(LibraryPreferences::filterLewd) },
|
||||
)
|
||||
// SY <--
|
||||
@ -142,7 +141,7 @@ private fun ColumnScope.FilterPage(
|
||||
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_tracked),
|
||||
state = filterTracker.toTriStateFilter(),
|
||||
state = filterTracker,
|
||||
onClick = { screenModel.toggleTracker(service.id.toInt()) },
|
||||
)
|
||||
}
|
||||
@ -152,7 +151,7 @@ private fun ColumnScope.FilterPage(
|
||||
val filterTracker by screenModel.libraryPreferences.filterTracking(service.id.toInt()).collectAsState()
|
||||
TriStateItem(
|
||||
label = stringResource(service.nameRes()),
|
||||
state = filterTracker.toTriStateFilter(),
|
||||
state = filterTracker,
|
||||
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.system.DeviceUtil
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.widget.TriState
|
||||
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.api.get
|
||||
import java.io.File
|
||||
@ -49,6 +50,7 @@ object Migrations {
|
||||
libraryPreferences: LibraryPreferences,
|
||||
readerPreferences: ReaderPreferences,
|
||||
backupPreferences: BackupPreferences,
|
||||
trackManager: TrackManager,
|
||||
): Boolean {
|
||||
val lastVersionCode = preferenceStore.getInt("last_version_code", 0)
|
||||
val oldVersion = lastVersionCode.get()
|
||||
@ -116,9 +118,9 @@ object Migrations {
|
||||
fun convertBooleanPrefToTriState(key: String): Int {
|
||||
val oldPrefValue = prefs.getBoolean(key, false)
|
||||
return if (oldPrefValue) {
|
||||
TriState.ENABLED_IS.value
|
||||
1
|
||||
} else {
|
||||
TriState.DISABLED.value
|
||||
0
|
||||
}
|
||||
}
|
||||
prefs.edit {
|
||||
@ -338,6 +340,30 @@ object Migrations {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,7 @@ import eu.kanade.presentation.components.TriStateItem
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.widget.TriState
|
||||
import eu.kanade.tachiyomi.widget.toTriStateFilter
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
import tachiyomi.domain.source.model.EXHSavedSearch
|
||||
import tachiyomi.presentation.core.components.CheckboxItem
|
||||
import tachiyomi.presentation.core.components.CollapsibleBox
|
||||
@ -156,7 +155,7 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit/* SY --> */, star
|
||||
label = filter.name,
|
||||
state = filter.state.toTriStateFilter(),
|
||||
) {
|
||||
filter.state = TriState.valueOf(filter.state).next().value
|
||||
filter.state = filter.state.toTriStateFilter().next().toTriStateInt()
|
||||
onUpdate()
|
||||
}
|
||||
}
|
||||
@ -224,3 +223,21 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit/* SY --> */, star
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ import eu.kanade.tachiyomi.source.online.all.MergedSource
|
||||
import eu.kanade.tachiyomi.util.chapter.getNextUnread
|
||||
import eu.kanade.tachiyomi.util.preference.asHotFlow
|
||||
import eu.kanade.tachiyomi.util.removeCovers
|
||||
import eu.kanade.tachiyomi.widget.TriState
|
||||
import exh.favorites.FavoritesSyncHelper
|
||||
import exh.md.utils.FollowStatus
|
||||
import exh.md.utils.MdUtil
|
||||
@ -100,6 +99,7 @@ import tachiyomi.domain.manga.interactor.SetCustomMangaInfo
|
||||
import tachiyomi.domain.manga.model.CustomMangaInfo
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.manga.model.MangaUpdate
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
import tachiyomi.domain.track.interactor.GetTracks
|
||||
import tachiyomi.domain.track.interactor.GetTracksPerManga
|
||||
import tachiyomi.domain.track.model.Track
|
||||
@ -223,15 +223,15 @@ class LibraryScreenModel(
|
||||
getLibraryItemPreferencesFlow(),
|
||||
getTrackingFilterFlow(),
|
||||
) { prefs, trackFilter ->
|
||||
val a = (
|
||||
prefs.filterDownloaded or
|
||||
prefs.filterUnread or
|
||||
prefs.filterStarted or
|
||||
prefs.filterBookmarked or
|
||||
prefs.filterCompleted
|
||||
) != TriState.DISABLED.value
|
||||
val b = trackFilter.values.any { it != TriState.DISABLED.value }
|
||||
a || b
|
||||
(
|
||||
listOf(
|
||||
prefs.filterDownloaded,
|
||||
prefs.filterUnread,
|
||||
prefs.filterStarted,
|
||||
prefs.filterBookmarked,
|
||||
prefs.filterCompleted,
|
||||
) + trackFilter.values
|
||||
).any { it != TriStateFilter.DISABLED }
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.onEach {
|
||||
@ -270,7 +270,7 @@ class LibraryScreenModel(
|
||||
*/
|
||||
private suspend fun LibraryMap.applyFilters(
|
||||
trackMap: Map<Long, List<Long>>,
|
||||
loggedInTrackServices: Map<Long, Int>,
|
||||
loggedInTrackServices: Map<Long, TriStateFilter>,
|
||||
): LibraryMap {
|
||||
val prefs = getLibraryItemPreferencesFlow().first()
|
||||
val downloadedOnly = prefs.globalFilterDownloaded
|
||||
@ -282,8 +282,8 @@ class LibraryScreenModel(
|
||||
|
||||
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
|
||||
|
||||
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_NOT.value) it.key else null }
|
||||
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_IS.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 == TriStateFilter.ENABLED_IS) it.key else null }
|
||||
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
||||
|
||||
// SY -->
|
||||
@ -291,12 +291,12 @@ class LibraryScreenModel(
|
||||
// SY <--
|
||||
|
||||
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() ||
|
||||
it.downloadCount > 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
|
||||
} else {
|
||||
!isDownloaded
|
||||
@ -304,10 +304,10 @@ class LibraryScreenModel(
|
||||
}
|
||||
|
||||
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
|
||||
return@unread if (filterUnread == TriState.ENABLED_IS.value) {
|
||||
return@unread if (filterUnread == TriStateFilter.ENABLED_IS) {
|
||||
isUnread
|
||||
} else {
|
||||
!isUnread
|
||||
@ -315,10 +315,10 @@ class LibraryScreenModel(
|
||||
}
|
||||
|
||||
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
|
||||
return@started if (filterStarted == TriState.ENABLED_IS.value) {
|
||||
return@started if (filterStarted == TriStateFilter.ENABLED_IS) {
|
||||
hasStarted
|
||||
} else {
|
||||
!hasStarted
|
||||
@ -326,10 +326,10 @@ class LibraryScreenModel(
|
||||
}
|
||||
|
||||
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
|
||||
return@bookmarked if (filterBookmarked == TriState.ENABLED_IS.value) {
|
||||
return@bookmarked if (filterBookmarked == TriStateFilter.ENABLED_IS) {
|
||||
hasBookmarks
|
||||
} else {
|
||||
!hasBookmarks
|
||||
@ -337,10 +337,10 @@ class LibraryScreenModel(
|
||||
}
|
||||
|
||||
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
|
||||
return@completed if (filterCompleted == TriState.ENABLED_IS.value) {
|
||||
return@completed if (filterCompleted == TriStateFilter.ENABLED_IS) {
|
||||
isCompleted
|
||||
} else {
|
||||
!isCompleted
|
||||
@ -369,10 +369,10 @@ class LibraryScreenModel(
|
||||
|
||||
// SY -->
|
||||
val filterFnLewd: (LibraryItem) -> Boolean = lewd@{
|
||||
if (filterLewd == TriState.DISABLED.value) return@lewd true
|
||||
if (filterLewd == TriStateFilter.DISABLED) return@lewd true
|
||||
val isLewd = it.libraryManga.manga.isLewd()
|
||||
|
||||
return@lewd if (filterLewd == TriState.ENABLED_IS.value) {
|
||||
return@lewd if (filterLewd == TriStateFilter.ENABLED_IS) {
|
||||
isLewd
|
||||
} else {
|
||||
!isLewd
|
||||
@ -501,13 +501,13 @@ class LibraryScreenModel(
|
||||
localBadge = it[1] as Boolean,
|
||||
languageBadge = it[2] as Boolean,
|
||||
globalFilterDownloaded = it[3] as Boolean,
|
||||
filterDownloaded = it[4] as Int,
|
||||
filterUnread = it[5] as Int,
|
||||
filterStarted = it[6] as Int,
|
||||
filterBookmarked = it[7] as Int,
|
||||
filterCompleted = it[8] as Int,
|
||||
filterDownloaded = it[4] as TriStateFilter,
|
||||
filterUnread = it[5] as TriStateFilter,
|
||||
filterStarted = it[6] as TriStateFilter,
|
||||
filterBookmarked = it[7] as TriStateFilter,
|
||||
filterCompleted = it[8] as TriStateFilter,
|
||||
// SY -->
|
||||
filterLewd = it[9] as Int,
|
||||
filterLewd = it[9] as TriStateFilter,
|
||||
// SY <--
|
||||
)
|
||||
},
|
||||
@ -602,7 +602,7 @@ class LibraryScreenModel(
|
||||
*
|
||||
* @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 }
|
||||
return if (loggedServices.isNotEmpty()) {
|
||||
val prefFlows = loggedServices
|
||||
@ -883,7 +883,7 @@ class LibraryScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun filterLibrary(unfiltered: List<LibraryItem>, query: String?, loggedInTrackServices: Map<Long, Int>): List<LibraryItem> {
|
||||
suspend fun filterLibrary(unfiltered: List<LibraryItem>, query: String?, loggedInTrackServices: Map<Long, TriStateFilter>): List<LibraryItem> {
|
||||
return if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
|
||||
// Prepare filter object
|
||||
val parsedQuery = searchEngine.parseQuery(query)
|
||||
@ -947,7 +947,7 @@ class LibraryScreenModel(
|
||||
checkGenre: Boolean = true,
|
||||
searchTags: List<SearchTag>? = null,
|
||||
searchTitles: List<SearchTitle>? = null,
|
||||
loggedInTrackServices: Map<Long, Int>,
|
||||
loggedInTrackServices: Map<Long, TriStateFilter>,
|
||||
): Boolean {
|
||||
val manga = libraryManga.manga
|
||||
val sourceIdString = manga.source.takeUnless { it == LocalSource.ID }?.toString()
|
||||
@ -1268,13 +1268,13 @@ class LibraryScreenModel(
|
||||
val languageBadge: Boolean,
|
||||
|
||||
val globalFilterDownloaded: Boolean,
|
||||
val filterDownloaded: Int,
|
||||
val filterUnread: Int,
|
||||
val filterStarted: Int,
|
||||
val filterBookmarked: Int,
|
||||
val filterCompleted: Int,
|
||||
val filterDownloaded: TriStateFilter,
|
||||
val filterUnread: TriStateFilter,
|
||||
val filterStarted: TriStateFilter,
|
||||
val filterBookmarked: TriStateFilter,
|
||||
val filterCompleted: TriStateFilter,
|
||||
// SY -->
|
||||
val filterLewd: Int,
|
||||
val filterLewd: TriStateFilter,
|
||||
// SY <--
|
||||
)
|
||||
|
||||
|
@ -10,13 +10,13 @@ import eu.kanade.domain.category.interactor.SetSortModeForCategory
|
||||
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 tachiyomi.core.preference.Preference
|
||||
import tachiyomi.core.preference.getAndSet
|
||||
import tachiyomi.core.util.lang.launchIO
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.model.LibrarySort
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
@ -38,9 +38,9 @@ class LibrarySettingsScreenModel(
|
||||
preference(libraryPreferences).toggle()
|
||||
}
|
||||
|
||||
fun toggleFilter(preference: (LibraryPreferences) -> Preference<Int>) {
|
||||
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriStateFilter>) {
|
||||
preference(libraryPreferences).getAndSet {
|
||||
TriState.valueOf(it).next().value
|
||||
it.next()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +167,7 @@ class MainActivity : BaseActivity() {
|
||||
libraryPreferences = libraryPreferences,
|
||||
readerPreferences = Injekt.get(),
|
||||
backupPreferences = Injekt.get(),
|
||||
trackManager = Injekt.get(),
|
||||
)
|
||||
} else {
|
||||
false
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import tachiyomi.core.preference.getEnum
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.data.DatabaseHandler
|
||||
import tachiyomi.data.category.categoryMapper
|
||||
@ -63,6 +64,7 @@ import tachiyomi.domain.chapter.model.ChapterUpdate
|
||||
import tachiyomi.domain.manga.interactor.GetManga
|
||||
import tachiyomi.domain.manga.model.MangaUpdate
|
||||
import tachiyomi.domain.manga.model.MergedMangaReference
|
||||
import tachiyomi.domain.manga.model.TriStateFilter
|
||||
import tachiyomi.domain.source.model.FeedSavedSearch
|
||||
import tachiyomi.domain.source.model.SavedSearch
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -101,6 +103,7 @@ object EXHMigrations {
|
||||
libraryPreferences: LibraryPreferences,
|
||||
readerPreferences: ReaderPreferences,
|
||||
backupPreferences: BackupPreferences,
|
||||
trackManager: TrackManager,
|
||||
): Boolean {
|
||||
val lastVersionCode = preferenceStore.getInt("eh_last_version_code", 0)
|
||||
val oldVersion = lastVersionCode.get()
|
||||
@ -519,6 +522,29 @@ object EXHMigrations {
|
||||
prefs.edit {
|
||||
remove("automatic_ext_updates")
|
||||
}
|
||||
val prefKeys = listOf(
|
||||
"pref_filter_library_downloaded",
|
||||
"pref_filter_library_unread",
|
||||
"pref_filter_library_started",
|
||||
"pref_filter_library_bookmarked",
|
||||
"pref_filter_library_completed",
|
||||
"pref_filter_library_lewd",
|
||||
) + 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (oldVersion under 1) { } (1 is current release version)
|
||||
|
@ -16,6 +16,7 @@ import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.domain.ui.UiPreferences
|
||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.network.NetworkPreferences
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.all.NHentai
|
||||
@ -49,6 +50,7 @@ object DebugFunctions {
|
||||
val libraryPrefs: LibraryPreferences by injectLazy()
|
||||
val readerPrefs: ReaderPreferences by injectLazy()
|
||||
val backupPrefs: BackupPreferences by injectLazy()
|
||||
val trackManager: TrackManager by injectLazy()
|
||||
val sourceManager: SourceManager by injectLazy()
|
||||
val updateManga: UpdateManga by injectLazy()
|
||||
val getFavorites: GetFavorites by injectLazy()
|
||||
@ -61,13 +63,13 @@ object DebugFunctions {
|
||||
fun forceUpgradeMigration() {
|
||||
val lastVersionCode = prefsStore.getInt("eh_last_version_code", 0)
|
||||
lastVersionCode.set(1)
|
||||
EXHMigrations.upgrade(app, prefsStore, basePrefs, uiPrefs, networkPrefs, sourcePrefs, securityPrefs, libraryPrefs, readerPrefs, backupPrefs)
|
||||
EXHMigrations.upgrade(app, prefsStore, basePrefs, uiPrefs, networkPrefs, sourcePrefs, securityPrefs, libraryPrefs, readerPrefs, backupPrefs, trackManager)
|
||||
}
|
||||
|
||||
fun forceSetupJobs() {
|
||||
val lastVersionCode = prefsStore.getInt("eh_last_version_code", 0)
|
||||
lastVersionCode.set(0)
|
||||
EXHMigrations.upgrade(app, prefsStore, basePrefs, uiPrefs, networkPrefs, sourcePrefs, securityPrefs, libraryPrefs, readerPrefs, backupPrefs)
|
||||
EXHMigrations.upgrade(app, prefsStore, basePrefs, uiPrefs, networkPrefs, sourcePrefs, securityPrefs, libraryPrefs, readerPrefs, backupPrefs, trackManager)
|
||||
}
|
||||
|
||||
fun resetAgedFlagInEXHManga() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user