Skip to content

Commit

Permalink
Category filter for remove after read (#1596)
Browse files Browse the repository at this point in the history
* Add remove read category to preferences

* Only delete read chapters if they are in category

* exclude only
  • Loading branch information
Chik3r committed Sep 23, 2023
1 parent 95d86b2 commit b5bab8f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit b5bab8f

Please sign in to comment.