From c9fbe8f8478d594ab9f1ce2a6ba903b51b547562 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Tue, 10 Aug 2021 16:55:50 -0400 Subject: [PATCH] Switching reader pagelayout button actions single click: * when using automatic layout: switches between single (or split page) and double page mode * when not: opens popup to switch between the 3 long click: open same popup --- .../tachiyomi/ui/reader/ReaderActivity.kt | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) 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 64103f74cf..f3bd250f9c 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 @@ -556,37 +556,19 @@ class ReaderActivity : with(doublePage) { compatToolTipText = getString(R.string.page_layout) setOnClickListener { - val config = (viewer as? PagerViewer)?.config - val selectedId = when { - config?.doublePages == true -> PageLayout.DOUBLE_PAGES - config?.splitPages == true -> PageLayout.SPLIT_PAGES - else -> PageLayout.SINGLE_PAGE - } - popupMenu( - items = listOf( - PageLayout.SINGLE_PAGE, - PageLayout.DOUBLE_PAGES, - PageLayout.SPLIT_PAGES, - ).map { it.value to it.stringRes }, - selectedItemId = selectedId.value, - ) { - val newLayout = PageLayout.fromPreference(itemId) - - if (preferences.pageLayout().get() == PageLayout.AUTOMATIC.value) { - (viewer as? PagerViewer)?.config?.let { config -> - config.doublePages = newLayout == PageLayout.DOUBLE_PAGES - if (newLayout == PageLayout.SINGLE_PAGE) { - preferences.automaticSplitsPage().set(false) - } else if (newLayout == PageLayout.SPLIT_PAGES) { - preferences.automaticSplitsPage().set(true) - } - reloadChapters(config.doublePages, true) - } - } else { - preferences.pageLayout().set(newLayout.value) + if (preferences.pageLayout().get() == PageLayout.AUTOMATIC.value) { + (viewer as? PagerViewer)?.config?.let { config -> + config.doublePages = !config.doublePages + reloadChapters(config.doublePages, true) } + } else { + showPageLayoutMenu() } } + setOnLongClickListener { + showPageLayoutMenu() + true + } } cropBordersSheetButton.setOnClickListener { val pref = @@ -788,6 +770,41 @@ class ReaderActivity : } } + fun showPageLayoutMenu() { + with(binding.chaptersSheet.doublePage) { + val config = (viewer as? PagerViewer)?.config + val selectedId = when { + config?.doublePages == true -> PageLayout.DOUBLE_PAGES + config?.splitPages == true -> PageLayout.SPLIT_PAGES + else -> PageLayout.SINGLE_PAGE + } + popupMenu( + items = listOf( + PageLayout.SINGLE_PAGE, + PageLayout.DOUBLE_PAGES, + PageLayout.SPLIT_PAGES, + ).map { it.value to it.stringRes }, + selectedItemId = selectedId.value, + ) { + val newLayout = PageLayout.fromPreference(itemId) + + if (preferences.pageLayout().get() == PageLayout.AUTOMATIC.value) { + (viewer as? PagerViewer)?.config?.let { config -> + config.doublePages = newLayout == PageLayout.DOUBLE_PAGES + if (newLayout == PageLayout.SINGLE_PAGE) { + preferences.automaticSplitsPage().set(false) + } else if (newLayout == PageLayout.SPLIT_PAGES) { + preferences.automaticSplitsPage().set(true) + } + reloadChapters(config.doublePages, true) + } + } else { + preferences.pageLayout().set(newLayout.value) + } + } + } + } + /** * Sets the visibility of the menu according to [visible] and with an optional parameter to * [animate] the views.