From b2caeedafa46060f1ed6601afc4c4d4534df88bb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 21 Nov 2019 20:38:42 +0800 Subject: [PATCH] up --- .../app/ui/config/WebDavConfigFragment.kt | 33 +++++++++++++++++++ .../io/legado/app/ui/main/MainActivity.kt | 33 +++---------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index cbea0803b..104bf4326 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -7,12 +7,23 @@ import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import io.legado.app.App import io.legado.app.R +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { @@ -86,8 +97,30 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference when (preference?.key) { "web_dav_backup" -> Backup.backup() "web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) + "import_old" -> importOld() } return super.onPreferenceTreeClick(preference) } + private fun importOld() { + Coroutine.async { + if (withContext(Dispatchers.IO) { App.db.bookDao().allBookCount == 0 }) { + alert(title = "导入") { + message = "是否导入旧版本数据" + yesButton { + PermissionsCompat.Builder(this@WebDavConfigFragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Restore.importYueDuData(requireContext()) + } + .request() + } + noButton { + } + }.show().applyTint() + } + } + } + } \ No newline at end of file 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 0440dde8e..adbd87842 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 @@ -14,22 +14,17 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.help.ActivityHelp -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup -import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.ui.main.bookshelf.BookshelfFragment import io.legado.app.ui.main.explore.ExploreFragment import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.rss.RssFragment -import io.legado.app.utils.* +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.getViewModel +import io.legado.app.utils.observeEvent +import io.legado.app.utils.putPrefInt import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -60,26 +55,6 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), return false } - private fun restore() { - - launch { - if (withContext(IO) { App.db.bookDao().allBookCount == 0 }) { - alert(title = "导入") { - message = "是否导入旧版本数据" - yesButton { - PermissionsCompat.Builder(this@MainActivity) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { viewModel.importYueDuData() } - .request() - } - noButton { - } - }.show().applyTint() - } - } - } - private fun upVersion() { if (getPrefInt("versionCode") != App.INSTANCE.versionCode) { putPrefInt("versionCode", App.INSTANCE.versionCode)