feat: 优化

pull/209/head
kunfei 5 years ago
parent 89d45b80a1
commit 043f8fbe0f
  1. 28
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 2
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt

@ -19,7 +19,7 @@ import kotlinx.coroutines.launch
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class],
version = 11,
version = 12,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {
@ -31,7 +31,16 @@ abstract class AppDatabase : RoomDatabase() {
fun createDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.fallbackToDestructiveMigration()
.addMigrations(object : Migration(10, 11) {
.addMigrations(migration_10_11, migration_11_12)
.addCallback(object : Callback() {
override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
GlobalScope.launch { Restore.restoreDatabase(Backup.backupPath) }
}
})
.build()
}
private val migration_10_11 = object : Migration(10, 11) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE txtTocRules")
database.execSQL(
@ -42,13 +51,16 @@ abstract class AppDatabase : RoomDatabase() {
"""
)
}
})
.addCallback(object : Callback() {
override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
GlobalScope.launch { Restore.restoreDatabase(Backup.backupPath) }
}
})
.build()
private val migration_11_12 = object : Migration(11, 12) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"""
ALTER TABLE rssSources ADD css TEXT
"""
)
}
}
}

@ -34,9 +34,11 @@ data class RssSource(
var ruleImage: String? = null,
var ruleLink: String? = null,
var ruleContent: String? = null,
var css: String? = null,
var header: String? = null,
var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false,
var customOrder: Int = 0
) : Parcelable, JsExtensions {

@ -16,6 +16,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help
@ -42,8 +43,8 @@ class ReadAloudConfigDialog : DialogFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = LinearLayout(context)
view.setBackgroundResource(R.color.background)
val view = LinearLayout(requireContext())
view.setBackgroundColor(requireContext().backgroundColor)
view.id = R.id.tag1
container?.addView(view)
return view

Loading…
Cancel
Save