Skip to content

Commit

Permalink
Various PIN bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Feb 26, 2020
1 parent 0a883dc commit dc689d3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ public void onItemLongClick(View maskTarget, MessageRecord messageRecord) {

if (messageRecord.isSecure() &&
!messageRecord.isUpdate() &&
!recipient.get().isBlocked() &&
((ConversationAdapter) list.getAdapter()).getSelectedItems().isEmpty())
{
isReacting = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.animation.Animator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.annotation.RawRes;
Expand Down Expand Up @@ -75,6 +77,7 @@ private void updateLabel(@NonNull ConfirmKbsPinViewModel.Label label) {
break;
case CREATING_PIN:
getLabel().setText(R.string.ConfirmKbsPinFragment__creating_pin);
getInput().setEnabled(false);
break;
case RE_ENTER_PIN:
getLabel().setText(R.string.ConfirmKbsPinFragment__re_enter_pin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onV1RegistrationLockPinRequiredOrIncorrect(long timeRemaining) {
@Override
public void onSuccess(Boolean r) {
Navigation.findNavController(requireView())
.navigate(EnterCodeFragmentDirections.actionRequireKbsLockPin(timeRemaining));
.navigate(EnterCodeFragmentDirections.actionRequireKbsLockPin(timeRemaining, true));
}
});
}
Expand All @@ -141,7 +141,7 @@ public void onKbsRegistrationLockPinRequired(long timeRemaining, @NonNull TokenR
@Override
public void onSuccess(Boolean r) {
Navigation.findNavController(requireView())
.navigate(EnterCodeFragmentDirections.actionRequireKbsLockPin(timeRemaining));
.navigate(EnterCodeFragmentDirections.actionRequireKbsLockPin(timeRemaining, false));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
keyboardToggle = view.findViewById(R.id.kbs_lock_keyboard_toggle);
forgotPin = view.findViewById(R.id.kbs_lock_forgot_pin);

timeRemaining = RegistrationLockFragmentArgs.fromBundle(requireArguments()).getTimeRemaining();
RegistrationLockFragmentArgs args = RegistrationLockFragmentArgs.fromBundle(requireArguments());

timeRemaining = args.getTimeRemaining();

if (args.getIsV1RegistrationLock()) {
keyboardToggle.setVisibility(View.GONE);
}

forgotPin.setVisibility(View.GONE);
forgotPin.setOnClickListener(v -> handleForgottenPin(timeRemaining));
Expand All @@ -78,10 +84,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
return false;
});

pinEntry.setFocusable(true);
if (pinEntry.requestFocus()) {
ServiceUtil.getInputMethodManager(pinEntry.getContext()).showSoftInput(pinEntry, 0);
}
enableAndFocusPinEntry();

pinButton.setOnClickListener((v) -> {
hideKeyboard(requireContext(), pinEntry);
Expand Down Expand Up @@ -136,6 +139,8 @@ private PinKeyboardType getPinEntryKeyboardType() {
}

private void handlePinEntry() {
pinEntry.setEnabled(false);

final String pin = pinEntry.getText().toString();

int trimmedLength = pin.replace(" ", "").length();
Expand Down Expand Up @@ -179,6 +184,7 @@ public void onV1RegistrationLockPinRequiredOrIncorrect(long timeRemaining) {

cancelSpinning(pinButton);
pinEntry.getText().clear();
enableAndFocusPinEntry();

errorLabel.setText(R.string.RegistrationLockFragment__incorrect_pin);
}
Expand All @@ -192,6 +198,7 @@ public void onKbsRegistrationLockPinRequired(long timeRemaining, @NonNull TokenR
public void onIncorrectKbsRegistrationLockPin(@NonNull TokenResponse tokenResponse) {
cancelSpinning(pinButton);
pinEntry.getText().clear();
enableAndFocusPinEntry();

model.setKeyBackupCurrentToken(tokenResponse);

Expand Down Expand Up @@ -224,6 +231,7 @@ public void onIncorrectKbsRegistrationLockPin(@NonNull TokenResponse tokenRespon
@Override
public void onRateLimited() {
cancelSpinning(pinButton);
enableAndFocusPinEntry();

new AlertDialog.Builder(requireContext())
.setTitle(R.string.RegistrationActivity_too_many_attempts)
Expand All @@ -244,6 +252,7 @@ public void onKbsAccountLocked(@Nullable Long timeRemaining) {
@Override
public void onError() {
cancelSpinning(pinButton);
enableAndFocusPinEntry();

Toast.makeText(requireContext(), R.string.RegistrationActivity_error_connecting_to_service, Toast.LENGTH_LONG).show();
}
Expand Down Expand Up @@ -283,4 +292,13 @@ private void updateKeyboard(@NonNull PinKeyboardType keyboard) {
return R.string.RegistrationLockFragment__enter_numeric_pin;
}
}

private void enableAndFocusPinEntry() {
pinEntry.setEnabled(true);
pinEntry.setFocusable(true);

if (pinEntry.requestFocus()) {
ServiceUtil.getInputMethodManager(pinEntry.getContext()).showSoftInput(pinEntry, 0);
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/navigation/registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
android:name="timeRemaining"
app:argType="long" />

<argument
android:name="isV1RegistrationLock"
app:argType="boolean" />

</fragment>

<fragment
Expand Down

0 comments on commit dc689d3

Please sign in to comment.