From b1240e7efafd1961ee7cc08325d3f309e56ed58c Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 24 Jan 2024 11:53:53 +0200 Subject: [PATCH] Last read order in favorites #705 --- .../kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt | 2 +- .../org/koitharu/kotatsu/favourites/data/FavouritesDao.kt | 2 +- .../org/koitharu/kotatsu/history/data/HistoryDao.kt | 2 +- .../koitharu/kotatsu/history/ui/HistoryListViewModel.kt | 2 +- .../org/koitharu/kotatsu/list/domain/ListSortOrder.kt | 8 ++++---- app/src/main/res/values/strings.xml | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 0afb79590..d87ffe78d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -347,7 +347,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { set(value) = prefs.edit { putEnumValue(KEY_LOCAL_LIST_ORDER, value) } var historySortOrder: ListSortOrder - get() = prefs.getEnumValue(KEY_HISTORY_ORDER, ListSortOrder.UPDATED) + get() = prefs.getEnumValue(KEY_HISTORY_ORDER, ListSortOrder.LAST_READ) set(value) = prefs.edit { putEnumValue(KEY_HISTORY_ORDER, value) } var allFavoritesSortOrder: ListSortOrder 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 d569ba69a..ec9590951 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 @@ -193,8 +193,8 @@ abstract class FavouritesDao { ListSortOrder.ALPHABETIC -> "manga.title ASC" ListSortOrder.ALPHABETIC_REVERSE -> "manga.title DESC" ListSortOrder.NEW_CHAPTERS -> "IFNULL((SELECT chapters_new FROM tracks WHERE tracks.manga_id = manga.manga_id), 0) DESC" - ListSortOrder.UPDATED, // for legacy support ListSortOrder.PROGRESS -> "IFNULL((SELECT percent FROM history WHERE history.manga_id = manga.manga_id), 0) DESC" + ListSortOrder.LAST_READ -> "IFNULL((SELECT updated_at FROM history WHERE history.manga_id = manga.manga_id), 0) 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 34314f881..fc60e5103 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 @@ -35,7 +35,7 @@ abstract class HistoryDao { fun observeAll(order: ListSortOrder): Flow> { val orderBy = when (order) { - ListSortOrder.UPDATED -> "history.updated_at DESC" + ListSortOrder.LAST_READ -> "history.updated_at DESC" ListSortOrder.NEWEST -> "history.created_at DESC" ListSortOrder.PROGRESS -> "history.percent DESC" ListSortOrder.ALPHABETIC -> "manga.title" 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 d3e0561fc..91c192ac4 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 @@ -172,7 +172,7 @@ class HistoryListViewModel @Inject constructor( } private fun MangaHistory.header(order: ListSortOrder): ListHeader? = when (order) { - ListSortOrder.UPDATED -> ListHeader(calculateTimeAgo(updatedAt)) + ListSortOrder.LAST_READ -> ListHeader(calculateTimeAgo(updatedAt)) ListSortOrder.NEWEST -> ListHeader(calculateTimeAgo(createdAt)) ListSortOrder.PROGRESS -> ListHeader( when (percent) { 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 8142a97eb..7637cb600 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 @@ -9,7 +9,6 @@ enum class ListSortOrder( @StringRes val titleResId: Int, ) { - UPDATED(R.string.updated), NEWEST(R.string.order_added), PROGRESS(R.string.progress), ALPHABETIC(R.string.by_name), @@ -17,14 +16,15 @@ enum class ListSortOrder( RATING(R.string.by_rating), RELEVANCE(R.string.by_relevance), NEW_CHAPTERS(R.string.new_chapters), + LAST_READ(R.string.last_read), ; - fun isGroupingSupported() = this == UPDATED || this == NEWEST || this == PROGRESS + fun isGroupingSupported() = this == LAST_READ || this == NEWEST || this == PROGRESS companion object { - val HISTORY: Set = EnumSet.of(UPDATED, NEWEST, PROGRESS, ALPHABETIC, ALPHABETIC_REVERSE, NEW_CHAPTERS) - val FAVORITES: Set = EnumSet.of(ALPHABETIC, ALPHABETIC_REVERSE, NEWEST, RATING, NEW_CHAPTERS, PROGRESS) + val HISTORY: Set = EnumSet.of(LAST_READ, NEWEST, PROGRESS, ALPHABETIC, ALPHABETIC_REVERSE, NEW_CHAPTERS) + val FAVORITES: Set = EnumSet.of(ALPHABETIC, ALPHABETIC_REVERSE, NEWEST, RATING, NEW_CHAPTERS, PROGRESS, LAST_READ) val SUGGESTIONS: Set = EnumSet.of(RELEVANCE) operator fun invoke(value: String, fallback: ListSortOrder) = entries.find(value) ?: fallback diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49d15819a..a57b3ebe9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -566,4 +566,5 @@ Unknown volume Your reading progress will not be saved Vertical + Last read