diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index d77ba10d9..ea421c3eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -190,6 +190,14 @@ class PreferencesHelper(private val context: Context) { return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true) } + fun removeAfterRead(): Boolean { + return prefs.getBoolean(getKey(R.string.pref_remove_after_read_key), false) + } + + fun removeAfterReadPrevious(): Boolean { + return prefs.getBoolean(getKey(R.string.pref_remove_after_read_previous_key), false) + } + fun removeAfterMarkedAsRead(): Boolean { return prefs.getBoolean(getKey(R.string.pref_remove_after_marked_as_read_key), false) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 33036a09d..a325b74f5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -252,6 +252,7 @@ class ReaderActivity : BaseRxActivity() { nextChapterBtn?.isVisible = presenter.hasNextChapter() } + private fun getOrCreateViewer(manga: Manga): BaseReader { val mangaViewer = if (manga.viewer == 0) preferences.defaultViewer else manga.viewer diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index f21a12738..6235a1430 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -85,7 +85,7 @@ class ReaderPresenter : BasePresenter() { { view, pair -> view.onAdjacentChapters(pair.first, pair.second) }) startable(PRELOAD_NEXT_CHAPTER, { getPreloadNextChapterObservable() }, - { }, + { }, { error -> Timber.e("Error preloading chapter") }) @@ -335,10 +335,32 @@ class ReaderPresenter : BasePresenter() { // Save current progress of the chapter. Mark as read if the chapter is finished if (activePage.isLastPage) { chapter.read = true + + // Check if remove after read is selected by user + if (prefs.removeAfterRead()) { + if (prefs.removeAfterReadPrevious() ) { + if (previousChapter != null) { + deleteChapter(previousChapter!!, manga) + } + } else { + deleteChapter(chapter, manga) + } + } } db.insertChapter(chapter).asRxObservable().subscribe() } + /** + * Delete selected chapter + * @param chapter chapter that is selected + * * + * @param manga manga that belongs to chapter + */ + fun deleteChapter(chapter: Chapter, manga: Manga) { + val source = sourceManager.get(manga.source)!! + downloadManager.deleteChapter(source, manga, chapter) + } + // If the current chapter has been read, we check with this one // If not, we check if the previous chapter has been read // We know the chapter we have to check, but we don't know yet if an update is required. @@ -417,5 +439,4 @@ class ReaderPresenter : BasePresenter() { manga.viewer = viewer db.insertManga(manga).executeAsBlocking() } - } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt index 671334049..bb8dfb866 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt @@ -20,7 +20,6 @@ import java.io.File class SettingsDownloadsFragment : SettingsNestedFragment() { val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) } - companion object { val DOWNLOAD_DIR_CODE = 103 diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 64eb4576b..3690052d1 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -37,6 +37,10 @@ pref_download_slots_key pref_download_only_over_wifi_key pref_remove_after_marked_as_read_key + pref_category_remove_after_read_key + + pref_remove_after_read_key + pref_remove_after_read_previous_key pref_source_languages diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e34fde24..749dbb89e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -135,8 +135,13 @@ Simultaneous downloads Only download over Wi-Fi Remove when marked as read + Remove after read + Remove after read + Current chapter + Previous chapter Custom directory + Languages Select the languages to show sources from diff --git a/app/src/main/res/xml/pref_downloads.xml b/app/src/main/res/xml/pref_downloads.xml index eb367f69c..f23a9f60b 100644 --- a/app/src/main/res/xml/pref_downloads.xml +++ b/app/src/main/res/xml/pref_downloads.xml @@ -3,26 +3,41 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + android:key="@string/pref_download_directory_key" + android:title="@string/pref_download_directory"/> - - - + android:title="@string/pref_download_only_over_wifi"/> + android:key="@string/pref_download_slots_key" + android:summary="%s" + android:title="@string/pref_download_slots"/> + + + + + + + \ No newline at end of file