Disable keyboard suggestions when typing PIN.

Converts `PinKeyboardType` to Kotlin and introduces methods to consistently configure PIN entry fields throughout the app, including a fix to disable keyboard suggestions.
This commit is contained in:
jeffrey-signal
2025-09-10 14:20:46 -04:00
committed by GitHub
parent 179bb6e1da
commit 79ee14826d
11 changed files with 187 additions and 251 deletions

View File

@@ -6,8 +6,6 @@
package org.thoughtcrime.securesms.registration.ui.registrationlock
import android.os.Bundle
import android.text.InputType
import android.text.method.PasswordTransformationMethod
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
@@ -45,6 +43,9 @@ class RegistrationLockFragment : LoggingFragment(R.layout.fragment_registration_
private var timeRemaining: Long = 0
private val pinEntryKeyboardType: PinKeyboardType
get() = PinKeyboardType.fromEditText(editText = binding.kbsLockPinInput)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setDebugLogSubmitMultiTapView(view.findViewById(R.id.kbs_lock_pin_title))
@@ -74,13 +75,9 @@ class RegistrationLockFragment : LoggingFragment(R.layout.fragment_registration_
}
binding.kbsLockKeyboardToggle.setOnClickListener {
val keyboardType: PinKeyboardType = getPinEntryKeyboardType()
updateKeyboard(keyboardType.other)
binding.kbsLockKeyboardToggle.setIconResource(keyboardType.iconResource)
updateKeyboard(pinEntryKeyboardType.other)
}
val keyboardType: PinKeyboardType = getPinEntryKeyboardType().getOther()
binding.kbsLockKeyboardToggle.setIconResource(keyboardType.iconResource)
updateKeyboard(pinEntryKeyboardType)
viewModel.lockedTimeRemaining.observe(viewLifecycleOwner) { t: Long -> timeRemaining = t }
@@ -138,7 +135,7 @@ class RegistrationLockFragment : LoggingFragment(R.layout.fragment_registration_
return
}
SignalStore.pin.keyboardType = getPinEntryKeyboardType()
SignalStore.pin.keyboardType = pinEntryKeyboardType
binding.kbsLockPinConfirm.setSpinning()
@@ -263,25 +260,14 @@ class RegistrationLockFragment : LoggingFragment(R.layout.fragment_registration_
private fun enableAndFocusPinEntry() {
binding.kbsLockPinInput.setEnabled(true)
binding.kbsLockPinInput.setFocusable(true)
binding.kbsLockPinInput.transformationMethod = PasswordTransformationMethod.getInstance()
ViewUtil.focusAndShowKeyboard(binding.kbsLockPinInput)
}
private fun getPinEntryKeyboardType(): PinKeyboardType {
val isNumeric = (binding.kbsLockPinInput.inputType and InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_NUMBER
return if (isNumeric) PinKeyboardType.NUMERIC else PinKeyboardType.ALPHA_NUMERIC
}
private fun updateKeyboard(keyboard: PinKeyboardType) {
val isAlphaNumeric = keyboard == PinKeyboardType.ALPHA_NUMERIC
binding.kbsLockPinInput.setInputType(
if (isAlphaNumeric) InputType.TYPE_CLASS_TEXT else InputType.TYPE_CLASS_NUMBER
private fun updateKeyboard(newType: PinKeyboardType) {
newType.applyTo(
pinEditText = binding.kbsLockPinInput,
toggleTypeButton = binding.kbsLockKeyboardToggle
)
binding.kbsLockPinInput.getText().clear()
binding.kbsLockPinInput.transformationMethod = PasswordTransformationMethod.getInstance()
}
private fun sendEmailToSupport() {

View File

@@ -6,8 +6,6 @@
package org.thoughtcrime.securesms.registration.ui.reregisterwithpin
import android.os.Bundle
import android.text.InputType
import android.text.method.PasswordTransformationMethod
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.Toast
@@ -43,6 +41,9 @@ class ReRegisterWithPinFragment : LoggingFragment(R.layout.fragment_registration
private val binding: FragmentRegistrationPinRestoreEntryV2Binding by ViewBinderDelegate(FragmentRegistrationPinRestoreEntryV2Binding::bind)
private val pinEntryKeyboardType: PinKeyboardType
get() = PinKeyboardType.fromEditText(editText = binding.pinRestorePinInput)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@@ -71,12 +72,9 @@ class ReRegisterWithPinFragment : LoggingFragment(R.layout.fragment_registration
}
binding.pinRestoreKeyboardToggle.setOnClickListener {
val currentKeyboardType: PinKeyboardType = getPinEntryKeyboardType()
updateKeyboard(currentKeyboardType.other)
binding.pinRestoreKeyboardToggle.setIconResource(currentKeyboardType.iconResource)
updateKeyboard(newType = pinEntryKeyboardType.other)
}
binding.pinRestoreKeyboardToggle.setIconResource(getPinEntryKeyboardType().other.iconResource)
updateKeyboard(newType = pinEntryKeyboardType)
LiveDataUtil
.combineLatest(registrationViewModel.uiState, reRegisterViewModel.uiState) { reg, rereg -> reg to rereg }
@@ -192,20 +190,14 @@ class ReRegisterWithPinFragment : LoggingFragment(R.layout.fragment_registration
private fun enableAndFocusPinEntry() {
binding.pinRestorePinInput.isEnabled = true
binding.pinRestorePinInput.isFocusable = true
binding.pinRestorePinInput.transformationMethod = PasswordTransformationMethod.getInstance()
ViewUtil.focusAndShowKeyboard(binding.pinRestorePinInput)
}
private fun getPinEntryKeyboardType(): PinKeyboardType {
val isNumeric = binding.pinRestorePinInput.inputType and InputType.TYPE_MASK_CLASS == InputType.TYPE_CLASS_NUMBER
return if (isNumeric) PinKeyboardType.NUMERIC else PinKeyboardType.ALPHA_NUMERIC
}
private fun updateKeyboard(keyboard: PinKeyboardType) {
val isAlphaNumeric = keyboard == PinKeyboardType.ALPHA_NUMERIC
binding.pinRestorePinInput.inputType = if (isAlphaNumeric) InputType.TYPE_CLASS_TEXT else InputType.TYPE_CLASS_NUMBER
binding.pinRestorePinInput.text?.clear()
binding.pinRestorePinInput.transformationMethod = PasswordTransformationMethod.getInstance()
private fun updateKeyboard(newType: PinKeyboardType) {
newType.applyTo(
pinEditText = binding.pinRestorePinInput,
toggleTypeButton = binding.pinRestoreKeyboardToggle
)
}
private fun onNeedHelpClicked() {