mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Category filter for remove after read (#1596)
* Add remove read category to preferences * Only delete read chapters if they are in category * exclude only
This commit is contained in:
parent
95d86b2fa1
commit
b5bab8f43f
4 changed files with 26 additions and 6 deletions
|
@ -262,7 +262,7 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun backupInterval() = flowPrefs.getInt(Keys.backupInterval, 0)
|
||||
|
||||
fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1)
|
||||
fun removeAfterReadSlots() = flowPrefs.getInt(Keys.removeAfterReadSlots, -1)
|
||||
|
||||
fun removeAfterMarkedAsRead() = prefs.getBoolean(Keys.removeAfterMarkedAsRead, false)
|
||||
|
||||
|
@ -409,6 +409,8 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun removeBookmarkedChapters() = flowPrefs.getBoolean("pref_remove_bookmarked", false)
|
||||
|
||||
fun removeExcludeCategories() = flowPrefs.getStringSet("remove_exclude_categories", emptySet())
|
||||
|
||||
fun showAllCategories() = flowPrefs.getBoolean("show_all_categories", true)
|
||||
|
||||
fun showAllCategoriesWhenSearchingSingleCategory() = flowPrefs.getBoolean("show_all_categories_when_searching_single_category", false)
|
||||
|
|
|
@ -561,7 +561,7 @@ class ReaderViewModel(
|
|||
private fun deleteChapterIfNeeded(currentChapter: ReaderChapter) {
|
||||
// Determine which chapter should be deleted and enqueue
|
||||
val currentChapterPosition = chapterList.indexOf(currentChapter)
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots().get()
|
||||
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
||||
|
||||
if (removeAfterReadSlots != 0 && chapterToDownload != null) {
|
||||
|
@ -571,6 +571,15 @@ class ReaderViewModel(
|
|||
}
|
||||
// Check if deleting option is enabled and chapter exists
|
||||
if (removeAfterReadSlots != -1 && chapterToDelete != null) {
|
||||
val excludedCategories = preferences.removeExcludeCategories().get().map(String::toInt)
|
||||
if (excludedCategories.any()) {
|
||||
val categories = db.getCategoriesForManga(manga!!).executeAsBlocking()
|
||||
.mapNotNull { it.id }
|
||||
.ifEmpty { listOf(0) }
|
||||
|
||||
if (categories.any { it in excludedCategories }) return
|
||||
}
|
||||
|
||||
enqueueDeleteReadChapters(chapterToDelete)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,9 @@ class SettingsDownloadController : SettingsController() {
|
|||
summaryRes = R.string.split_tall_images_summary
|
||||
}
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
val categories = listOf(Category.createDefault(context)) + dbCategories
|
||||
|
||||
preferenceCategory {
|
||||
titleRes = R.string.remove_after_read
|
||||
|
||||
|
@ -64,7 +67,7 @@ class SettingsDownloadController : SettingsController() {
|
|||
defaultValue = false
|
||||
}
|
||||
intListPreference(activity) {
|
||||
key = Keys.removeAfterReadSlots
|
||||
bindTo(preferences.removeAfterReadSlots())
|
||||
titleRes = R.string.remove_after_read
|
||||
entriesRes = arrayOf(
|
||||
R.string.never,
|
||||
|
@ -77,15 +80,20 @@ class SettingsDownloadController : SettingsController() {
|
|||
entryRange = -1..4
|
||||
defaultValue = -1
|
||||
}
|
||||
multiSelectListPreferenceMat(activity) {
|
||||
bindTo(preferences.removeExcludeCategories())
|
||||
titleRes = R.string.pref_remove_exclude_categories
|
||||
entries = categories.map { it.name }
|
||||
entryValues = categories.map { it.id.toString() }
|
||||
noSelectionRes = R.string.none
|
||||
preferences.removeAfterReadSlots().asImmediateFlowIn(viewScope) { isVisible = it != -1 }
|
||||
}
|
||||
switchPreference {
|
||||
bindTo(preferences.removeBookmarkedChapters())
|
||||
titleRes = R.string.allow_deleting_bookmarked_chapters
|
||||
}
|
||||
}
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
val categories = listOf(Category.createDefault(context)) + dbCategories
|
||||
|
||||
preferenceCategory {
|
||||
titleRes = R.string.download_new_chapters
|
||||
|
||||
|
|
|
@ -969,6 +969,7 @@
|
|||
<string name="remove_when_marked_as_read">Remove when marked as read</string>
|
||||
<string name="allow_deleting_bookmarked_chapters">Allow deleting bookmarked chapters</string>
|
||||
<string name="remove_after_read">Remove after read</string>
|
||||
<string name="pref_remove_exclude_categories">Excluded categories</string>
|
||||
<string name="custom_location">Custom location</string>
|
||||
<string name="last_read_chapter">Last read chapter</string>
|
||||
<string name="second_to_last">Second to last chapter</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue