mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 04:28:55 +01:00
Reader: Save reading progress with SQLDelight (#7185)
* Use SQLDelight in reader to update history * Move chapter progress to sqldelight * Review Changes Co-Authored-By: inorichi <len@kanade.eu> * Review Changes 2 Co-authored-by: FourTOne5 <59261191+FourTOne5@users.noreply.github.com> Co-authored-by: inorichi <len@kanade.eu>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package eu.kanade.domain
|
||||
|
||||
import eu.kanade.data.chapter.ChapterRepositoryImpl
|
||||
import eu.kanade.data.history.HistoryRepositoryImpl
|
||||
import eu.kanade.data.manga.MangaRepositoryImpl
|
||||
import eu.kanade.data.source.SourceRepositoryImpl
|
||||
import eu.kanade.domain.chapter.interactor.UpdateChapter
|
||||
import eu.kanade.domain.chapter.repository.ChapterRepository
|
||||
import eu.kanade.domain.extension.interactor.GetExtensionLanguages
|
||||
import eu.kanade.domain.extension.interactor.GetExtensionSources
|
||||
import eu.kanade.domain.extension.interactor.GetExtensionUpdates
|
||||
@@ -12,6 +15,7 @@ import eu.kanade.domain.history.interactor.GetHistory
|
||||
import eu.kanade.domain.history.interactor.GetNextChapterForManga
|
||||
import eu.kanade.domain.history.interactor.RemoveHistoryById
|
||||
import eu.kanade.domain.history.interactor.RemoveHistoryByMangaId
|
||||
import eu.kanade.domain.history.interactor.UpsertHistory
|
||||
import eu.kanade.domain.history.repository.HistoryRepository
|
||||
import eu.kanade.domain.manga.interactor.GetFavoritesBySourceId
|
||||
import eu.kanade.domain.manga.interactor.ResetViewerFlags
|
||||
@@ -38,9 +42,13 @@ class DomainModule : InjektModule {
|
||||
addFactory { GetNextChapterForManga(get()) }
|
||||
addFactory { ResetViewerFlags(get()) }
|
||||
|
||||
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
||||
addFactory { UpdateChapter(get()) }
|
||||
|
||||
addSingletonFactory<HistoryRepository> { HistoryRepositoryImpl(get()) }
|
||||
addFactory { DeleteHistoryTable(get()) }
|
||||
addFactory { GetHistory(get()) }
|
||||
addFactory { UpsertHistory(get()) }
|
||||
addFactory { RemoveHistoryById(get()) }
|
||||
addFactory { RemoveHistoryByMangaId(get()) }
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.domain.chapter.interactor
|
||||
|
||||
import eu.kanade.domain.chapter.model.ChapterUpdate
|
||||
import eu.kanade.domain.chapter.repository.ChapterRepository
|
||||
|
||||
class UpdateChapter(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(chapterUpdate: ChapterUpdate) {
|
||||
chapterRepository.update(chapterUpdate)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.kanade.domain.chapter.model
|
||||
|
||||
data class ChapterUpdate(
|
||||
val id: Long,
|
||||
val mangaId: Long? = null,
|
||||
val read: Boolean? = null,
|
||||
val bookmark: Boolean? = null,
|
||||
val lastPageRead: Long? = null,
|
||||
val dateFetch: Long? = null,
|
||||
val sourceOrder: Long? = null,
|
||||
val url: String? = null,
|
||||
val name: String? = null,
|
||||
val dateUpload: Long? = null,
|
||||
val chapterNumber: Float? = null,
|
||||
val scanlator: String? = null,
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.kanade.domain.chapter.repository
|
||||
|
||||
import eu.kanade.domain.chapter.model.ChapterUpdate
|
||||
|
||||
interface ChapterRepository {
|
||||
|
||||
suspend fun update(chapterUpdate: ChapterUpdate)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.domain.history.interactor
|
||||
|
||||
import eu.kanade.domain.history.model.HistoryUpdate
|
||||
import eu.kanade.domain.history.repository.HistoryRepository
|
||||
|
||||
class UpsertHistory(
|
||||
private val historyRepository: HistoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(historyUpdate: HistoryUpdate) {
|
||||
historyRepository.upsertHistory(historyUpdate)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ package eu.kanade.domain.history.model
|
||||
import java.util.Date
|
||||
|
||||
data class History(
|
||||
val id: Long?,
|
||||
val id: Long,
|
||||
val chapterId: Long,
|
||||
val readAt: Date?,
|
||||
val readDuration: Long,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package eu.kanade.domain.history.model
|
||||
|
||||
import java.util.Date
|
||||
|
||||
data class HistoryUpdate(
|
||||
val chapterId: Long,
|
||||
val readAt: Date,
|
||||
val sessionReadDuration: Long,
|
||||
)
|
||||
@@ -10,4 +10,5 @@ data class HistoryWithRelations(
|
||||
val thumbnailUrl: String,
|
||||
val chapterNumber: Float,
|
||||
val readAt: Date?,
|
||||
val readDuration: Long,
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.kanade.domain.history.repository
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.domain.history.model.HistoryUpdate
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
|
||||
interface HistoryRepository {
|
||||
@@ -15,4 +16,6 @@ interface HistoryRepository {
|
||||
suspend fun resetHistoryByMangaId(mangaId: Long)
|
||||
|
||||
suspend fun deleteAllHistory(): Boolean
|
||||
|
||||
suspend fun upsertHistory(historyUpdate: HistoryUpdate)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user