Skip to content

Commit

Permalink
Fix crash in getIntentForPinCreate(), show 'Create' in prefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 3, 2020
1 parent 835ef02 commit 77caa9e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ public class CreateKbsPinActivity extends BaseActionBarActivity {
private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();

public static Intent getIntentForPinCreate(@NonNull Context context) {
return new Intent(context, CreateKbsPinActivity.class);
return getIntent(context, true);
}

public static Intent getIntentForPinUpdate(@NonNull Context context) {
Intent intent = getIntentForPinCreate(context);

intent.putExtra(IS_NEW_PIN, true);
return getIntent(context, false);
}

private static Intent getIntent(@NonNull Context context, boolean isNewPin) {
Intent intent = new Intent(context, CreateKbsPinActivity.class);
intent.putExtra(IS_NEW_PIN, isNewPin);
return intent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 All @@ -23,7 +24,6 @@
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.lock.RegistrationLockDialog;
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
import org.thoughtcrime.securesms.lock.v2.PinUtil;
Expand Down Expand Up @@ -56,8 +56,16 @@ public void onCreate(Bundle paramBundle) {
Preference kbsGroup = this.findPreference("prefs_lock_v2");

if (FeatureFlags.pinsForAll()) {
Preference preference = this.findPreference("pref_kbs_change");
regGroup.setVisible(false);
kbsPinChange.setOnPreferenceClickListener(new KbsPinChangeListener());

if (PinUtil.userHasPin(ApplicationDependencies.getApplication())) {
kbsPinChange.setOnPreferenceClickListener(new KbsPinUpdateListener());
preference.setWidgetLayoutResource(R.layout.kbs_pin_change_preference);
} else {
kbsPinChange.setOnPreferenceClickListener(new KbsPinCreateListener());
preference.setWidgetLayoutResource(R.layout.kbs_pin_create_preference);
}
} else {
kbsGroup.setVisible(false);
regLock.setChecked(PinUtil.userHasPin(requireContext()));
Expand Down Expand Up @@ -171,14 +179,22 @@ public boolean onPreferenceClick(Preference preference) {
}
}

private class KbsPinChangeListener implements Preference.OnPreferenceClickListener {
private class KbsPinUpdateListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(CreateKbsPinActivity.getIntentForPinUpdate(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
return true;
}
}

private class KbsPinCreateListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
return true;
}
}

private class AccountLockClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/kbs_pin_create_preference.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/preferences_app_protection__create" />
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@
<string name="preferences_app_protection__signal_pin">Signal PIN</string>
<string name="preferences_app_protection__pin">PIN</string>
<string name="preferences_app_protection__change">Change</string>
<string name="preferences_app_protection__create">Create</string>
<string name="preferences_app_protection__your_pin_adds_an_extra_layer_of_security_and_backs">Your PIN adds an extra layer of security and backs up your account. You\'ll be asked for it when you register your phone number with Signal. If you forget your PIN, you\'ll be locked out of your account for 7 days.</string>
<string name="AppProtectionPreferenceFragment_none">None</string>
<string name="registration_activity__the_registration_lock_pin_is_not_the_same_as_the_sms_verification_code_you_just_received_please_enter_the_pin_you_previously_configured_in_the_application">The Registration Lock PIN is not the same as the SMS verification code you just received. Please enter the PIN you previously configured in the application.</string>
Expand Down

0 comments on commit 77caa9e

Please sign in to comment.