From 35baf4b58dae76f9bc72c6fce61ca7c6c91e5777 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Fri, 13 Oct 2023 16:26:30 +0300 Subject: [PATCH] Add option to order history and favorites by new chapters --- app/build.gradle | 4 ++-- .../kotatsu/favourites/data/FavouritesDao.kt | 15 +++++++-------- .../koitharu/kotatsu/history/data/HistoryDao.kt | 1 + .../kotatsu/history/ui/HistoryListViewModel.kt | 1 + .../koitharu/kotatsu/list/domain/ListSortOrder.kt | 7 ++++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0380deccc..bae905869 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId 'org.koitharu.kotatsu' minSdk = 21 targetSdk = 34 - versionCode = 584 - versionName = '6.1.6' + versionCode = 585 + versionName = '6.2-a1' generatedDensities = [] testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner" ksp { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt index dc2acef7e..5b23ad3c0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt @@ -83,8 +83,9 @@ abstract class FavouritesDao { @Language("RoomSql") val query = SimpleSQLiteQuery( - "SELECT m.cover_url AS url, m.source AS source FROM favourites AS f LEFT JOIN manga AS m ON f.manga_id = m.manga_id " + - "WHERE f.category_id = ? AND deleted_at = 0 ORDER BY $orderBy", + "SELECT manga.cover_url AS url, manga.source AS source FROM favourites " + + "LEFT JOIN manga ON favourites.manga_id = manga.manga_id " + + "WHERE favourites.category_id = ? AND deleted_at = 0 ORDER BY $orderBy", arrayOf(categoryId), ) return findCoversImpl(query) @@ -164,12 +165,10 @@ abstract class FavouritesDao { protected abstract suspend fun setDeletedAtAll(categoryId: Long, deletedAt: Long) private fun getOrderBy(sortOrder: ListSortOrder) = when (sortOrder) { - ListSortOrder.RATING -> "rating DESC" - ListSortOrder.NEWEST, - ListSortOrder.UPDATED, - -> "created_at DESC" - - ListSortOrder.ALPHABETIC -> "title ASC" + ListSortOrder.RATING -> "manga.rating DESC" + ListSortOrder.NEWEST -> "favourites.created_at DESC" + ListSortOrder.ALPHABETIC -> "manga.title ASC" + ListSortOrder.NEW_CHAPTERS -> "(SELECT chapters_new FROM tracks WHERE tracks.manga_id = manga.manga_id) DESC" else -> throw IllegalArgumentException("Sort order $sortOrder is not supported") } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryDao.kt index 7530fcf25..25636902b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryDao.kt @@ -39,6 +39,7 @@ abstract class HistoryDao { ListSortOrder.NEWEST -> "history.created_at DESC" ListSortOrder.PROGRESS -> "history.percent DESC" ListSortOrder.ALPHABETIC -> "manga.title" + ListSortOrder.NEW_CHAPTERS -> "(SELECT chapters_new FROM tracks WHERE tracks.manga_id = manga.manga_id) DESC" else -> throw IllegalArgumentException("Sort order $order is not supported") } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt index 9bc462785..a263b7038 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt @@ -178,6 +178,7 @@ class HistoryListViewModel @Inject constructor( ListSortOrder.ALPHABETIC, ListSortOrder.RELEVANCE, + ListSortOrder.NEW_CHAPTERS, ListSortOrder.RATING -> null } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/domain/ListSortOrder.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/domain/ListSortOrder.kt index 9286b0aff..673f85773 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/domain/ListSortOrder.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/domain/ListSortOrder.kt @@ -15,15 +15,16 @@ enum class ListSortOrder( ALPHABETIC(R.string.by_name), RATING(R.string.by_rating), RELEVANCE(R.string.by_relevance), + NEW_CHAPTERS(R.string.new_chapters), ; fun isGroupingSupported() = this == UPDATED || this == NEWEST || this == PROGRESS companion object { - val HISTORY = EnumSet.of(UPDATED, NEWEST, PROGRESS, ALPHABETIC) - val FAVORITES = EnumSet.of(ALPHABETIC, NEWEST, RATING) - val SUGGESTIONS = EnumSet.of(RELEVANCE) + val HISTORY: Set = EnumSet.of(UPDATED, NEWEST, PROGRESS, ALPHABETIC, NEW_CHAPTERS) + val FAVORITES: Set = EnumSet.of(ALPHABETIC, NEWEST, RATING, NEW_CHAPTERS) + val SUGGESTIONS: Set = EnumSet.of(RELEVANCE) operator fun invoke(value: String, fallback: ListSortOrder) = entries.find(value) ?: fallback }