From 74fd70416fa63a4732df89de28bce05a925788e5 Mon Sep 17 00:00:00 2001 From: ddmgy Date: Sun, 24 Sep 2017 14:01:07 -0400 Subject: [PATCH] Add option to sort library by source. (#985) * Add option to sort library by source. * Implement change suggested by NoodleMage. --- .../eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt | 6 +++++- .../java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 5 +++++ .../main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt index 6c1d4a0405..7f90523c69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt @@ -117,7 +117,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A private val unread = Item.MultiSort(R.string.action_filter_unread, this) - override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total) + private val source = Item.MultiSort(R.string.manga_info_source_label, this) + + override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total, source) override val header = Item.Header(R.string.action_sort) @@ -133,6 +135,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A lastUpdated.state = if (sorting == LibrarySort.LAST_UPDATED) order else SORT_NONE unread.state = if (sorting == LibrarySort.UNREAD) order else SORT_NONE total.state = if (sorting == LibrarySort.TOTAL) order else SORT_NONE + source.state = if (sorting == LibrarySort.SOURCE) order else SORT_NONE } override fun onItemClicked(item: Item) { @@ -153,6 +156,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A lastUpdated -> LibrarySort.LAST_UPDATED unread -> LibrarySort.UNREAD total -> LibrarySort.TOTAL + source -> LibrarySort.SOURCE else -> throw Exception("Unknown sorting") }) preferences.librarySortingAscending().set(if (item.state == SORT_ASC) true else false) 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 7661f218f8..30edf6fed4 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 @@ -174,6 +174,11 @@ class LibraryPresenter( val mange2TotalChapter = totalChapterManga[manga2.id!!] ?: 0 manga1TotalChapter.compareTo(mange2TotalChapter) } + LibrarySort.SOURCE -> { + val source1Name = sourceManager.get(manga1.source)?.name ?: "" + val source2Name = sourceManager.get(manga2.source)?.name ?: "" + source1Name.compareTo(source2Name) + } else -> throw Exception("Unknown sorting mode") } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt index 677eeb244d..57c9f28b17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt @@ -7,4 +7,5 @@ object LibrarySort { const val LAST_UPDATED = 2 const val UNREAD = 3 const val TOTAL = 4 + const val SOURCE = 5 } \ No newline at end of file