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
|
package eu.kanade.tachiyomi.data.database.queries
|
||||||
|
|
||||||
import com.pushtorefresh.storio.sqlite.queries.DeleteQuery
|
|
||||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||||
import eu.kanade.tachiyomi.data.database.DbProvider
|
import eu.kanade.tachiyomi.data.database.DbProvider
|
||||||
import eu.kanade.tachiyomi.data.database.inTransactionReturn
|
import eu.kanade.tachiyomi.data.database.inTransactionReturn
|
||||||
|
@ -105,13 +104,4 @@ interface HistoryQueries : DbProvider {
|
||||||
.prepare()
|
.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.fullAppBarHeight
|
||||||
import eu.kanade.tachiyomi.util.view.scrollViewWith
|
import eu.kanade.tachiyomi.util.view.scrollViewWith
|
||||||
import eu.kanade.tachiyomi.util.view.snack
|
import eu.kanade.tachiyomi.util.view.snack
|
||||||
import yokai.i18n.MR
|
|
||||||
import yokai.util.lang.getString
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import yokai.i18n.MR
|
||||||
|
import yokai.util.lang.getString
|
||||||
import android.R as AR
|
import android.R as AR
|
||||||
|
|
||||||
class ClearDatabaseController :
|
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.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BaseCoroutinePresenter
|
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.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.withUIContext
|
import eu.kanade.tachiyomi.util.system.withUIContext
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import yokai.data.DatabaseHandler
|
||||||
|
|
||||||
class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>() {
|
class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>() {
|
||||||
|
|
||||||
private val db = Injekt.get<DatabaseHelper>()
|
private val db = Injekt.get<DatabaseHelper>()
|
||||||
|
|
||||||
|
private val handler = Injekt.get<DatabaseHandler>()
|
||||||
|
|
||||||
private val sourceManager = Injekt.get<SourceManager>()
|
private val sourceManager = Injekt.get<SourceManager>()
|
||||||
|
|
||||||
var sortBy = SortSources.ALPHA
|
var sortBy = SortSources.ALPHA
|
||||||
|
@ -26,26 +30,31 @@ class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>()
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
presenterScope.launchUI {
|
||||||
getDatabaseSources()
|
getDatabaseSources()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun clearDatabaseForSourceIds(sources: List<Long>, keepReadManga: Boolean) {
|
fun clearDatabaseForSourceIds(sources: List<Long>, keepReadManga: Boolean) {
|
||||||
|
presenterScope.launchIO {
|
||||||
if (keepReadManga) {
|
if (keepReadManga) {
|
||||||
db.deleteMangasNotInLibraryAndNotReadBySourceIds(sources).executeAsBlocking()
|
db.deleteMangasNotInLibraryAndNotReadBySourceIds(sources).executeAsBlocking()
|
||||||
} else {
|
} else {
|
||||||
db.deleteMangasNotInLibraryBySourceIds(sources).executeAsBlocking()
|
db.deleteMangasNotInLibraryBySourceIds(sources).executeAsBlocking()
|
||||||
}
|
}
|
||||||
db.deleteHistoryNoLastRead().executeAsBlocking()
|
handler.await { historyQueries.deleteAllUnread() }
|
||||||
getDatabaseSources()
|
getDatabaseSources()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun reorder(sortBy: SortSources) {
|
fun reorder(sortBy: SortSources) {
|
||||||
this.sortBy = sortBy
|
this.sortBy = sortBy
|
||||||
|
presenterScope.launchUI {
|
||||||
getDatabaseSources()
|
getDatabaseSources()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getDatabaseSources() {
|
private suspend fun getDatabaseSources() = withUIContext {
|
||||||
presenterScope.launchUI {
|
|
||||||
hasStubSources = false
|
hasStubSources = false
|
||||||
val sources = db.getSourceIdsWithNonLibraryManga().executeAsBlocking()
|
val sources = db.getSourceIdsWithNonLibraryManga().executeAsBlocking()
|
||||||
.map {
|
.map {
|
||||||
|
@ -64,9 +73,6 @@ class ClearDatabasePresenter : BaseCoroutinePresenter<ClearDatabaseController>()
|
||||||
{ it.source.name },
|
{ it.source.name },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
withUIContext {
|
|
||||||
view?.setItems(sources)
|
view?.setItems(sources)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ SELECT last_insert_rowid();
|
||||||
deleteAll:
|
deleteAll:
|
||||||
DELETE FROM history;
|
DELETE FROM history;
|
||||||
|
|
||||||
|
deleteAllUnread:
|
||||||
|
DELETE FROM history WHERE history_last_read = 0;
|
||||||
|
|
||||||
getByMangaId:
|
getByMangaId:
|
||||||
SELECT history.*
|
SELECT history.*
|
||||||
FROM history
|
FROM history
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue