From bc33a75b6b450376265c1d7c61118dd81ef72452 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 16 May 2025 15:07:37 +0700 Subject: [PATCH] fix(update-errors): Fix range selection & ordering latest error first (#914) * Fix range selection * Sort error list by latest error first * Correct non-nullable lastUpdate & fix comment --- app/build.gradle.kts | 4 ++-- .../LibraryUpdateErrorScreenModel.kt | 8 +++++--- .../LibraryUpdateErrorMapper.kt | 3 ++- .../LibraryUpdateErrorRepositoryImpl.kt | 12 +++-------- .../LibraryUpdateErrorWithRelationsMapper.kt | 5 +++-- .../tachiyomi/data/libraryUpdateError.sq | 14 +++++++------ .../sqldelight/tachiyomi/migrations/39.sqm | 20 +++++++++++++++++++ .../tachiyomi/view/libraryUpdateErrorView.sq | 8 +++++--- .../model/LibraryUpdateError.kt | 1 + .../model/LibraryUpdateErrorWithRelations.kt | 1 + 10 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 data/src/main/sqldelight/tachiyomi/migrations/39.sqm diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6242bc47f..7b722a7dc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,8 +25,8 @@ android { defaultConfig { applicationId = "app.komikku" - versionCode = 73 - versionName = "1.13.1" + versionCode = 74 + versionName = "1.13.2" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/libraryUpdateError/LibraryUpdateErrorScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/libraryUpdateError/LibraryUpdateErrorScreenModel.kt index ef73b2062..71d3dff4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/libraryUpdateError/LibraryUpdateErrorScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/libraryUpdateError/LibraryUpdateErrorScreenModel.kt @@ -32,7 +32,7 @@ class LibraryUpdateErrorScreenModel( mutableState.update { it.copy( isLoading = false, - items = toLibraryUpdateErrorItems(errors), + items = errors.toLibraryUpdateErrorItems(), messages = errorMessages, ) } @@ -40,13 +40,15 @@ class LibraryUpdateErrorScreenModel( } } - private fun toLibraryUpdateErrorItems(errors: List): List { - return errors.map { error -> + private fun List.toLibraryUpdateErrorItems(): List { + return map { error -> LibraryUpdateErrorItem( error = error, selected = error.errorId in selectedErrorIds, ) } + // Sort by messageId to group errors by type, preserving last_update order within groups (from DB) + .sortedBy { it.error.messageId } } fun toggleSelection( diff --git a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorMapper.kt b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorMapper.kt index 6a6e9d123..42ab492b3 100644 --- a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorMapper.kt +++ b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorMapper.kt @@ -2,10 +2,11 @@ package tachiyomi.data.libraryUpdateError import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateError -val libraryUpdateErrorMapper: (Long, Long, Long) -> LibraryUpdateError = { id, mangaId, messageId -> +val libraryUpdateErrorMapper: (Long, Long, Long, Long) -> LibraryUpdateError = { id, mangaId, messageId, lastUpdate -> LibraryUpdateError( id = id, mangaId = mangaId, messageId = messageId, + lastUpdate = lastUpdate, ) } diff --git a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt index 7fb014f7a..7b1089eeb 100644 --- a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt @@ -11,17 +11,13 @@ class LibraryUpdateErrorRepositoryImpl( override suspend fun getAll(): List { return handler.awaitList { - libraryUpdateErrorQueries.getAllErrors( - libraryUpdateErrorMapper, - ) + libraryUpdateErrorQueries.getAllErrors(libraryUpdateErrorMapper) } } override fun getAllAsFlow(): Flow> { return handler.subscribeToList { - libraryUpdateErrorQueries.getAllErrors( - libraryUpdateErrorMapper, - ) + libraryUpdateErrorQueries.getAllErrors(libraryUpdateErrorMapper) } } @@ -39,9 +35,7 @@ class LibraryUpdateErrorRepositoryImpl( override suspend fun deleteMangaError(mangaId: Long) { return handler.await { - libraryUpdateErrorQueries.deleteMangaError( - mangaId = mangaId, - ) + libraryUpdateErrorQueries.deleteMangaError(mangaId = mangaId) } } diff --git a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorWithRelationsMapper.kt b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorWithRelationsMapper.kt index 1b6dba47f..b8b0d3b71 100644 --- a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorWithRelationsMapper.kt +++ b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorWithRelationsMapper.kt @@ -4,8 +4,8 @@ import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateErrorWithRelations import tachiyomi.domain.manga.model.MangaCover val libraryUpdateErrorWithRelationsMapper: - (Long, String, Long, Boolean, String?, Long, Long, Long) -> LibraryUpdateErrorWithRelations = - { mangaId, mangaTitle, mangaSource, favorite, mangaThumbnail, coverLastModified, errorId, messageId -> + (Long, String, Long, Boolean, String?, Long, Long, Long, Long) -> LibraryUpdateErrorWithRelations = + { mangaId, mangaTitle, mangaSource, favorite, mangaThumbnail, coverLastModified, errorId, messageId, lastUpdate -> LibraryUpdateErrorWithRelations( mangaId = mangaId, mangaTitle = mangaTitle, @@ -19,5 +19,6 @@ val libraryUpdateErrorWithRelationsMapper: ), errorId = errorId, messageId = messageId, + lastUpdate = lastUpdate, ) } diff --git a/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq b/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq index e5a537910..0cd6ffb62 100644 --- a/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq +++ b/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq @@ -1,7 +1,8 @@ CREATE TABLE libraryUpdateError ( _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, manga_id INTEGER NOT NULL UNIQUE, - message_id INTEGER NOT NULL + message_id INTEGER NOT NULL, + last_update INTEGER NOT NULL DEFAULT 0 ); getAllErrors: @@ -9,15 +10,16 @@ SELECT * FROM libraryUpdateError; insert: -INSERT INTO libraryUpdateError(manga_id, message_id) VALUES (:mangaId, :messageId); +INSERT INTO libraryUpdateError(manga_id, message_id, last_update) VALUES (:mangaId, :messageId, strftime('%s', 'now')); upsert: -INSERT INTO libraryUpdateError(manga_id, message_id) -VALUES (:mangaId, :messageId) +INSERT INTO libraryUpdateError(manga_id, message_id, last_update) +VALUES (:mangaId, :messageId, strftime('%s', 'now')) ON CONFLICT(manga_id) DO UPDATE SET - message_id = :messageId + message_id = :messageId, + last_update = strftime('%s', 'now') WHERE manga_id = :mangaId; deleteAllErrors: @@ -38,4 +40,4 @@ WHERE NOT EXISTS ( FROM mangas WHERE libraryUpdateError.manga_id = mangas._id AND mangas.favorite == 1 -); \ No newline at end of file +); diff --git a/data/src/main/sqldelight/tachiyomi/migrations/39.sqm b/data/src/main/sqldelight/tachiyomi/migrations/39.sqm new file mode 100644 index 000000000..3352b0416 --- /dev/null +++ b/data/src/main/sqldelight/tachiyomi/migrations/39.sqm @@ -0,0 +1,20 @@ +ALTER TABLE libraryUpdateError +ADD COLUMN last_update INTEGER NOT NULL DEFAULT 0; + +DROP VIEW IF EXISTS libraryUpdateErrorView; + +CREATE VIEW libraryUpdateErrorView AS +SELECT + mangas._id AS mangaId, + mangas.title AS mangaTitle, + mangas.source, + mangas.favorite, + mangas.thumbnail_url AS thumbnailUrl, + mangas.cover_last_modified AS coverLastModified, + libraryUpdateError._id AS errorId, + libraryUpdateError.message_id AS messageId, + libraryUpdateError.last_update AS lastUpdate +FROM mangas JOIN libraryUpdateError +ON mangas._id = libraryUpdateError.manga_id +WHERE favorite = 1 +ORDER BY lastUpdate DESC; diff --git a/data/src/main/sqldelight/tachiyomi/view/libraryUpdateErrorView.sq b/data/src/main/sqldelight/tachiyomi/view/libraryUpdateErrorView.sq index 303b95eaf..1dc5fa060 100644 --- a/data/src/main/sqldelight/tachiyomi/view/libraryUpdateErrorView.sq +++ b/data/src/main/sqldelight/tachiyomi/view/libraryUpdateErrorView.sq @@ -7,11 +7,13 @@ SELECT mangas.thumbnail_url AS thumbnailUrl, mangas.cover_last_modified AS coverLastModified, libraryUpdateError._id AS errorId, - libraryUpdateError.message_id AS messageId + libraryUpdateError.message_id AS messageId, + libraryUpdateError.last_update AS lastUpdate FROM mangas JOIN libraryUpdateError ON mangas._id = libraryUpdateError.manga_id -WHERE favorite = 1; +WHERE favorite = 1 +ORDER BY lastUpdate DESC; errors: SELECT * -FROM libraryUpdateErrorView; \ No newline at end of file +FROM libraryUpdateErrorView; diff --git a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateError.kt b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateError.kt index 7838d378a..a82cfd835 100644 --- a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateError.kt +++ b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateError.kt @@ -6,4 +6,5 @@ data class LibraryUpdateError( val id: Long, val mangaId: Long, val messageId: Long, + val lastUpdate: Long = 0L, ) : Serializable diff --git a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateErrorWithRelations.kt b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateErrorWithRelations.kt index f2c514cbc..f2bca4da5 100644 --- a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateErrorWithRelations.kt +++ b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/model/LibraryUpdateErrorWithRelations.kt @@ -9,4 +9,5 @@ data class LibraryUpdateErrorWithRelations( val mangaCover: MangaCover, val errorId: Long, val messageId: Long, + val lastUpdate: Long, )