Implement exclude categories from deletion
This commit is contained in:
parent
eea1f696ca
commit
405b0580fc
@ -338,4 +338,6 @@ object PreferenceKeys {
|
||||
const val sortTagsForLibrary = "sort_tags_for_library"
|
||||
|
||||
const val createLegacyBackup = "create_legacy_backup"
|
||||
|
||||
const val dontDeleteFromCategories = "dont_delete_from_categories"
|
||||
}
|
||||
|
@ -458,4 +458,6 @@ class PreferencesHelper(val context: Context) {
|
||||
fun sortTagsForLibrary() = flowPrefs.getStringSet(Keys.sortTagsForLibrary, mutableSetOf())
|
||||
|
||||
fun createLegacyBackup() = flowPrefs.getBoolean(Keys.createLegacyBackup, false)
|
||||
|
||||
fun dontDeleteFromCategories() = flowPrefs.getStringSet(Keys.dontDeleteFromCategories, emptySet())
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
import exh.source.EnhancedHttpSource.Companion.getMainSource
|
||||
import exh.util.asObservable
|
||||
import exh.util.await
|
||||
import exh.util.shouldDeleteChapters
|
||||
import exh.util.trimOrNull
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -807,7 +808,7 @@ class MangaPresenter(
|
||||
launchIO {
|
||||
db.updateChaptersProgress(chapters).executeAsBlocking()
|
||||
|
||||
if (preferences.removeAfterMarkedAsRead()) {
|
||||
if (preferences.removeAfterMarkedAsRead() /* SY --> */ && manga.shouldDeleteChapters(db, preferences) /* SY <-- */) {
|
||||
deleteChapters(chapters)
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import exh.EXH_SOURCE_ID
|
||||
import exh.MERGED_SOURCE_ID
|
||||
import exh.md.utils.FollowStatus
|
||||
import exh.util.defaultReaderType
|
||||
import exh.util.shouldDeleteChapters
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.singleOrNull
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@ -453,7 +454,10 @@ class ReaderPresenter(
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
||||
// Check if deleting option is enabled and chapter exists
|
||||
if (removeAfterReadSlots != -1 && chapterToDelete != null) {
|
||||
// SY -->
|
||||
val manga = manga
|
||||
// SY <--
|
||||
if (removeAfterReadSlots != -1 && chapterToDelete != null && (manga == null || manga.shouldDeleteChapters(db, preferences)) /* SY <-- */) {
|
||||
enqueueDeleteReadChapters(chapterToDelete)
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class ReaderChapterSheet(private val activity: ReaderActivity) : BottomSheetDial
|
||||
private var sheetBehavior: BottomSheetBehavior<*>? = null
|
||||
|
||||
private val binding = ReaderChaptersSheetBinding.inflate(activity.layoutInflater, null, false)
|
||||
private var initialized = false
|
||||
|
||||
var presenter: ReaderPresenter
|
||||
var adapter: FastAdapter<ReaderChapterItem>? = null
|
||||
@ -79,7 +80,7 @@ class ReaderChapterSheet(private val activity: ReaderActivity) : BottomSheetDial
|
||||
)
|
||||
|
||||
binding.chapterRecycler.layoutManager = LinearLayoutManager(context)
|
||||
refreshList()
|
||||
// refreshList()
|
||||
binding.webviewButton.clicks()
|
||||
.onEach { activity.openMangaInBrowser() }
|
||||
.launchIn(activity.scope)
|
||||
@ -106,6 +107,10 @@ class ReaderChapterSheet(private val activity: ReaderActivity) : BottomSheetDial
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
if (!initialized) {
|
||||
refreshList()
|
||||
initialized = true
|
||||
}
|
||||
binding.pageText.text = activity.binding.pageText.text
|
||||
binding.pageSeekbar.max = activity.binding.pageSeekbar.max
|
||||
binding.pageSeekbar.progress = activity.binding.pageSeekbar.progress
|
||||
|
@ -112,6 +112,34 @@ class SettingsDownloadController : SettingsController() {
|
||||
titleRes = R.string.pref_remove_bookmarked_chapters
|
||||
defaultValue = false
|
||||
}
|
||||
// SY -->
|
||||
multiSelectListPreference {
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
val categories = listOf(Category.createDefault()) + dbCategories
|
||||
|
||||
key = Keys.dontDeleteFromCategories
|
||||
titleRes = R.string.pref_dont_delete_from_categories
|
||||
entries = categories.map { it.name }.toTypedArray()
|
||||
entryValues = categories.map { it.id.toString() }.toTypedArray()
|
||||
|
||||
preferences.dontDeleteFromCategories().asFlow()
|
||||
.onEach { mutableSet ->
|
||||
val selectedCategories = mutableSet
|
||||
.mapNotNull { id -> categories.find { it.id == id.toInt() } }
|
||||
.sortedBy { it.order }
|
||||
|
||||
summary = context.getString(
|
||||
R.string.pref_dont_delete_from_categories_summary,
|
||||
if (selectedCategories.isEmpty()) {
|
||||
context.getString(R.string.all)
|
||||
} else {
|
||||
selectedCategories.joinToString { it.name }
|
||||
}
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
|
20
app/src/main/java/exh/util/MangaExtensions.kt
Normal file
20
app/src/main/java/exh/util/MangaExtensions.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package exh.util
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
||||
fun Manga.shouldDeleteChapters(db: DatabaseHelper, prefs: PreferencesHelper): Boolean {
|
||||
if (!favorite) return true
|
||||
|
||||
val categoriesToNotDeleteFrom = prefs.dontDeleteFromCategories().get().map(String::toInt)
|
||||
if (categoriesToNotDeleteFrom.isEmpty()) return true
|
||||
|
||||
// Get all categories, else default category (0)
|
||||
val categoriesForManga =
|
||||
db.getCategoriesForManga(this).executeAsBlocking()
|
||||
.mapNotNull { it.id }
|
||||
.takeUnless { it.isEmpty() } ?: listOf(0)
|
||||
|
||||
return categoriesForManga.any { it !in categoriesToNotDeleteFrom }
|
||||
}
|
@ -189,6 +189,8 @@
|
||||
<!-- Download settings -->
|
||||
<string name="save_chapter_as_cbz">Save Chapters as CBZ</string>
|
||||
<string name="save_chapter_as_cbz_level">CBZ Compression level</string>
|
||||
<string name="pref_dont_delete_from_categories">Categories to exclude from deletion</string>
|
||||
<string name="pref_dont_delete_from_categories_summary">If a manga is only in these categories, chapters will not be deleted when marking as read and when finishing a chapter.\nCategories:\n%1$s</string>
|
||||
|
||||
<!-- Security settings -->
|
||||
<string name="biometric_lock_times">Biometric lock times</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user