From 4393e9d9b3e24ebc8abcb7a504fcd45f67aee174 Mon Sep 17 00:00:00 2001 From: DaviDeMeo <21010903+DaviDeMeo@users.noreply.github.com> Date: Sat, 3 Jul 2021 02:10:45 +0200 Subject: [PATCH] Add a button that pick a random manga to read (#876) * add random button functionality * Add random manga setting, this should close #873 It open only manga with unread chapter, if we feel is needed we could add a setting to open even read manga * Add random manga functionality to hopper long press Also revert previous changes to preference and ui --- .../eu/kanade/tachiyomi/ui/library/LibraryController.kt | 9 +++++++++ app/src/main/res/drawable/ic_dice_outline_24dp.xml | 9 +++++++++ app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 20 insertions(+) create mode 100644 app/src/main/res/drawable/ic_dice_outline_24dp.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 5e36a0207d..c3e90cbf7e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -438,6 +438,14 @@ class LibraryController( filterTooltip?.show() } + private fun openRandomManga() { + val items = adapter.currentItems.filter { (it is LibraryItem && !it.manga.isBlank() && !it.manga.isHidden() && (!it.manga.initialized || it.manga.unread > 0)) } + if (items.isNotEmpty()) { + val item = items.random() as LibraryItem + openManga(item.manga) + } + } + private fun showGroupOptions() { val groupItems = mutableListOf(BY_DEFAULT, BY_TAG, BY_SOURCE, BY_STATUS) if (presenter.isLoggedIntoTracking) { @@ -673,6 +681,7 @@ class LibraryController( binding.roundedCategoryHopper.categoryButton.setOnLongClickListener { when (preferences.hopperLongPressAction().get()) { + 4 -> openRandomManga() 3 -> showGroupOptions() 2 -> showDisplayOptions() 1 -> if (canCollapseOrExpandCategory() != null) presenter.toggleAllCategoryVisibility() diff --git a/app/src/main/res/drawable/ic_dice_outline_24dp.xml b/app/src/main/res/drawable/ic_dice_outline_24dp.xml new file mode 100644 index 0000000000..a59a3ded08 --- /dev/null +++ b/app/src/main/res/drawable/ic_dice_outline_24dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 5d1e742d95..ab94e0c9f9 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -22,6 +22,7 @@ @string/expand_collapse_all_categories @string/display_options @string/group_library_by + @string/open_random_manga diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f91ce47da2..06e7bda120 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -133,6 +133,7 @@ Always show current category Category hopper long-press action Expand/collapse all categories + Open a random Manga Expand all categories Collapse all categories Reorder filters