mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-28 18:48:51 +03:00
Changed data-mappers to use function format (#10045)
The lambda-format was really confusing to read and keep which anonymous data item was corresponding to which field. Now it's directly inspectable in the IDE
This commit is contained in:
parent
8e4cedf173
commit
15423bfc84
15 changed files with 300 additions and 319 deletions
|
@ -1,12 +0,0 @@
|
||||||
package tachiyomi.data.category
|
|
||||||
|
|
||||||
import tachiyomi.domain.category.model.Category
|
|
||||||
|
|
||||||
val categoryMapper: (Long, String, Long, Long) -> Category = { id, name, order, flags ->
|
|
||||||
Category(
|
|
||||||
id = id,
|
|
||||||
name = name,
|
|
||||||
order = order,
|
|
||||||
flags = flags,
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -12,26 +12,26 @@ class CategoryRepositoryImpl(
|
||||||
) : CategoryRepository {
|
) : CategoryRepository {
|
||||||
|
|
||||||
override suspend fun get(id: Long): Category? {
|
override suspend fun get(id: Long): Category? {
|
||||||
return handler.awaitOneOrNull { categoriesQueries.getCategory(id, categoryMapper) }
|
return handler.awaitOneOrNull { categoriesQueries.getCategory(id, ::mapCategory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getAll(): List<Category> {
|
override suspend fun getAll(): List<Category> {
|
||||||
return handler.awaitList { categoriesQueries.getCategories(categoryMapper) }
|
return handler.awaitList { categoriesQueries.getCategories(::mapCategory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllAsFlow(): Flow<List<Category>> {
|
override fun getAllAsFlow(): Flow<List<Category>> {
|
||||||
return handler.subscribeToList { categoriesQueries.getCategories(categoryMapper) }
|
return handler.subscribeToList { categoriesQueries.getCategories(::mapCategory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCategoriesByMangaId(mangaId: Long): List<Category> {
|
override suspend fun getCategoriesByMangaId(mangaId: Long): List<Category> {
|
||||||
return handler.awaitList {
|
return handler.awaitList {
|
||||||
categoriesQueries.getCategoriesByMangaId(mangaId, categoryMapper)
|
categoriesQueries.getCategoriesByMangaId(mangaId, ::mapCategory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCategoriesByMangaIdAsFlow(mangaId: Long): Flow<List<Category>> {
|
override fun getCategoriesByMangaIdAsFlow(mangaId: Long): Flow<List<Category>> {
|
||||||
return handler.subscribeToList {
|
return handler.subscribeToList {
|
||||||
categoriesQueries.getCategoriesByMangaId(mangaId, categoryMapper)
|
categoriesQueries.getCategoriesByMangaId(mangaId, ::mapCategory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,4 +81,18 @@ class CategoryRepositoryImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapCategory(
|
||||||
|
id: Long,
|
||||||
|
name: String,
|
||||||
|
order: Long,
|
||||||
|
flags: Long,
|
||||||
|
): Category {
|
||||||
|
return Category(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
order = order,
|
||||||
|
flags = flags,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package tachiyomi.data.chapter
|
|
||||||
|
|
||||||
import tachiyomi.domain.chapter.model.Chapter
|
|
||||||
|
|
||||||
val chapterMapper: (
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
String,
|
|
||||||
String,
|
|
||||||
String?,
|
|
||||||
Boolean,
|
|
||||||
Boolean,
|
|
||||||
Long,
|
|
||||||
Double,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
) -> Chapter =
|
|
||||||
{ id, mangaId, url, name, scanlator, read, bookmark, lastPageRead, chapterNumber, sourceOrder, dateFetch, dateUpload, lastModifiedAt ->
|
|
||||||
Chapter(
|
|
||||||
id = id,
|
|
||||||
mangaId = mangaId,
|
|
||||||
read = read,
|
|
||||||
bookmark = bookmark,
|
|
||||||
lastPageRead = lastPageRead,
|
|
||||||
dateFetch = dateFetch,
|
|
||||||
sourceOrder = sourceOrder,
|
|
||||||
url = url,
|
|
||||||
name = name,
|
|
||||||
dateUpload = dateUpload,
|
|
||||||
chapterNumber = chapterNumber,
|
|
||||||
scanlator = scanlator,
|
|
||||||
lastModifiedAt = lastModifiedAt,
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -77,27 +77,27 @@ class ChapterRepositoryImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getChapterByMangaId(mangaId: Long): List<Chapter> {
|
override suspend fun getChapterByMangaId(mangaId: Long): List<Chapter> {
|
||||||
return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) }
|
return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, ::mapChapter) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List<Chapter> {
|
override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List<Chapter> {
|
||||||
return handler.awaitList {
|
return handler.awaitList {
|
||||||
chaptersQueries.getBookmarkedChaptersByMangaId(
|
chaptersQueries.getBookmarkedChaptersByMangaId(
|
||||||
mangaId,
|
mangaId,
|
||||||
chapterMapper,
|
::mapChapter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getChapterById(id: Long): Chapter? {
|
override suspend fun getChapterById(id: Long): Chapter? {
|
||||||
return handler.awaitOneOrNull { chaptersQueries.getChapterById(id, chapterMapper) }
|
return handler.awaitOneOrNull { chaptersQueries.getChapterById(id, ::mapChapter) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow<List<Chapter>> {
|
override suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow<List<Chapter>> {
|
||||||
return handler.subscribeToList {
|
return handler.subscribeToList {
|
||||||
chaptersQueries.getChaptersByMangaId(
|
chaptersQueries.getChaptersByMangaId(
|
||||||
mangaId,
|
mangaId,
|
||||||
chapterMapper,
|
::mapChapter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,8 +107,38 @@ class ChapterRepositoryImpl(
|
||||||
chaptersQueries.getChapterByUrlAndMangaId(
|
chaptersQueries.getChapterByUrlAndMangaId(
|
||||||
url,
|
url,
|
||||||
mangaId,
|
mangaId,
|
||||||
chapterMapper,
|
::mapChapter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapChapter(
|
||||||
|
id: Long,
|
||||||
|
mangaId: Long,
|
||||||
|
url: String,
|
||||||
|
name: String,
|
||||||
|
scanlator: String?,
|
||||||
|
read: Boolean,
|
||||||
|
bookmark: Boolean,
|
||||||
|
lastPageRead: Long,
|
||||||
|
chapterNumber: Double,
|
||||||
|
sourceOrder: Long,
|
||||||
|
dateFetch: Long,
|
||||||
|
dateUpload: Long,
|
||||||
|
lastModifiedAt: Long,
|
||||||
|
): Chapter = Chapter(
|
||||||
|
id = id,
|
||||||
|
mangaId = mangaId,
|
||||||
|
read = read,
|
||||||
|
bookmark = bookmark,
|
||||||
|
lastPageRead = lastPageRead,
|
||||||
|
dateFetch = dateFetch,
|
||||||
|
sourceOrder = sourceOrder,
|
||||||
|
url = url,
|
||||||
|
name = name,
|
||||||
|
dateUpload = dateUpload,
|
||||||
|
chapterNumber = chapterNumber,
|
||||||
|
scanlator = scanlator,
|
||||||
|
lastModifiedAt = lastModifiedAt,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,30 +5,32 @@ import tachiyomi.domain.history.model.HistoryWithRelations
|
||||||
import tachiyomi.domain.manga.model.MangaCover
|
import tachiyomi.domain.manga.model.MangaCover
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
val historyMapper: (Long, Long, Date?, Long) -> History = { id, chapterId, readAt, readDuration ->
|
object HistoryMapper {
|
||||||
History(
|
fun mapHistory(
|
||||||
|
id: Long,
|
||||||
|
chapterId: Long,
|
||||||
|
readAt: Date?,
|
||||||
|
readDuration: Long,
|
||||||
|
): History = History(
|
||||||
id = id,
|
id = id,
|
||||||
chapterId = chapterId,
|
chapterId = chapterId,
|
||||||
readAt = readAt,
|
readAt = readAt,
|
||||||
readDuration = readDuration,
|
readDuration = readDuration,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
val historyWithRelationsMapper: (
|
fun mapHistoryWithRelations(
|
||||||
Long,
|
historyId: Long,
|
||||||
Long,
|
mangaId: Long,
|
||||||
Long,
|
chapterId: Long,
|
||||||
String,
|
title: String,
|
||||||
String?,
|
thumbnailUrl: String?,
|
||||||
Long,
|
sourceId: Long,
|
||||||
Boolean,
|
isFavorite: Boolean,
|
||||||
Long,
|
coverLastModified: Long,
|
||||||
Double,
|
chapterNumber: Double,
|
||||||
Date?,
|
readAt: Date?,
|
||||||
Long,
|
readDuration: Long,
|
||||||
) -> HistoryWithRelations = {
|
): HistoryWithRelations = HistoryWithRelations(
|
||||||
historyId, mangaId, chapterId, title, thumbnailUrl, sourceId, isFavorite, coverLastModified, chapterNumber, readAt, readDuration ->
|
|
||||||
HistoryWithRelations(
|
|
||||||
id = historyId,
|
id = historyId,
|
||||||
chapterId = chapterId,
|
chapterId = chapterId,
|
||||||
mangaId = mangaId,
|
mangaId = mangaId,
|
||||||
|
|
|
@ -15,13 +15,13 @@ class HistoryRepositoryImpl(
|
||||||
|
|
||||||
override fun getHistory(query: String): Flow<List<HistoryWithRelations>> {
|
override fun getHistory(query: String): Flow<List<HistoryWithRelations>> {
|
||||||
return handler.subscribeToList {
|
return handler.subscribeToList {
|
||||||
historyViewQueries.history(query, historyWithRelationsMapper)
|
historyViewQueries.history(query, HistoryMapper::mapHistoryWithRelations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getLastHistory(): HistoryWithRelations? {
|
override suspend fun getLastHistory(): HistoryWithRelations? {
|
||||||
return handler.awaitOneOrNull {
|
return handler.awaitOneOrNull {
|
||||||
historyViewQueries.getLatestHistory(historyWithRelationsMapper)
|
historyViewQueries.getLatestHistory(HistoryMapper::mapHistoryWithRelations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class HistoryRepositoryImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getHistoryByMangaId(mangaId: Long): List<History> {
|
override suspend fun getHistoryByMangaId(mangaId: Long): List<History> {
|
||||||
return handler.awaitList { historyQueries.getHistoryByMangaId(mangaId, historyMapper) }
|
return handler.awaitList { historyQueries.getHistoryByMangaId(mangaId, HistoryMapper::mapHistory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetHistory(historyId: Long) {
|
override suspend fun resetHistory(historyId: Long) {
|
||||||
|
|
|
@ -4,120 +4,116 @@ import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||||
import tachiyomi.domain.library.model.LibraryManga
|
import tachiyomi.domain.library.model.LibraryManga
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
|
|
||||||
val mangaMapper: (
|
object MangaMapper {
|
||||||
Long,
|
fun mapManga(
|
||||||
Long,
|
id: Long,
|
||||||
String,
|
source: Long,
|
||||||
String?,
|
url: String,
|
||||||
String?,
|
artist: String?,
|
||||||
String?,
|
author: String?,
|
||||||
List<String>?,
|
description: String?,
|
||||||
String,
|
genre: List<String>?,
|
||||||
Long,
|
title: String,
|
||||||
String?,
|
status: Long,
|
||||||
Boolean,
|
thumbnailUrl: String?,
|
||||||
Long?,
|
favorite: Boolean,
|
||||||
Long?,
|
lastUpdate: Long?,
|
||||||
Boolean,
|
nextUpdate: Long?,
|
||||||
Long,
|
initialized: Boolean,
|
||||||
Long,
|
viewerFlags: Long,
|
||||||
Long,
|
chapterFlags: Long,
|
||||||
Long,
|
coverLastModified: Long,
|
||||||
UpdateStrategy,
|
dateAdded: Long,
|
||||||
Long,
|
updateStrategy: UpdateStrategy,
|
||||||
Long,
|
calculateInterval: Long,
|
||||||
Long?,
|
lastModifiedAt: Long,
|
||||||
) -> Manga =
|
favoriteModifiedAt: Long?,
|
||||||
{ id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, calculateInterval, lastModifiedAt, favoriteModifiedAt ->
|
): Manga = Manga(
|
||||||
Manga(
|
id = id,
|
||||||
id = id,
|
source = source,
|
||||||
source = source,
|
favorite = favorite,
|
||||||
favorite = favorite,
|
lastUpdate = lastUpdate ?: 0,
|
||||||
lastUpdate = lastUpdate ?: 0,
|
nextUpdate = nextUpdate ?: 0,
|
||||||
nextUpdate = nextUpdate ?: 0,
|
fetchInterval = calculateInterval.toInt(),
|
||||||
fetchInterval = calculateInterval.toInt(),
|
dateAdded = dateAdded,
|
||||||
dateAdded = dateAdded,
|
viewerFlags = viewerFlags,
|
||||||
viewerFlags = viewerFlags,
|
chapterFlags = chapterFlags,
|
||||||
chapterFlags = chapterFlags,
|
coverLastModified = coverLastModified,
|
||||||
coverLastModified = coverLastModified,
|
url = url,
|
||||||
url = url,
|
title = title,
|
||||||
title = title,
|
artist = artist,
|
||||||
artist = artist,
|
author = author,
|
||||||
author = author,
|
description = description,
|
||||||
description = description,
|
genre = genre,
|
||||||
genre = genre,
|
status = status,
|
||||||
status = status,
|
thumbnailUrl = thumbnailUrl,
|
||||||
thumbnailUrl = thumbnailUrl,
|
updateStrategy = updateStrategy,
|
||||||
updateStrategy = updateStrategy,
|
initialized = initialized,
|
||||||
initialized = initialized,
|
lastModifiedAt = lastModifiedAt,
|
||||||
lastModifiedAt = lastModifiedAt,
|
favoriteModifiedAt = favoriteModifiedAt,
|
||||||
favoriteModifiedAt = favoriteModifiedAt,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val libraryManga: (
|
fun mapLibraryManga(
|
||||||
Long,
|
id: Long,
|
||||||
Long,
|
source: Long,
|
||||||
String,
|
url: String,
|
||||||
String?,
|
artist: String?,
|
||||||
String?,
|
author: String?,
|
||||||
String?,
|
description: String?,
|
||||||
List<String>?,
|
genre: List<String>?,
|
||||||
String,
|
title: String,
|
||||||
Long,
|
status: Long,
|
||||||
String?,
|
thumbnailUrl: String?,
|
||||||
Boolean,
|
favorite: Boolean,
|
||||||
Long?,
|
lastUpdate: Long?,
|
||||||
Long?,
|
nextUpdate: Long?,
|
||||||
Boolean,
|
initialized: Boolean,
|
||||||
Long,
|
viewerFlags: Long,
|
||||||
Long,
|
chapterFlags: Long,
|
||||||
Long,
|
coverLastModified: Long,
|
||||||
Long,
|
dateAdded: Long,
|
||||||
UpdateStrategy,
|
updateStrategy: UpdateStrategy,
|
||||||
Long,
|
calculateInterval: Long,
|
||||||
Long,
|
lastModifiedAt: Long,
|
||||||
Long?,
|
favoriteModifiedAt: Long?,
|
||||||
Long,
|
totalCount: Long,
|
||||||
Double,
|
readCount: Double,
|
||||||
Long,
|
latestUpload: Long,
|
||||||
Long,
|
chapterFetchedAt: Long,
|
||||||
Long,
|
lastRead: Long,
|
||||||
Double,
|
bookmarkCount: Double,
|
||||||
Long,
|
category: Long,
|
||||||
) -> LibraryManga =
|
): LibraryManga = LibraryManga(
|
||||||
{ id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, calculateInterval, lastModifiedAt, favoriteModifiedAt, totalCount, readCount, latestUpload, chapterFetchedAt, lastRead, bookmarkCount, category ->
|
manga = mapManga(
|
||||||
LibraryManga(
|
id,
|
||||||
manga = mangaMapper(
|
source,
|
||||||
id,
|
url,
|
||||||
source,
|
artist,
|
||||||
url,
|
author,
|
||||||
artist,
|
description,
|
||||||
author,
|
genre,
|
||||||
description,
|
title,
|
||||||
genre,
|
status,
|
||||||
title,
|
thumbnailUrl,
|
||||||
status,
|
favorite,
|
||||||
thumbnailUrl,
|
lastUpdate,
|
||||||
favorite,
|
nextUpdate,
|
||||||
lastUpdate,
|
initialized,
|
||||||
nextUpdate,
|
viewerFlags,
|
||||||
initialized,
|
chapterFlags,
|
||||||
viewerFlags,
|
coverLastModified,
|
||||||
chapterFlags,
|
dateAdded,
|
||||||
coverLastModified,
|
updateStrategy,
|
||||||
dateAdded,
|
calculateInterval,
|
||||||
updateStrategy,
|
lastModifiedAt,
|
||||||
calculateInterval,
|
favoriteModifiedAt,
|
||||||
lastModifiedAt,
|
),
|
||||||
favoriteModifiedAt,
|
category = category,
|
||||||
),
|
totalChapters = totalCount,
|
||||||
category = category,
|
readCount = readCount.toLong(),
|
||||||
totalChapters = totalCount,
|
bookmarkCount = bookmarkCount.toLong(),
|
||||||
readCount = readCount.toLong(),
|
latestUpload = latestUpload,
|
||||||
bookmarkCount = bookmarkCount.toLong(),
|
chapterFetchedAt = chapterFetchedAt,
|
||||||
latestUpload = latestUpload,
|
lastRead = lastRead,
|
||||||
chapterFetchedAt = chapterFetchedAt,
|
)
|
||||||
lastRead = lastRead,
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,11 +16,11 @@ class MangaRepositoryImpl(
|
||||||
) : MangaRepository {
|
) : MangaRepository {
|
||||||
|
|
||||||
override suspend fun getMangaById(id: Long): Manga {
|
override suspend fun getMangaById(id: Long): Manga {
|
||||||
return handler.awaitOne { mangasQueries.getMangaById(id, mangaMapper) }
|
return handler.awaitOne { mangasQueries.getMangaById(id, MangaMapper::mapManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getMangaByIdAsFlow(id: Long): Flow<Manga> {
|
override suspend fun getMangaByIdAsFlow(id: Long): Flow<Manga> {
|
||||||
return handler.subscribeToOne { mangasQueries.getMangaById(id, mangaMapper) }
|
return handler.subscribeToOne { mangasQueries.getMangaById(id, MangaMapper::mapManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getMangaByUrlAndSourceId(url: String, sourceId: Long): Manga? {
|
override suspend fun getMangaByUrlAndSourceId(url: String, sourceId: Long): Manga? {
|
||||||
|
@ -28,7 +28,7 @@ class MangaRepositoryImpl(
|
||||||
mangasQueries.getMangaByUrlAndSource(
|
mangasQueries.getMangaByUrlAndSource(
|
||||||
url,
|
url,
|
||||||
sourceId,
|
sourceId,
|
||||||
mangaMapper,
|
MangaMapper::mapManga,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,30 +38,30 @@ class MangaRepositoryImpl(
|
||||||
mangasQueries.getMangaByUrlAndSource(
|
mangasQueries.getMangaByUrlAndSource(
|
||||||
url,
|
url,
|
||||||
sourceId,
|
sourceId,
|
||||||
mangaMapper,
|
MangaMapper::mapManga,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getFavorites(): List<Manga> {
|
override suspend fun getFavorites(): List<Manga> {
|
||||||
return handler.awaitList { mangasQueries.getFavorites(mangaMapper) }
|
return handler.awaitList { mangasQueries.getFavorites(MangaMapper::mapManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getLibraryManga(): List<LibraryManga> {
|
override suspend fun getLibraryManga(): List<LibraryManga> {
|
||||||
return handler.awaitList { libraryViewQueries.library(libraryManga) }
|
return handler.awaitList { libraryViewQueries.library(MangaMapper::mapLibraryManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLibraryMangaAsFlow(): Flow<List<LibraryManga>> {
|
override fun getLibraryMangaAsFlow(): Flow<List<LibraryManga>> {
|
||||||
return handler.subscribeToList { libraryViewQueries.library(libraryManga) }
|
return handler.subscribeToList { libraryViewQueries.library(MangaMapper::mapLibraryManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFavoritesBySourceId(sourceId: Long): Flow<List<Manga>> {
|
override fun getFavoritesBySourceId(sourceId: Long): Flow<List<Manga>> {
|
||||||
return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) }
|
return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, MangaMapper::mapManga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDuplicateLibraryManga(id: Long, title: String): List<Manga> {
|
override suspend fun getDuplicateLibraryManga(id: Long, title: String): List<Manga> {
|
||||||
return handler.awaitList {
|
return handler.awaitList {
|
||||||
mangasQueries.getDuplicateLibraryManga(title, id, mangaMapper)
|
mangasQueries.getDuplicateLibraryManga(title, id, MangaMapper::mapManga)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package tachiyomi.data.source
|
|
||||||
|
|
||||||
import tachiyomi.domain.source.model.Source
|
|
||||||
import tachiyomi.domain.source.model.StubSource
|
|
||||||
|
|
||||||
val sourceMapper: (eu.kanade.tachiyomi.source.Source) -> Source = { source ->
|
|
||||||
Source(
|
|
||||||
id = source.id,
|
|
||||||
lang = source.lang,
|
|
||||||
name = source.name,
|
|
||||||
supportsLatest = false,
|
|
||||||
isStub = false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val sourceDataMapper: (Long, String, String) -> StubSource = { id, lang, name ->
|
|
||||||
StubSource(id = id, lang = lang, name = name)
|
|
||||||
}
|
|
|
@ -1,48 +1,50 @@
|
||||||
package tachiyomi.data.source
|
package tachiyomi.data.source
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import tachiyomi.data.DatabaseHandler
|
import tachiyomi.data.DatabaseHandler
|
||||||
import tachiyomi.domain.source.model.Source
|
|
||||||
import tachiyomi.domain.source.model.SourceWithCount
|
import tachiyomi.domain.source.model.SourceWithCount
|
||||||
import tachiyomi.domain.source.model.StubSource
|
import tachiyomi.domain.source.model.StubSource
|
||||||
import tachiyomi.domain.source.repository.SourcePagingSourceType
|
import tachiyomi.domain.source.repository.SourcePagingSourceType
|
||||||
import tachiyomi.domain.source.repository.SourceRepository
|
import tachiyomi.domain.source.repository.SourceRepository
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
|
import tachiyomi.domain.source.model.Source as DomainSource
|
||||||
|
|
||||||
class SourceRepositoryImpl(
|
class SourceRepositoryImpl(
|
||||||
private val sourceManager: SourceManager,
|
private val sourceManager: SourceManager,
|
||||||
private val handler: DatabaseHandler,
|
private val handler: DatabaseHandler,
|
||||||
) : SourceRepository {
|
) : SourceRepository {
|
||||||
|
|
||||||
override fun getSources(): Flow<List<Source>> {
|
override fun getSources(): Flow<List<DomainSource>> {
|
||||||
return sourceManager.catalogueSources.map { sources ->
|
return sourceManager.catalogueSources.map { sources ->
|
||||||
sources.map {
|
sources.map {
|
||||||
sourceMapper(it).copy(
|
mapSourceToDomainSource(it).copy(
|
||||||
supportsLatest = it.supportsLatest,
|
supportsLatest = it.supportsLatest,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOnlineSources(): Flow<List<Source>> {
|
override fun getOnlineSources(): Flow<List<DomainSource>> {
|
||||||
return sourceManager.catalogueSources.map { sources ->
|
return sourceManager.catalogueSources.map { sources ->
|
||||||
sources
|
sources
|
||||||
.filterIsInstance<HttpSource>()
|
.filterIsInstance<HttpSource>()
|
||||||
.map(sourceMapper)
|
.map(::mapSourceToDomainSource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSourcesWithFavoriteCount(): Flow<List<Pair<Source, Long>>> {
|
override fun getSourcesWithFavoriteCount(): Flow<List<Pair<DomainSource, Long>>> {
|
||||||
val sourceIdWithFavoriteCount = handler.subscribeToList { mangasQueries.getSourceIdWithFavoriteCount() }
|
val sourceIdWithFavoriteCount =
|
||||||
|
handler.subscribeToList { mangasQueries.getSourceIdWithFavoriteCount() }
|
||||||
return sourceIdWithFavoriteCount.map { sourceIdsWithCount ->
|
return sourceIdWithFavoriteCount.map { sourceIdsWithCount ->
|
||||||
sourceIdsWithCount
|
sourceIdsWithCount
|
||||||
.map { (sourceId, count) ->
|
.map { (sourceId, count) ->
|
||||||
val source = sourceManager.getOrStub(sourceId)
|
val source = sourceManager.getOrStub(sourceId)
|
||||||
val domainSource = sourceMapper(source).copy(
|
val domainSource = mapSourceToDomainSource(source).copy(
|
||||||
isStub = source is StubSource,
|
isStub = source is StubSource,
|
||||||
)
|
)
|
||||||
domainSource to count
|
domainSource to count
|
||||||
|
@ -51,11 +53,12 @@ class SourceRepositoryImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSourcesWithNonLibraryManga(): Flow<List<SourceWithCount>> {
|
override fun getSourcesWithNonLibraryManga(): Flow<List<SourceWithCount>> {
|
||||||
val sourceIdWithNonLibraryManga = handler.subscribeToList { mangasQueries.getSourceIdsWithNonLibraryManga() }
|
val sourceIdWithNonLibraryManga =
|
||||||
|
handler.subscribeToList { mangasQueries.getSourceIdsWithNonLibraryManga() }
|
||||||
return sourceIdWithNonLibraryManga.map { sourceId ->
|
return sourceIdWithNonLibraryManga.map { sourceId ->
|
||||||
sourceId.map { (sourceId, count) ->
|
sourceId.map { (sourceId, count) ->
|
||||||
val source = sourceManager.getOrStub(sourceId)
|
val source = sourceManager.getOrStub(sourceId)
|
||||||
val domainSource = sourceMapper(source).copy(
|
val domainSource = mapSourceToDomainSource(source).copy(
|
||||||
isStub = source is StubSource,
|
isStub = source is StubSource,
|
||||||
)
|
)
|
||||||
SourceWithCount(domainSource, count)
|
SourceWithCount(domainSource, count)
|
||||||
|
@ -81,4 +84,12 @@ class SourceRepositoryImpl(
|
||||||
val source = sourceManager.get(sourceId) as CatalogueSource
|
val source = sourceManager.get(sourceId) as CatalogueSource
|
||||||
return SourceLatestPagingSource(source)
|
return SourceLatestPagingSource(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapSourceToDomainSource(source: Source): DomainSource = DomainSource(
|
||||||
|
id = source.id,
|
||||||
|
lang = source.lang,
|
||||||
|
name = source.name,
|
||||||
|
supportsLatest = false,
|
||||||
|
isStub = false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,20 @@ class StubSourceRepositoryImpl(
|
||||||
) : StubSourceRepository {
|
) : StubSourceRepository {
|
||||||
|
|
||||||
override fun subscribeAll(): Flow<List<StubSource>> {
|
override fun subscribeAll(): Flow<List<StubSource>> {
|
||||||
return handler.subscribeToList { sourcesQueries.findAll(sourceDataMapper) }
|
return handler.subscribeToList { sourcesQueries.findAll(::mapStubSource) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getStubSource(id: Long): StubSource? {
|
override suspend fun getStubSource(id: Long): StubSource? {
|
||||||
return handler.awaitOneOrNull { sourcesQueries.findOne(id, sourceDataMapper) }
|
return handler.awaitOneOrNull { sourcesQueries.findOne(id, ::mapStubSource) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun upsertStubSource(id: Long, lang: String, name: String) {
|
override suspend fun upsertStubSource(id: Long, lang: String, name: String) {
|
||||||
handler.await { sourcesQueries.upsert(id, lang, name) }
|
handler.await { sourcesQueries.upsert(id, lang, name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapStubSource(
|
||||||
|
id: Long,
|
||||||
|
lang: String,
|
||||||
|
name: String,
|
||||||
|
): StubSource = StubSource(id = id, lang = lang, name = name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package tachiyomi.data.track
|
|
||||||
|
|
||||||
import tachiyomi.domain.track.model.Track
|
|
||||||
|
|
||||||
val trackMapper: (
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long?,
|
|
||||||
String,
|
|
||||||
Double,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Double,
|
|
||||||
String,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
) -> Track =
|
|
||||||
{ id, mangaId, syncId, remoteId, libraryId, title, lastChapterRead, totalChapters, status, score, remoteUrl, startDate, finishDate ->
|
|
||||||
Track(
|
|
||||||
id = id,
|
|
||||||
mangaId = mangaId,
|
|
||||||
syncId = syncId,
|
|
||||||
remoteId = remoteId,
|
|
||||||
libraryId = libraryId,
|
|
||||||
title = title,
|
|
||||||
lastChapterRead = lastChapterRead,
|
|
||||||
totalChapters = totalChapters,
|
|
||||||
status = status,
|
|
||||||
score = score,
|
|
||||||
remoteUrl = remoteUrl,
|
|
||||||
startDate = startDate,
|
|
||||||
finishDate = finishDate,
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -10,24 +10,24 @@ class TrackRepositoryImpl(
|
||||||
) : TrackRepository {
|
) : TrackRepository {
|
||||||
|
|
||||||
override suspend fun getTrackById(id: Long): Track? {
|
override suspend fun getTrackById(id: Long): Track? {
|
||||||
return handler.awaitOneOrNull { manga_syncQueries.getTrackById(id, trackMapper) }
|
return handler.awaitOneOrNull { manga_syncQueries.getTrackById(id, ::mapTrack) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getTracksByMangaId(mangaId: Long): List<Track> {
|
override suspend fun getTracksByMangaId(mangaId: Long): List<Track> {
|
||||||
return handler.awaitList {
|
return handler.awaitList {
|
||||||
manga_syncQueries.getTracksByMangaId(mangaId, trackMapper)
|
manga_syncQueries.getTracksByMangaId(mangaId, ::mapTrack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTracksAsFlow(): Flow<List<Track>> {
|
override fun getTracksAsFlow(): Flow<List<Track>> {
|
||||||
return handler.subscribeToList {
|
return handler.subscribeToList {
|
||||||
manga_syncQueries.getTracks(trackMapper)
|
manga_syncQueries.getTracks(::mapTrack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTracksByMangaIdAsFlow(mangaId: Long): Flow<List<Track>> {
|
override fun getTracksByMangaIdAsFlow(mangaId: Long): Flow<List<Track>> {
|
||||||
return handler.subscribeToList {
|
return handler.subscribeToList {
|
||||||
manga_syncQueries.getTracksByMangaId(mangaId, trackMapper)
|
manga_syncQueries.getTracksByMangaId(mangaId, ::mapTrack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,4 +68,34 @@ class TrackRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapTrack(
|
||||||
|
id: Long,
|
||||||
|
mangaId: Long,
|
||||||
|
syncId: Long,
|
||||||
|
remoteId: Long,
|
||||||
|
libraryId: Long?,
|
||||||
|
title: String,
|
||||||
|
lastChapterRead: Double,
|
||||||
|
totalChapters: Long,
|
||||||
|
status: Long,
|
||||||
|
score: Double,
|
||||||
|
remoteUrl: String,
|
||||||
|
startDate: Long,
|
||||||
|
finishDate: Long,
|
||||||
|
): Track = Track(
|
||||||
|
id = id,
|
||||||
|
mangaId = mangaId,
|
||||||
|
syncId = syncId,
|
||||||
|
remoteId = remoteId,
|
||||||
|
libraryId = libraryId,
|
||||||
|
title = title,
|
||||||
|
lastChapterRead = lastChapterRead,
|
||||||
|
totalChapters = totalChapters,
|
||||||
|
status = status,
|
||||||
|
score = score,
|
||||||
|
remoteUrl = remoteUrl,
|
||||||
|
startDate = startDate,
|
||||||
|
finishDate = finishDate,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
package tachiyomi.data.updates
|
|
||||||
|
|
||||||
import tachiyomi.domain.manga.model.MangaCover
|
|
||||||
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
|
||||||
|
|
||||||
val updateWithRelationMapper: (
|
|
||||||
Long,
|
|
||||||
String,
|
|
||||||
Long,
|
|
||||||
String,
|
|
||||||
String?,
|
|
||||||
Boolean,
|
|
||||||
Boolean,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Boolean,
|
|
||||||
String?,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
Long,
|
|
||||||
) -> UpdatesWithRelations = {
|
|
||||||
mangaId, mangaTitle, chapterId, chapterName, scanlator, read, bookmark, lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, _, dateFetch ->
|
|
||||||
UpdatesWithRelations(
|
|
||||||
mangaId = mangaId,
|
|
||||||
mangaTitle = mangaTitle,
|
|
||||||
chapterId = chapterId,
|
|
||||||
chapterName = chapterName,
|
|
||||||
scanlator = scanlator,
|
|
||||||
read = read,
|
|
||||||
bookmark = bookmark,
|
|
||||||
lastPageRead = lastPageRead,
|
|
||||||
sourceId = sourceId,
|
|
||||||
dateFetch = dateFetch,
|
|
||||||
coverData = MangaCover(
|
|
||||||
mangaId = mangaId,
|
|
||||||
sourceId = sourceId,
|
|
||||||
isMangaFavorite = favorite,
|
|
||||||
url = thumbnailUrl,
|
|
||||||
lastModified = coverLastModified,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -2,6 +2,7 @@ package tachiyomi.data.updates
|
||||||
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import tachiyomi.data.DatabaseHandler
|
import tachiyomi.data.DatabaseHandler
|
||||||
|
import tachiyomi.domain.manga.model.MangaCover
|
||||||
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
||||||
import tachiyomi.domain.updates.repository.UpdatesRepository
|
import tachiyomi.domain.updates.repository.UpdatesRepository
|
||||||
|
|
||||||
|
@ -19,14 +20,14 @@ class UpdatesRepositoryImpl(
|
||||||
read = read,
|
read = read,
|
||||||
after = after,
|
after = after,
|
||||||
limit = limit,
|
limit = limit,
|
||||||
mapper = updateWithRelationMapper,
|
mapper = ::mapUpdatesWithRelations,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>> {
|
override fun subscribeAll(after: Long, limit: Long): Flow<List<UpdatesWithRelations>> {
|
||||||
return databaseHandler.subscribeToList {
|
return databaseHandler.subscribeToList {
|
||||||
updatesViewQueries.getRecentUpdates(after, limit, updateWithRelationMapper)
|
updatesViewQueries.getRecentUpdates(after, limit, ::mapUpdatesWithRelations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +41,43 @@ class UpdatesRepositoryImpl(
|
||||||
read = read,
|
read = read,
|
||||||
after = after,
|
after = after,
|
||||||
limit = limit,
|
limit = limit,
|
||||||
mapper = updateWithRelationMapper,
|
mapper = ::mapUpdatesWithRelations,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mapUpdatesWithRelations(
|
||||||
|
mangaId: Long,
|
||||||
|
mangaTitle: String,
|
||||||
|
chapterId: Long,
|
||||||
|
chapterName: String,
|
||||||
|
scanlator: String?,
|
||||||
|
read: Boolean,
|
||||||
|
bookmark: Boolean,
|
||||||
|
lastPageRead: Long,
|
||||||
|
sourceId: Long,
|
||||||
|
favorite: Boolean,
|
||||||
|
thumbnailUrl: String?,
|
||||||
|
coverLastModified: Long,
|
||||||
|
dateUpload: Long,
|
||||||
|
dateFetch: Long,
|
||||||
|
): UpdatesWithRelations = UpdatesWithRelations(
|
||||||
|
mangaId = mangaId,
|
||||||
|
mangaTitle = mangaTitle,
|
||||||
|
chapterId = chapterId,
|
||||||
|
chapterName = chapterName,
|
||||||
|
scanlator = scanlator,
|
||||||
|
read = read,
|
||||||
|
bookmark = bookmark,
|
||||||
|
lastPageRead = lastPageRead,
|
||||||
|
sourceId = sourceId,
|
||||||
|
dateFetch = dateFetch,
|
||||||
|
coverData = MangaCover(
|
||||||
|
mangaId = mangaId,
|
||||||
|
sourceId = sourceId,
|
||||||
|
isMangaFavorite = favorite,
|
||||||
|
url = thumbnailUrl,
|
||||||
|
lastModified = coverLastModified,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue