mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Allow exclusion on Delete After Read per category (#5857)
* Added the exclude category from delete after being read * Stopped it from adding a wildcard to the import * Placed the remove after read to the download manager
This commit is contained in:
parent
7b3c18bb97
commit
a051079c6a
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import com.jakewharton.rxrelay.BehaviorRelay
|
import com.jakewharton.rxrelay.BehaviorRelay
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
@ -15,6 +16,8 @@ import eu.kanade.tachiyomi.source.model.Page
|
|||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +27,10 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
*
|
*
|
||||||
* @param context the application context.
|
* @param context the application context.
|
||||||
*/
|
*/
|
||||||
class DownloadManager(private val context: Context) {
|
class DownloadManager(
|
||||||
|
private val context: Context,
|
||||||
|
private val db: DatabaseHelper = Injekt.get()
|
||||||
|
) {
|
||||||
|
|
||||||
private val sourceManager: SourceManager by injectLazy()
|
private val sourceManager: SourceManager by injectLazy()
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
@ -241,7 +247,7 @@ class DownloadManager(private val context: Context) {
|
|||||||
val filteredChapters = if (isCancelling) {
|
val filteredChapters = if (isCancelling) {
|
||||||
chapters
|
chapters
|
||||||
} else {
|
} else {
|
||||||
getChaptersToDelete(chapters)
|
getChaptersToDelete(chapters, manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
launchIO {
|
launchIO {
|
||||||
@ -296,7 +302,7 @@ class DownloadManager(private val context: Context) {
|
|||||||
* @param manga the manga of the chapters.
|
* @param manga the manga of the chapters.
|
||||||
*/
|
*/
|
||||||
fun enqueueDeleteChapters(chapters: List<Chapter>, manga: Manga) {
|
fun enqueueDeleteChapters(chapters: List<Chapter>, manga: Manga) {
|
||||||
pendingDeleter.addChapters(getChaptersToDelete(chapters), manga)
|
pendingDeleter.addChapters(getChaptersToDelete(chapters, manga), manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -336,8 +342,19 @@ class DownloadManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getChaptersToDelete(chapters: List<Chapter>): List<Chapter> {
|
private fun getChaptersToDelete(chapters: List<Chapter>, manga: Manga): List<Chapter> {
|
||||||
return if (!preferences.removeBookmarkedChapters()) {
|
// Retrieve the categories that are set to exclude from being deleted on read
|
||||||
|
val categoriesToExclude = preferences.removeExcludeCategories().get().map(String::toInt)
|
||||||
|
val categoriesForManga =
|
||||||
|
manga.let { it ->
|
||||||
|
db.getCategoriesForManga(it).executeAsBlocking()
|
||||||
|
.mapNotNull { it.id }
|
||||||
|
.takeUnless { it.isEmpty() }
|
||||||
|
} ?: listOf(0)
|
||||||
|
|
||||||
|
return if (categoriesForManga.intersect(categoriesToExclude).isNotEmpty()) {
|
||||||
|
chapters.filterNot { it.read }
|
||||||
|
} else if (!preferences.removeBookmarkedChapters()) {
|
||||||
chapters.filterNot { it.bookmark }
|
chapters.filterNot { it.bookmark }
|
||||||
} else {
|
} else {
|
||||||
chapters
|
chapters
|
||||||
|
@ -179,6 +179,7 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val downloadNewCategories = "download_new_categories"
|
const val downloadNewCategories = "download_new_categories"
|
||||||
const val downloadNewCategoriesExclude = "download_new_categories_exclude"
|
const val downloadNewCategoriesExclude = "download_new_categories_exclude"
|
||||||
|
const val removeExcludeCategories = "remove_exclude_categories"
|
||||||
|
|
||||||
const val libraryDisplayMode = "pref_display_mode_library"
|
const val libraryDisplayMode = "pref_display_mode_library"
|
||||||
|
|
||||||
|
@ -232,6 +232,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun removeBookmarkedChapters() = prefs.getBoolean(Keys.removeBookmarkedChapters, false)
|
fun removeBookmarkedChapters() = prefs.getBoolean(Keys.removeBookmarkedChapters, false)
|
||||||
|
|
||||||
|
fun removeExcludeCategories() = flowPrefs.getStringSet(Keys.removeExcludeCategories, emptySet())
|
||||||
|
|
||||||
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24)
|
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24)
|
||||||
|
|
||||||
fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(UNMETERED_NETWORK))
|
fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(UNMETERED_NETWORK))
|
||||||
|
@ -409,6 +409,7 @@ class ReaderPresenter(
|
|||||||
val currentChapterPosition = chapterList.indexOf(currentChapter)
|
val currentChapterPosition = chapterList.indexOf(currentChapter)
|
||||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||||
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
||||||
|
|
||||||
// Check if deleting option is enabled and chapter exists
|
// Check if deleting option is enabled and chapter exists
|
||||||
if (removeAfterReadSlots != -1 && chapterToDelete != null) {
|
if (removeAfterReadSlots != -1 && chapterToDelete != null) {
|
||||||
enqueueDeleteReadChapters(chapterToDelete)
|
enqueueDeleteReadChapters(chapterToDelete)
|
||||||
|
@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
|||||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||||
import eu.kanade.tachiyomi.util.preference.entriesRes
|
import eu.kanade.tachiyomi.util.preference.entriesRes
|
||||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||||
|
import eu.kanade.tachiyomi.util.preference.multiSelectListPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.onClick
|
import eu.kanade.tachiyomi.util.preference.onClick
|
||||||
import eu.kanade.tachiyomi.util.preference.preference
|
import eu.kanade.tachiyomi.util.preference.preference
|
||||||
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||||
@ -44,6 +45,9 @@ class SettingsDownloadController : SettingsController() {
|
|||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||||
titleRes = R.string.pref_category_downloads
|
titleRes = R.string.pref_category_downloads
|
||||||
|
|
||||||
|
val dbCategories = db.getCategories().executeAsBlocking()
|
||||||
|
val categories = listOf(Category.createDefault(context)) + dbCategories
|
||||||
|
|
||||||
preference {
|
preference {
|
||||||
key = Keys.downloadsDirectory
|
key = Keys.downloadsDirectory
|
||||||
titleRes = R.string.pref_download_directory
|
titleRes = R.string.pref_download_directory
|
||||||
@ -93,10 +97,26 @@ class SettingsDownloadController : SettingsController() {
|
|||||||
titleRes = R.string.pref_remove_bookmarked_chapters
|
titleRes = R.string.pref_remove_bookmarked_chapters
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
}
|
multiSelectListPreference {
|
||||||
|
key = Keys.removeExcludeCategories
|
||||||
|
titleRes = R.string.pref_remove_exclude_categories
|
||||||
|
entries = categories.map { it.name }.toTypedArray()
|
||||||
|
entryValues = categories.map { it.id.toString() }.toTypedArray()
|
||||||
|
|
||||||
val dbCategories = db.getCategories().executeAsBlocking()
|
preferences.removeExcludeCategories().asFlow()
|
||||||
val categories = listOf(Category.createDefault(context)) + dbCategories
|
.onEach { mutable ->
|
||||||
|
val selected = mutable
|
||||||
|
.mapNotNull { id -> categories.find { it.id == id.toInt() } }
|
||||||
|
.sortedBy { it.order }
|
||||||
|
|
||||||
|
summary = if (selected.isEmpty()) {
|
||||||
|
resources?.getString(R.string.none)
|
||||||
|
} else {
|
||||||
|
selected.joinToString { it.name }
|
||||||
|
}
|
||||||
|
}.launchIn(viewScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
preferenceCategory {
|
preferenceCategory {
|
||||||
titleRes = R.string.pref_category_auto_download
|
titleRes = R.string.pref_category_auto_download
|
||||||
|
@ -382,6 +382,7 @@
|
|||||||
<string name="pref_remove_after_marked_as_read">After marked as read</string>
|
<string name="pref_remove_after_marked_as_read">After marked as read</string>
|
||||||
<string name="pref_remove_after_read">Automatically after reading</string>
|
<string name="pref_remove_after_read">Automatically after reading</string>
|
||||||
<string name="pref_remove_bookmarked_chapters">Allow deleting bookmarked chapters</string>
|
<string name="pref_remove_bookmarked_chapters">Allow deleting bookmarked chapters</string>
|
||||||
|
<string name="pref_remove_exclude_categories">Categories to exclude in deleting</string>
|
||||||
<string name="custom_dir">Custom location</string>
|
<string name="custom_dir">Custom location</string>
|
||||||
<string name="disabled">Disabled</string>
|
<string name="disabled">Disabled</string>
|
||||||
<string name="last_read_chapter">Last read chapter</string>
|
<string name="last_read_chapter">Last read chapter</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user