From abbc7b572ac1fe3ccb9a54edc42ddb06863ff58b Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Mon, 21 Mar 2016 18:51:40 +0100 Subject: [PATCH] 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