From 2bafc6789578a0ad64c278c3ae5982cb5c368529 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 18 Nov 2019 15:10:45 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/data/AppDatabase.kt | 4 ++-- .../io/legado/app/data/entities/SearchBook.kt | 16 +++++++++++----- .../java/io/legado/app/help/storage/Restore.kt | 9 --------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 3d4549de3..41aaa31a9 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.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() diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index acca6db8f..59ae54492 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -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 = "", diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index cc18a7238..afd464688 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -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)