diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
index 33eb06558..ed5ce5e8b 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
@@ -98,4 +98,7 @@ interface MangaQueries : DbProvider {
.observesTables(MangaTable.TABLE)
.build())
.prepare()
+
+ fun getTotalChapterManga() = db.get().listOfObjects(Manga::class.java)
+ .withQuery(RawQuery.builder().query(getTotalChapterMangaQuery()).observesTables(MangaTable.TABLE).build()).prepare();
}
\ No newline at end of file
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
index cac21db3f..daa5c48fd 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
@@ -93,6 +93,15 @@ fun getLastReadMangaQuery() = """
ORDER BY max DESC
"""
+fun getTotalChapterMangaQuery()= """
+ SELECT ${Manga.TABLE}.*
+ FROM ${Manga.TABLE}
+ JOIN ${Chapter.TABLE}
+ ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
+ GROUP BY ${Manga.TABLE}.${Manga.COL_ID}
+ ORDER by COUNT(*)
+"""
+
/**
* Query to get the categories for a manga.
*/
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 8c3cb176c..2edd7a634 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
@@ -105,13 +105,15 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
private val alphabetically = Item.MultiSort(R.string.action_sort_alpha, this)
+ private val total = Item.MultiSort(R.string.action_sort_total, this)
+
private val lastRead = Item.MultiSort(R.string.action_sort_last_read, this)
private val lastUpdated = Item.MultiSort(R.string.action_sort_last_updated, this)
private val unread = Item.MultiSort(R.string.action_filter_unread, this)
- override val items = listOf(alphabetically, lastRead, lastUpdated, unread)
+ override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total)
override val header = Item.Header(R.string.action_sort)
@@ -126,6 +128,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
lastRead.state = if (sorting == LibrarySort.LAST_READ) order else SORT_NONE
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
}
override fun onItemClicked(item: Item) {
@@ -145,6 +148,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
lastRead -> LibrarySort.LAST_READ
lastUpdated -> LibrarySort.LAST_UPDATED
unread -> LibrarySort.UNREAD
+ total -> LibrarySort.TOTAL
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 a7c32b2e1..e09e837cc 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
@@ -146,6 +146,10 @@ class LibraryPresenter(
var counter = 0
db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ }
}
+ val totalChapterManga by lazy {
+ var counter = 0
+ db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
+ }
val sortFn: (Manga, Manga) -> Int = { manga1, manga2 ->
when (sortingMode) {
@@ -158,6 +162,11 @@ class LibraryPresenter(
}
LibrarySort.LAST_UPDATED -> manga2.last_update.compareTo(manga1.last_update)
LibrarySort.UNREAD -> manga1.unread.compareTo(manga2.unread)
+ LibrarySort.TOTAL -> {
+ val manga1TotalChapter = totalChapterManga[manga1.id!!] ?: 0
+ val mange2TotalChapter = totalChapterManga[manga2.id!!] ?: 0
+ manga1TotalChapter.compareTo(mange2TotalChapter)
+ }
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 35cff3a98..677eeb244 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
@@ -6,5 +6,5 @@ object LibrarySort {
const val LAST_READ = 1
const val LAST_UPDATED = 2
const val UNREAD = 3
-
+ const val TOTAL = 4
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e0d4b1499..718d9a345 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -30,6 +30,7 @@
Read
Remove filter
Alphabetically
+ Total chapters
Last read
Last updated
Search