mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Minor settings sheet cleanup
This commit is contained in:
parent
d400ac2a49
commit
07fdb74fbc
@ -36,17 +36,17 @@ class LibraryPreferences(
|
||||
|
||||
// region Filter
|
||||
|
||||
fun filterDownloaded() = preferenceStore.getInt("pref_filter_library_downloaded", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterDownloaded() = preferenceStore.getInt("pref_filter_library_downloaded", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
fun filterUnread() = preferenceStore.getInt("pref_filter_library_unread", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterUnread() = preferenceStore.getInt("pref_filter_library_unread", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
fun filterStarted() = preferenceStore.getInt("pref_filter_library_started", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterStarted() = preferenceStore.getInt("pref_filter_library_started", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
fun filterBookmarked() = preferenceStore.getInt("pref_filter_library_bookmarked", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterBookmarked() = preferenceStore.getInt("pref_filter_library_bookmarked", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
fun filterCompleted() = preferenceStore.getInt("pref_filter_library_completed", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterCompleted() = preferenceStore.getInt("pref_filter_library_completed", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
fun filterTracking(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value)
|
||||
fun filterTracking(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
|
||||
|
||||
// endregion
|
||||
|
||||
|
@ -3,6 +3,7 @@ package eu.kanade.presentation.manga
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@ -104,6 +105,68 @@ fun ChapterSettingsDialog(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.FilterPage(
|
||||
downloadFilter: TriStateFilter,
|
||||
onDownloadFilterChanged: ((TriStateFilter) -> Unit)?,
|
||||
unreadFilter: TriStateFilter,
|
||||
onUnreadFilterChanged: (TriStateFilter) -> Unit,
|
||||
bookmarkedFilter: TriStateFilter,
|
||||
onBookmarkedFilterChanged: (TriStateFilter) -> Unit,
|
||||
) {
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.label_downloaded),
|
||||
state = downloadFilter,
|
||||
onClick = onDownloadFilterChanged,
|
||||
)
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_unread),
|
||||
state = unreadFilter,
|
||||
onClick = onUnreadFilterChanged,
|
||||
)
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_bookmarked),
|
||||
state = bookmarkedFilter,
|
||||
onClick = onBookmarkedFilterChanged,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.SortPage(
|
||||
sortingMode: Long,
|
||||
sortDescending: Boolean,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
listOf(
|
||||
R.string.sort_by_source to Manga.CHAPTER_SORTING_SOURCE,
|
||||
R.string.sort_by_number to Manga.CHAPTER_SORTING_NUMBER,
|
||||
R.string.sort_by_upload_date to Manga.CHAPTER_SORTING_UPLOAD_DATE,
|
||||
).map { (titleRes, mode) ->
|
||||
SortItem(
|
||||
label = stringResource(titleRes),
|
||||
sortDescending = sortDescending.takeIf { sortingMode == mode },
|
||||
onClick = { onItemSelected(mode) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.DisplayPage(
|
||||
displayMode: Long,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
listOf(
|
||||
R.string.show_title to Manga.CHAPTER_DISPLAY_NAME,
|
||||
R.string.show_chapter_number to Manga.CHAPTER_DISPLAY_NUMBER,
|
||||
).map { (titleRes, mode) ->
|
||||
RadioItem(
|
||||
label = stringResource(titleRes),
|
||||
selected = displayMode == mode,
|
||||
onClick = { onItemSelected(mode) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SetAsDefaultDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
@ -152,69 +215,3 @@ private fun SetAsDefaultDialog(
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterPage(
|
||||
downloadFilter: TriStateFilter,
|
||||
onDownloadFilterChanged: ((TriStateFilter) -> Unit)?,
|
||||
unreadFilter: TriStateFilter,
|
||||
onUnreadFilterChanged: (TriStateFilter) -> Unit,
|
||||
bookmarkedFilter: TriStateFilter,
|
||||
onBookmarkedFilterChanged: (TriStateFilter) -> Unit,
|
||||
) {
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.label_downloaded),
|
||||
state = downloadFilter,
|
||||
onClick = onDownloadFilterChanged,
|
||||
)
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_unread),
|
||||
state = unreadFilter,
|
||||
onClick = onUnreadFilterChanged,
|
||||
)
|
||||
TriStateItem(
|
||||
label = stringResource(R.string.action_filter_bookmarked),
|
||||
state = bookmarkedFilter,
|
||||
onClick = onBookmarkedFilterChanged,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SortPage(
|
||||
sortingMode: Long,
|
||||
sortDescending: Boolean,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
SortItem(
|
||||
label = stringResource(R.string.sort_by_source),
|
||||
sortDescending = sortDescending.takeIf { sortingMode == Manga.CHAPTER_SORTING_SOURCE },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_SOURCE) },
|
||||
)
|
||||
SortItem(
|
||||
label = stringResource(R.string.sort_by_number),
|
||||
sortDescending = sortDescending.takeIf { sortingMode == Manga.CHAPTER_SORTING_NUMBER },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_NUMBER) },
|
||||
)
|
||||
SortItem(
|
||||
label = stringResource(R.string.sort_by_upload_date),
|
||||
sortDescending = sortDescending.takeIf { sortingMode == Manga.CHAPTER_SORTING_UPLOAD_DATE },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_UPLOAD_DATE) },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayPage(
|
||||
displayMode: Long,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
RadioItem(
|
||||
label = stringResource(R.string.show_title),
|
||||
selected = displayMode == Manga.CHAPTER_DISPLAY_NAME,
|
||||
onClick = { onItemSelected(Manga.CHAPTER_DISPLAY_NAME) },
|
||||
)
|
||||
RadioItem(
|
||||
label = stringResource(R.string.show_chapter_number),
|
||||
selected = displayMode == Manga.CHAPTER_DISPLAY_NUMBER,
|
||||
onClick = { onItemSelected(Manga.CHAPTER_DISPLAY_NUMBER) },
|
||||
)
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ object Migrations {
|
||||
fun convertBooleanPrefToTriState(key: String): Int {
|
||||
val oldPrefValue = prefs.getBoolean(key, false)
|
||||
return if (oldPrefValue) {
|
||||
ExtendedNavigationView.Item.TriStateGroup.State.INCLUDE.value
|
||||
ExtendedNavigationView.Item.TriStateGroup.State.ENABLED_IS.value
|
||||
} else {
|
||||
ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value
|
||||
ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value
|
||||
}
|
||||
}
|
||||
prefs.edit {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -115,16 +115,16 @@ open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
class TriStateGroup(resId: Int, group: Group) : MultiStateGroup(resId, group) {
|
||||
|
||||
enum class State(val value: Int) {
|
||||
IGNORE(0),
|
||||
INCLUDE(1),
|
||||
EXCLUDE(2),
|
||||
DISABLED(0),
|
||||
ENABLED_IS(1),
|
||||
ENABLED_NOT(2),
|
||||
}
|
||||
|
||||
override fun getStateDrawable(context: Context): Drawable? {
|
||||
return when (state) {
|
||||
State.IGNORE.value -> tintVector(context, R.drawable.ic_check_box_outline_blank_24dp, R.attr.colorControlNormal)
|
||||
State.INCLUDE.value -> tintVector(context, R.drawable.ic_check_box_24dp)
|
||||
State.EXCLUDE.value -> tintVector(context, R.drawable.ic_check_box_x_24dp)
|
||||
State.DISABLED.value -> tintVector(context, R.drawable.ic_check_box_outline_blank_24dp, R.attr.colorControlNormal)
|
||||
State.ENABLED_IS.value -> tintVector(context, R.drawable.ic_check_box_24dp)
|
||||
State.ENABLED_NOT.value -> tintVector(context, R.drawable.ic_check_box_x_24dp)
|
||||
else -> throw Exception("Unknown state")
|
||||
}
|
||||
}
|
||||
|
@ -55,5 +55,5 @@ sealed class LibraryDisplayMode(
|
||||
}
|
||||
}
|
||||
|
||||
val Category.display: LibraryDisplayMode
|
||||
get() = LibraryDisplayMode.valueOf(flags)
|
||||
val Category?.display: LibraryDisplayMode
|
||||
get() = LibraryDisplayMode.valueOf(this?.flags)
|
||||
|
@ -69,7 +69,8 @@ data class LibrarySort(
|
||||
val directions = setOf(Direction.Ascending, Direction.Descending)
|
||||
val default = LibrarySort(Type.Alphabetical, Direction.Ascending)
|
||||
|
||||
fun valueOf(flag: Long): LibrarySort {
|
||||
fun valueOf(flag: Long?): LibrarySort {
|
||||
if (flag == null) return default
|
||||
return LibrarySort(
|
||||
Type.valueOf(flag),
|
||||
Direction.valueOf(flag),
|
||||
@ -115,5 +116,5 @@ data class LibrarySort(
|
||||
}
|
||||
}
|
||||
|
||||
val Category.sort: LibrarySort
|
||||
get() = LibrarySort.valueOf(flags)
|
||||
val Category?.sort: LibrarySort
|
||||
get() = LibrarySort.valueOf(this?.flags)
|
||||
|
Loading…
Reference in New Issue
Block a user