#638 - Convert IntoScreenActivity to use the password confirmation method utility

This commit is contained in:
Joshua Soberg 2020-09-05 12:49:53 -04:00
parent 30bd3f61e8
commit 9d97832e8c

View file

@ -54,6 +54,7 @@ import com.heinrichreimersoftware.materialintro.slide.FragmentSlide;
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide;
import org.shadowice.flocke.andotp.R;
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
import org.shadowice.flocke.andotp.Utilities.Constants;
import org.shadowice.flocke.andotp.Utilities.Settings;
import org.shadowice.flocke.andotp.Utilities.UIHelper;
@ -380,7 +381,7 @@ public class IntroScreenActivity extends IntroActivity {
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
setPasswordTransformationMethod();
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
minLength = Constants.AUTH_MIN_PASSWORD_LENGTH;
lengthWarning = getString(R.string.settings_label_short_password, minLength);
@ -390,33 +391,6 @@ public class IntroScreenActivity extends IntroActivity {
focusOnPasswordInput();
}
private void setPasswordTransformationMethod() {
passwordLayout.setEndIconOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wasShowingPassword = passwordInput.getTransformationMethod() instanceof PasswordTransformationMethod;
// Dispatch password visibility change to both password and confirm inputs
dispatchPasswordVisibilityChange(passwordInput, wasShowingPassword);
dispatchPasswordVisibilityChange(passwordConfirm, wasShowingPassword);
passwordLayout.refreshDrawableState();
}
});
passwordInput.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordConfirm.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
private void dispatchPasswordVisibilityChange(EditText editText, boolean wasShowingPassword) {
final int selection = editText.getSelectionEnd();
if (wasShowingPassword) {
editText.setTransformationMethod(null);
} else {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
if (selection >= 0) {
editText.setSelection(selection);
}
}
private void focusOnPasswordInput() {
if (getIntroActivity().getCurrentSlidePosition() == slidePos) {
passwordInput.requestFocus();
@ -433,7 +407,7 @@ public class IntroScreenActivity extends IntroActivity {
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
setPasswordTransformationMethod();
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
minLength = Constants.AUTH_MIN_PIN_LENGTH;
lengthWarning = getString(R.string.settings_label_short_pin, minLength);