mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Fix inconsistent default PIN keyboard type.
This commit is contained in:
committed by
Greyson Parrelli
parent
7f429dc769
commit
c24993960d
@@ -31,10 +31,12 @@ import androidx.compose.ui.res.vectorResource
|
||||
import androidx.core.app.DialogCompat
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.launch
|
||||
import org.signal.core.ui.compose.Dialogs
|
||||
import org.signal.core.ui.compose.Dividers
|
||||
import org.signal.core.ui.compose.Previews
|
||||
@@ -112,24 +114,21 @@ class AccountSettingsFragment : ComposeFragment() {
|
||||
val turnOffButton = DialogCompat.requireViewById(dialog, R.id.reminder_disable_turn_off)
|
||||
val changeKeyboard = DialogCompat.requireViewById(dialog, R.id.reminder_change_keyboard) as MaterialButton
|
||||
|
||||
changeKeyboard.setOnClickListener {
|
||||
val newType = PinKeyboardType.fromEditText(pinEditText).other
|
||||
newType.applyTo(
|
||||
pinEditText = pinEditText,
|
||||
toggleTypeButton = changeKeyboard
|
||||
)
|
||||
pinEditText.typeface = Typeface.DEFAULT
|
||||
dialog.lifecycleScope.launch {
|
||||
viewModel.state.collect { state ->
|
||||
state.pinKeyboardType.applyTo(
|
||||
pinEditText = pinEditText,
|
||||
toggleTypeButton = changeKeyboard
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
changeKeyboard.setOnClickListener { viewModel.togglePinKeyboardType() }
|
||||
|
||||
pinEditText.post {
|
||||
ViewUtil.focusAndShowKeyboard(pinEditText)
|
||||
}
|
||||
|
||||
SignalStore.pin.keyboardType.applyTo(
|
||||
pinEditText = pinEditText,
|
||||
toggleTypeButton = changeKeyboard
|
||||
)
|
||||
|
||||
pinEditText.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun onTextChanged(text: String) {
|
||||
turnOffButton.isEnabled = text.length >= SvrConstants.MINIMUM_PIN_LENGTH
|
||||
@@ -459,6 +458,7 @@ private fun AccountSettingsScreenPreview() {
|
||||
AccountSettingsScreen(
|
||||
state = AccountSettingsState(
|
||||
hasPin = true,
|
||||
pinKeyboardType = PinKeyboardType.NUMERIC,
|
||||
hasRestoredAep = true,
|
||||
pinRemindersEnabled = true,
|
||||
registrationLockEnabled = true,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.account
|
||||
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
|
||||
data class AccountSettingsState(
|
||||
val hasPin: Boolean,
|
||||
val pinKeyboardType: PinKeyboardType,
|
||||
val hasRestoredAep: Boolean,
|
||||
val pinRemindersEnabled: Boolean,
|
||||
val registrationLockEnabled: Boolean,
|
||||
|
||||
@@ -18,9 +18,16 @@ class AccountSettingsViewModel : ViewModel() {
|
||||
store.update { getCurrentState() }
|
||||
}
|
||||
|
||||
fun togglePinKeyboardType() {
|
||||
store.update { previousState ->
|
||||
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentState(): AccountSettingsState {
|
||||
return AccountSettingsState(
|
||||
hasPin = SignalStore.svr.hasPin() && !SignalStore.svr.hasOptedOut(),
|
||||
pinKeyboardType = SignalStore.pin.keyboardType,
|
||||
hasRestoredAep = SignalStore.account.restoredAccountEntropyPool,
|
||||
pinRemindersEnabled = SignalStore.pin.arePinRemindersEnabled() && SignalStore.svr.hasPin(),
|
||||
registrationLockEnabled = SignalStore.svr.isRegistrationLockEnabled,
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.thoughtcrime.securesms.components.ViewBinderDelegate
|
||||
import org.thoughtcrime.securesms.components.settings.app.changenumber.ChangeNumberUtil.changeNumberSuccess
|
||||
import org.thoughtcrime.securesms.databinding.FragmentRegistrationLockBinding
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
import org.thoughtcrime.securesms.lock.v2.SvrConstants
|
||||
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult
|
||||
import org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate
|
||||
@@ -51,9 +50,6 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
|
||||
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)
|
||||
RegistrationViewDelegate.setDebugLogSubmitMultiTapView(view.findViewById(R.id.kbs_lock_pin_title))
|
||||
@@ -93,10 +89,7 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
handlePinEntry()
|
||||
}
|
||||
|
||||
binding.kbsLockKeyboardToggle.setOnClickListener {
|
||||
updateKeyboard(pinEntryKeyboardType.other)
|
||||
}
|
||||
updateKeyboard(pinEntryKeyboardType)
|
||||
binding.kbsLockKeyboardToggle.setOnClickListener { viewModel.togglePinKeyboardType() }
|
||||
|
||||
viewModel.liveLockedTimeRemaining.observe(viewLifecycleOwner) { t: Long -> timeRemaining = t }
|
||||
|
||||
@@ -123,6 +116,11 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
if (state.changeNumberOutcome == ChangeNumberOutcome.VerificationCodeWorked) {
|
||||
handleSuccessfulPinEntry(state.enteredPin)
|
||||
}
|
||||
|
||||
state.pinKeyboardType.applyTo(
|
||||
pinEditText = binding.kbsLockPinInput,
|
||||
toggleTypeButton = binding.kbsLockKeyboardToggle
|
||||
)
|
||||
}
|
||||
|
||||
private fun handlePinEntry() {
|
||||
@@ -275,13 +273,6 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
ViewUtil.focusAndShowKeyboard(binding.kbsLockPinInput)
|
||||
}
|
||||
|
||||
private fun updateKeyboard(newType: PinKeyboardType) {
|
||||
newType.applyTo(
|
||||
pinEditText = binding.kbsLockPinInput,
|
||||
toggleTypeButton = binding.kbsLockKeyboardToggle
|
||||
)
|
||||
}
|
||||
|
||||
private fun navigateToAccountLocked() {
|
||||
findNavController().safeNavigate(ChangeNumberRegistrationLockFragmentDirections.actionChangeNumberRegistrationLockToChangeNumberAccountLocked())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.thoughtcrime.securesms.components.settings.app.changenumber
|
||||
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
import org.thoughtcrime.securesms.registration.data.network.Challenge
|
||||
import org.thoughtcrime.securesms.registration.data.network.VerificationCodeRequestResult
|
||||
import org.thoughtcrime.securesms.registration.ui.countrycode.Country
|
||||
@@ -19,6 +21,7 @@ data class ChangeNumberState(
|
||||
val number: NumberViewState = NumberViewState.INITIAL,
|
||||
val enteredCode: String? = null,
|
||||
val enteredPin: String = "",
|
||||
val pinKeyboardType: PinKeyboardType = SignalStore.pin.keyboardType,
|
||||
val oldPhoneNumber: NumberViewState = NumberViewState.INITIAL,
|
||||
val sessionId: String? = null,
|
||||
val changeNumberOutcome: ChangeNumberOutcome? = null,
|
||||
|
||||
@@ -150,6 +150,12 @@ class ChangeNumberViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun togglePinKeyboardType() {
|
||||
store.update { previousState ->
|
||||
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
|
||||
}
|
||||
}
|
||||
|
||||
fun incrementIncorrectCodeAttempts() {
|
||||
store.update {
|
||||
it.copy(incorrectCodeAttempts = it.incorrectCodeAttempts + 1)
|
||||
|
||||
Reference in New Issue
Block a user