From 15423bfc8476179dff20ed49e5aa92a5387061ff Mon Sep 17 00:00:00 2001 From: Caleb Morris Date: Sat, 21 Oct 2023 18:42:09 -0700 Subject: [PATCH] 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 --- .../tachiyomi/data/category/CategoryMapper.kt | 12 - .../data/category/CategoryRepositoryImpl.kt | 24 +- .../tachiyomi/data/chapter/ChapterMapper.kt | 36 --- .../data/chapter/ChapterRepositoryImpl.kt | 40 ++- .../tachiyomi/data/history/HistoryMapper.kt | 38 +-- .../data/history/HistoryRepositoryImpl.kt | 6 +- .../java/tachiyomi/data/manga/MangaMapper.kt | 228 +++++++++--------- .../data/manga/MangaRepositoryImpl.kt | 18 +- .../tachiyomi/data/source/SourceMapper.kt | 18 -- .../data/source/SourceRepositoryImpl.kt | 31 ++- .../data/source/StubSourceRepositoryImpl.kt | 10 +- .../java/tachiyomi/data/track/TrackMapper.kt | 36 --- .../data/track/TrackRepositoryImpl.kt | 38 ++- .../tachiyomi/data/updates/UpdatesMapper.kt | 42 ---- .../data/updates/UpdatesRepositoryImpl.kt | 42 +++- 15 files changed, 300 insertions(+), 319 deletions(-) delete mode 100644 data/src/main/java/tachiyomi/data/category/CategoryMapper.kt delete mode 100644 data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt delete mode 100644 data/src/main/java/tachiyomi/data/source/SourceMapper.kt delete mode 100644 data/src/main/java/tachiyomi/data/track/TrackMapper.kt delete mode 100644 data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt diff --git a/data/src/main/java/tachiyomi/data/category/CategoryMapper.kt b/data/src/main/java/tachiyomi/data/category/CategoryMapper.kt deleted file mode 100644 index 37f18ae808..0000000000 --- a/data/src/main/java/tachiyomi/data/category/CategoryMapper.kt +++ /dev/null @@ -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, - ) -} diff --git a/data/src/main/java/tachiyomi/data/category/CategoryRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/category/CategoryRepositoryImpl.kt index 75cfbf7d17..bf379978e4 100644 --- a/data/src/main/java/tachiyomi/data/category/CategoryRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/category/CategoryRepositoryImpl.kt @@ -12,26 +12,26 @@ class CategoryRepositoryImpl( ) : CategoryRepository { 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 { - return handler.awaitList { categoriesQueries.getCategories(categoryMapper) } + return handler.awaitList { categoriesQueries.getCategories(::mapCategory) } } override fun getAllAsFlow(): Flow> { - return handler.subscribeToList { categoriesQueries.getCategories(categoryMapper) } + return handler.subscribeToList { categoriesQueries.getCategories(::mapCategory) } } override suspend fun getCategoriesByMangaId(mangaId: Long): List { return handler.awaitList { - categoriesQueries.getCategoriesByMangaId(mangaId, categoryMapper) + categoriesQueries.getCategoriesByMangaId(mangaId, ::mapCategory) } } override fun getCategoriesByMangaIdAsFlow(mangaId: Long): Flow> { 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, + ) + } } diff --git a/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt b/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt deleted file mode 100644 index c8243682fa..0000000000 --- a/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt +++ /dev/null @@ -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, - ) - } diff --git a/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt index 594a592ac4..1249c8967a 100644 --- a/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt @@ -77,27 +77,27 @@ class ChapterRepositoryImpl( } override suspend fun getChapterByMangaId(mangaId: Long): List { - return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) } + return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, ::mapChapter) } } override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List { return handler.awaitList { chaptersQueries.getBookmarkedChaptersByMangaId( mangaId, - chapterMapper, + ::mapChapter, ) } } 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> { return handler.subscribeToList { chaptersQueries.getChaptersByMangaId( mangaId, - chapterMapper, + ::mapChapter, ) } } @@ -107,8 +107,38 @@ class ChapterRepositoryImpl( chaptersQueries.getChapterByUrlAndMangaId( url, 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, + ) } diff --git a/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt b/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt index 134a1c91cb..709c5800d8 100644 --- a/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt +++ b/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt @@ -5,30 +5,32 @@ import tachiyomi.domain.history.model.HistoryWithRelations import tachiyomi.domain.manga.model.MangaCover import java.util.Date -val historyMapper: (Long, Long, Date?, Long) -> History = { id, chapterId, readAt, readDuration -> - History( +object HistoryMapper { + fun mapHistory( + id: Long, + chapterId: Long, + readAt: Date?, + readDuration: Long, + ): History = History( id = id, chapterId = chapterId, readAt = readAt, readDuration = readDuration, ) -} -val historyWithRelationsMapper: ( - Long, - Long, - Long, - String, - String?, - Long, - Boolean, - Long, - Double, - Date?, - Long, -) -> HistoryWithRelations = { - historyId, mangaId, chapterId, title, thumbnailUrl, sourceId, isFavorite, coverLastModified, chapterNumber, readAt, readDuration -> - HistoryWithRelations( + fun mapHistoryWithRelations( + historyId: Long, + mangaId: Long, + chapterId: Long, + title: String, + thumbnailUrl: String?, + sourceId: Long, + isFavorite: Boolean, + coverLastModified: Long, + chapterNumber: Double, + readAt: Date?, + readDuration: Long, + ): HistoryWithRelations = HistoryWithRelations( id = historyId, chapterId = chapterId, mangaId = mangaId, diff --git a/data/src/main/java/tachiyomi/data/history/HistoryRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/history/HistoryRepositoryImpl.kt index 7f349afc2c..103a0995be 100644 --- a/data/src/main/java/tachiyomi/data/history/HistoryRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/history/HistoryRepositoryImpl.kt @@ -15,13 +15,13 @@ class HistoryRepositoryImpl( override fun getHistory(query: String): Flow> { return handler.subscribeToList { - historyViewQueries.history(query, historyWithRelationsMapper) + historyViewQueries.history(query, HistoryMapper::mapHistoryWithRelations) } } override suspend fun getLastHistory(): HistoryWithRelations? { return handler.awaitOneOrNull { - historyViewQueries.getLatestHistory(historyWithRelationsMapper) + historyViewQueries.getLatestHistory(HistoryMapper::mapHistoryWithRelations) } } @@ -30,7 +30,7 @@ class HistoryRepositoryImpl( } override suspend fun getHistoryByMangaId(mangaId: Long): List { - return handler.awaitList { historyQueries.getHistoryByMangaId(mangaId, historyMapper) } + return handler.awaitList { historyQueries.getHistoryByMangaId(mangaId, HistoryMapper::mapHistory) } } override suspend fun resetHistory(historyId: Long) { diff --git a/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt b/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt index 43bb1ed0c5..d9937b2858 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt @@ -4,120 +4,116 @@ import eu.kanade.tachiyomi.source.model.UpdateStrategy import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.manga.model.Manga -val mangaMapper: ( - Long, - Long, - String, - String?, - String?, - String?, - List?, - String, - Long, - String?, - Boolean, - Long?, - Long?, - Boolean, - Long, - Long, - Long, - Long, - UpdateStrategy, - Long, - Long, - Long?, -) -> Manga = - { id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, calculateInterval, lastModifiedAt, favoriteModifiedAt -> - Manga( - id = id, - source = source, - favorite = favorite, - lastUpdate = lastUpdate ?: 0, - nextUpdate = nextUpdate ?: 0, - fetchInterval = calculateInterval.toInt(), - dateAdded = dateAdded, - viewerFlags = viewerFlags, - chapterFlags = chapterFlags, - coverLastModified = coverLastModified, - url = url, - title = title, - artist = artist, - author = author, - description = description, - genre = genre, - status = status, - thumbnailUrl = thumbnailUrl, - updateStrategy = updateStrategy, - initialized = initialized, - lastModifiedAt = lastModifiedAt, - favoriteModifiedAt = favoriteModifiedAt, - ) - } +object MangaMapper { + fun mapManga( + id: Long, + source: Long, + url: String, + artist: String?, + author: String?, + description: String?, + genre: List?, + title: String, + status: Long, + thumbnailUrl: String?, + favorite: Boolean, + lastUpdate: Long?, + nextUpdate: Long?, + initialized: Boolean, + viewerFlags: Long, + chapterFlags: Long, + coverLastModified: Long, + dateAdded: Long, + updateStrategy: UpdateStrategy, + calculateInterval: Long, + lastModifiedAt: Long, + favoriteModifiedAt: Long?, + ): Manga = Manga( + id = id, + source = source, + favorite = favorite, + lastUpdate = lastUpdate ?: 0, + nextUpdate = nextUpdate ?: 0, + fetchInterval = calculateInterval.toInt(), + dateAdded = dateAdded, + viewerFlags = viewerFlags, + chapterFlags = chapterFlags, + coverLastModified = coverLastModified, + url = url, + title = title, + artist = artist, + author = author, + description = description, + genre = genre, + status = status, + thumbnailUrl = thumbnailUrl, + updateStrategy = updateStrategy, + initialized = initialized, + lastModifiedAt = lastModifiedAt, + favoriteModifiedAt = favoriteModifiedAt, + ) -val libraryManga: ( - Long, - Long, - String, - String?, - String?, - String?, - List?, - String, - Long, - String?, - Boolean, - Long?, - Long?, - Boolean, - Long, - Long, - Long, - Long, - UpdateStrategy, - Long, - Long, - Long?, - Long, - Double, - Long, - Long, - Long, - Double, - Long, -) -> 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 -> - LibraryManga( - manga = mangaMapper( - id, - source, - url, - artist, - author, - description, - genre, - title, - status, - thumbnailUrl, - favorite, - lastUpdate, - nextUpdate, - initialized, - viewerFlags, - chapterFlags, - coverLastModified, - dateAdded, - updateStrategy, - calculateInterval, - lastModifiedAt, - favoriteModifiedAt, - ), - category = category, - totalChapters = totalCount, - readCount = readCount.toLong(), - bookmarkCount = bookmarkCount.toLong(), - latestUpload = latestUpload, - chapterFetchedAt = chapterFetchedAt, - lastRead = lastRead, - ) - } + fun mapLibraryManga( + id: Long, + source: Long, + url: String, + artist: String?, + author: String?, + description: String?, + genre: List?, + title: String, + status: Long, + thumbnailUrl: String?, + favorite: Boolean, + lastUpdate: Long?, + nextUpdate: Long?, + initialized: Boolean, + viewerFlags: Long, + chapterFlags: Long, + coverLastModified: Long, + dateAdded: Long, + updateStrategy: UpdateStrategy, + calculateInterval: Long, + lastModifiedAt: Long, + favoriteModifiedAt: Long?, + totalCount: Long, + readCount: Double, + latestUpload: Long, + chapterFetchedAt: Long, + lastRead: Long, + bookmarkCount: Double, + category: Long, + ): LibraryManga = LibraryManga( + manga = mapManga( + id, + source, + url, + artist, + author, + description, + genre, + title, + status, + thumbnailUrl, + favorite, + lastUpdate, + nextUpdate, + initialized, + viewerFlags, + chapterFlags, + coverLastModified, + dateAdded, + updateStrategy, + calculateInterval, + lastModifiedAt, + favoriteModifiedAt, + ), + category = category, + totalChapters = totalCount, + readCount = readCount.toLong(), + bookmarkCount = bookmarkCount.toLong(), + latestUpload = latestUpload, + chapterFetchedAt = chapterFetchedAt, + lastRead = lastRead, + ) +} diff --git a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt index 39bbcb99f7..5d8364f319 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt @@ -16,11 +16,11 @@ class MangaRepositoryImpl( ) : MangaRepository { 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 { - return handler.subscribeToOne { mangasQueries.getMangaById(id, mangaMapper) } + return handler.subscribeToOne { mangasQueries.getMangaById(id, MangaMapper::mapManga) } } override suspend fun getMangaByUrlAndSourceId(url: String, sourceId: Long): Manga? { @@ -28,7 +28,7 @@ class MangaRepositoryImpl( mangasQueries.getMangaByUrlAndSource( url, sourceId, - mangaMapper, + MangaMapper::mapManga, ) } } @@ -38,30 +38,30 @@ class MangaRepositoryImpl( mangasQueries.getMangaByUrlAndSource( url, sourceId, - mangaMapper, + MangaMapper::mapManga, ) } } override suspend fun getFavorites(): List { - return handler.awaitList { mangasQueries.getFavorites(mangaMapper) } + return handler.awaitList { mangasQueries.getFavorites(MangaMapper::mapManga) } } override suspend fun getLibraryManga(): List { - return handler.awaitList { libraryViewQueries.library(libraryManga) } + return handler.awaitList { libraryViewQueries.library(MangaMapper::mapLibraryManga) } } override fun getLibraryMangaAsFlow(): Flow> { - return handler.subscribeToList { libraryViewQueries.library(libraryManga) } + return handler.subscribeToList { libraryViewQueries.library(MangaMapper::mapLibraryManga) } } override fun getFavoritesBySourceId(sourceId: Long): Flow> { - return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) } + return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, MangaMapper::mapManga) } } override suspend fun getDuplicateLibraryManga(id: Long, title: String): List { return handler.awaitList { - mangasQueries.getDuplicateLibraryManga(title, id, mangaMapper) + mangasQueries.getDuplicateLibraryManga(title, id, MangaMapper::mapManga) } } diff --git a/data/src/main/java/tachiyomi/data/source/SourceMapper.kt b/data/src/main/java/tachiyomi/data/source/SourceMapper.kt deleted file mode 100644 index 8b598152e0..0000000000 --- a/data/src/main/java/tachiyomi/data/source/SourceMapper.kt +++ /dev/null @@ -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) -} diff --git a/data/src/main/java/tachiyomi/data/source/SourceRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/source/SourceRepositoryImpl.kt index c5f1ee6086..e8cf8f43c1 100644 --- a/data/src/main/java/tachiyomi/data/source/SourceRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/source/SourceRepositoryImpl.kt @@ -1,48 +1,50 @@ package tachiyomi.data.source import eu.kanade.tachiyomi.source.CatalogueSource +import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.online.HttpSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import tachiyomi.data.DatabaseHandler -import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.model.SourceWithCount import tachiyomi.domain.source.model.StubSource import tachiyomi.domain.source.repository.SourcePagingSourceType import tachiyomi.domain.source.repository.SourceRepository import tachiyomi.domain.source.service.SourceManager +import tachiyomi.domain.source.model.Source as DomainSource class SourceRepositoryImpl( private val sourceManager: SourceManager, private val handler: DatabaseHandler, ) : SourceRepository { - override fun getSources(): Flow> { + override fun getSources(): Flow> { return sourceManager.catalogueSources.map { sources -> sources.map { - sourceMapper(it).copy( + mapSourceToDomainSource(it).copy( supportsLatest = it.supportsLatest, ) } } } - override fun getOnlineSources(): Flow> { + override fun getOnlineSources(): Flow> { return sourceManager.catalogueSources.map { sources -> sources .filterIsInstance() - .map(sourceMapper) + .map(::mapSourceToDomainSource) } } - override fun getSourcesWithFavoriteCount(): Flow>> { - val sourceIdWithFavoriteCount = handler.subscribeToList { mangasQueries.getSourceIdWithFavoriteCount() } + override fun getSourcesWithFavoriteCount(): Flow>> { + val sourceIdWithFavoriteCount = + handler.subscribeToList { mangasQueries.getSourceIdWithFavoriteCount() } return sourceIdWithFavoriteCount.map { sourceIdsWithCount -> sourceIdsWithCount .map { (sourceId, count) -> val source = sourceManager.getOrStub(sourceId) - val domainSource = sourceMapper(source).copy( + val domainSource = mapSourceToDomainSource(source).copy( isStub = source is StubSource, ) domainSource to count @@ -51,11 +53,12 @@ class SourceRepositoryImpl( } override fun getSourcesWithNonLibraryManga(): Flow> { - val sourceIdWithNonLibraryManga = handler.subscribeToList { mangasQueries.getSourceIdsWithNonLibraryManga() } + val sourceIdWithNonLibraryManga = + handler.subscribeToList { mangasQueries.getSourceIdsWithNonLibraryManga() } return sourceIdWithNonLibraryManga.map { sourceId -> sourceId.map { (sourceId, count) -> val source = sourceManager.getOrStub(sourceId) - val domainSource = sourceMapper(source).copy( + val domainSource = mapSourceToDomainSource(source).copy( isStub = source is StubSource, ) SourceWithCount(domainSource, count) @@ -81,4 +84,12 @@ class SourceRepositoryImpl( val source = sourceManager.get(sourceId) as CatalogueSource return SourceLatestPagingSource(source) } + + private fun mapSourceToDomainSource(source: Source): DomainSource = DomainSource( + id = source.id, + lang = source.lang, + name = source.name, + supportsLatest = false, + isStub = false, + ) } diff --git a/data/src/main/java/tachiyomi/data/source/StubSourceRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/source/StubSourceRepositoryImpl.kt index 9dd0681391..157e1eb2f1 100644 --- a/data/src/main/java/tachiyomi/data/source/StubSourceRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/source/StubSourceRepositoryImpl.kt @@ -10,14 +10,20 @@ class StubSourceRepositoryImpl( ) : StubSourceRepository { override fun subscribeAll(): Flow> { - return handler.subscribeToList { sourcesQueries.findAll(sourceDataMapper) } + return handler.subscribeToList { sourcesQueries.findAll(::mapStubSource) } } 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) { handler.await { sourcesQueries.upsert(id, lang, name) } } + + private fun mapStubSource( + id: Long, + lang: String, + name: String, + ): StubSource = StubSource(id = id, lang = lang, name = name) } diff --git a/data/src/main/java/tachiyomi/data/track/TrackMapper.kt b/data/src/main/java/tachiyomi/data/track/TrackMapper.kt deleted file mode 100644 index a4a9714f6a..0000000000 --- a/data/src/main/java/tachiyomi/data/track/TrackMapper.kt +++ /dev/null @@ -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, - ) - } diff --git a/data/src/main/java/tachiyomi/data/track/TrackRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/track/TrackRepositoryImpl.kt index 0643c5c301..1966a013bc 100644 --- a/data/src/main/java/tachiyomi/data/track/TrackRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/track/TrackRepositoryImpl.kt @@ -10,24 +10,24 @@ class TrackRepositoryImpl( ) : TrackRepository { 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 { return handler.awaitList { - manga_syncQueries.getTracksByMangaId(mangaId, trackMapper) + manga_syncQueries.getTracksByMangaId(mangaId, ::mapTrack) } } override fun getTracksAsFlow(): Flow> { return handler.subscribeToList { - manga_syncQueries.getTracks(trackMapper) + manga_syncQueries.getTracks(::mapTrack) } } override fun getTracksByMangaIdAsFlow(mangaId: Long): Flow> { 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, + ) } diff --git a/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt b/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt deleted file mode 100644 index 56e9743a9f..0000000000 --- a/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt +++ /dev/null @@ -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, - ), - ) -} diff --git a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt index b50aee4be9..0af6bcd50c 100644 --- a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt @@ -2,6 +2,7 @@ package tachiyomi.data.updates import kotlinx.coroutines.flow.Flow import tachiyomi.data.DatabaseHandler +import tachiyomi.domain.manga.model.MangaCover import tachiyomi.domain.updates.model.UpdatesWithRelations import tachiyomi.domain.updates.repository.UpdatesRepository @@ -19,14 +20,14 @@ class UpdatesRepositoryImpl( read = read, after = after, limit = limit, - mapper = updateWithRelationMapper, + mapper = ::mapUpdatesWithRelations, ) } } override fun subscribeAll(after: Long, limit: Long): Flow> { return databaseHandler.subscribeToList { - updatesViewQueries.getRecentUpdates(after, limit, updateWithRelationMapper) + updatesViewQueries.getRecentUpdates(after, limit, ::mapUpdatesWithRelations) } } @@ -40,8 +41,43 @@ class UpdatesRepositoryImpl( read = read, after = after, 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, + ), + ) }