Add filter library by customized update frequency

Supersedes #9619

Co-authored-by: quangkieu <quangkieu@users.noreply.github.com>
This commit is contained in:
arkon 2024-01-07 16:03:12 -05:00
parent e6c6c32d81
commit 028da099dd
4 changed files with 44 additions and 42 deletions

View file

@ -74,6 +74,8 @@ private fun ColumnScope.FilterPage(
) { ) {
val filterDownloaded by screenModel.libraryPreferences.filterDownloaded().collectAsState() val filterDownloaded by screenModel.libraryPreferences.filterDownloaded().collectAsState()
val downloadedOnly by screenModel.preferences.downloadedOnly().collectAsState() val downloadedOnly by screenModel.preferences.downloadedOnly().collectAsState()
val autoUpdateMangaRestrictions by screenModel.libraryPreferences.autoUpdateMangaRestrictions().collectAsState()
TriStateItem( TriStateItem(
label = stringResource(MR.strings.label_downloaded), label = stringResource(MR.strings.label_downloaded),
state = if (downloadedOnly) { state = if (downloadedOnly) {
@ -108,6 +110,14 @@ private fun ColumnScope.FilterPage(
state = filterCompleted, state = filterCompleted,
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompleted) }, onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompleted) },
) )
if (LibraryPreferences.MANGA_OUTSIDE_RELEASE_PERIOD in autoUpdateMangaRestrictions) {
val filterIntervalCustom by screenModel.libraryPreferences.filterIntervalCustom().collectAsState()
TriStateItem(
label = stringResource(MR.strings.action_filter_interval_custom),
state = filterIntervalCustom,
onClick = { screenModel.toggleFilter(LibraryPreferences::filterIntervalCustom) },
)
}
val trackers = remember { screenModel.trackers } val trackers = remember { screenModel.trackers }
when (trackers.size) { when (trackers.size) {

View file

@ -157,6 +157,7 @@ class LibraryScreenModel(
prefs.filterStarted, prefs.filterStarted,
prefs.filterBookmarked, prefs.filterBookmarked,
prefs.filterCompleted, prefs.filterCompleted,
prefs.filterIntervalCustom,
) + trackFilter.values ) + trackFilter.values
).any { it != TriState.DISABLED } ).any { it != TriState.DISABLED }
} }
@ -178,12 +179,13 @@ class LibraryScreenModel(
): LibraryMap { ): LibraryMap {
val prefs = getLibraryItemPreferencesFlow().first() val prefs = getLibraryItemPreferencesFlow().first()
val downloadedOnly = prefs.globalFilterDownloaded val downloadedOnly = prefs.globalFilterDownloaded
val filterDownloaded = val skipOutsideReleasePeriod = prefs.skipOutsideReleasePeriod
if (downloadedOnly) TriState.ENABLED_IS else prefs.filterDownloaded val filterDownloaded = if (downloadedOnly) TriState.ENABLED_IS else prefs.filterDownloaded
val filterUnread = prefs.filterUnread val filterUnread = prefs.filterUnread
val filterStarted = prefs.filterStarted val filterStarted = prefs.filterStarted
val filterBookmarked = prefs.filterBookmarked val filterBookmarked = prefs.filterBookmarked
val filterCompleted = prefs.filterCompleted val filterCompleted = prefs.filterCompleted
val filterIntervalCustom = prefs.filterIntervalCustom
val isNotLoggedInAnyTrack = loggedInTrackers.isEmpty() val isNotLoggedInAnyTrack = loggedInTrackers.isEmpty()
@ -215,6 +217,14 @@ class LibraryScreenModel(
applyFilter(filterCompleted) { it.libraryManga.manga.status.toInt() == SManga.COMPLETED } applyFilter(filterCompleted) { it.libraryManga.manga.status.toInt() == SManga.COMPLETED }
} }
val filterFnIntervalCustom: (LibraryItem) -> Boolean = {
if (skipOutsideReleasePeriod) {
applyFilter(filterIntervalCustom) { it.libraryManga.manga.fetchInterval < 0 }
} else {
true
}
}
val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item -> val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item ->
if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true
@ -225,7 +235,7 @@ class LibraryScreenModel(
val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks } val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks }
val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it in includedTracks } val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it in includedTracks }
return@tracking !isExcluded && isIncluded !isExcluded && isIncluded
} }
val filterFn: (LibraryItem) -> Boolean = { val filterFn: (LibraryItem) -> Boolean = {
@ -234,6 +244,7 @@ class LibraryScreenModel(
filterFnStarted(it) && filterFnStarted(it) &&
filterFnBookmarked(it) && filterFnBookmarked(it) &&
filterFnCompleted(it) && filterFnCompleted(it) &&
filterFnIntervalCustom(it) &&
filterFnTracking(it) filterFnTracking(it)
} }
@ -320,6 +331,7 @@ class LibraryScreenModel(
libraryPreferences.downloadBadge().changes(), libraryPreferences.downloadBadge().changes(),
libraryPreferences.localBadge().changes(), libraryPreferences.localBadge().changes(),
libraryPreferences.languageBadge().changes(), libraryPreferences.languageBadge().changes(),
libraryPreferences.autoUpdateMangaRestrictions().changes(),
preferences.downloadedOnly().changes(), preferences.downloadedOnly().changes(),
libraryPreferences.filterDownloaded().changes(), libraryPreferences.filterDownloaded().changes(),
@ -327,20 +339,22 @@ class LibraryScreenModel(
libraryPreferences.filterStarted().changes(), libraryPreferences.filterStarted().changes(),
libraryPreferences.filterBookmarked().changes(), libraryPreferences.filterBookmarked().changes(),
libraryPreferences.filterCompleted().changes(), libraryPreferences.filterCompleted().changes(),
transform = { libraryPreferences.filterIntervalCustom().changes(),
ItemPreferences( ) {
downloadBadge = it[0] as Boolean, ItemPreferences(
localBadge = it[1] as Boolean, downloadBadge = it[0] as Boolean,
languageBadge = it[2] as Boolean, localBadge = it[1] as Boolean,
globalFilterDownloaded = it[3] as Boolean, languageBadge = it[2] as Boolean,
filterDownloaded = it[4] as TriState, skipOutsideReleasePeriod = LibraryPreferences.MANGA_OUTSIDE_RELEASE_PERIOD in (it[3] as Set<*>),
filterUnread = it[5] as TriState, globalFilterDownloaded = it[4] as Boolean,
filterStarted = it[6] as TriState, filterDownloaded = it[5] as TriState,
filterBookmarked = it[7] as TriState, filterUnread = it[6] as TriState,
filterCompleted = it[8] as TriState, filterStarted = it[7] as TriState,
) filterBookmarked = it[8] as TriState,
}, filterCompleted = it[9] as TriState,
) filterIntervalCustom = it[10] as TriState,
)
}
} }
/** /**
@ -699,6 +713,7 @@ class LibraryScreenModel(
val downloadBadge: Boolean, val downloadBadge: Boolean,
val localBadge: Boolean, val localBadge: Boolean,
val languageBadge: Boolean, val languageBadge: Boolean,
val skipOutsideReleasePeriod: Boolean,
val globalFilterDownloaded: Boolean, val globalFilterDownloaded: Boolean,
val filterDownloaded: TriState, val filterDownloaded: TriState,
@ -706,6 +721,7 @@ class LibraryScreenModel(
val filterStarted: TriState, val filterStarted: TriState,
val filterBookmarked: TriState, val filterBookmarked: TriState,
val filterCompleted: TriState, val filterCompleted: TriState,
val filterIntervalCustom: TriState,
) )
@Immutable @Immutable

View file

@ -85,26 +85,6 @@ class LibraryPreferences(
TriState.DISABLED, TriState.DISABLED,
) )
fun filterIntervalLong() = preferenceStore.getEnum(
"pref_filter_library_interval_long",
TriState.DISABLED,
)
fun filterIntervalLate() = preferenceStore.getEnum(
"pref_filter_library_interval_late",
TriState.DISABLED,
)
fun filterIntervalDropped() = preferenceStore.getEnum(
"pref_filter_library_interval_dropped",
TriState.DISABLED,
)
fun filterIntervalPassed() = preferenceStore.getEnum(
"pref_filter_library_interval_passed",
TriState.DISABLED,
)
fun filterTracking(id: Int) = preferenceStore.getEnum( fun filterTracking(id: Int) = preferenceStore.getEnum(
"pref_filter_library_tracked_${id}_v2", "pref_filter_library_tracked_${id}_v2",
TriState.DISABLED, TriState.DISABLED,

View file

@ -54,11 +54,7 @@
<string name="action_filter_bookmarked">Bookmarked</string> <string name="action_filter_bookmarked">Bookmarked</string>
<string name="action_filter_tracked">Tracked</string> <string name="action_filter_tracked">Tracked</string>
<string name="action_filter_unread">Unread</string> <string name="action_filter_unread">Unread</string>
<string name="action_filter_interval_custom">Customized fetch interval</string> <string name="action_filter_interval_custom">Customized update frequency</string>
<string name="action_filter_interval_long">Fetch monthly (28 days)</string>
<string name="action_filter_interval_late">Late 10+ check</string>
<string name="action_filter_interval_dropped">Dropped? Late 20+ and 2 months</string>
<string name="action_filter_interval_passed">Passed check period</string>
<!-- reserved for #4048 --> <!-- reserved for #4048 -->
<string name="action_filter_empty">Remove filter</string> <string name="action_filter_empty">Remove filter</string>
<string name="action_sort_alpha">Alphabetically</string> <string name="action_sort_alpha">Alphabetically</string>