Minor settings sheet cleanup

This commit is contained in:
arkon
2023-02-18 19:00:19 -05:00
parent d400ac2a49
commit 07fdb74fbc
8 changed files with 104 additions and 106 deletions

View File

@@ -149,8 +149,8 @@ class LibraryScreenModel(
prefs.filterStarted or
prefs.filterBookmarked or
prefs.filterCompleted
) != TriStateGroup.State.IGNORE.value
val b = trackFilter.values.any { it != TriStateGroup.State.IGNORE.value }
) != TriStateGroup.State.DISABLED.value
val b = trackFilter.values.any { it != TriStateGroup.State.DISABLED.value }
a || b
}
.distinctUntilChanged()
@@ -179,17 +179,17 @@ class LibraryScreenModel(
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.EXCLUDE.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.INCLUDE.value) it.key else null }
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_NOT.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_IS.value) it.key else null }
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{
if (!downloadedOnly && filterDownloaded == TriStateGroup.State.IGNORE.value) return@downloaded true
if (!downloadedOnly && filterDownloaded == TriStateGroup.State.DISABLED.value) return@downloaded true
val isDownloaded = it.libraryManga.manga.isLocal() ||
it.downloadCount > 0 ||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.INCLUDE.value) {
return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.ENABLED_IS.value) {
isDownloaded
} else {
!isDownloaded
@@ -197,10 +197,10 @@ class LibraryScreenModel(
}
val filterFnUnread: (LibraryItem) -> Boolean = unread@{
if (filterUnread == TriStateGroup.State.IGNORE.value) return@unread true
if (filterUnread == TriStateGroup.State.DISABLED.value) return@unread true
val isUnread = it.libraryManga.unreadCount > 0
return@unread if (filterUnread == TriStateGroup.State.INCLUDE.value) {
return@unread if (filterUnread == TriStateGroup.State.ENABLED_IS.value) {
isUnread
} else {
!isUnread
@@ -208,10 +208,10 @@ class LibraryScreenModel(
}
val filterFnStarted: (LibraryItem) -> Boolean = started@{
if (filterStarted == TriStateGroup.State.IGNORE.value) return@started true
if (filterStarted == TriStateGroup.State.DISABLED.value) return@started true
val hasStarted = it.libraryManga.hasStarted
return@started if (filterStarted == TriStateGroup.State.INCLUDE.value) {
return@started if (filterStarted == TriStateGroup.State.ENABLED_IS.value) {
hasStarted
} else {
!hasStarted
@@ -219,10 +219,10 @@ class LibraryScreenModel(
}
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{
if (filterBookmarked == TriStateGroup.State.IGNORE.value) return@bookmarked true
if (filterBookmarked == TriStateGroup.State.DISABLED.value) return@bookmarked true
val hasBookmarks = it.libraryManga.hasBookmarks
return@bookmarked if (filterBookmarked == TriStateGroup.State.INCLUDE.value) {
return@bookmarked if (filterBookmarked == TriStateGroup.State.ENABLED_IS.value) {
hasBookmarks
} else {
!hasBookmarks
@@ -230,10 +230,10 @@ class LibraryScreenModel(
}
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{
if (filterCompleted == TriStateGroup.State.IGNORE.value) return@completed true
if (filterCompleted == TriStateGroup.State.DISABLED.value) return@completed true
val isCompleted = it.libraryManga.manga.status.toInt() == SManga.COMPLETED
return@completed if (filterCompleted == TriStateGroup.State.INCLUDE.value) {
return@completed if (filterCompleted == TriStateGroup.State.ENABLED_IS.value) {
isCompleted
} else {
!isCompleted

View File

@@ -96,7 +96,7 @@ class LibrarySettingsSheet(
* Returns true if there's at least one filter from [FilterGroup] active.
*/
fun hasActiveFilters(): Boolean {
return filterGroup.items.filterIsInstance<Item.TriStateGroup>().any { it.state != State.IGNORE.value }
return filterGroup.items.filterIsInstance<Item.TriStateGroup>().any { it.state != State.DISABLED.value }
}
inner class FilterGroup : Group {
@@ -132,7 +132,7 @@ class LibrarySettingsSheet(
override fun initModels() {
if (preferences.downloadedOnly().get()) {
downloaded.state = State.INCLUDE.value
downloaded.state = State.ENABLED_IS.value
downloaded.enabled = false
} else {
downloaded.state = libraryPreferences.filterDownloaded().get()
@@ -151,9 +151,9 @@ class LibrarySettingsSheet(
override fun onItemClicked(item: Item) {
item as Item.TriStateGroup
val newState = when (item.state) {
State.IGNORE.value -> State.INCLUDE.value
State.INCLUDE.value -> State.EXCLUDE.value
State.EXCLUDE.value -> State.IGNORE.value
State.DISABLED.value -> State.ENABLED_IS.value
State.ENABLED_IS.value -> State.ENABLED_NOT.value
State.ENABLED_NOT.value -> State.DISABLED.value
else -> throw Exception("Unknown State")
}
item.state = newState
@@ -212,7 +212,7 @@ class LibrarySettingsSheet(
override val footer = null
override fun initModels() {
val sort = currentCategory?.sort ?: LibrarySort.default
val sort = currentCategory.sort
val order = if (sort.isAscending) Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC
alphabetically.state =
@@ -306,7 +306,7 @@ class LibrarySettingsSheet(
// Gets user preference of currently selected display mode at current category
private fun getDisplayModePreference(): LibraryDisplayMode {
return currentCategory?.display ?: LibraryDisplayMode.default
return currentCategory.display
}
inner class DisplayGroup : Group {