From abbc7b572ac1fe3ccb9a54edc42ddb06863ff58b Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Mon, 21 Mar 2016 18:51:40 +0100 Subject: [PATCH 1/3] Implements Download next 1/5/10/all chapters for issue #42 --- .../ui/manga/chapter/ChaptersFragment.kt | 25 ++++++++++++++++--- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt index 90c0dc3095..fa94338f6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt @@ -27,7 +27,6 @@ import nucleus.factory.RequiresPresenter import rx.Observable import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers -import java.util.* @RequiresPresenter(ChaptersPresenter::class) class ChaptersFragment : BaseRxFragment(), ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener { @@ -217,23 +216,41 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac private fun showDownloadDialog() { // Get available modes - val modes = listOf(getString(R.string.download_all), getString(R.string.download_unread)) + val modes = listOf(getString(R.string.download_1), getString(R.string.download_5), getString(R.string.download_10), + getString(R.string.download_unread), getString(R.string.download_all)) MaterialDialog.Builder(activity) .title(R.string.manga_download) .negativeText(android.R.string.cancel) .items(modes) .itemsCallback { dialog, view, i, charSequence -> - val chapters = ArrayList() + var chapters: MutableList = arrayListOf() + // i = 0: Download 1 + // i = 1: Download 5 + // i = 2: Download 10 + // i = 3: Download unread + // i = 4: Download all for (chapter in presenter.chapters) { if (!chapter.isDownloaded) { - if (i == 0 || (i == 1 && !chapter.read)) { + if (i == 4 || (i != 4 && !chapter.read)) { chapters.add(chapter) } } } if (chapters.size > 0) { + when (i) { + // Set correct chapters size if desired + 0 -> chapters = chapters.subList(0, 1) + 1 -> { + if (chapters.size >= 5) + chapters = chapters.subList(0, 5) + } + 2 -> { + if (chapters.size >= 10) + chapters = chapters.subList(0, 10) + } + } onDownload(Observable.from(chapters)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0e1d97fcaa..737ee66a41 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -208,6 +208,9 @@ Show title Show chapter number Download + Download next chapter + Download next 5 chapters + Download next 10 chapters Download all Download unread From 499c2213eefbdb2d627a80bfb7fcd93f86b49e14 Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Mon, 21 Mar 2016 21:06:20 +0100 Subject: [PATCH 2/3] 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"/> + + + Date: Mon, 21 Mar 2016 22:30:30 +0100 Subject: [PATCH 3/3] Can now choose to automatically remove chapter after reading (or previous). Fix #42 --- .../data/preference/PreferencesHelper.kt | 8 ++++ .../tachiyomi/ui/reader/ReaderActivity.kt | 1 + .../tachiyomi/ui/reader/ReaderPresenter.kt | 25 ++++++++++- .../ui/setting/SettingsDownloadsFragment.kt | 1 - app/src/main/res/values/keys.xml | 4 ++ app/src/main/res/values/strings.xml | 5 +++ app/src/main/res/xml/pref_downloads.xml | 43 +++++++++++++------ 7 files changed, 70 insertions(+), 17 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 d77ba10d90..ea421c3eb0 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 33036a09db..a325b74f59 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 f21a127389..6235a14308 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 671334049f..bb8dfb8661 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 64eb4576bb..3690052d10 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 5e34fde24d..749dbb89ec 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 eb367f69cb..f23a9f60bd 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