Skip to content

Commit

Permalink
CreatePinActivity naming update and copy fixes.
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 b29b3d0 commit e14861d
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void onClick(@NonNull View widget) {
dialog.dismiss();
RegistrationLockReminders.scheduleReminder(context, true);

fragment.startActivityForResult(CreateKbsPinActivity.getIntentForPinUpdate(context), CreateKbsPinActivity.REQUEST_NEW_PIN);
fragment.startActivityForResult(CreateKbsPinActivity.getIntentForPinChangeFromForgotPin(context), CreateKbsPinActivity.REQUEST_NEW_PIN);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@

public class ConfirmKbsPinFragment extends BaseKbsPinFragment<ConfirmKbsPinViewModel> {

private ConfirmKbsPinFragmentArgs args;
private ConfirmKbsPinViewModel viewModel;

@Override
protected void initializeViewStates() {
args = ConfirmKbsPinFragmentArgs.fromBundle(requireArguments());
ConfirmKbsPinFragmentArgs args = ConfirmKbsPinFragmentArgs.fromBundle(requireArguments());

if (args.getIsNewPin()) {
initializeViewStatesForPinCreate();
if (args.getIsPinChange()) {
initializeViewStatesForPinChange();
} else {
initializeViewStatesForPinUpdate();
initializeViewStatesForPinCreate();
}
}

@Override
protected ConfirmKbsPinViewModel initializeViewModel() {
ConfirmKbsPinFragmentArgs args = ConfirmKbsPinFragmentArgs.fromBundle(requireArguments());
KbsPin userEntry = Preconditions.checkNotNull(args.getUserEntry());
PinKeyboardType keyboard = args.getKeyboard();
ConfirmKbsPinRepository repository = new ConfirmKbsPinRepository();
Expand All @@ -60,7 +60,7 @@ private void initializeViewStatesForPinCreate() {
getLabel().setText("");
}

private void initializeViewStatesForPinUpdate() {
private void initializeViewStatesForPinChange() {
getTitle().setText(R.string.CreateKbsPinFragment__create_a_new_pin);
getDescription().setText(R.string.ConfirmKbsPinFragment__confirm_your_pin);
getKeyboardToggle().setVisibility(View.INVISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,37 @@ public class CreateKbsPinActivity extends BaseActionBarActivity {

public static final int REQUEST_NEW_PIN = 27698;

private static final String IS_NEW_PIN = "is_new_pin";

private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();

public static Intent getIntentForPinCreate(@NonNull Context context) {
return getIntent(context, true);
public static @NonNull Intent getIntentForPinCreate(@NonNull Context context) {
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
.setIsForgotPin(false)
.setIsPinChange(false)
.build();

return getIntentWithArgs(context, args);
}

public static Intent getIntentForPinUpdate(@NonNull Context context) {
return getIntent(context, false);
public static @NonNull Intent getIntentForPinChangeFromForgotPin(@NonNull Context context) {
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
.setIsForgotPin(true)
.setIsPinChange(true)
.build();

return getIntentWithArgs(context, args);
}

private static Intent getIntent(@NonNull Context context, boolean isNewPin) {
Intent intent = new Intent(context, CreateKbsPinActivity.class);
intent.putExtra(IS_NEW_PIN, isNewPin);
return intent;
public static @NonNull Intent getIntentForPinChangeFromSettings(@NonNull Context context) {
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
.setIsForgotPin(false)
.setIsPinChange(true)
.build();

return getIntentWithArgs(context, args);
}

private static @NonNull Intent getIntentWithArgs(@NonNull Context context, @NonNull CreateKbsPinFragmentArgs args) {
return new Intent(context, CreateKbsPinActivity.class).putExtras(args.toBundle());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@

public class CreateKbsPinFragment extends BaseKbsPinFragment<CreateKbsPinViewModel> {

private CreateKbsPinFragmentArgs args;
private static final int PIN_LOCKOUT_DAYS = 7;

@Override
protected void initializeViewStates() {
args = CreateKbsPinFragmentArgs.fromBundle(requireArguments());
CreateKbsPinFragmentArgs args = CreateKbsPinFragmentArgs.fromBundle(requireArguments());

if (args.getIsNewPin()) {
initializeViewStatesForPinCreate();
if (args.getIsPinChange()) {
initializeViewStatesForPinChange(args.getIsForgotPin());
} else {
initializeViewStatesForPinUpdate();
initializeViewStatesForPinCreate();
}

getLabel().setText(getPinLengthRestrictionText(R.plurals.CreateKbsPinFragment__pin_must_be_at_least_digits));
getConfirm().setEnabled(false);
}

private void initializeViewStatesForPinUpdate() {
private void initializeViewStatesForPinChange(boolean isForgotPin) {
getTitle().setText(R.string.CreateKbsPinFragment__create_a_new_pin);
getDescription().setText(R.string.CreateKbsPinFragment__because_youre_still_logged_in);

if (isForgotPin) {
getDescription().setText(requireContext().getResources()
.getQuantityString(R.plurals.CreateKbsPinFragment__you_can_choose_a_new_pin_because_this_device_is_registered,
PIN_LOCKOUT_DAYS,
PIN_LOCKOUT_DAYS));
} else {
getDescription().setText(R.string.CreateKbsPinFragment__pins_add_an_extra_layer_of_security);
}
}

private void initializeViewStatesForPinCreate() {
Expand All @@ -37,9 +45,11 @@ private void initializeViewStatesForPinCreate() {

@Override
protected CreateKbsPinViewModel initializeViewModel() {
CreateKbsPinViewModel viewModel = ViewModelProviders.of(this).get(CreateKbsPinViewModel.class);
CreateKbsPinViewModel viewModel = ViewModelProviders.of(this).get(CreateKbsPinViewModel.class);
CreateKbsPinFragmentArgs args = CreateKbsPinFragmentArgs.fromBundle(requireArguments());


viewModel.getNavigationEvents().observe(getViewLifecycleOwner(), e -> onConfirmPin(e.getUserEntry(), e.getKeyboard()));
viewModel.getNavigationEvents().observe(getViewLifecycleOwner(), e -> onConfirmPin(e.getUserEntry(), e.getKeyboard(), args.getIsPinChange()));
viewModel.getKeyboard().observe(getViewLifecycleOwner(), k -> {
getLabel().setText(getLabelText(k));
getInput().getText().clear();
Expand All @@ -48,12 +58,12 @@ protected CreateKbsPinViewModel initializeViewModel() {
return viewModel;
}

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

action.setUserEntry(userEntry);
action.setKeyboard(keyboard);
action.setIsNewPin(args.getIsNewPin());
action.setIsPinChange(isPinChange);

Navigation.findNavController(requireView()).navigate(action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -13,12 +12,10 @@
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.TextSecurePreferences;

public final class KbsSplashFragment extends Fragment {

Expand All @@ -45,7 +42,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
primaryAction.setOnClickListener(v -> onCreatePin());
secondaryAction.setOnClickListener(v -> onLearnMore());

if (TextSecurePreferences.isV1RegistrationLockEnabled(requireContext())) {
if (PinUtil.userHasPin(requireContext())) {
setUpRegLockEnabled();
} else {
setUpRegLockDisabled();
Expand Down Expand Up @@ -74,7 +71,11 @@ private void setUpRegLockDisabled() {
}

private void onCreatePin() {
Navigation.findNavController(requireView()).navigate(KbsSplashFragmentDirections.actionCreateKbsPin());
KbsSplashFragmentDirections.ActionCreateKbsPin action = KbsSplashFragmentDirections.actionCreateKbsPin();

action.setIsPinChange(PinUtil.userHasPin(requireContext()));

Navigation.findNavController(requireView()).navigate(action);
}

private void onLearnMore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static Map<Event, MegaphoneSchedule> buildDisplayOrder() {
return builder.setTitle(R.string.KbsMegaphone__introducing_pins)
.setBody(R.string.KbsMegaphone__your_registration_lock_is_now_called_a_pin)
.setButtonText(R.string.KbsMegaphone__update_pin, (megaphone, listener) -> {
Intent intent = CreateKbsPinActivity.getIntentForPinUpdate(ApplicationDependencies.getApplication());
Intent intent = CreateKbsPinActivity.getIntentForPinChangeFromSettings(ApplicationDependencies.getApplication());

listener.onMegaphoneNavigationRequested(intent, CreateKbsPinActivity.REQUEST_NEW_PIN);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -182,7 +181,7 @@ public boolean onPreferenceClick(Preference preference) {
private class KbsPinUpdateListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(CreateKbsPinActivity.getIntentForPinUpdate(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
startActivityForResult(CreateKbsPinActivity.getIntentForPinChangeFromSettings(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

if (!isReregister()) {
final Intent main = new Intent(activity, MainActivity.class);
final Intent next = getRoutedIntent(activity, EditProfileActivity.class, main);
final Intent next = chainIntents(new Intent(activity, EditProfileActivity.class), main);

next.putExtra(EditProfileActivity.SHOW_TOOLBAR, false);

Context context = requireContext();
if (FeatureFlags.pinsForAll() && !PinUtil.userHasPin(context)) {
activity.startActivity(getRoutedIntent(activity, CreateKbsPinActivity.class, next));
activity.startActivity(chainIntents(CreateKbsPinActivity.getIntentForPinCreate(context), next));
} else {
activity.startActivity(next);
}
Expand All @@ -52,9 +52,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}

private static Intent getRoutedIntent(@NonNull Context context, Class<?> destination, @Nullable Intent nextIntent) {
final Intent intent = new Intent(context, destination);
if (nextIntent != null) intent.putExtra("next_intent", nextIntent);
return intent;
private static Intent chainIntents(@NonNull Intent sourceIntent, @Nullable Intent nextIntent) {
if (nextIntent != null) sourceIntent.putExtra("next_intent", nextIntent);
return sourceIntent;
}
}
9 changes: 7 additions & 2 deletions app/src/main/res/navigation/create_kbs_pin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

<argument
app:argType="boolean"
android:name="is_new_pin"
android:name="is_pin_change"
android:defaultValue="false" />

<argument
app:argType="boolean"
android:name="is_forgot_pin"
android:defaultValue="false" />

</fragment>
Expand All @@ -34,7 +39,7 @@

<argument
app:argType="boolean"
android:name="is_new_pin"
android:name="is_pin_change"
android:defaultValue="false" />

<argument
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/navigation/kbs_migration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
app:popExitAnim="@anim/nav_default_pop_exit_anim" >

<argument
app:argType="boolean"
android:name="is_pin_change"
android:defaultValue="false" />

</action>

</fragment>

Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,10 @@
<item quantity="other">PIN must be at least %1$d digits</item>
</plurals>
<string name="CreateKbsPinFragment__create_a_new_pin">Create a new PIN</string>
<string name="CreateKbsPinFragment__because_youre_still_logged_in">Because you\'re still logged in, you can create a new PIN. When you\'re logged out, there is no way to recover your PIN.</string>
<plurals name="CreateKbsPinFragment__you_can_choose_a_new_pin_because_this_device_is_registered">
<item quantity="one">You can choose a new PIN because this device is registered. If you forget your PIN, you may need to wait %1$d day to register again.</item>
<item quantity="other">You can choose a new PIN because this device is registered. If you forget your PIN, you may need to wait %1$d days to register again.</item>
</plurals>
<string name="CreateKbsPinFragment__create_your_pin">Create your PIN</string>
<string name="CreateKbsPinFragment__pins_add_an_extra_layer_of_security">PINs add an extra layer of security to your account. It\'s important to remember this PIN, as it can\'t be recovered.</string>

Expand All @@ -1715,7 +1718,7 @@
<string name="KbsSplashFragment__introducing_pins">Introducing PINs</string>
<string name="KbsSplashFragment__pins_add_another_level_of_security_to_your_account">PINs add another level of security to your account. Create one now.</string>
<string name="KbsSplashFragment__learn_more">Learn More</string>
<string name="KbsSplashFragment__learn_more_link">https://signal.org/blog/secure-value-recovery/</string>
<string name="KbsSplashFragment__learn_more_link">https://support.signal.org/hc/en-us/articles/360007059792-Registration-Lock</string>
<string name="KbsSplashFragment__registration_lock_equals_pin">Registration Lock = PIN</string>
<string name="KbsSplashFragment__your_registration_lock_is_now_called_a_pin">Your Registration Lock is now called a PIN, and it does more. Update it now.</string>
<string name="KbsSplashFragment__read_more_about_pins">Read more about PINs.</string>
Expand All @@ -1735,7 +1738,7 @@
<string name="AccountLockedFragment__your_account_has_been_locked_to_protect_your_privacy">Your account has been locked to protect your privacy and security. After %1$d days of inactivity in your account you\'ll be able to re-register this phone number without needing your pin. All content will be deleted.</string>
<string name="AccountLockedFragment__next">Next</string>
<string name="AccountLockedFragment__learn_more">Learn More</string>
<string name="AccountLockedFragment__learn_more_url">https://signal.org/blog/secure-value-recovery/</string>
<string name="AccountLockedFragment__learn_more_url">https://support.signal.org/hc/en-us/articles/360007059792-Registration-Lock</string>

<!-- KbsLockFragment -->
<string name="RegistrationLockFragment__enter_your_pin">Enter your PIN</string>
Expand Down

0 comments on commit e14861d

Please sign in to comment.