Migrate History screen database calls to SQLDelight (#6933)
* Migrate History screen database call to SQLDelight - Move all migrations to SQLDelight - Move all tables to SQLDelight Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com> * Changes from review comments * Add adapters to database * Remove logging of database version in App * Change query name for paging source queries * Update migrations * Make SQLite Callback handle migration - To ensure it updates the database * Use SQLDelight Schema version for Callback database version Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>
This commit is contained in:
@@ -3,18 +3,17 @@ package eu.kanade.domain.history.interactor
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import eu.kanade.data.history.local.HistoryPagingSource
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
import eu.kanade.domain.history.repository.HistoryRepository
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class GetHistory(
|
||||
private val repository: HistoryRepository
|
||||
) {
|
||||
|
||||
fun subscribe(query: String): Flow<PagingData<MangaChapterHistory>> {
|
||||
fun subscribe(query: String): Flow<PagingData<HistoryWithRelations>> {
|
||||
return Pager(
|
||||
PagingConfig(pageSize = HistoryPagingSource.PAGE_SIZE)
|
||||
PagingConfig(pageSize = 25)
|
||||
) {
|
||||
repository.getHistory(query)
|
||||
}.flow
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package eu.kanade.domain.history.interactor
|
||||
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.domain.history.repository.HistoryRepository
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
||||
class GetNextChapterForManga(
|
||||
private val repository: HistoryRepository
|
||||
) {
|
||||
|
||||
suspend fun await(manga: Manga, chapter: Chapter): Chapter? {
|
||||
return repository.getNextChapterForManga(manga, chapter)
|
||||
suspend fun await(mangaId: Long, chapterId: Long): Chapter? {
|
||||
return repository.getNextChapterForManga(mangaId, chapterId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
package eu.kanade.domain.history.interactor
|
||||
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
import eu.kanade.domain.history.repository.HistoryRepository
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.HistoryImpl
|
||||
|
||||
class RemoveHistoryById(
|
||||
private val repository: HistoryRepository
|
||||
) {
|
||||
|
||||
suspend fun await(history: History): Boolean {
|
||||
// Workaround for list not freaking out when changing reference varaible
|
||||
val history = HistoryImpl().apply {
|
||||
id = history.id
|
||||
chapter_id = history.chapter_id
|
||||
last_read = history.last_read
|
||||
time_read = history.time_read
|
||||
}
|
||||
return repository.resetHistory(history)
|
||||
suspend fun await(history: HistoryWithRelations) {
|
||||
repository.resetHistory(history.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ class RemoveHistoryByMangaId(
|
||||
private val repository: HistoryRepository
|
||||
) {
|
||||
|
||||
suspend fun await(mangaId: Long): Boolean {
|
||||
return repository.resetHistoryByMangaId(mangaId)
|
||||
suspend fun await(mangaId: Long) {
|
||||
repository.resetHistoryByMangaId(mangaId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package eu.kanade.domain.history.model
|
||||
|
||||
import java.util.*
|
||||
|
||||
data class History(
|
||||
val id: Long?,
|
||||
val chapterId: Long,
|
||||
val readAt: Date?
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.domain.history.model
|
||||
|
||||
import java.util.*
|
||||
|
||||
data class HistoryWithRelations(
|
||||
val id: Long,
|
||||
val chapterId: Long,
|
||||
val mangaId: Long,
|
||||
val title: String,
|
||||
val thumbnailUrl: String,
|
||||
val chapterNumber: Float,
|
||||
val readAt: Date?
|
||||
)
|
||||
@@ -1,22 +1,18 @@
|
||||
package eu.kanade.domain.history.repository
|
||||
|
||||
import eu.kanade.data.history.local.HistoryPagingSource
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import androidx.paging.PagingSource
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
|
||||
interface HistoryRepository {
|
||||
|
||||
fun getHistory(query: String): HistoryPagingSource
|
||||
fun getHistory(query: String): PagingSource<Long, HistoryWithRelations>
|
||||
|
||||
suspend fun getHistory(limit: Int, page: Int, query: String): List<MangaChapterHistory>
|
||||
suspend fun getNextChapterForManga(mangaId: Long, chapterId: Long): Chapter?
|
||||
|
||||
suspend fun getNextChapterForManga(manga: Manga, chapter: Chapter): Chapter?
|
||||
suspend fun resetHistory(historyId: Long)
|
||||
|
||||
suspend fun resetHistory(history: History): Boolean
|
||||
|
||||
suspend fun resetHistoryByMangaId(mangaId: Long): Boolean
|
||||
suspend fun resetHistoryByMangaId(mangaId: Long)
|
||||
|
||||
suspend fun deleteAllHistory(): Boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user