From 66ff502e1f6f5e4af63a0156b35af54ca008a0ac Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 19:27:45 +0800 Subject: [PATCH] up --- .../app/ui/config/WebDavConfigFragment.kt | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 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 9eb761712..2cb612578 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 @@ -1,5 +1,6 @@ package io.legado.app.ui.config +import android.content.Intent import android.os.Build import android.os.Bundle import android.text.InputType @@ -26,6 +27,8 @@ import io.legado.app.utils.getPrefString class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { + private val oldDataRequestCode = 23156 + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { fun bindPreferenceSummaryToValue(preference: Preference?) { preference?.apply { @@ -105,7 +108,18 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference WebDavHelp.showRestoreDialog(requireContext()) } .request() - "import_old" -> needInstallApps { + "import_old" -> importOldData() + } + return super.onPreferenceTreeClick(preference) + } + + private fun importOldData() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, oldDataRequestCode) + } catch (e: Exception) { + needInstallApps { alert(title = "导入") { message = "是否导入旧版本数据" yesButton { @@ -122,7 +136,6 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference }.show().applyTint() } } - return super.onPreferenceTreeClick(preference) } private fun needInstallApps(callback: () -> Unit) { @@ -147,4 +160,13 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference callback() } } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + oldDataRequestCode -> { + + } + } + } } \ No newline at end of file