This commit is contained in:
kunfei
2022-03-12 09:10:37 +08:00
parent 79795da135
commit db9630304b
3 changed files with 30 additions and 14 deletions
@@ -1,6 +1,8 @@
package io.legado.app.data
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
@@ -9,6 +11,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.constant.AppConst
import io.legado.app.data.dao.*
import io.legado.app.data.entities.*
import io.legado.app.help.DefaultData
import splitties.init.appCtx
import java.util.*
@@ -94,6 +97,23 @@ abstract class AppDatabase : RoomDatabase() {
db.execSQL("update rssSources set loginUi = null where loginUi = 'null'")
db.execSQL("update httpTTS set loginUi = null where loginUi = 'null'")
db.execSQL("update httpTTS set concurrentRate = '0' where loginUi is null")
db.query("select * from keyboardAssists order by serialNo").use {
if (it.count == 0) {
DefaultData.keyboardAssists.forEach { keyboardAssist ->
val contentValues = ContentValues().apply {
put("type", keyboardAssist.type)
put("key", keyboardAssist.key)
put("value", keyboardAssist.value)
put("serialNo", keyboardAssist.serialNo)
}
db.insert(
"keyboardAssists",
SQLiteDatabase.CONFLICT_REPLACE,
contentValues
)
}
}
}
}
}
@@ -2,25 +2,24 @@ package io.legado.app.data.dao
import androidx.room.*
import io.legado.app.data.entities.KeyboardAssist
import io.legado.app.help.DefaultData
import kotlinx.coroutines.flow.Flow
@Dao
interface KeyboardAssistsDao {
@get:Query("select * from keyboardAssists")
@get:Query("select * from keyboardAssists order by serialNo")
val all: List<KeyboardAssist>
@Query("select * from keyboardAssists where type = :type")
@Query("select * from keyboardAssists where type = :type order by serialNo")
fun getByType(type: Int): List<KeyboardAssist>
@get:Query("select * from keyboardAssists")
@get:Query("select * from keyboardAssists order by serialNo")
val flowAll: Flow<List<KeyboardAssist>>
@Query("select * from keyboardAssists where type = :type")
@Query("select * from keyboardAssists where type = :type order by serialNo")
fun flowByType(type: Int): Flow<List<KeyboardAssist>>
@get:Query("select max(serialNo) from keyboardAssists")
@get:Query("select max(serialNo) from keyboardAssists order by serialNo")
val maxSerialNo: Int
@Insert(onConflict = OnConflictStrategy.REPLACE)
@@ -32,11 +31,4 @@ interface KeyboardAssistsDao {
@Delete
fun delete(vararg keyboardAssist: KeyboardAssist)
fun getOrDefault(): List<KeyboardAssist> {
return all.ifEmpty {
insert(*DefaultData.keyboardAssists.toTypedArray())
DefaultData.keyboardAssists
}
}
}
@@ -1,8 +1,12 @@
package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(tableName = "keyboardAssists", primaryKeys = ["type", "key"])
data class KeyboardAssist(
@ColumnInfo(defaultValue = "0")
@@ -13,4 +17,4 @@ data class KeyboardAssist(
var value: String,
@ColumnInfo(defaultValue = "0")
var serialNo: Int = 0
)
) : Parcelable