diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java b/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java new file mode 100644 index 00000000..e7eae249 --- /dev/null +++ b/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java @@ -0,0 +1,55 @@ +package org.shadowice.flocke.andotp.Preferences; + +import android.content.Context; +import android.content.res.TypedArray; +import android.preference.DialogPreference; +import android.support.design.widget.TextInputEditText; +import android.util.AttributeSet; +import android.view.View; + +import org.shadowice.flocke.andotp.R; + +public class PasswordPreference extends DialogPreference { + private static final String DEFAULT_VALUE = ""; + + private TextInputEditText passwordInput; + private String value = DEFAULT_VALUE; + + public PasswordPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.component_password); + } + + @Override + protected void onBindDialogView(View view) { + passwordInput = (TextInputEditText) view.findViewById(R.id.passwordEdit); + + passwordInput.setText(value); + + super.onBindDialogView(view); + } + + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getString(index); + } + + @Override + protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) { + if (restorePersistedValue) { + value = getPersistedString(DEFAULT_VALUE); + } else { + value = (String) defaultValue; + persistString(value); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + value = passwordInput.getText().toString(); + persistString(value); + } + } +} diff --git a/app/src/main/res/layout/component_password.xml b/app/src/main/res/layout/component_password.xml new file mode 100644 index 00000000..97cee9d2 --- /dev/null +++ b/app/src/main/res/layout/component_password.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 2f4355f3..c032a559 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -18,11 +18,10 @@ android:summary="@string/settings_desc_auth_device" android:defaultValue="false" /> - + android:summary="@string/settings_desc_backup_password" />