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 = "导入") {