更新界面
This commit is contained in:
1 parent
9e6ed4a770
commit
3516af6a9f
6 files changed
+114
-38
No files matched your search
@@ -93,7 +93,7 @@ object AppWebDav {
|
|||||||
@Throws(WebDavException::class)
|
@Throws(WebDavException::class)
|
||||||
private suspend fun checkAuthorization(authorization: Authorization) {
|
private suspend fun checkAuthorization(authorization: Authorization) {
|
||||||
if (!WebDav(rootWebDavUrl, authorization).check()) {
|
if (!WebDav(rootWebDavUrl, authorization).check()) {
|
||||||
appCtx.removePref(PreferKey.webDavPassword)
|
//appCtx.removePref(PreferKey.webDavPassword)
|
||||||
appCtx.toastOnUi(R.string.webdav_application_authorization_error)
|
appCtx.toastOnUi(R.string.webdav_application_authorization_error)
|
||||||
throw WebDavException(appCtx.getString(R.string.webdav_application_authorization_error))
|
throw WebDavException(appCtx.getString(R.string.webdav_application_authorization_error))
|
||||||
}
|
}
|
||||||
@@ -154,6 +154,31 @@ object AppWebDav {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun testWebDav(): Boolean {
|
||||||
|
return kotlin.runCatching {
|
||||||
|
val account = appCtx.getPrefString(PreferKey.webDavAccount)
|
||||||
|
val password = appCtx.getPrefString(PreferKey.webDavPassword)
|
||||||
|
if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
|
||||||
|
appCtx.toastOnUi("账号或密码为空")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val auth = Authorization(account, password)
|
||||||
|
checkAuthorization(auth)
|
||||||
|
|
||||||
|
appCtx.toastOnUi("WebDAV 服务正常")
|
||||||
|
true
|
||||||
|
}.getOrElse {
|
||||||
|
it.printStackTrace()
|
||||||
|
if (it !is WebDavException) {
|
||||||
|
appCtx.toastOnUi(it.message ?: "未知错误")
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* webDav备份
|
* webDav备份
|
||||||
* @param fileName 备份文件名
|
* @param fileName 备份文件名
|
||||||
|
|||||||
@@ -1,24 +1,32 @@
|
|||||||
package io.legato.kazusa.ui.config
|
package io.legato.kazusa.ui.config
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.EditText
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.google.android.material.dialog.MaterialDialogs
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.constant.AppLog
|
import io.legato.kazusa.constant.AppLog
|
||||||
import io.legato.kazusa.constant.PreferKey
|
import io.legato.kazusa.constant.PreferKey
|
||||||
|
import io.legato.kazusa.databinding.DialogWebdavAuthBinding
|
||||||
import io.legato.kazusa.exception.NoStackTraceException
|
import io.legato.kazusa.exception.NoStackTraceException
|
||||||
import io.legato.kazusa.help.AppWebDav
|
import io.legato.kazusa.help.AppWebDav
|
||||||
|
import io.legato.kazusa.help.AppWebDav.testWebDav
|
||||||
import io.legato.kazusa.help.config.AppConfig
|
import io.legato.kazusa.help.config.AppConfig
|
||||||
import io.legato.kazusa.help.config.LocalConfig
|
import io.legato.kazusa.help.config.LocalConfig
|
||||||
import io.legato.kazusa.help.coroutine.Coroutine
|
import io.legato.kazusa.help.coroutine.Coroutine
|
||||||
@@ -53,6 +61,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
|
import androidx.core.content.edit
|
||||||
|
|
||||||
class BackupConfigFragment : PreferenceFragment(),
|
class BackupConfigFragment : PreferenceFragment(),
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener,
|
SharedPreferences.OnSharedPreferenceChangeListener,
|
||||||
@@ -107,12 +116,6 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
addPreferencesFromResource(R.xml.pref_config_backup)
|
addPreferencesFromResource(R.xml.pref_config_backup)
|
||||||
findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let {
|
|
||||||
it.setOnBindEditTextListener { editText ->
|
|
||||||
editText.inputType =
|
|
||||||
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
findPreference<EditTextPreference>(PreferKey.webDavDir)?.let {
|
findPreference<EditTextPreference>(PreferKey.webDavDir)?.let {
|
||||||
it.setOnBindEditTextListener { editText ->
|
it.setOnBindEditTextListener { editText ->
|
||||||
editText.text = AppConfig.webDavDir?.toEditable()
|
editText.text = AppConfig.webDavDir?.toEditable()
|
||||||
@@ -124,8 +127,6 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl))
|
upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl))
|
||||||
upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount))
|
|
||||||
upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword))
|
|
||||||
upPreferenceSummary(PreferKey.webDavDir, AppConfig.webDavDir)
|
upPreferenceSummary(PreferKey.webDavDir, AppConfig.webDavDir)
|
||||||
upPreferenceSummary(PreferKey.webDavDeviceName, AppConfig.webDavDeviceName)
|
upPreferenceSummary(PreferKey.webDavDeviceName, AppConfig.webDavDeviceName)
|
||||||
upPreferenceSummary(PreferKey.backupPath, getPrefString(PreferKey.backupPath))
|
upPreferenceSummary(PreferKey.backupPath, getPrefString(PreferKey.backupPath))
|
||||||
@@ -149,7 +150,6 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
|
|
||||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
menuInflater.inflate(R.menu.backup_restore, menu)
|
menuInflater.inflate(R.menu.backup_restore, menu)
|
||||||
menu.applyTint(requireContext())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
@@ -194,20 +194,6 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
preference.summary = value
|
preference.summary = value
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.webDavAccount ->
|
|
||||||
if (value.isNullOrBlank()) {
|
|
||||||
preference.summary = getString(R.string.web_dav_account_s)
|
|
||||||
} else {
|
|
||||||
preference.summary = value
|
|
||||||
}
|
|
||||||
|
|
||||||
PreferKey.webDavPassword ->
|
|
||||||
if (value.isNullOrEmpty()) {
|
|
||||||
preference.summary = getString(R.string.web_dav_pw_s)
|
|
||||||
} else {
|
|
||||||
preference.summary = "*".repeat(value.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
PreferKey.webDavDir -> preference.summary = when (value) {
|
PreferKey.webDavDir -> preference.summary = when (value) {
|
||||||
null -> "legado"
|
null -> "legado"
|
||||||
else -> value
|
else -> value
|
||||||
@@ -229,6 +215,17 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
when (preference.key) {
|
when (preference.key) {
|
||||||
PreferKey.backupPath -> selectBackupPath.launch()
|
PreferKey.backupPath -> selectBackupPath.launch()
|
||||||
PreferKey.restoreIgnore -> backupIgnore()
|
PreferKey.restoreIgnore -> backupIgnore()
|
||||||
|
"web_dav_test" -> {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
testWebDav()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"web_dav_auth" -> {
|
||||||
|
showWebDavAuthDialog()
|
||||||
|
lifecycleScope.launch {
|
||||||
|
testWebDav()
|
||||||
|
}
|
||||||
|
}
|
||||||
"web_dav_backup" -> backup()
|
"web_dav_backup" -> backup()
|
||||||
"web_dav_restore" -> restore()
|
"web_dav_restore" -> restore()
|
||||||
"import_old" -> restoreOld.launch()
|
"import_old" -> restoreOld.launch()
|
||||||
@@ -236,6 +233,33 @@ class BackupConfigFragment : PreferenceFragment(),
|
|||||||
return super.onPreferenceTreeClick(preference)
|
return super.onPreferenceTreeClick(preference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showWebDavAuthDialog() {
|
||||||
|
val binding = DialogWebdavAuthBinding.inflate(layoutInflater).apply {
|
||||||
|
editAccount.setText(PreferenceManager.getDefaultSharedPreferences(requireContext()).getString(PreferKey.webDavAccount, ""))
|
||||||
|
editPassword.setText(PreferenceManager.getDefaultSharedPreferences(requireContext()).getString(PreferKey.webDavPassword, ""))
|
||||||
|
editPassword.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||||
|
}
|
||||||
|
|
||||||
|
alert(titleResource = R.string.web_dav_account) {
|
||||||
|
customView { binding.root }
|
||||||
|
|
||||||
|
okButton {
|
||||||
|
val account = binding.editAccount.text.toString()
|
||||||
|
val password = binding.editPassword.text.toString()
|
||||||
|
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
|
||||||
|
putString(PreferKey.webDavAccount, account)
|
||||||
|
.putString(PreferKey.webDavPassword, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
upPreferenceSummary(PreferKey.webDavAccount, account)
|
||||||
|
upPreferenceSummary(PreferKey.webDavPassword, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelButton()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备份忽略设置
|
* 备份忽略设置
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>()
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
setSupportActionBar(binding.topBar)
|
||||||
when (val configTag = intent.getStringExtra("configTag")) {
|
when (val configTag = intent.getStringExtra("configTag")) {
|
||||||
ConfigTag.OTHER_CONFIG -> replaceFragment<OtherConfigFragment>(configTag)
|
ConfigTag.OTHER_CONFIG -> replaceFragment<OtherConfigFragment>(configTag)
|
||||||
ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag)
|
ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="24dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/edit_account"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/web_dav_account" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:endIconMode="password_toggle">
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/edit_password"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/web_dav_pw"
|
||||||
|
android:inputType="textPassword" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -8,11 +8,6 @@
|
|||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Welcome主题 -->
|
|
||||||
<style name="AppTheme.Welcome" parent="Base.AppTheme">
|
|
||||||
<item name="android:windowNoTitle">true</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="Base.AppTheme" parent="Theme.Material3.DynamicColors.DayNight.NoActionBar">
|
<style name="Base.AppTheme" parent="Theme.Material3.DynamicColors.DayNight.NoActionBar">
|
||||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||||
<item name="android:windowLightStatusBar">true</item>
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
|||||||
@@ -15,16 +15,10 @@
|
|||||||
android:summary="@string/web_dav_url_s"
|
android:summary="@string/web_dav_url_s"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.EditTextPreference
|
<io.legato.kazusa.lib.prefs.Preference
|
||||||
android:key="web_dav_account"
|
android:key="web_dav_auth"
|
||||||
android:title="@string/web_dav_account"
|
android:title="@string/web_dav_account"
|
||||||
android:summary="@string/web_dav_account_s"
|
android:summary="设置 WebDAV 账号和密码"
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.EditTextPreference
|
|
||||||
android:key="web_dav_password"
|
|
||||||
android:title="@string/web_dav_pw"
|
|
||||||
android:summary="@string/web_dav_pw_s"
|
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.EditTextPreference
|
<io.legato.kazusa.lib.prefs.EditTextPreference
|
||||||
@@ -41,6 +35,12 @@
|
|||||||
app:allowDividerBelow="false"
|
app:allowDividerBelow="false"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<io.legato.kazusa.lib.prefs.Preference
|
||||||
|
android:key="web_dav_test"
|
||||||
|
android:title="测试 WebDav 配置"
|
||||||
|
android:summary="测试 WebDav 服务工作状态"
|
||||||
|
app:iconSpaceReserved="false"/>
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.SwitchPreference
|
<io.legato.kazusa.lib.prefs.SwitchPreference
|
||||||
android:key="syncBookProgress"
|
android:key="syncBookProgress"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
|||||||
Reference in new issue
Block a user