|
|
@ -1,9 +1,7 @@ |
|
|
|
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.provider.Settings |
|
|
|
|
|
|
|
import android.text.InputType |
|
|
|
import android.text.InputType |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import androidx.preference.EditTextPreference |
|
|
|
import androidx.preference.EditTextPreference |
|
|
@ -11,6 +9,7 @@ import androidx.preference.ListPreference |
|
|
|
import androidx.preference.Preference |
|
|
|
import androidx.preference.Preference |
|
|
|
import androidx.preference.PreferenceFragmentCompat |
|
|
|
import androidx.preference.PreferenceFragmentCompat |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.help.IntentHelp |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.help.storage.Backup |
|
|
|
import io.legado.app.help.storage.Backup |
|
|
@ -21,12 +20,22 @@ import io.legado.app.lib.dialogs.noButton |
|
|
|
import io.legado.app.lib.dialogs.yesButton |
|
|
|
import io.legado.app.lib.dialogs.yesButton |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
|
|
|
|
import io.legado.app.utils.LogUtils |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.getPrefString |
|
|
|
import io.legado.app.utils.getPrefString |
|
|
|
|
|
|
|
|
|
|
|
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { |
|
|
|
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
|
|
|
|
fun bindPreferenceSummaryToValue(preference: Preference?) { |
|
|
|
|
|
|
|
preference?.apply { |
|
|
|
|
|
|
|
onPreferenceChangeListener = this@WebDavConfigFragment |
|
|
|
|
|
|
|
onPreferenceChange( |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
context.getPrefString(key) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
addPreferencesFromResource(R.xml.pref_config_web_dav) |
|
|
|
addPreferencesFromResource(R.xml.pref_config_web_dav) |
|
|
|
findPreference<EditTextPreference>("web_dav_url")?.let { |
|
|
|
findPreference<EditTextPreference>("web_dav_url")?.let { |
|
|
|
it.setOnBindEditTextListener { editText -> |
|
|
|
it.setOnBindEditTextListener { editText -> |
|
|
@ -82,47 +91,21 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun bindPreferenceSummaryToValue(preference: Preference?) { |
|
|
|
|
|
|
|
preference?.apply { |
|
|
|
|
|
|
|
onPreferenceChangeListener = this@WebDavConfigFragment |
|
|
|
|
|
|
|
onPreferenceChange( |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
context.getPrefString(key) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
|
|
|
when (preference?.key) { |
|
|
|
when (preference?.key) { |
|
|
|
"web_dav_backup" -> Backup.backup() |
|
|
|
"web_dav_backup" -> PermissionsCompat.Builder(this) |
|
|
|
"web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) |
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
"import_old" -> importOld() |
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
} |
|
|
|
.onGranted { Backup.backup() } |
|
|
|
return super.onPreferenceTreeClick(preference) |
|
|
|
.request() |
|
|
|
} |
|
|
|
"web_dav_restore" -> PermissionsCompat.Builder(this) |
|
|
|
|
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
private fun importOld() { |
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { |
|
|
|
.onGranted { |
|
|
|
val haveInstallPermission = context!!.packageManager.canRequestPackageInstalls() |
|
|
|
WebDavHelp.showRestoreDialog(requireContext()) |
|
|
|
if (haveInstallPermission) { |
|
|
|
|
|
|
|
startImport() |
|
|
|
|
|
|
|
} else { //没有安装外部来源应用的权限 |
|
|
|
|
|
|
|
alert(title = "开启权限提示") { |
|
|
|
|
|
|
|
message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" |
|
|
|
|
|
|
|
yesButton { |
|
|
|
|
|
|
|
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) |
|
|
|
|
|
|
|
startActivityForResult(intent, 666) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
noButton { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.show().applyTint() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
startImport() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.request() |
|
|
|
private fun startImport() { |
|
|
|
"import_old" -> needInstallApps { |
|
|
|
alert(title = "导入") { |
|
|
|
alert(title = "导入") { |
|
|
|
message = "是否导入旧版本数据" |
|
|
|
message = "是否导入旧版本数据" |
|
|
|
yesButton { |
|
|
|
yesButton { |
|
|
@ -138,5 +121,30 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.onPreferenceTreeClick(preference) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun needInstallApps(callback: () -> Unit) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun canRequestPackageInstalls() :Boolean { |
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { |
|
|
|
|
|
|
|
return requireContext().packageManager.canRequestPackageInstalls() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!canRequestPackageInstalls()) { |
|
|
|
|
|
|
|
alert(title = "开启权限提示") { |
|
|
|
|
|
|
|
message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" |
|
|
|
|
|
|
|
yesButton { |
|
|
|
|
|
|
|
IntentHelp.toInstallUnknown(requireContext()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
noButton { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.show().applyTint() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LogUtils.d("xxx","import old") |
|
|
|
|
|
|
|
callback() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |