From e5c03a068b39c3cfbf3919d3d2910cfbcbc48bdd Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 21 Nov 2019 17:37:44 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 4 ++-- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 4 +--- 2 files changed, 3 insertions(+), 5 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 3b897d794..cab698fbd 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -20,14 +20,14 @@ import io.legado.app.help.storage.Restore abstract class AppDatabase : RoomDatabase() { companion object { - var DestructiveMigration = false + private const val DATABASE_NAME = "legado.db" + fun createDatabase(context: Context): AppDatabase { return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) .fallbackToDestructiveMigration() .addCallback(object : Callback() { override fun onDestructiveMigration(db: SupportSQLiteDatabase) { - DestructiveMigration = true Restore.restore() } }) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 71c159377..0440dde8e 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -13,7 +13,6 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus -import io.legado.app.data.AppDatabase import io.legado.app.help.ActivityHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -48,7 +47,6 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) view_pager_main.addOnPageChangeListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this) - restore() upVersion() } @@ -63,7 +61,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } private fun restore() { - if (AppDatabase.DestructiveMigration) return + launch { if (withContext(IO) { App.db.bookDao().allBookCount == 0 }) { alert(title = "导入") {