From eb4c7c6841d6531ab2dd1633f993e3fab9871914 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Jan 2020 17:35:48 -0500 Subject: [PATCH] Remove display/sorting mode dialogs --- .../ui/manga/chapter/ChaptersController.kt | 74 +++++++++++-------- .../ui/manga/chapter/SetDisplayModeDialog.kt | 43 ----------- .../ui/manga/chapter/SetSortingDialog.kt | 43 ----------- app/src/main/res/menu/chapters.xml | 29 ++++++-- app/src/main/res/values/strings.xml | 6 +- 5 files changed, 70 insertions(+), 125 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.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 5cf05976ac..9f9a8cac8a 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 @@ -34,8 +34,6 @@ class ChaptersController : NucleusController(), FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, ChaptersAdapter.OnMenuItemClickListener, - SetDisplayModeDialog.Listener, - SetSortingDialog.Listener, DownloadCustomChaptersDialog.Listener, DeleteChaptersDialog.Listener { @@ -147,17 +145,46 @@ class ChaptersController : NucleusController(), if (presenter.onlyUnread()) //Disable read filter option if unread filter is enabled. menuFilterRead.isEnabled = false + + // Display mode submenu + if (presenter.manga.displayMode == Manga.DISPLAY_NAME) { + menu.findItem(R.id.display_title).isChecked = true + } else { + menu.findItem(R.id.display_chapter_number).isChecked = true + } + + // Sorting mode submenu + if (presenter.manga.sorting == Manga.SORTING_SOURCE) { + menu.findItem(R.id.sort_by_source).isChecked = true + } else { + menu.findItem(R.id.sort_by_number).isChecked = true + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.action_display_mode -> showDisplayModeDialog() + R.id.display_title -> { + item.isChecked = true + setDisplayMode(Manga.DISPLAY_NAME) + } + R.id.display_chapter_number -> { + item.isChecked = true + setDisplayMode(Manga.DISPLAY_NUMBER) + } + + R.id.sort_by_source -> { + item.isChecked = true + presenter.setSorting(Manga.SORTING_SOURCE) + } + R.id.sort_by_number -> { + item.isChecked = true + presenter.setSorting(Manga.SORTING_NUMBER) + } 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 presenter.setUnreadFilter(item.isChecked) @@ -456,42 +483,16 @@ class ChaptersController : NucleusController(), // OVERFLOW MENU DIALOGS - private fun showDisplayModeDialog() { - val preselected = if (presenter.manga.displayMode == Manga.DISPLAY_NAME) 0 else 1 - SetDisplayModeDialog(this, preselected).showDialog(router) - } - - override fun setDisplayMode(id: Int) { + private fun setDisplayMode(id: Int) { presenter.setDisplayMode(id) adapter?.notifyDataSetChanged() } - private fun showSortingDialog() { - val preselected = if (presenter.manga.sorting == Manga.SORTING_SOURCE) 0 else 1 - SetSortingDialog(this, preselected).showDialog(router) - } - - override fun setSorting(id: Int) { - presenter.setSorting(id) - } - private fun getUnreadChaptersSorted() = presenter.chapters .filter { !it.read && it.status == Download.NOT_DOWNLOADED } .distinctBy { it.name } .sortedByDescending { it.source_order } - override fun downloadCustomChapters(amount: Int) { - val chaptersToDownload = getUnreadChaptersSorted().take(amount) - if (chaptersToDownload.isNotEmpty()) { - downloadChapters(chaptersToDownload) - } - } - - private fun showCustomDownloadDialog() { - DownloadCustomChaptersDialog(this, presenter.chapters.size).showDialog(router) - } - - private fun downloadChapters(choice: Int) { val chaptersToDownload = when (choice) { R.id.download_next -> getUnreadChaptersSorted().take(1) @@ -509,4 +510,15 @@ class ChaptersController : NucleusController(), downloadChapters(chaptersToDownload) } } + + private fun showCustomDownloadDialog() { + DownloadCustomChaptersDialog(this, presenter.chapters.size).showDialog(router) + } + + override fun downloadCustomChapters(amount: Int) { + val chaptersToDownload = getUnreadChaptersSorted().take(amount) + if (chaptersToDownload.isNotEmpty()) { + downloadChapters(chaptersToDownload) + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.kt deleted file mode 100644 index 56ce4affef..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetDisplayModeDialog.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.data.database.models.Manga -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -class SetDisplayModeDialog(bundle: Bundle? = null) : DialogController(bundle) - where T : Controller, T : SetDisplayModeDialog.Listener { - - private val selectedIndex = args.getInt("selected", -1) - - constructor(target: T, selectedIndex: Int = -1) : this(Bundle().apply { - putInt("selected", selectedIndex) - }) { - targetController = target - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val activity = activity!! - val ids = intArrayOf(Manga.DISPLAY_NAME, Manga.DISPLAY_NUMBER) - val choices = intArrayOf(R.string.show_title, R.string.show_chapter_number) - .map { activity.getString(it) } - - return MaterialDialog.Builder(activity) - .title(R.string.action_display_mode) - .items(choices) - .itemsIds(ids) - .itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> - (targetController as? Listener)?.setDisplayMode(itemView.id) - true - } - .build() - } - - interface Listener { - fun setDisplayMode(id: Int) - } - -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.kt deleted file mode 100644 index 861afaf1bc..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/SetSortingDialog.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.data.database.models.Manga -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -class SetSortingDialog(bundle: Bundle? = null) : DialogController(bundle) - where T : Controller, T : SetSortingDialog.Listener { - - private val selectedIndex = args.getInt("selected", -1) - - constructor(target: T, selectedIndex: Int = -1) : this(Bundle().apply { - putInt("selected", selectedIndex) - }) { - targetController = target - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val activity = activity!! - val ids = intArrayOf(Manga.SORTING_SOURCE, Manga.SORTING_NUMBER) - val choices = intArrayOf(R.string.sort_by_source, R.string.sort_by_number) - .map { activity.getString(it) } - - return MaterialDialog.Builder(activity) - .title(R.string.sorting_mode) - .items(choices) - .itemsIds(ids) - .itemsCallbackSingleChoice(selectedIndex) { _, itemView, _, _ -> - (targetController as? Listener)?.setSorting(itemView.id) - true - } - .build() - } - - interface Listener { - fun setSorting(id: Int) - } - -} \ No newline at end of file diff --git a/app/src/main/res/menu/chapters.xml b/app/src/main/res/menu/chapters.xml index 994042d678..b4c9951e88 100644 --- a/app/src/main/res/menu/chapters.xml +++ b/app/src/main/res/menu/chapters.xml @@ -37,17 +37,36 @@ app:showAsAction="ifRoom" /> + app:showAsAction="never"> + + + + + + + + app:showAsAction="never"> + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 062dbc81bd..9ff8c0f95f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,7 +76,7 @@ Open in browser Open in web view Add to home screen - Change display mode + Display mode Display Grid List @@ -387,8 +387,8 @@ Error Paused Could not fetch chapters - Show title - Show chapter number + Title + Chapter number Sorting mode By source By chapter number