From 5ea683b6868c06ec0b226b5f9379bc2d7a38f12f Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 27 Jan 2020 21:04:11 -0800 Subject: [PATCH] Added "Reverse order" option to d&d sorting to reduce menu size --- .../tachiyomi/ui/library/LibraryController.kt | 32 +++++++++++-------- .../tachiyomi/ui/library/LibraryPresenter.kt | 15 +++++---- app/src/main/res/menu/library.xml | 10 +++--- app/src/main/res/values-ru/strings.xml | 2 -- app/src/main/res/values/strings.xml | 3 +- 5 files changed, 32 insertions(+), 30 deletions(-) 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 6faed9ff6b..e919b77e24 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 @@ -219,15 +219,15 @@ class LibraryController( if (orderOfCat != null) { subMenu.setGroupCheckable(R.id.reorder_group, true, true) when (orderOfCat) { - 'a' -> subMenu.findItem(R.id.action_alpha_asc)?.isChecked = true - 'b' -> subMenu.findItem(R.id.action_alpha_dsc)?.isChecked = true - 'c' -> subMenu.findItem(R.id.action_update_asc)?.isChecked = true - 'd' -> subMenu.findItem(R.id.action_update_dsc)?.isChecked = true - 'e' -> subMenu.findItem(R.id.action_unread)?.isChecked = true - 'f' -> subMenu.findItem(R.id.action_last_read)?.isChecked = true + 'a', 'b' -> subMenu.findItem(R.id.action_alpha_asc)?.isChecked = true + 'c', 'd' -> subMenu.findItem(R.id.action_update_asc)?.isChecked = true + 'e', 'f' -> subMenu.findItem(R.id.action_unread)?.isChecked = true + 'g', 'h' -> subMenu.findItem(R.id.action_last_read)?.isChecked = true } + subMenu.findItem(R.id.action_reverse)?.isVisible = true } else { + subMenu.findItem(R.id.action_reverse)?.isVisible = false subMenu.setGroupCheckable(R.id.reorder_group, false, false) } } @@ -479,12 +479,11 @@ class LibraryController( R.id.action_source_migration -> { router.pushController(MigrationController().withFadeTransaction()) } - R.id.action_alpha_asc -> reOrder(1) - R.id.action_alpha_dsc -> reOrder(2) - R.id.action_update_asc -> reOrder(3) - R.id.action_update_dsc -> reOrder(4) - R.id.action_unread -> reOrder(5) - R.id.action_last_read -> reOrder(6) + R.id.action_alpha_asc -> reOrder(0) + R.id.action_update_asc -> reOrder(1) + R.id.action_unread -> reOrder(2) + R.id.action_last_read -> reOrder(3) + R.id.action_reverse -> reOrder(-1) else -> return super.onOptionsItemSelected(item) } @@ -492,8 +491,15 @@ class LibraryController( } private fun reOrder(type: Int) { + val modType = if (type == -1) { + val t = (adapter?.categories?.getOrNull(library_pager.currentItem)?.mangaSort + ?.minus('a') ?: 0) + 1 + if (t % 2 != 0) t + 1 + else t - 1 + } + else 2 * type + 1 adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let { - reorganizeRelay.call(it to type) + reorganizeRelay.call(it to modType) onSortChanged() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 7eb1202f25..76006470c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -236,19 +236,20 @@ class LibraryPresenter( val category = catListing.find { it.id == i1.manga.category } when { category?.mangaSort != null -> { - when (category.mangaSort) { - 'a' -> sortAlphabetical(i1, i2) - 'b' -> sortAlphabetical(i2, i1) - 'c' -> i2.manga.last_update.compareTo(i1.manga.last_update) - 'd' -> i1.manga.last_update.compareTo(i2.manga.last_update) - 'e' -> i2.manga.unread.compareTo(i1.manga.unread) - 'f' -> { + var sort = when (category.mangaSort) { + 'a', 'b' -> sortAlphabetical(i1, i2) + 'c', 'd' -> i2.manga.last_update.compareTo(i1.manga.last_update) + 'e', 'f' -> i2.manga.unread.compareTo(i1.manga.unread) + 'g', 'h' -> { val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size val manga2LastRead = lastReadManga[i2.manga.id!!] ?: lastReadManga.size manga1LastRead.compareTo(manga2LastRead) } else -> sortAlphabetical(i1, i2) } + if ((category.mangaSort!! - 'a') % 2 == 1 ) + sort *= -1 + sort } category?.mangaOrder?.isEmpty() == false -> { val order = category.mangaOrder diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml index 8de98f1797..31d5100fd7 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -42,15 +42,9 @@ - - @@ -59,6 +53,10 @@ android:title="@string/action_sort_last_read"/> + + diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 35905f8bb6..3afe841107 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -75,14 +75,12 @@ По убыванию Перетаскивание По статусу вкл/выкл - Последняя обновленная (обр. порядок) Последняя прочитанная Последняя обновленная По количеству глав По возрастанию Старт Стоп - Название (обр. порядок) Отслеживать Отменить Обновить diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fea56d1155..cd1fffe069 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,9 +107,8 @@ Migrate now Copy now Reorder - Title (descending) + Reverse order Last updated - Last updated (desc.) Hide title Show title Newest