mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:38:33 +00:00
Fixed PIN reminders showing too often, reminder UI improvements.
This commit is contained in:
parent
944adb5d7c
commit
0b6a52277d
@ -20,7 +20,7 @@ public final class PinValues {
|
|||||||
|
|
||||||
public void onEntrySuccess() {
|
public void onEntrySuccess() {
|
||||||
long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
|
long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
|
||||||
Log.w(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
|
Log.i(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
|
||||||
|
|
||||||
store.beginWrite()
|
store.beginWrite()
|
||||||
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
|
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
|
||||||
@ -28,18 +28,29 @@ public final class PinValues {
|
|||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEntryFailure() {
|
public void onEntrySuccessWithWrongGuess() {
|
||||||
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
|
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
|
||||||
Log.w(TAG, "onEntryFailure() nextInterval: " + nextInterval);
|
Log.i(TAG, "onEntrySuccessWithWrongGuess() nextInterval: " + nextInterval);
|
||||||
|
|
||||||
|
store.beginWrite()
|
||||||
|
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
|
||||||
|
.putLong(NEXT_INTERVAL, nextInterval)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntrySkipWithWrongGuess() {
|
||||||
|
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
|
||||||
|
Log.i(TAG, "onEntrySkipWithWrongGuess() nextInterval: " + nextInterval);
|
||||||
|
|
||||||
store.beginWrite()
|
store.beginWrite()
|
||||||
.putLong(NEXT_INTERVAL, nextInterval)
|
.putLong(NEXT_INTERVAL, nextInterval)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onPinChange() {
|
public void onPinChange() {
|
||||||
long nextInterval = SignalPinReminders.INITIAL_INTERVAL;
|
long nextInterval = SignalPinReminders.INITIAL_INTERVAL;
|
||||||
Log.w(TAG, "onPinChange() nextInterval: " + nextInterval);
|
Log.i(TAG, "onPinChange() nextInterval: " + nextInterval);
|
||||||
|
|
||||||
store.beginWrite()
|
store.beginWrite()
|
||||||
.putLong(NEXT_INTERVAL, nextInterval)
|
.putLong(NEXT_INTERVAL, nextInterval)
|
||||||
|
@ -26,6 +26,7 @@ import androidx.core.app.DialogCompat;
|
|||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||||
@ -41,6 +42,8 @@ public final class SignalPinReminderDialog {
|
|||||||
private static final String TAG = Log.tag(SignalPinReminderDialog.class);
|
private static final String TAG = Log.tag(SignalPinReminderDialog.class);
|
||||||
|
|
||||||
public static void show(@NonNull Context context, @NonNull Launcher launcher, @NonNull Callback mainCallback) {
|
public static void show(@NonNull Context context, @NonNull Launcher launcher, @NonNull Callback mainCallback) {
|
||||||
|
Log.i(TAG, "Showing PIN reminder dialog.");
|
||||||
|
|
||||||
AlertDialog dialog = new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.RationaleDialogDark_SignalAccent : R.style.RationaleDialogLight_SignalAccent)
|
AlertDialog dialog = new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.RationaleDialogDark_SignalAccent : R.style.RationaleDialogLight_SignalAccent)
|
||||||
.setView(R.layout.kbs_pin_reminder_view)
|
.setView(R.layout.kbs_pin_reminder_view)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
@ -55,8 +58,8 @@ public final class SignalPinReminderDialog {
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
dialog.getWindow().setLayout((int)(metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);
|
dialog.getWindow().setLayout((int)(metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
|
||||||
TextInputLayout pinWrapper = (TextInputLayout) DialogCompat.requireViewById(dialog, R.id.pin_wrapper);
|
|
||||||
EditText pinEditText = (EditText) DialogCompat.requireViewById(dialog, R.id.pin);
|
EditText pinEditText = (EditText) DialogCompat.requireViewById(dialog, R.id.pin);
|
||||||
|
TextView pinStatus = (TextView) DialogCompat.requireViewById(dialog, R.id.pin_status);
|
||||||
TextView reminder = (TextView) DialogCompat.requireViewById(dialog, R.id.reminder);
|
TextView reminder = (TextView) DialogCompat.requireViewById(dialog, R.id.reminder);
|
||||||
View skip = DialogCompat.requireViewById(dialog, R.id.skip);
|
View skip = DialogCompat.requireViewById(dialog, R.id.skip);
|
||||||
View submit = DialogCompat.requireViewById(dialog, R.id.submit);
|
View submit = DialogCompat.requireViewById(dialog, R.id.submit);
|
||||||
@ -92,7 +95,7 @@ public final class SignalPinReminderDialog {
|
|||||||
reminder.setText(new SpannableStringBuilder(reminderText).append(" ").append(forgotText));
|
reminder.setText(new SpannableStringBuilder(reminderText).append(" ").append(forgotText));
|
||||||
reminder.setMovementMethod(LinkMovementMethod.getInstance());
|
reminder.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
PinVerifier.Callback callback = getPinWatcherCallback(context, dialog, pinWrapper, mainCallback);
|
PinVerifier.Callback callback = getPinWatcherCallback(context, dialog, pinEditText, pinStatus, mainCallback);
|
||||||
PinVerifier verifier = SignalStore.kbsValues().isV2RegistrationLockEnabled()
|
PinVerifier verifier = SignalStore.kbsValues().isV2RegistrationLockEnabled()
|
||||||
? new V2PinVerifier()
|
? new V2PinVerifier()
|
||||||
: new V1PinVerifier(context);
|
: new V1PinVerifier(context);
|
||||||
@ -102,16 +105,29 @@ public final class SignalPinReminderDialog {
|
|||||||
mainCallback.onReminderDismissed(callback.hadWrongGuess());
|
mainCallback.onReminderDismissed(callback.hadWrongGuess());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
submit.setEnabled(false);
|
||||||
submit.setOnClickListener(v -> {
|
submit.setOnClickListener(v -> {
|
||||||
Editable pinEditable = pinEditText.getText();
|
Editable pinEditable = pinEditText.getText();
|
||||||
|
|
||||||
verifier.verifyPin(pinEditable == null ? null : pinEditable.toString(), callback);
|
verifier.verifyPin(pinEditable == null ? null : pinEditable.toString(), callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pinEditText.addTextChangedListener(new SimpleTextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(String text) {
|
||||||
|
if (text.length() >= KbsConstants.MINIMUM_POSSIBLE_PIN_LENGTH) {
|
||||||
|
submit.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
submit.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PinVerifier.Callback getPinWatcherCallback(@NonNull Context context,
|
private static PinVerifier.Callback getPinWatcherCallback(@NonNull Context context,
|
||||||
@NonNull AlertDialog dialog,
|
@NonNull AlertDialog dialog,
|
||||||
@NonNull TextInputLayout inputWrapper,
|
@NonNull EditText inputText,
|
||||||
|
@NonNull TextView statusText,
|
||||||
@NonNull Callback mainCallback)
|
@NonNull Callback mainCallback)
|
||||||
{
|
{
|
||||||
return new PinVerifier.Callback() {
|
return new PinVerifier.Callback() {
|
||||||
@ -119,14 +135,17 @@ public final class SignalPinReminderDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPinCorrect() {
|
public void onPinCorrect() {
|
||||||
|
Log.i(TAG, "Correct PIN entry.");
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
mainCallback.onReminderCompleted(hadWrongGuess);
|
mainCallback.onReminderCompleted(hadWrongGuess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPinWrong() {
|
public void onPinWrong() {
|
||||||
|
Log.i(TAG, "Incorrect PIN entry.");
|
||||||
hadWrongGuess = true;
|
hadWrongGuess = true;
|
||||||
inputWrapper.setError(context.getString(R.string.KbsReminderDialog__incorrect_pin_try_again));
|
inputText.getText().clear();
|
||||||
|
statusText.setText(context.getString(R.string.KbsReminderDialog__incorrect_pin_try_again));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,13 +13,12 @@ import org.thoughtcrime.securesms.database.model.MegaphoneRecord;
|
|||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.lock.RegistrationLockDialog;
|
|
||||||
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
|
|
||||||
import org.thoughtcrime.securesms.lock.SignalPinReminderDialog;
|
import org.thoughtcrime.securesms.lock.SignalPinReminderDialog;
|
||||||
import org.thoughtcrime.securesms.lock.SignalPinReminders;
|
import org.thoughtcrime.securesms.lock.SignalPinReminders;
|
||||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||||
import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity;
|
import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity;
|
||||||
import org.thoughtcrime.securesms.lock.v2.PinUtil;
|
import org.thoughtcrime.securesms.lock.v2.PinUtil;
|
||||||
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -42,6 +41,8 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public final class Megaphones {
|
public final class Megaphones {
|
||||||
|
|
||||||
|
private static final String TAG = Log.tag(Megaphones.class);
|
||||||
|
|
||||||
private Megaphones() {}
|
private Megaphones() {}
|
||||||
|
|
||||||
static @Nullable Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
|
static @Nullable Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
|
||||||
@ -81,7 +82,7 @@ public final class Megaphones {
|
|||||||
return new LinkedHashMap<Event, MegaphoneSchedule>() {{
|
return new LinkedHashMap<Event, MegaphoneSchedule>() {{
|
||||||
put(Event.REACTIONS, new ForeverSchedule(true));
|
put(Event.REACTIONS, new ForeverSchedule(true));
|
||||||
put(Event.PINS_FOR_ALL, new PinsForAllSchedule());
|
put(Event.PINS_FOR_ALL, new PinsForAllSchedule());
|
||||||
put(Event.PIN_REMINDER, new PinReminderSchedule());
|
put(Event.PIN_REMINDER, new SignalPinReminderSchedule());
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,15 +162,17 @@ public final class Megaphones {
|
|||||||
SignalPinReminderDialog.show(controller.getMegaphoneActivity(), controller::onMegaphoneNavigationRequested, new SignalPinReminderDialog.Callback() {
|
SignalPinReminderDialog.show(controller.getMegaphoneActivity(), controller::onMegaphoneNavigationRequested, new SignalPinReminderDialog.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onReminderDismissed(boolean includedFailure) {
|
public void onReminderDismissed(boolean includedFailure) {
|
||||||
|
Log.i(TAG, "[PinReminder] onReminderDismissed(" + includedFailure + ")");
|
||||||
if (includedFailure) {
|
if (includedFailure) {
|
||||||
SignalStore.pinValues().onEntryFailure();
|
SignalStore.pinValues().onEntrySkipWithWrongGuess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReminderCompleted(boolean includedFailure) {
|
public void onReminderCompleted(boolean includedFailure) {
|
||||||
|
Log.i(TAG, "[PinReminder] onReminderCompleted(" + includedFailure + ")");
|
||||||
if (includedFailure) {
|
if (includedFailure) {
|
||||||
SignalStore.pinValues().onEntryFailure();
|
SignalStore.pinValues().onEntrySuccessWithWrongGuess();
|
||||||
} else {
|
} else {
|
||||||
SignalStore.pinValues().onEntrySuccess();
|
SignalStore.pinValues().onEntrySuccess();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.megaphone;
|
|||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
|
|
||||||
final class PinReminderSchedule implements MegaphoneSchedule {
|
final class SignalPinReminderSchedule implements MegaphoneSchedule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldDisplay(int seenCount, long lastSeen, long firstVisible, long currentTime) {
|
public boolean shouldDisplay(int seenCount, long lastSeen, long firstVisible, long currentTime) {
|
@ -5,7 +5,8 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="20dp">
|
android:padding="20dp"
|
||||||
|
tools:layout_width="300dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/pin_reminder_title"
|
android:id="@+id/pin_reminder_title"
|
||||||
@ -19,25 +20,32 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
|
||||||
android:id="@+id/pin_wrapper"
|
<EditText
|
||||||
|
android:id="@+id/pin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="105sp"
|
||||||
|
android:paddingTop="40dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="?attr/registration_lock_reminder_view_pin_text_color"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/pin_reminder_title"
|
||||||
|
tools:text="******"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/pin_status"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="80dp"
|
|
||||||
android:paddingTop="40dp"
|
|
||||||
android:paddingEnd="80dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/pin_reminder_title"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent">
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
|
||||||
android:id="@+id/pin"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="?attr/registration_lock_reminder_view_pin_text_color" />
|
android:textColor="@color/core_red"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/pin"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
tools:text="@string/KbsReminderDialog__incorrect_pin_try_again">
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</TextView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/reminder"
|
android:id="@+id/reminder"
|
||||||
@ -47,7 +55,7 @@
|
|||||||
android:paddingTop="40dp"
|
android:paddingTop="40dp"
|
||||||
android:paddingBottom="40dp"
|
android:paddingBottom="40dp"
|
||||||
style="@style/Signal.Text.Preview"
|
style="@style/Signal.Text.Preview"
|
||||||
app:layout_constraintTop_toBottomOf="@id/pin_wrapper"
|
app:layout_constraintTop_toBottomOf="@id/pin_status"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
tools:text="@string/KbsReminderDialog__to_help_you_memorize_your_pin" />
|
tools:text="@string/KbsReminderDialog__to_help_you_memorize_your_pin" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user