Tweak db migration, cleanup code
Keep the time field in DownloadInfo for future sort by start / complete time function
This commit is contained in:
1 parent
5c33ca1c9a
commit
f38f3989e7
8 files changed
+45
-525
No files matched your search
@@ -2,6 +2,7 @@ package com.hippo.ehviewer.dao
|
||||
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.DeleteColumn
|
||||
import androidx.room.DeleteTable
|
||||
import androidx.room.RenameColumn
|
||||
import androidx.room.RoomDatabase
|
||||
@@ -19,24 +20,18 @@ class HistoryMigration : AutoMigrationSpec {
|
||||
}
|
||||
}
|
||||
|
||||
class QuickSearchMigration : AutoMigrationSpec {
|
||||
class AddPositionColumn : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("UPDATE QUICK_SEARCH SET POSITION = (SELECT COUNT(*) FROM QUICK_SEARCH T WHERE T.TIME < QUICK_SEARCH.TIME)")
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadLabelMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("UPDATE DOWNLOAD_LABELS SET POSITION = (SELECT COUNT(*) FROM DOWNLOAD_LABELS T WHERE T.TIME < DOWNLOAD_LABELS.TIME)")
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("UPDATE DOWNLOADS SET POSITION = (SELECT COUNT(*) FROM DOWNLOADS T WHERE T.TIME < DOWNLOADS.TIME)")
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteColumn(tableName = "QUICK_SEARCH", columnName = "TIME")
|
||||
@DeleteColumn(tableName = "DOWNLOAD_LABELS", columnName = "TIME")
|
||||
class DropTimeColumn : AutoMigrationSpec
|
||||
|
||||
class ThumbKeyMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
val needMigrationTables = arrayOf(
|
||||
@@ -59,7 +54,7 @@ class ThumbKeyMigration : AutoMigrationSpec {
|
||||
|
||||
@Database(
|
||||
entities = [DownloadInfo::class, DownloadLabel::class, DownloadDirname::class, Filter::class, HistoryInfo::class, LocalFavoriteInfo::class, QuickSearch::class],
|
||||
version = 13,
|
||||
version = 12,
|
||||
exportSchema = true,
|
||||
autoMigrations = [
|
||||
AutoMigration(
|
||||
@@ -92,17 +87,12 @@ class ThumbKeyMigration : AutoMigrationSpec {
|
||||
AutoMigration(
|
||||
from = 10,
|
||||
to = 11,
|
||||
spec = QuickSearchMigration::class,
|
||||
spec = AddPositionColumn::class,
|
||||
),
|
||||
AutoMigration(
|
||||
from = 11,
|
||||
to = 12,
|
||||
spec = DownloadLabelMigration::class,
|
||||
),
|
||||
AutoMigration(
|
||||
from = 12,
|
||||
to = 13,
|
||||
spec = DownloadMigration::class,
|
||||
spec = DropTimeColumn::class,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ class DownloadInfo() : BaseGalleryInfo() {
|
||||
@ColumnInfo(name = "LABEL")
|
||||
var label: String? = null
|
||||
|
||||
@ColumnInfo(name = "POSITION", defaultValue = "0")
|
||||
@ColumnInfo(name = "POSITION")
|
||||
var position: Int = 0
|
||||
|
||||
@Ignore
|
||||
|
||||
@@ -3,17 +3,13 @@ package com.hippo.ehviewer.dao
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.time.Instant
|
||||
|
||||
@Entity(tableName = "DOWNLOAD_LABELS")
|
||||
data class DownloadLabel(
|
||||
@ColumnInfo(name = "LABEL")
|
||||
var label: String,
|
||||
|
||||
@ColumnInfo(name = "TIME")
|
||||
var time: Long = Instant.now().toEpochMilli(),
|
||||
|
||||
@ColumnInfo(name = "POSITION", defaultValue = "0")
|
||||
@ColumnInfo(name = "POSITION")
|
||||
var position: Int,
|
||||
|
||||
@PrimaryKey
|
||||
|
||||
@@ -34,9 +34,6 @@ data class QuickSearch(
|
||||
@ColumnInfo(name = "PAGE_TO")
|
||||
var pageTo: Int = 0,
|
||||
|
||||
@ColumnInfo(name = "TIME")
|
||||
var time: Long = 0,
|
||||
|
||||
@ColumnInfo(name = "POSITION", defaultValue = "0")
|
||||
@ColumnInfo(name = "POSITION")
|
||||
var position: Int = 0,
|
||||
)
|
||||
@@ -84,7 +84,7 @@ object DownloadManager : OnSpiderListener {
|
||||
it.key?.let { label ->
|
||||
if (!containLabel(label)) {
|
||||
// Add non existing label to DB and list
|
||||
labelList.add(EhDB.addDownloadLabel(DownloadLabel(label, position = labelList.size)))
|
||||
labelList.add(EhDB.addDownloadLabel(DownloadLabel(label, labelList.size)))
|
||||
}
|
||||
}
|
||||
it.key to LinkedList(it.value)
|
||||
@@ -677,7 +677,7 @@ object DownloadManager : OnSpiderListener {
|
||||
if (label == null || containLabel(label)) {
|
||||
return
|
||||
}
|
||||
labelList.add(EhDB.addDownloadLabel(DownloadLabel(label, position = labelList.size)))
|
||||
labelList.add(EhDB.addDownloadLabel(DownloadLabel(label, labelList.size)))
|
||||
map[label] = LinkedList()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user