mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Allow skipping registration PIN intervals on success
Closes #7517 Closes #7518
This commit is contained in:
parent
b168e14985
commit
9c0129c4b0
@ -6,14 +6,22 @@ import android.support.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class RegistrationLockReminders {
|
||||
|
||||
public static final long INITIAL_INTERVAL = TimeUnit.HOURS.toMillis(6);
|
||||
|
||||
private static final NavigableSet<Long> INTERVALS = new TreeSet<Long>() {{
|
||||
add(TimeUnit.HOURS.toMillis(6));
|
||||
add(TimeUnit.HOURS.toMillis(12));
|
||||
add(TimeUnit.DAYS.toMillis(1));
|
||||
add(TimeUnit.DAYS.toMillis(3));
|
||||
add(TimeUnit.DAYS.toMillis(7));
|
||||
}};
|
||||
|
||||
public static final long INITIAL_INTERVAL = INTERVALS.first();
|
||||
|
||||
public static boolean needsReminder(@NonNull Context context) {
|
||||
if (!TextSecurePreferences.isRegistrationtLockEnabled(context)) return false;
|
||||
|
||||
@ -24,20 +32,16 @@ public class RegistrationLockReminders {
|
||||
}
|
||||
|
||||
public static void scheduleReminder(@NonNull Context context, boolean success) {
|
||||
long lastReminderInterval = TextSecurePreferences.getRegistrationLockNextReminderInterval(context);
|
||||
long nextReminderInterval;
|
||||
Long nextReminderInterval;
|
||||
|
||||
if (success) {
|
||||
if (lastReminderInterval <= TimeUnit.HOURS.toMillis(6)) nextReminderInterval = TimeUnit.HOURS.toMillis(12);
|
||||
else if (lastReminderInterval <= TimeUnit.HOURS.toMillis(12)) nextReminderInterval = TimeUnit.DAYS.toMillis(1);
|
||||
else if (lastReminderInterval <= TimeUnit.DAYS.toMillis(1)) nextReminderInterval = TimeUnit.DAYS.toMillis(3);
|
||||
else if (lastReminderInterval <= TimeUnit.DAYS.toMillis(3)) nextReminderInterval = TimeUnit.DAYS.toMillis(7);
|
||||
else nextReminderInterval = TimeUnit.DAYS.toMillis(7);
|
||||
long timeSinceLastReminder = System.currentTimeMillis() - TextSecurePreferences.getRegistrationLockLastReminderTime(context);
|
||||
nextReminderInterval = INTERVALS.higher(timeSinceLastReminder);
|
||||
if (nextReminderInterval == null) nextReminderInterval = INTERVALS.last();
|
||||
} else {
|
||||
if (lastReminderInterval >= TimeUnit.DAYS.toMillis(7)) nextReminderInterval = TimeUnit.DAYS.toMillis(3);
|
||||
else if (lastReminderInterval >= TimeUnit.DAYS.toMillis(3)) nextReminderInterval = TimeUnit.DAYS.toMillis(1);
|
||||
else if (lastReminderInterval >= TimeUnit.DAYS.toMillis(1)) nextReminderInterval = TimeUnit.HOURS.toMillis(12);
|
||||
else nextReminderInterval = TimeUnit.HOURS.toMillis(6);
|
||||
long lastReminderInterval = TextSecurePreferences.getRegistrationLockNextReminderInterval(context);
|
||||
nextReminderInterval = INTERVALS.lower(lastReminderInterval);
|
||||
if (nextReminderInterval == null) nextReminderInterval = INTERVALS.first();
|
||||
}
|
||||
|
||||
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
|
||||
|
Loading…
Reference in New Issue
Block a user