Skip to content

Commit

Permalink
Apply KBS Lock fixes and pluralization
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Feb 3, 2020
1 parent 4a8c312 commit 279dcb1
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.thoughtcrime.securesms.lock.v2.KbsKeyboardType;
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType;
import org.thoughtcrime.securesms.util.JsonUtils;
import org.whispersystems.signalservice.api.RegistrationLockData;
import org.whispersystems.signalservice.api.kbs.MasterKey;
Expand Down Expand Up @@ -117,14 +117,14 @@ public boolean isV2RegistrationLockEnabled() {
}
}

public void setKeyboardType(@NonNull KbsKeyboardType keyboardType) {
public void setKeyboardType(@NonNull PinKeyboardType keyboardType) {
store.beginWrite()
.putString(KEYBOARD_TYPE, keyboardType.getCode())
.commit();
}

@CheckResult
public @NonNull KbsKeyboardType getKeyboardType() {
return KbsKeyboardType.fromCode(store.getString(KEYBOARD_TYPE, null));
public @NonNull PinKeyboardType getKeyboardType() {
return PinKeyboardType.fromCode(store.getString(KEYBOARD_TYPE, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ private boolean handleEditorAction(@NonNull View view, int actionId, @NonNull Ke
return true;
}

private void updateKeyboard(@NonNull KbsKeyboardType keyboard) {
boolean isAlphaNumeric = keyboard == KbsKeyboardType.ALPHA_NUMERIC;
private void updateKeyboard(@NonNull PinKeyboardType keyboard) {
boolean isAlphaNumeric = keyboard == PinKeyboardType.ALPHA_NUMERIC;

input.setInputType(isAlphaNumeric ? InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD
: InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
}

private @StringRes int resolveKeyboardToggleText(@NonNull KbsKeyboardType keyboard) {
if (keyboard == KbsKeyboardType.ALPHA_NUMERIC) {
private @StringRes int resolveKeyboardToggleText(@NonNull PinKeyboardType keyboard) {
if (keyboard == PinKeyboardType.ALPHA_NUMERIC) {
return R.string.BaseKbsPinFragment__create_numeric_pin;
} else {
return R.string.BaseKbsPinFragment__create_alphanumeric_pin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.thoughtcrime.securesms.lock.v2;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

interface BaseKbsPinViewModel {
LiveData<KbsPin> getUserEntry();

LiveData<KbsKeyboardType> getKeyboard();
LiveData<PinKeyboardType> getKeyboard();

@MainThread
void setUserEntry(String userEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void initializeViewStates() {
@Override
protected ConfirmKbsPinViewModel initializeViewModel() {
KbsPin userEntry = Preconditions.checkNotNull(args.getUserEntry());
KbsKeyboardType keyboard = args.getKeyboard();
PinKeyboardType keyboard = args.getKeyboard();
ConfirmKbsPinRepository repository = new ConfirmKbsPinRepository();
ConfirmKbsPinViewModel.Factory factory = new ConfirmKbsPinViewModel.Factory(userEntry, keyboard, repository);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.megaphone.Megaphones;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
import org.whispersystems.signalservice.api.KeyBackupService;
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
import org.whispersystems.signalservice.api.RegistrationLockData;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.kbs.HashedPin;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
Expand All @@ -29,7 +27,7 @@ final class ConfirmKbsPinRepository {

private static final String TAG = Log.tag(ConfirmKbsPinRepository.class);

void setPin(@NonNull KbsPin kbsPin, @NonNull KbsKeyboardType keyboard, @NonNull Consumer<PinSetResult> resultConsumer) {
void setPin(@NonNull KbsPin kbsPin, @NonNull PinKeyboardType keyboard, @NonNull Consumer<PinSetResult> resultConsumer) {

Context context = ApplicationDependencies.getApplication();
String pinValue = kbsPin.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ final class ConfirmKbsPinViewModel extends ViewModel implements BaseKbsPinViewMo
private final ConfirmKbsPinRepository repository;

private final MutableLiveData<KbsPin> userEntry = new MutableLiveData<>(KbsPin.EMPTY);
private final MutableLiveData<KbsKeyboardType> keyboard = new MutableLiveData<>(KbsKeyboardType.NUMERIC);
private final MutableLiveData<PinKeyboardType> keyboard = new MutableLiveData<>(PinKeyboardType.NUMERIC);
private final MutableLiveData<SaveAnimation> saveAnimation = new MutableLiveData<>(SaveAnimation.NONE);
private final MutableLiveData<Label> label = new MutableLiveData<>(Label.RE_ENTER_PIN);

private final KbsPin pinToConfirm;

private ConfirmKbsPinViewModel(@NonNull KbsPin pinToConfirm,
@NonNull KbsKeyboardType keyboard,
@NonNull PinKeyboardType keyboard,
@NonNull ConfirmKbsPinRepository repository)
{
this.keyboard.setValue(keyboard);
Expand Down Expand Up @@ -65,7 +65,7 @@ public LiveData<KbsPin> getUserEntry() {
}

@Override
public LiveData<KbsKeyboardType> getKeyboard() {
public LiveData<PinKeyboardType> getKeyboard() {
return keyboard;
}

Expand Down Expand Up @@ -109,11 +109,11 @@ enum SaveAnimation {
static final class Factory implements ViewModelProvider.Factory {

private final KbsPin pinToConfirm;
private final KbsKeyboardType keyboard;
private final PinKeyboardType keyboard;
private final ConfirmKbsPinRepository repository;

Factory(@NonNull KbsPin pinToConfirm,
@NonNull KbsKeyboardType keyboard,
@NonNull PinKeyboardType keyboard,
@NonNull ConfirmKbsPinRepository repository)
{
this.pinToConfirm = pinToConfirm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected CreateKbsPinViewModel initializeViewModel() {
return viewModel;
}

private void onConfirmPin(@NonNull KbsPin userEntry, @NonNull KbsKeyboardType keyboard) {
private void onConfirmPin(@NonNull KbsPin userEntry, @NonNull PinKeyboardType keyboard) {
CreateKbsPinFragmentDirections.ActionConfirmPin action = CreateKbsPinFragmentDirections.actionConfirmPin();

action.setUserEntry(userEntry);
Expand All @@ -56,8 +56,8 @@ private void onConfirmPin(@NonNull KbsPin userEntry, @NonNull KbsKeyboardType ke
Navigation.findNavController(requireView()).navigate(action);
}

private String getLabelText(@NonNull KbsKeyboardType keyboard) {
if (keyboard == KbsKeyboardType.ALPHA_NUMERIC) {
private String getLabelText(@NonNull PinKeyboardType keyboard) {
if (keyboard == PinKeyboardType.ALPHA_NUMERIC) {
return getPinLengthRestrictionText(R.plurals.CreateKbsPinFragment__pin_must_be_at_least_characters);
} else {
return getPinLengthRestrictionText(R.plurals.CreateKbsPinFragment__pin_must_be_at_least_digits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
import androidx.core.util.Preconditions;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.livedata.LiveDataPair;

public final class CreateKbsPinViewModel extends ViewModel implements BaseKbsPinViewModel {

private final MutableLiveData<KbsPin> userEntry = new MutableLiveData<>(KbsPin.EMPTY);
private final MutableLiveData<KbsKeyboardType> keyboard = new MutableLiveData<>(KbsKeyboardType.NUMERIC);
private final MutableLiveData<PinKeyboardType> keyboard = new MutableLiveData<>(PinKeyboardType.NUMERIC);
private final SingleLiveEvent<NavigationEvent> events = new SingleLiveEvent<>();

@Override
Expand All @@ -24,7 +21,7 @@ public LiveData<KbsPin> getUserEntry() {
}

@Override
public LiveData<KbsKeyboardType> getKeyboard() {
public LiveData<PinKeyboardType> getKeyboard() {
return keyboard;
}

Expand All @@ -51,9 +48,9 @@ public void confirm() {

static final class NavigationEvent {
private final KbsPin userEntry;
private final KbsKeyboardType keyboard;
private final PinKeyboardType keyboard;

NavigationEvent(@NonNull KbsPin userEntry, @NonNull KbsKeyboardType keyboard) {
NavigationEvent(@NonNull KbsPin userEntry, @NonNull PinKeyboardType keyboard) {
this.userEntry = userEntry;
this.keyboard = keyboard;
}
Expand All @@ -62,7 +59,7 @@ KbsPin getUserEntry() {
return userEntry;
}

KbsKeyboardType getKeyboard() {
PinKeyboardType getKeyboard() {
return keyboard;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import androidx.annotation.Nullable;

public enum KbsKeyboardType {
public enum PinKeyboardType {
NUMERIC("numeric"),
ALPHA_NUMERIC("alphaNumeric");

private final String code;

KbsKeyboardType(String code) {
PinKeyboardType(String code) {
this.code = code;
}

KbsKeyboardType getOther() {
public PinKeyboardType getOther() {
if (this == NUMERIC) return ALPHA_NUMERIC;
else return NUMERIC;
}
Expand All @@ -21,8 +21,8 @@ public String getCode() {
return code;
}

public static KbsKeyboardType fromCode(@Nullable String code) {
for (KbsKeyboardType type : KbsKeyboardType.values()) {
public static PinKeyboardType fromCode(@Nullable String code) {
for (PinKeyboardType type : PinKeyboardType.values()) {
if (type.code.equals(code)) {
return type;
}
Expand Down

0 comments on commit 279dcb1

Please sign in to comment.