pull/49/head
kunfei 5 years ago
parent 4b974aa962
commit 2bafc67895
  1. 4
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 16
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  3. 9
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -7,7 +7,7 @@ import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.data.dao.*
import io.legado.app.data.entities.*
import io.legado.app.utils.putPrefBoolean
import io.legado.app.help.storage.Restore
@Database(
@ -26,7 +26,7 @@ abstract class AppDatabase : RoomDatabase() {
.fallbackToDestructiveMigration()
.addCallback(object : Callback() {
override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
context.putPrefBoolean("dbChange", true)
Restore.restore()
}
})
.build()

@ -1,17 +1,23 @@
package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import androidx.room.*
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "searchBooks", indices = [(Index(value = ["bookUrl"], unique = true))])
@Entity(
tableName = "searchBooks",
indices = [(Index(value = ["bookUrl"], unique = true))],
foreignKeys = [(ForeignKey(
entity = BookSource::class,
parentColumns = ["bookSourceUrl"],
childColumns = ["origin"],
onDelete = ForeignKey.CASCADE
))]
)
data class SearchBook(
@PrimaryKey
var bookUrl: String = "",

@ -143,11 +143,6 @@ object Restore {
Log.d(AppConst.APP_TAG, "Added ${book.name}")
}
App.db.bookDao().insert(*books.toTypedArray())
val count = books.size
uiThread {
context.toast(if (count > 0) "成功地导入 $count 本新书和音频" else "没有发现新书或音频")
}
}
} catch (e: Exception) {
Log.e(AppConst.APP_TAG, "Failed to import book shelf.", e)
@ -194,10 +189,6 @@ object Restore {
replaceRules.add(rule)
}
App.db.replaceRuleDao().insert(*replaceRules.toTypedArray())
val count = replaceRules.size
uiThread {
context.toast(if (count > 0) "成功地导入 $count 条净化替换规则" else "没有发现新的净化替换规则")
}
}
} catch (e: Exception) {
Log.e(AppConst.APP_TAG, e.localizedMessage)

Loading…
Cancel
Save