Added library update errors screen

(cherry picked from commit 7cf37d52f959ac65f53cf7657563fb4428bd9188)
This commit is contained in:
ImaginaryDesignation
2023-07-02 12:03:32 +05:30
committed by Cuong-Tran
parent f7752a98b2
commit ee78212c75
32 changed files with 1154 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
package tachiyomi.data.libraryUpdateError
import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateError
val libraryUpdateErrorMapper: (Long, Long, Long) -> LibraryUpdateError = { id, mangaId, messageId ->
LibraryUpdateError(
id = id,
mangaId = mangaId,
messageId = messageId,
)
}

View File

@@ -0,0 +1,59 @@
package tachiyomi.data.libraryUpdateError
import kotlinx.coroutines.flow.Flow
import tachiyomi.data.DatabaseHandler
import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateError
import tachiyomi.domain.libraryUpdateError.repository.LibraryUpdateErrorRepository
class LibraryUpdateErrorRepositoryImpl(
private val handler: DatabaseHandler,
) : LibraryUpdateErrorRepository {
override suspend fun getAll(): List<LibraryUpdateError> {
return handler.awaitList {
libraryUpdateErrorQueries.getAllErrors(
libraryUpdateErrorMapper,
)
}
}
override fun getAllAsFlow(): Flow<List<LibraryUpdateError>> {
return handler.subscribeToList {
libraryUpdateErrorQueries.getAllErrors(
libraryUpdateErrorMapper,
)
}
}
override suspend fun deleteAll() {
return handler.await { libraryUpdateErrorQueries.deleteAllErrors() }
}
override suspend fun delete(errorId: Long) {
return handler.await {
libraryUpdateErrorQueries.deleteError(
_id = errorId,
)
}
}
override suspend fun insert(libraryUpdateError: LibraryUpdateError) {
return handler.await(inTransaction = true) {
libraryUpdateErrorQueries.insert(
mangaId = libraryUpdateError.mangaId,
messageId = libraryUpdateError.messageId,
)
}
}
override suspend fun insertAll(libraryUpdateErrors: List<LibraryUpdateError>) {
return handler.await(inTransaction = true) {
libraryUpdateErrors.forEach {
libraryUpdateErrorQueries.insert(
mangaId = it.mangaId,
messageId = it.messageId,
)
}
}
}
}

View File

@@ -0,0 +1,23 @@
package tachiyomi.data.libraryUpdateError
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 ->
LibraryUpdateErrorWithRelations(
mangaId = mangaId,
mangaTitle = mangaTitle,
mangaSource = mangaSource,
mangaCover = MangaCover(
mangaId = mangaId,
sourceId = mangaSource,
isMangaFavorite = favorite,
url = mangaThumbnail,
lastModified = coverLastModified,
),
errorId = errorId,
messageId = messageId,
)
}

View File

@@ -0,0 +1,19 @@
package tachiyomi.data.libraryUpdateError
import kotlinx.coroutines.flow.Flow
import tachiyomi.data.DatabaseHandler
import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateErrorWithRelations
import tachiyomi.domain.libraryUpdateError.repository.LibraryUpdateErrorWithRelationsRepository
class LibraryUpdateErrorWithRelationsRepositoryImpl(
private val handler: DatabaseHandler,
) : LibraryUpdateErrorWithRelationsRepository {
override fun subscribeAll(): Flow<List<LibraryUpdateErrorWithRelations>> {
return handler.subscribeToList {
libraryUpdateErrorViewQueries.errors(
libraryUpdateErrorWithRelationsMapper,
)
}
}
}

View File

@@ -0,0 +1,10 @@
package tachiyomi.data.libraryUpdateErrorMessage
import tachiyomi.domain.libraryUpdateErrorMessage.model.LibraryUpdateErrorMessage
val LibraryUpdateErrorMessageMapper: (Long, String) -> LibraryUpdateErrorMessage = { id, message ->
LibraryUpdateErrorMessage(
id = id,
message = message,
)
}

View File

@@ -0,0 +1,47 @@
package tachiyomi.data.libraryUpdateErrorMessage
import kotlinx.coroutines.flow.Flow
import tachiyomi.data.DatabaseHandler
import tachiyomi.domain.libraryUpdateErrorMessage.model.LibraryUpdateErrorMessage
import tachiyomi.domain.libraryUpdateErrorMessage.repository.LibraryUpdateErrorMessageRepository
class LibraryUpdateErrorMessageRepositoryImpl(
private val handler: DatabaseHandler,
) : LibraryUpdateErrorMessageRepository {
override suspend fun getAll(): List<LibraryUpdateErrorMessage> {
return handler.awaitList {
libraryUpdateErrorMessageQueries.getAllErrorMessages(
LibraryUpdateErrorMessageMapper,
)
}
}
override fun getAllAsFlow(): Flow<List<LibraryUpdateErrorMessage>> {
return handler.subscribeToList {
libraryUpdateErrorMessageQueries.getAllErrorMessages(
LibraryUpdateErrorMessageMapper,
)
}
}
override suspend fun deleteAll() {
return handler.await { libraryUpdateErrorMessageQueries.deleteAllErrorMessages() }
}
override suspend fun insert(libraryUpdateErrorMessage: LibraryUpdateErrorMessage): Long? {
return handler.awaitOneOrNullExecutable(inTransaction = true) {
libraryUpdateErrorMessageQueries.insert(libraryUpdateErrorMessage.message)
libraryUpdateErrorMessageQueries.selectLastInsertedRowId()
}
}
override suspend fun insertAll(libraryUpdateErrorMessages: List<LibraryUpdateErrorMessage>): List<Pair<Long, String>> {
return handler.await(inTransaction = true) {
libraryUpdateErrorMessages.map {
libraryUpdateErrorMessageQueries.insert(it.message)
libraryUpdateErrorMessageQueries.selectLastInsertedRowId().executeAsOne() to it.message
}
}
}
}

View File

@@ -0,0 +1,19 @@
CREATE TABLE libraryUpdateError (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
manga_id INTEGER NOT NULL,
message_id INTEGER NOT NULL
);
getAllErrors:
SELECT *
FROM libraryUpdateError;
insert:
INSERT INTO libraryUpdateError(manga_id, message_id) VALUES (:mangaId, :messageId);
deleteAllErrors:
DELETE FROM libraryUpdateError;
deleteError:
DELETE FROM libraryUpdateError
WHERE _id = :_id;

View File

@@ -0,0 +1,17 @@
CREATE TABLE libraryUpdateErrorMessage (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
message TEXT NOT NULL UNIQUE
);
getAllErrorMessages:
SELECT *
FROM libraryUpdateErrorMessage;
insert:
INSERT INTO libraryUpdateErrorMessage(message) VALUES (:message);
deleteAllErrorMessages:
DELETE FROM libraryUpdateErrorMessage;
selectLastInsertedRowId:
SELECT last_insert_rowid();

View File

@@ -0,0 +1,26 @@
DROP VIEW IF EXISTS libraryUpdateErrorView;
CREATE TABLE IF NOT EXISTS libraryUpdateError (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
manga_id INTEGER NOT NULL,
message_id INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS libraryUpdateErrorMessage (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
message TEXT NOT NULL UNIQUE
);
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
FROM mangas JOIN libraryUpdateError
ON mangas._id = libraryUpdateError.manga_id
WHERE favorite = 1;

View File

@@ -0,0 +1,17 @@
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
FROM mangas JOIN libraryUpdateError
ON mangas._id = libraryUpdateError.manga_id
WHERE favorite = 1;
errors:
SELECT *
FROM libraryUpdateErrorView;