From 499c2213eefbdb2d627a80bfb7fcd93f86b49e14 Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Mon, 21 Mar 2016 21:06:20 +0100 Subject: [PATCH] Implements delete chapter when set as read for issue #42 --- .../data/preference/PreferencesHelper.kt | 4 ++++ .../ui/manga/chapter/ChaptersPresenter.kt | 7 ++++++- .../ui/recent/RecentChaptersFragment.kt | 8 +++---- .../ui/recent/RecentChaptersHolder.kt | 4 ++-- .../ui/recent/RecentChaptersPresenter.kt | 21 ++++++++++++------- app/src/main/res/values/keys.xml | 2 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_downloads.xml | 6 ++++++ 8 files changed, 39 insertions(+), 14 deletions(-) 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 3d5dc78474..d77ba10d90 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,10 @@ class PreferencesHelper(private val context: Context) { return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true) } + fun removeAfterMarkedAsRead(): Boolean { + return prefs.getBoolean(getKey(R.string.pref_remove_after_marked_as_read_key), false) + } + fun libraryUpdateInterval(): Preference { return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index 98149151f7..97a68756d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -103,7 +103,7 @@ class ChaptersPresenter : BasePresenter() { } start(CHAPTER_STATUS_CHANGES) } - .subscribe{ chaptersSubject.onNext(it) }) + .subscribe { chaptersSubject.onNext(it) }) } } @@ -191,6 +191,11 @@ class ChaptersPresenter : BasePresenter() { .doOnNext { chapter -> chapter.read = read if (!read) chapter.last_page_read = 0 + + // Delete chapter when marked as read if desired by user. + if (preferences.removeAfterMarkedAsRead() && read) { + deleteChapter(chapter) + } } .toList() .flatMap { chapters -> db.insertChapters(chapters).asRxObservable() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt index 2b64234134..1fecbaf420 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt @@ -202,9 +202,9 @@ class RecentChaptersFragment : BaseRxFragment(), Flexib * @param chapters selected chapter * @return true */ - fun onMarkAsRead(chapters: Observable): Boolean { + fun onMarkAsRead(chapters: Observable, manga : Manga): Boolean { // Set marked as read - presenter.markChaptersRead(chapters, true) + presenter.markChaptersRead(chapters, manga, true) return true } @@ -214,9 +214,9 @@ class RecentChaptersFragment : BaseRxFragment(), Flexib * @param chapters selected chapter * @return true */ - fun onMarkAsUnread(chapters: Observable): Boolean { + fun onMarkAsUnread(chapters: Observable , manga : Manga): Boolean { // Set marked as unread - presenter.markChaptersRead(chapters, false) + presenter.markChaptersRead(chapters, manga, false) return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt index 25eb0bd945..601e80b59c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt @@ -125,8 +125,8 @@ class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapte when (menuItem.itemId) { R.id.action_download -> adapter.fragment.onDownload(chapterObservable, it.manga) R.id.action_delete -> adapter.fragment.onDelete(chapterObservable, it.manga) - R.id.action_mark_as_read -> adapter.fragment.onMarkAsRead(chapterObservable); - R.id.action_mark_as_unread -> adapter.fragment.onMarkAsUnread(chapterObservable); + R.id.action_mark_as_read -> adapter.fragment.onMarkAsRead(chapterObservable, it.manga); + R.id.action_mark_as_unread -> adapter.fragment.onMarkAsUnread(chapterObservable, it.manga); } false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt index 7e892db083..ab9e86be25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaChapter import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.event.DownloadChaptersEvent import eu.kanade.tachiyomi.event.ReaderEvent @@ -25,6 +26,11 @@ class RecentChaptersPresenter : BasePresenter() { */ @Inject lateinit var db: DatabaseHelper + /** + * Used to get settings + */ + @Inject lateinit var preferences: PreferencesHelper + /** * Used to get information from download manager */ @@ -291,15 +297,16 @@ class RecentChaptersPresenter : BasePresenter() { * * * @param read read status */ - fun markChaptersRead(selectedChapters: Observable, read: Boolean) { - add(selectedChapters - .subscribeOn(Schedulers.io()) - .map { chapter -> + fun markChaptersRead(selectedChapters: Observable, manga: Manga, read: Boolean) { + add(selectedChapters.subscribeOn(Schedulers.io()) + .doOnNext { chapter -> chapter.read = read - if (!read) { - chapter.last_page_read = 0 + if (!read) chapter.last_page_read = 0 + + // Delete chapter when marked as read if desired by user. + if (preferences.removeAfterMarkedAsRead() && read) { + deleteChapter(chapter,manga) } - chapter } .toList() .flatMap { chapters -> db.insertChapters(chapters).asRxObservable() } diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index fbdd4828c5..64eb4576bb 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -36,6 +36,8 @@ pref_download_directory_key pref_download_slots_key pref_download_only_over_wifi_key + pref_remove_after_marked_as_read_key + pref_source_languages diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 737ee66a41..5e34fde24d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ Downloads directory Simultaneous downloads Only download over Wi-Fi + Remove when marked as read Custom directory diff --git a/app/src/main/res/xml/pref_downloads.xml b/app/src/main/res/xml/pref_downloads.xml index a7710af1f0..eb367f69cb 100644 --- a/app/src/main/res/xml/pref_downloads.xml +++ b/app/src/main/res/xml/pref_downloads.xml @@ -11,6 +11,12 @@ android:key="@string/pref_download_only_over_wifi_key" android:defaultValue="true"/> + + +