pull/66/head
kunfei 5 years ago
parent dadce9f8a7
commit 66ff502e1f
  1. 26
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt

@ -1,5 +1,6 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType
@ -26,6 +27,8 @@ import io.legado.app.utils.getPrefString
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
private val oldDataRequestCode = 23156
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
fun bindPreferenceSummaryToValue(preference: Preference?) { fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.apply { preference?.apply {
@ -105,7 +108,18 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
WebDavHelp.showRestoreDialog(requireContext()) WebDavHelp.showRestoreDialog(requireContext())
} }
.request() .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 = "导入") { alert(title = "导入") {
message = "是否导入旧版本数据" message = "是否导入旧版本数据"
yesButton { yesButton {
@ -122,7 +136,6 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
}.show().applyTint() }.show().applyTint()
} }
} }
return super.onPreferenceTreeClick(preference)
} }
private fun needInstallApps(callback: () -> Unit) { private fun needInstallApps(callback: () -> Unit) {
@ -147,4 +160,13 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
callback() callback()
} }
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
oldDataRequestCode -> {
}
}
}
} }
Loading…
Cancel
Save