mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 00:29:11 +01:00
Fix inconsistent default PIN keyboard type.
This commit is contained in:
committed by
Greyson Parrelli
parent
7f429dc769
commit
c24993960d
@@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.pin;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -29,7 +28,6 @@ import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.ProfileUploadJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.RestoreDecisionStateUtil;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType;
|
||||
import org.thoughtcrime.securesms.lock.v2.SvrConstants;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.profiles.edit.CreateProfileActivity;
|
||||
@@ -100,15 +98,14 @@ public class PinRestoreEntryFragment extends LoggingFragment {
|
||||
onPinSubmitted();
|
||||
});
|
||||
|
||||
keyboardToggle.setOnClickListener((v) -> {
|
||||
getPinEntryKeyboardType().getOther().applyTo(pinEntry, keyboardToggle);
|
||||
});
|
||||
getPinEntryKeyboardType().applyTo(pinEntry, keyboardToggle);
|
||||
keyboardToggle.setOnClickListener((v) -> viewModel.toggleKeyboardType());
|
||||
}
|
||||
|
||||
private void initViewModel() {
|
||||
viewModel = new ViewModelProvider(this).get(PinRestoreViewModel.class);
|
||||
|
||||
viewModel.getKeyboardType().observe(getViewLifecycleOwner(), keyboardType -> keyboardType.applyTo(pinEntry, keyboardToggle));
|
||||
|
||||
viewModel.triesRemaining.observe(getViewLifecycleOwner(), this::presentTriesRemaining);
|
||||
viewModel.getEvent().observe(getViewLifecycleOwner(), this::presentEvent);
|
||||
}
|
||||
@@ -175,13 +172,9 @@ public class PinRestoreEntryFragment extends LoggingFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private PinKeyboardType getPinEntryKeyboardType() {
|
||||
return PinKeyboardType.fromEditText(pinEntry);
|
||||
}
|
||||
|
||||
private void onPinSubmitted() {
|
||||
pinEntry.setEnabled(false);
|
||||
viewModel.onPinSubmitted(pinEntry.getText().toString(), getPinEntryKeyboardType());
|
||||
viewModel.onPinSubmitted(pinEntry.getText().toString());
|
||||
pinButton.setSpinning();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
import org.thoughtcrime.securesms.lock.v2.SvrConstants
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData
|
||||
@@ -19,11 +20,18 @@ class PinRestoreViewModel : ViewModel() {
|
||||
@JvmField
|
||||
val triesRemaining: DefaultValueLiveData<TriesRemaining> = DefaultValueLiveData(TriesRemaining(10, false))
|
||||
|
||||
private val _keyboardType = DefaultValueLiveData(SignalStore.pin.keyboardType)
|
||||
val keyboardType: LiveData<PinKeyboardType> = _keyboardType
|
||||
|
||||
private val event: SingleLiveEvent<Event> = SingleLiveEvent()
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
fun onPinSubmitted(pin: String, pinKeyboardType: PinKeyboardType) {
|
||||
fun toggleKeyboardType() {
|
||||
_keyboardType.value = _keyboardType.value.other
|
||||
}
|
||||
|
||||
fun onPinSubmitted(pin: String) {
|
||||
val trimmedLength = pin.trim().length
|
||||
if (trimmedLength == 0) {
|
||||
event.postValue(Event.EMPTY_PIN)
|
||||
@@ -35,7 +43,7 @@ class PinRestoreViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
disposables += Single
|
||||
.fromCallable { repo.restoreMasterKeyPostRegistration(pin, pinKeyboardType) }
|
||||
.fromCallable { repo.restoreMasterKeyPostRegistration(pin, _keyboardType.value) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { result ->
|
||||
@@ -43,16 +51,20 @@ class PinRestoreViewModel : ViewModel() {
|
||||
is SecureValueRecovery.RestoreResponse.Success -> {
|
||||
event.postValue(Event.SUCCESS)
|
||||
}
|
||||
|
||||
is SecureValueRecovery.RestoreResponse.PinMismatch -> {
|
||||
event.postValue(Event.PIN_INCORRECT)
|
||||
triesRemaining.postValue(TriesRemaining(result.triesRemaining, true))
|
||||
}
|
||||
|
||||
SecureValueRecovery.RestoreResponse.Missing -> {
|
||||
event.postValue(Event.PIN_LOCKED)
|
||||
}
|
||||
|
||||
is SecureValueRecovery.RestoreResponse.NetworkError -> {
|
||||
event.postValue(Event.NETWORK_ERROR)
|
||||
}
|
||||
|
||||
is SecureValueRecovery.RestoreResponse.ApplicationError -> {
|
||||
event.postValue(Event.NETWORK_ERROR)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user