pull/34/head
kunfei 5 years ago
parent 5e1d7ccdcc
commit 1f02e47a59
  1. 20
      app/src/main/java/io/legado/app/lib/theme/prefs/ATEEditTextPreference.kt
  2. 5
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  3. 4
      app/src/main/res/xml/pref_config_web_dav.xml

@ -25,10 +25,9 @@ class ATEEditTextPreference(context: Context?, attrs: AttributeSet?) :
DialogInterface.OnClickListener, DialogInterface.OnDismissListener { DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private var builder: AlertDialog.Builder? = null private var builder: AlertDialog.Builder? = null
private var dialog: AlertDialog? = null private var dialog: AlertDialog? = null
private var editText: EditText? = null private var editText: EditText? = null
var inputType: Int? = null
/** Which button was clicked. */ /** Which button was clicked. */
private var mWhichButtonClicked: Int = 0 private var mWhichButtonClicked: Int = 0
@ -92,10 +91,11 @@ class ATEEditTextPreference(context: Context?, attrs: AttributeSet?) :
checkNotNull(editText) { "Dialog view must contain an EditText with id" + " @android:id/edit" } checkNotNull(editText) { "Dialog view must contain an EditText with id" + " @android:id/edit" }
view.findViewById<TextView>(android.R.id.message).visibility = View.GONE view.findViewById<TextView>(android.R.id.message).visibility = View.GONE
inputType?.let {
editText?.inputType = it
}
editText?.let { editText?.let {
ATH.setTint(it, ThemeStore.accentColor(context)) ATH.setTint(it, ThemeStore.accentColor(context))
it.requestFocus() it.requestFocus()
it.setText(text) it.setText(text)
// Place cursor at the end // Place cursor at the end
@ -108,14 +108,10 @@ class ATEEditTextPreference(context: Context?, attrs: AttributeSet?) :
} }
override fun onDismiss(dialog: DialogInterface?) { override fun onDismiss(dialog: DialogInterface?) {
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE) if (mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE) {
text = editText?.text.toString()
text = editText?.text.toString() callChangeListener(text)
callChangeListener(text) }
}
protected fun onDialogClosed(positiveResult: Boolean) {
} }
override fun onSaveInstanceState(): Parcelable { override fun onSaveInstanceState(): Parcelable {

@ -1,12 +1,14 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.view.View import android.view.View
import androidx.preference.ListPreference 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.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.prefs.ATEEditTextPreference
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
@ -15,6 +17,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
addPreferencesFromResource(R.xml.pref_config_web_dav) addPreferencesFromResource(R.xml.pref_config_web_dav)
bindPreferenceSummaryToValue(findPreference("web_dav_url")) bindPreferenceSummaryToValue(findPreference("web_dav_url"))
bindPreferenceSummaryToValue(findPreference("web_dav_account")) bindPreferenceSummaryToValue(findPreference("web_dav_account"))
findPreference<ATEEditTextPreference>("web_dav_password")?.let {
it.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
}
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

@ -6,22 +6,18 @@
android:key="web_dav_url" android:key="web_dav_url"
android:title="WebDav 服务器地址" android:title="WebDav 服务器地址"
android:summary="输入你的服务器地址" android:summary="输入你的服务器地址"
android:singleLine="true"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEEditTextPreference <io.legado.app.lib.theme.prefs.ATEEditTextPreference
android:key="web_dav_account" android:key="web_dav_account"
android:title="WebDav 账号" android:title="WebDav 账号"
android:summary="输入你的WebDav账号" android:summary="输入你的WebDav账号"
android:singleLine="true"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEEditTextPreference <io.legado.app.lib.theme.prefs.ATEEditTextPreference
android:key="web_dav_password" android:key="web_dav_password"
android:title="WebDav 密码" android:title="WebDav 密码"
android:summary="输入你的WebDav授权密码" android:summary="输入你的WebDav授权密码"
android:singleLine="true"
android:inputType="textPassword"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.Preference <androidx.preference.Preference

Loading…
Cancel
Save