pull/78/head
kunfei 5 years ago
parent 985f484b29
commit 6423f91798
  1. 10
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  2. 4
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  3. 5
      app/src/main/res/xml/pref_config_backup.xml

@ -31,7 +31,7 @@ import kotlinx.coroutines.Dispatchers.IO
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
class WebDavConfigFragment : PreferenceFragmentCompat(), class BackupConfigFragment : PreferenceFragmentCompat(),
Preference.OnPreferenceChangeListener, Preference.OnPreferenceChangeListener,
CoroutineScope { CoroutineScope {
private lateinit var job: Job private lateinit var job: Job
@ -46,14 +46,14 @@ class WebDavConfigFragment : PreferenceFragmentCompat(),
job = Job() job = Job()
fun bindPreferenceSummaryToValue(preference: Preference?) { fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.apply { preference?.apply {
onPreferenceChangeListener = this@WebDavConfigFragment onPreferenceChangeListener = this@BackupConfigFragment
onPreferenceChange( onPreferenceChange(
this, this,
context.getPrefString(key) context.getPrefString(key)
) )
} }
} }
addPreferencesFromResource(R.xml.pref_config_web_dav) addPreferencesFromResource(R.xml.pref_config_backup)
findPreference<EditTextPreference>("web_dav_url")?.let { findPreference<EditTextPreference>("web_dav_url")?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) ATH.setTint(editText, requireContext().accentColor)
@ -74,6 +74,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(),
} }
bindPreferenceSummaryToValue(it) bindPreferenceSummaryToValue(it)
} }
bindPreferenceSummaryToValue(findPreference(PreferKey.backupPath))
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -115,6 +116,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
PreferKey.backupPath -> selectBackupFolder()
"web_dav_backup" -> backup() "web_dav_backup" -> backup()
"web_dav_restore" -> restore() "web_dav_restore" -> restore()
"import_old" -> importOldData() "import_old" -> importOldData()
@ -206,7 +208,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(),
alert(title = "导入") { alert(title = "导入") {
message = "是否导入旧版本数据" message = "是否导入旧版本数据"
yesButton { yesButton {
PermissionsCompat.Builder(this@WebDavConfigFragment) PermissionsCompat.Builder(this@BackupConfigFragment)
.addPermissions(*Permissions.Group.STORAGE) .addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage) .rationale(R.string.tip_perm_request_storage)
.onGranted { .onGranted {

@ -36,9 +36,9 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config)
} }
ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { ConfigViewModel.TYPE_WEB_DAV_CONFIG -> {
title_bar.title = getString(R.string.backup_restore) title_bar.title = getString(R.string.backup_restore)
val fTag = "webDavFragment" val fTag = "backupFragment"
var configFragment = supportFragmentManager.findFragmentByTag(fTag) var configFragment = supportFragmentManager.findFragmentByTag(fTag)
if (configFragment == null) configFragment = WebDavConfigFragment() if (configFragment == null) configFragment = BackupConfigFragment()
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.configFrameLayout, configFragment, fTag) .replace(R.id.configFrameLayout, configFragment, fTag)
.commit() .commit()

@ -28,6 +28,11 @@
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false"> <io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false">
<androidx.preference.Preference
android:key="backupUri"
android:title="备份路径"
app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference
android:key="web_dav_backup" android:key="web_dav_backup"
android:title="备份" android:title="备份"
Loading…
Cancel
Save