mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 11:15:44 +00:00
Update PIN switch keyboard button to be more straightforward.
Addresses #12866.
This commit is contained in:
committed by
Nicholas Tinsley
parent
2dd0221680
commit
8ae115028e
@@ -7,7 +7,6 @@ import android.graphics.Typeface
|
||||
import android.text.InputType
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
@@ -18,6 +17,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.Navigation
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.thoughtcrime.securesms.R
|
||||
@@ -208,15 +208,15 @@ class AccountSettingsFragment : DSLSettingsFragment(R.string.AccountSettingsFrag
|
||||
val statusText = DialogCompat.requireViewById(dialog, R.id.reminder_disable_status) as TextView
|
||||
val cancelButton = DialogCompat.requireViewById(dialog, R.id.reminder_disable_cancel)
|
||||
val turnOffButton = DialogCompat.requireViewById(dialog, R.id.reminder_disable_turn_off)
|
||||
val changeKeyboard = DialogCompat.requireViewById(dialog, R.id.reminder_change_keyboard) as Button
|
||||
val changeKeyboard = DialogCompat.requireViewById(dialog, R.id.reminder_change_keyboard) as MaterialButton
|
||||
|
||||
changeKeyboard.setOnClickListener {
|
||||
if (pinEditText.inputType and InputType.TYPE_CLASS_NUMBER == 0) {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
|
||||
changeKeyboard.setText(R.string.PinRestoreEntryFragment_enter_alphanumeric_pin)
|
||||
changeKeyboard.setIconResource(PinKeyboardType.ALPHA_NUMERIC.iconResource)
|
||||
} else {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
changeKeyboard.setText(R.string.PinRestoreEntryFragment_enter_numeric_pin)
|
||||
changeKeyboard.setIconResource(PinKeyboardType.NUMERIC.iconResource)
|
||||
}
|
||||
pinEditText.typeface = Typeface.DEFAULT
|
||||
}
|
||||
@@ -230,11 +230,11 @@ class AccountSettingsFragment : DSLSettingsFragment(R.string.AccountSettingsFrag
|
||||
when (SignalStore.pinValues().keyboardType) {
|
||||
PinKeyboardType.NUMERIC -> {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
|
||||
changeKeyboard.setText(R.string.PinRestoreEntryFragment_enter_alphanumeric_pin)
|
||||
changeKeyboard.setIconResource(PinKeyboardType.ALPHA_NUMERIC.iconResource)
|
||||
}
|
||||
PinKeyboardType.ALPHA_NUMERIC -> {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
changeKeyboard.setText(R.string.PinRestoreEntryFragment_enter_numeric_pin)
|
||||
changeKeyboard.setIconResource(PinKeyboardType.NUMERIC.iconResource)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,15 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
import org.thoughtcrime.securesms.LoggingFragment;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -36,7 +39,7 @@ public abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel>
|
||||
private LearnMoreTextView description;
|
||||
private EditText input;
|
||||
private TextView label;
|
||||
private TextView keyboardToggle;
|
||||
private MaterialButton keyboardToggle;
|
||||
private CircularProgressMaterialButton confirm;
|
||||
private ViewModel viewModel;
|
||||
|
||||
@@ -69,6 +72,7 @@ public abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel>
|
||||
viewModel.getKeyboard().observe(getViewLifecycleOwner(), keyboardType -> {
|
||||
updateKeyboard(keyboardType);
|
||||
keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
|
||||
keyboardToggle.setIconResource(keyboardType.getOther().getIconResource());
|
||||
});
|
||||
|
||||
description.setOnLinkClickListener(v -> {
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public enum PinKeyboardType {
|
||||
NUMERIC("numeric"),
|
||||
ALPHA_NUMERIC("alphaNumeric");
|
||||
@@ -30,4 +32,9 @@ public enum PinKeyboardType {
|
||||
|
||||
return NUMERIC;
|
||||
}
|
||||
|
||||
public int getIconResource() {
|
||||
if (this == ALPHA_NUMERIC) return R.drawable.ic_keyboard_24;
|
||||
else return R.drawable.ic_number_pad_conversation_filter_24;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.autofill.HintConstants;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
@@ -52,7 +52,7 @@ public class PinRestoreEntryFragment extends LoggingFragment {
|
||||
private View skipButton;
|
||||
private CircularProgressMaterialButton pinButton;
|
||||
private TextView errorLabel;
|
||||
private TextView keyboardToggle;
|
||||
private MaterialButton keyboardToggle;
|
||||
private PinRestoreViewModel viewModel;
|
||||
|
||||
@Override
|
||||
@@ -102,12 +102,12 @@ public class PinRestoreEntryFragment extends LoggingFragment {
|
||||
keyboardToggle.setOnClickListener((v) -> {
|
||||
PinKeyboardType keyboardType = getPinEntryKeyboardType();
|
||||
|
||||
keyboardToggle.setIconResource(keyboardType.getIconResource());
|
||||
|
||||
updateKeyboard(keyboardType.getOther());
|
||||
keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
|
||||
});
|
||||
|
||||
PinKeyboardType keyboardType = getPinEntryKeyboardType().getOther();
|
||||
keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
|
||||
keyboardToggle.setIconResource(getPinEntryKeyboardType().getOther().getIconResource());
|
||||
}
|
||||
|
||||
private void initViewModel() {
|
||||
@@ -260,14 +260,6 @@ public class PinRestoreEntryFragment extends LoggingFragment {
|
||||
pinEntry.getText().clear();
|
||||
}
|
||||
|
||||
private @StringRes static int resolveKeyboardToggleText(@NonNull PinKeyboardType keyboard) {
|
||||
if (keyboard == PinKeyboardType.ALPHA_NUMERIC) {
|
||||
return R.string.PinRestoreEntryFragment_enter_alphanumeric_pin;
|
||||
} else {
|
||||
return R.string.PinRestoreEntryFragment_enter_numeric_pin;
|
||||
}
|
||||
}
|
||||
|
||||
private void enableAndFocusPinEntry() {
|
||||
pinEntry.setEnabled(true);
|
||||
pinEntry.setFocusable(true);
|
||||
|
||||
@@ -10,10 +10,11 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
@@ -49,7 +50,7 @@ public abstract class BaseRegistrationLockFragment extends LoggingFragment {
|
||||
private View forgotPin;
|
||||
protected CircularProgressMaterialButton pinButton;
|
||||
private TextView errorLabel;
|
||||
private TextView keyboardToggle;
|
||||
private MaterialButton keyboardToggle;
|
||||
private long timeRemaining;
|
||||
|
||||
private BaseRegistrationViewModel viewModel;
|
||||
@@ -101,11 +102,11 @@ public abstract class BaseRegistrationLockFragment extends LoggingFragment {
|
||||
PinKeyboardType keyboardType = getPinEntryKeyboardType();
|
||||
|
||||
updateKeyboard(keyboardType.getOther());
|
||||
keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
|
||||
keyboardToggle.setIconResource(keyboardType.getIconResource());
|
||||
});
|
||||
|
||||
PinKeyboardType keyboardType = getPinEntryKeyboardType().getOther();
|
||||
keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
|
||||
keyboardToggle.setIconResource(keyboardType.getIconResource());
|
||||
|
||||
disposables.bindTo(getViewLifecycleOwner().getLifecycle());
|
||||
viewModel = getViewModel();
|
||||
@@ -274,14 +275,6 @@ public abstract class BaseRegistrationLockFragment extends LoggingFragment {
|
||||
pinEntry.getText().clear();
|
||||
}
|
||||
|
||||
private @StringRes static int resolveKeyboardToggleText(@NonNull PinKeyboardType keyboard) {
|
||||
if (keyboard == PinKeyboardType.ALPHA_NUMERIC) {
|
||||
return R.string.RegistrationLockFragment__enter_alphanumeric_pin;
|
||||
} else {
|
||||
return R.string.RegistrationLockFragment__enter_numeric_pin;
|
||||
}
|
||||
}
|
||||
|
||||
private void enableAndFocusPinEntry() {
|
||||
pinEntry.setEnabled(true);
|
||||
pinEntry.setFocusable(true);
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.text.InputType
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
@@ -74,13 +73,12 @@ class ReRegisterWithPinFragment : LoggingFragment(R.layout.pin_restore_entry_fra
|
||||
}
|
||||
|
||||
binding.pinRestoreKeyboardToggle.setOnClickListener {
|
||||
val keyboardType: PinKeyboardType = getPinEntryKeyboardType()
|
||||
updateKeyboard(keyboardType.other)
|
||||
binding.pinRestoreKeyboardToggle.setText(resolveKeyboardToggleText(keyboardType))
|
||||
val currentKeyboardType: PinKeyboardType = getPinEntryKeyboardType()
|
||||
updateKeyboard(currentKeyboardType.other)
|
||||
binding.pinRestoreKeyboardToggle.setIconResource(currentKeyboardType.iconResource)
|
||||
}
|
||||
|
||||
val keyboardType: PinKeyboardType = getPinEntryKeyboardType().other
|
||||
binding.pinRestoreKeyboardToggle.setText(resolveKeyboardToggleText(keyboardType))
|
||||
binding.pinRestoreKeyboardToggle.setIconResource(getPinEntryKeyboardType().other.iconResource)
|
||||
|
||||
reRegisterViewModel.updateTokenData(registrationViewModel.keyBackupCurrentToken)
|
||||
|
||||
@@ -212,15 +210,6 @@ class ReRegisterWithPinFragment : LoggingFragment(R.layout.pin_restore_entry_fra
|
||||
binding.pinRestorePinInput.text?.clear()
|
||||
}
|
||||
|
||||
@StringRes
|
||||
private fun resolveKeyboardToggleText(keyboard: PinKeyboardType): Int {
|
||||
return if (keyboard == PinKeyboardType.ALPHA_NUMERIC) {
|
||||
R.string.RegistrationLockFragment__enter_alphanumeric_pin
|
||||
} else {
|
||||
R.string.RegistrationLockFragment__enter_numeric_pin
|
||||
}
|
||||
}
|
||||
|
||||
private fun onNeedHelpClicked() {
|
||||
val message = if (reRegisterViewModel.isLocalVerification) R.string.ReRegisterWithPinFragment_need_help_local else R.string.PinRestoreEntryFragment_your_pin_is_a_d_digit_code
|
||||
|
||||
|
||||
Reference in New Issue
Block a user