From a253c255e8e1ee0cc0e158c3bf61f5352b06e656 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 --- .../ui/manga/chapter/ChaptersController.kt | 31 ++++++------- .../manga/chapter/DownloadChaptersDialog.kt | 43 ------------------- app/src/main/res/menu/chapters.xml | 23 +++++++++- 3 files changed, 34 insertions(+), 63 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 76a9ffdd50..82dd9c4241 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 @@ -47,7 +47,6 @@ class ChaptersController() : NucleusController(), ChaptersAdapter.OnMenuItemClickListener, SetDisplayModeDialog.Listener, SetSortingDialog.Listener, - DownloadChaptersDialog.Listener, DownloadCustomChaptersDialog.Listener, DeleteChaptersDialog.Listener { @@ -193,7 +192,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 @@ -526,10 +529,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 } @@ -547,23 +546,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 a3dfe078ce..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.afollestad.materialdialogs.list.listItems -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(activity) - .title(R.string.manga_download) - .negativeButton(android.R.string.cancel) - .listItems(items = choices){dialog, position, _ -> - (targetController as? Listener)?.downloadChapters(position) - dialog.dismiss() - } - } - - 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..e852e80f33 100644 --- a/app/src/main/res/menu/chapters.xml +++ b/app/src/main/res/menu/chapters.xml @@ -49,5 +49,26 @@ + app:showAsAction="never" > + + + + + + + + + \ No newline at end of file