Align pin reminder skip behavior with iOS.

This commit is contained in:
Alex Hart
2025-04-17 17:39:33 -03:00
committed by Cody Henthorne
parent 893725e304
commit 138dae0484
6 changed files with 68 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ public final class PinValues extends SignalStoreValues {
private static final String TAG = Log.tag(PinValues.class);
private static final String LAST_SUCCESSFUL_ENTRY = "pin.last_successful_entry";
private static final String LAST_REMINDER_TIME = "pin.last_reminder_time";
private static final String NEXT_INTERVAL = "pin.interval_index";
private static final String KEYBOARD_TYPE = "kbs.keyboard_type";
public static final String PIN_REMINDERS_ENABLED = "pin.pin_reminders_enabled";
@@ -40,9 +41,12 @@ public final class PinValues extends SignalStoreValues {
long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
Log.i(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
long now = System.currentTimeMillis();
getStore().beginWrite()
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
.putLong(LAST_SUCCESSFUL_ENTRY, now)
.putLong(NEXT_INTERVAL, nextInterval)
.putLong(LAST_REMINDER_TIME, now)
.apply();
SignalStore.svr().setPinIfNotPresent(pin);
@@ -52,28 +56,48 @@ public final class PinValues extends SignalStoreValues {
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
Log.i(TAG, "onEntrySuccessWithWrongGuess() nextInterval: " + nextInterval);
long now = System.currentTimeMillis();
getStore().beginWrite()
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
.putLong(LAST_SUCCESSFUL_ENTRY, now)
.putLong(NEXT_INTERVAL, nextInterval)
.putLong(LAST_REMINDER_TIME, now)
.apply();
SignalStore.svr().setPinIfNotPresent(pin);
}
public void onEntrySkipWithWrongGuess() {
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
Log.i(TAG, "onEntrySkipWithWrongGuess() nextInterval: " + nextInterval);
/**
* Updates LAST_REMINDER_TIME and in the case of a failed guess, ratches
* back the interval until next reminder.
*/
public void onEntrySkip(boolean includedFailure) {
long nextInterval;
putLong(NEXT_INTERVAL, nextInterval);
if (includedFailure) {
nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
} else {
nextInterval = getCurrentInterval();
}
Log.i(TAG, "onEntrySkip(includedFailure: " + includedFailure +") nextInterval: " + nextInterval);
getStore().beginWrite()
.putLong(NEXT_INTERVAL, nextInterval)
.putLong(LAST_REMINDER_TIME, System.currentTimeMillis())
.apply();
}
public void resetPinReminders() {
long nextInterval = SignalPinReminders.INITIAL_INTERVAL;
Log.i(TAG, "resetPinReminders() nextInterval: " + nextInterval, new Throwable());
long now = System.currentTimeMillis();
getStore().beginWrite()
.putLong(NEXT_INTERVAL, nextInterval)
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
.putLong(LAST_SUCCESSFUL_ENTRY, now)
.putLong(LAST_REMINDER_TIME, now)
.apply();
}
@@ -85,6 +109,10 @@ public final class PinValues extends SignalStoreValues {
return getLong(LAST_SUCCESSFUL_ENTRY, TextSecurePreferences.getRegistrationLockLastReminderTime(AppDependencies.getApplication()));
}
public long getLastReminderTime() {
return getLong(LAST_REMINDER_TIME, getLastSuccessfulEntryTime());
}
public void setKeyboardType(@NonNull PinKeyboardType keyboardType) {
putString(KEYBOARD_TYPE, keyboardType.getCode());
}

View File

@@ -40,6 +40,14 @@ public class SignalPinReminders {
put(FOUR_WEEKS, R.string.SignalPinReminders_well_remind_you_again_in_a_month);
}};
private static final Map<Long, Integer> SKIP_STRINGS = new HashMap<Long, Integer>() {{
put(ONE_DAY, R.string.SignalPinReminders__well_remind_you_again_tomorrow);
put(THREE_DAYS, R.string.SignalPinReminders__well_remind_you_again_in_a_few_days);
put(ONE_WEEK, R.string.SignalPinReminders__well_remind_you_again_in_a_week);
put(TWO_WEEKS, R.string.SignalPinReminders__well_remind_you_again_in_a_couple_weeks);
put(FOUR_WEEKS, R.string.SignalPinReminders__well_remind_you_again_in_a_month);
}};
public static final long INITIAL_INTERVAL = INTERVALS.first();
public static long getNextInterval(long currentInterval) {
@@ -62,4 +70,15 @@ public class SignalPinReminders {
return R.string.SignalPinReminders_well_remind_you_again_later;
}
}
public static @StringRes int getSkipReminderString(long interval) {
Integer stringRes = SKIP_STRINGS.get(interval);
if (stringRes != null) {
return stringRes;
} else {
Log.w(TAG, "Couldn't find a string for interval " + interval);
return R.string.SignalPinReminders__well_remind_you_again_later;
}
}
}

View File

@@ -16,6 +16,7 @@ public class LogSectionPin implements LogSection {
@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
return new StringBuilder().append("Last Successful Reminder Entry: ").append(SignalStore.pin().getLastSuccessfulEntryTime()).append("\n")
.append("Last Reminder Time: ").append(SignalStore.pin().getLastReminderTime()).append("\n")
.append("Next Reminder Interval: ").append(SignalStore.pin().getCurrentInterval()).append("\n")
.append("Reglock: ").append(SignalStore.svr().isRegistrationLockEnabled()).append("\n")
.append("Signal PIN: ").append(SignalStore.svr().hasPin()).append("\n")

View File

@@ -236,9 +236,10 @@ public final class Megaphones {
@Override
public void onReminderDismissed(boolean includedFailure) {
Log.i(TAG, "[PinReminder] onReminderDismissed(" + includedFailure + ")");
if (includedFailure) {
SignalStore.pin().onEntrySkipWithWrongGuess();
}
SignalStore.pin().onEntrySkip(includedFailure);
controller.onMegaphoneSnooze(Event.PIN_REMINDER);
controller.onMegaphoneToastRequested(controller.getMegaphoneActivity().getString(SignalPinReminders.getSkipReminderString(SignalStore.pin().getCurrentInterval())));
}
@Override

View File

@@ -22,9 +22,9 @@ final class SignalPinReminderSchedule implements MegaphoneSchedule {
return false;
}
long lastSuccessTime = SignalStore.pin().getLastSuccessfulEntryTime();
long interval = SignalStore.pin().getCurrentInterval();
long lastReminderTime = SignalStore.pin().getLastReminderTime();
long interval = SignalStore.pin().getCurrentInterval();
return currentTime - lastSuccessTime >= interval;
return currentTime - lastReminderTime >= interval;
}
}

View File

@@ -2769,6 +2769,12 @@
<string name="SignalPinReminders_well_remind_you_again_in_a_week">PIN verified successfully. We\'ll remind you again in a week.</string>
<string name="SignalPinReminders_well_remind_you_again_in_a_couple_weeks">PIN verified successfully. We\'ll remind you again in a couple weeks.</string>
<string name="SignalPinReminders_well_remind_you_again_in_a_month">PIN verified successfully. We\'ll remind you again in a month.</string>
<string name="SignalPinReminders__well_remind_you_again_later">We\'ll remind you again later.</string>
<string name="SignalPinReminders__well_remind_you_again_tomorrow">We\'ll remind you again tomorrow.</string>
<string name="SignalPinReminders__well_remind_you_again_in_a_few_days">We\'ll remind you again in a few days.</string>
<string name="SignalPinReminders__well_remind_you_again_in_a_week">We\'ll remind you again in a week.</string>
<string name="SignalPinReminders__well_remind_you_again_in_a_couple_weeks">We\'ll remind you again in a couple weeks.</string>
<string name="SignalPinReminders__well_remind_you_again_in_a_month">We\'ll remind you again in a month.</string>
<!-- Slide -->
<string name="Slide_image">Image</string>