pull/1705/head 3.22.031209
kunfei 3 years ago
parent 0db277bdfc
commit 424ce68c77
  1. 20
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 18
      app/src/main/java/io/legado/app/data/dao/KeyboardAssistsDao.kt
  3. 6
      app/src/main/java/io/legado/app/data/entities/KeyboardAssist.kt

@ -1,6 +1,8 @@
package io.legado.app.data package io.legado.app.data
import android.content.ContentValues
import android.content.Context import android.content.Context
import android.database.sqlite.SQLiteDatabase
import androidx.room.AutoMigration import androidx.room.AutoMigration
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
@ -9,6 +11,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.dao.* import io.legado.app.data.dao.*
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.DefaultData
import splitties.init.appCtx import splitties.init.appCtx
import java.util.* import java.util.*
@ -94,6 +97,23 @@ abstract class AppDatabase : RoomDatabase() {
db.execSQL("update rssSources set loginUi = null where loginUi = 'null'") 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 loginUi = null where loginUi = 'null'")
db.execSQL("update httpTTS set concurrentRate = '0' where loginUi is 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 androidx.room.*
import io.legado.app.data.entities.KeyboardAssist import io.legado.app.data.entities.KeyboardAssist
import io.legado.app.help.DefaultData
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@Dao @Dao
interface KeyboardAssistsDao { interface KeyboardAssistsDao {
@get:Query("select * from keyboardAssists") @get:Query("select * from keyboardAssists order by serialNo")
val all: List<KeyboardAssist> 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> fun getByType(type: Int): List<KeyboardAssist>
@get:Query("select * from keyboardAssists") @get:Query("select * from keyboardAssists order by serialNo")
val flowAll: Flow<List<KeyboardAssist>> 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>> 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 val maxSerialNo: Int
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
@ -32,11 +31,4 @@ interface KeyboardAssistsDao {
@Delete @Delete
fun delete(vararg keyboardAssist: KeyboardAssist) 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 package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(tableName = "keyboardAssists", primaryKeys = ["type", "key"]) @Entity(tableName = "keyboardAssists", primaryKeys = ["type", "key"])
data class KeyboardAssist( data class KeyboardAssist(
@ColumnInfo(defaultValue = "0") @ColumnInfo(defaultValue = "0")
@ -13,4 +17,4 @@ data class KeyboardAssist(
var value: String, var value: String,
@ColumnInfo(defaultValue = "0") @ColumnInfo(defaultValue = "0")
var serialNo: Int = 0 var serialNo: Int = 0
) ) : Parcelable
Loading…
Cancel
Save