mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 21:18:56 +01:00
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:
@@ -35,6 +35,7 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import dev.chrisbanes.insetter.applyInsetter
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.SelectableAdapter
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
@@ -118,6 +119,8 @@ class MangaController :
|
||||
DownloadCustomChaptersDialog.Listener,
|
||||
DeleteChaptersDialog.Listener {
|
||||
|
||||
constructor(history: HistoryWithRelations) : this(history.mangaId)
|
||||
|
||||
constructor(manga: Manga?, fromSource: Boolean = false) : super(
|
||||
bundleOf(
|
||||
MANGA_EXTRA to (manga?.id ?: 0),
|
||||
|
||||
@@ -6,9 +6,9 @@ import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.presentation.history.HistoryScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.databinding.ComposeControllerBinding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||
@@ -44,16 +44,16 @@ class HistoryController :
|
||||
HistoryScreen(
|
||||
composeView = binding.root,
|
||||
presenter = presenter,
|
||||
onClickItem = { (manga, _, _) ->
|
||||
router.pushController(MangaController(manga).withFadeTransaction())
|
||||
onClickItem = { history ->
|
||||
router.pushController(MangaController(history).withFadeTransaction())
|
||||
},
|
||||
onClickResume = { (manga, chapter, _) ->
|
||||
presenter.getNextChapterForManga(manga, chapter)
|
||||
onClickResume = { history ->
|
||||
presenter.getNextChapterForManga(history.mangaId, history.chapterId)
|
||||
},
|
||||
onClickDelete = { (manga, _, history), all ->
|
||||
onClickDelete = { history, all ->
|
||||
if (all) {
|
||||
// Reset last read of chapter to 0L
|
||||
presenter.removeAllFromHistory(manga.id!!)
|
||||
presenter.removeAllFromHistory(history.mangaId)
|
||||
} else {
|
||||
// Remove all chapters belonging to manga from library
|
||||
presenter.removeFromHistory(history)
|
||||
@@ -97,7 +97,7 @@ class HistoryController :
|
||||
fun openChapter(chapter: Chapter?) {
|
||||
val activity = activity ?: return
|
||||
if (chapter != null) {
|
||||
val intent = ReaderActivity.newIntent(activity, chapter.manga_id, chapter.id)
|
||||
val intent = ReaderActivity.newIntent(activity, chapter.mangaId, chapter.id)
|
||||
startActivity(intent)
|
||||
} else {
|
||||
activity.toast(R.string.no_next_chapter)
|
||||
|
||||
@@ -10,11 +10,8 @@ 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.model.HistoryWithRelations
|
||||
import eu.kanade.tachiyomi.R
|
||||
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 eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
@@ -58,20 +55,13 @@ class HistoryPresenter(
|
||||
.map { pagingData ->
|
||||
pagingData
|
||||
.map {
|
||||
UiModel.History(it)
|
||||
UiModel.Item(it)
|
||||
}
|
||||
.insertSeparators { before, after ->
|
||||
val beforeDate =
|
||||
before?.item?.history?.last_read?.toDateKey()
|
||||
val afterDate =
|
||||
after?.item?.history?.last_read?.toDateKey()
|
||||
val beforeDate = before?.item?.readAt?.time?.toDateKey() ?: Date(0)
|
||||
val afterDate = after?.item?.readAt?.time?.toDateKey() ?: Date(0)
|
||||
when {
|
||||
beforeDate == null && afterDate != null -> UiModel.Header(
|
||||
afterDate,
|
||||
)
|
||||
beforeDate != null && afterDate != null -> UiModel.Header(
|
||||
afterDate,
|
||||
)
|
||||
beforeDate.time != afterDate.time && afterDate.time != 0L -> UiModel.Header(afterDate)
|
||||
// Return null to avoid adding a separator between two items.
|
||||
else -> null
|
||||
}
|
||||
@@ -90,7 +80,7 @@ class HistoryPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun removeFromHistory(history: History) {
|
||||
fun removeFromHistory(history: HistoryWithRelations) {
|
||||
presenterScope.launchIO {
|
||||
removeHistoryById.await(history)
|
||||
}
|
||||
@@ -102,9 +92,9 @@ class HistoryPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun getNextChapterForManga(manga: Manga, chapter: Chapter) {
|
||||
fun getNextChapterForManga(mangaId: Long, chapterId: Long) {
|
||||
presenterScope.launchIO {
|
||||
val chapter = getNextChapterForManga.await(manga, chapter)
|
||||
val chapter = getNextChapterForManga.await(mangaId, chapterId)
|
||||
view?.openChapter(chapter)
|
||||
}
|
||||
}
|
||||
@@ -121,7 +111,7 @@ class HistoryPresenter(
|
||||
}
|
||||
|
||||
sealed class UiModel {
|
||||
data class History(val item: MangaChapterHistory) : UiModel()
|
||||
data class Item(val item: HistoryWithRelations) : UiModel()
|
||||
data class Header(val date: Date) : UiModel()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.setting.database
|
||||
|
||||
import android.os.Bundle
|
||||
import eu.kanade.tachiyomi.Database
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
@@ -13,6 +14,7 @@ import uy.kohesive.injekt.api.get
|
||||
class ClearDatabasePresenter : BasePresenter<ClearDatabaseController>() {
|
||||
|
||||
private val db = Injekt.get<DatabaseHelper>()
|
||||
private val database = Injekt.get<Database>()
|
||||
|
||||
private val sourceManager = Injekt.get<SourceManager>()
|
||||
|
||||
@@ -26,7 +28,7 @@ class ClearDatabasePresenter : BasePresenter<ClearDatabaseController>() {
|
||||
|
||||
fun clearDatabaseForSourceIds(sources: List<Long>) {
|
||||
db.deleteMangasNotInLibraryBySourceIds(sources).executeAsBlocking()
|
||||
db.deleteHistoryNoLastRead().executeAsBlocking()
|
||||
database.historyQueries.removeResettedHistory()
|
||||
}
|
||||
|
||||
private fun getDatabaseSourcesObservable(): Observable<List<ClearDatabaseSourceItem>> {
|
||||
|
||||
Reference in New Issue
Block a user