From 81c14ba6106ef8ea817370517290eb604caa777c Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 20 Jan 2020 14:37:27 -0800 Subject: [PATCH] Download dialog in chapters removed, now using submenu (cherry picked from commit a253c255e8e1ee0cc0e158c3bf61f5352b06e656) --- .../ui/manga/chapter/ChaptersController.kt | 31 ++++++------- .../manga/chapter/DownloadChaptersDialog.kt | 43 ------------------- app/src/main/res/menu/chapters.xml | 25 ++++++++++- 3 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 868a3fc412..5cf05976ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -36,7 +36,6 @@ class ChaptersController : NucleusController(), ChaptersAdapter.OnMenuItemClickListener, SetDisplayModeDialog.Listener, SetSortingDialog.Listener, - DownloadChaptersDialog.Listener, DownloadCustomChaptersDialog.Listener, DeleteChaptersDialog.Listener { @@ -153,7 +152,11 @@ class ChaptersController : NucleusController(), override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_display_mode -> showDisplayModeDialog() - R.id.manga_download -> showDownloadDialog() + + R.id.download_next, R.id.download_next_5, R.id.download_next_10, + R.id.download_custom, R.id.download_unread, R.id.download_all + -> downloadChapters(item.itemId) + R.id.action_sorting_mode -> showSortingDialog() R.id.action_filter_unread -> { item.isChecked = !item.isChecked @@ -472,10 +475,6 @@ class ChaptersController : NucleusController(), presenter.setSorting(id) } - private fun showDownloadDialog() { - DownloadChaptersDialog(this).showDialog(router) - } - private fun getUnreadChaptersSorted() = presenter.chapters .filter { !it.read && it.status == Download.NOT_DOWNLOADED } .distinctBy { it.name } @@ -493,23 +492,17 @@ class ChaptersController : NucleusController(), } - override fun downloadChapters(choice: Int) { - // i = 0: Download 1 - // i = 1: Download 5 - // i = 2: Download 10 - // i = 3: Download x - // i = 4: Download unread - // i = 5: Download all + private fun downloadChapters(choice: Int) { val chaptersToDownload = when (choice) { - 0 -> getUnreadChaptersSorted().take(1) - 1 -> getUnreadChaptersSorted().take(5) - 2 -> getUnreadChaptersSorted().take(10) - 3 -> { + R.id.download_next -> getUnreadChaptersSorted().take(1) + R.id.download_next_5 -> getUnreadChaptersSorted().take(5) + R.id.download_next_10 -> getUnreadChaptersSorted().take(10) + R.id.download_custom -> { showCustomDownloadDialog() return } - 4 -> presenter.chapters.filter { !it.read } - 5 -> presenter.chapters + R.id.download_unread -> presenter.chapters.filter { !it.read } + R.id.download_all -> presenter.chapters else -> emptyList() } if (chaptersToDownload.isNotEmpty()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt deleted file mode 100644 index 6b1f6077ad..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/DownloadChaptersDialog.kt +++ /dev/null @@ -1,43 +0,0 @@ -package eu.kanade.tachiyomi.ui.manga.chapter - -import android.app.Dialog -import android.os.Bundle -import com.afollestad.materialdialogs.MaterialDialog -import com.bluelinelabs.conductor.Controller -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -class DownloadChaptersDialog(bundle: Bundle? = null) : DialogController(bundle) - where T : Controller, T : DownloadChaptersDialog.Listener { - - constructor(target: T) : this() { - targetController = target - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val activity = activity!! - - val choices = intArrayOf( - R.string.download_1, - R.string.download_5, - R.string.download_10, - R.string.download_custom, - R.string.download_unread, - R.string.download_all - ).map { activity.getString(it) } - - return MaterialDialog.Builder(activity) - .title(R.string.manga_download) - .negativeText(android.R.string.cancel) - .items(choices) - .itemsCallback { _, _, position, _ -> - (targetController as? Listener)?.downloadChapters(position) - } - .build() - } - - interface Listener { - fun downloadChapters(choice: Int) - } - -} diff --git a/app/src/main/res/menu/chapters.xml b/app/src/main/res/menu/chapters.xml index d54639cd30..5cb625f090 100644 --- a/app/src/main/res/menu/chapters.xml +++ b/app/src/main/res/menu/chapters.xml @@ -49,5 +49,26 @@ - \ No newline at end of file + app:showAsAction="never"> + + + + + + + + + +