mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(db): Replace deleteHistoryNoLastRead
StorIO with SQLDelight eqv
This commit is contained in:
parent
f14118a8c1
commit
a199ff326d
4 changed files with 43 additions and 44 deletions
|
@ -1,6 +1,5 @@
|
|||
package eu.kanade.tachiyomi.data.database.queries
|
||||
|
||||
import com.pushtorefresh.storio.sqlite.queries.DeleteQuery
|
||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||
import eu.kanade.tachiyomi.data.database.DbProvider
|
||||
import eu.kanade.tachiyomi.data.database.inTransactionReturn
|
||||
|
@ -105,13 +104,4 @@ interface HistoryQueries : DbProvider {
|
|||
.prepare()
|
||||
}
|
||||
|
||||
fun deleteHistoryNoLastRead() = db.delete()
|
||||
.byQuery(
|
||||
DeleteQuery.builder()
|
||||
.table(HistoryTable.TABLE)
|
||||
.where("${HistoryTable.COL_LAST_READ} = ?")
|
||||
.whereArgs(0)
|
||||
.build(),
|
||||
)
|
||||
.prepare()
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ import eu.kanade.tachiyomi.util.view.activityBinding
|
|||
import eu.kanade.tachiyomi.util.view.fullAppBarHeight
|
||||
import eu.kanade.tachiyomi.util.view.scrollViewWith
|
||||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import android.R as AR
|
||||
|
||||
class ClearDatabaseController :
|
||||
|
|
|
@ -3,15 +3,19 @@ package eu.kanade.tachiyomi.ui.setting.controllers.database
|
|||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BaseCoroutinePresenter
|
||||
import eu.kanade.tachiyomi.util.system.launchIO
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.withUIContext
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.data.DatabaseHandler
|
||||
|
||||
class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>() {
|
||||
|
||||
private val db = Injekt.get<DatabaseHelper>()
|
||||
|
||||
private val handler = Injekt.get<DatabaseHandler>()
|
||||
|
||||
private val sourceManager = Injekt.get<SourceManager>()
|
||||
|
||||
var sortBy = SortSources.ALPHA
|
||||
|
@ -26,26 +30,31 @@ class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>()
|
|||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
presenterScope.launchUI {
|
||||
getDatabaseSources()
|
||||
}
|
||||
}
|
||||
|
||||
fun clearDatabaseForSourceIds(sources: List<Long>, keepReadManga: Boolean) {
|
||||
presenterScope.launchIO {
|
||||
if (keepReadManga) {
|
||||
db.deleteMangasNotInLibraryAndNotReadBySourceIds(sources).executeAsBlocking()
|
||||
} else {
|
||||
db.deleteMangasNotInLibraryBySourceIds(sources).executeAsBlocking()
|
||||
}
|
||||
db.deleteHistoryNoLastRead().executeAsBlocking()
|
||||
handler.await { historyQueries.deleteAllUnread() }
|
||||
getDatabaseSources()
|
||||
}
|
||||
}
|
||||
|
||||
fun reorder(sortBy: SortSources) {
|
||||
this.sortBy = sortBy
|
||||
presenterScope.launchUI {
|
||||
getDatabaseSources()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDatabaseSources() {
|
||||
presenterScope.launchUI {
|
||||
private suspend fun getDatabaseSources() = withUIContext {
|
||||
hasStubSources = false
|
||||
val sources = db.getSourceIdsWithNonLibraryManga().executeAsBlocking()
|
||||
.map {
|
||||
|
@ -64,9 +73,6 @@ class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>()
|
|||
{ it.source.name },
|
||||
),
|
||||
)
|
||||
withUIContext {
|
||||
view?.setItems(sources)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ SELECT last_insert_rowid();
|
|||
deleteAll:
|
||||
DELETE FROM history;
|
||||
|
||||
deleteAllUnread:
|
||||
DELETE FROM history WHERE history_last_read = 0;
|
||||
|
||||
getByMangaId:
|
||||
SELECT history.*
|
||||
FROM history
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue