mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-26 01:37:43 +00:00
parent
aff65abe91
commit
41d06fc8c2
@ -14,23 +14,6 @@ public class RegistrationLockReminders {
|
|||||||
|
|
||||||
public static final long INITIAL_INTERVAL = TimeUnit.HOURS.toMillis(6);
|
public static final long INITIAL_INTERVAL = TimeUnit.HOURS.toMillis(6);
|
||||||
|
|
||||||
private static Map<Long, Long> INTERVAL_PROGRESSION = new HashMap<Long, Long>() {{
|
|
||||||
put(TimeUnit.HOURS.toMillis(6), TimeUnit.HOURS.toMillis(12));
|
|
||||||
put(TimeUnit.HOURS.toMillis(12), TimeUnit.DAYS.toMillis(1));
|
|
||||||
put(TimeUnit.DAYS.toMillis(1), TimeUnit.DAYS.toMillis(3));
|
|
||||||
put(TimeUnit.DAYS.toMillis(3), TimeUnit.DAYS.toMillis(7));
|
|
||||||
put(TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(7));
|
|
||||||
}};
|
|
||||||
|
|
||||||
|
|
||||||
private static Map<Long, Long> INTERVAL_REGRESSION = new HashMap<Long, Long>() {{
|
|
||||||
put(TimeUnit.HOURS.toMillis(12), TimeUnit.HOURS.toMillis(6));
|
|
||||||
put(TimeUnit.DAYS.toMillis(1), TimeUnit.HOURS.toMillis(12));
|
|
||||||
put(TimeUnit.DAYS.toMillis(3), TimeUnit.DAYS.toMillis(1));
|
|
||||||
put(TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(3));
|
|
||||||
}};
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean needsReminder(@NonNull Context context) {
|
public static boolean needsReminder(@NonNull Context context) {
|
||||||
if (!TextSecurePreferences.isRegistrationtLockEnabled(context)) return false;
|
if (!TextSecurePreferences.isRegistrationtLockEnabled(context)) return false;
|
||||||
|
|
||||||
@ -41,15 +24,20 @@ public class RegistrationLockReminders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void scheduleReminder(@NonNull Context context, boolean success) {
|
public static void scheduleReminder(@NonNull Context context, boolean success) {
|
||||||
long lastReminderInterval = TextSecurePreferences.getRegistrationLockNextReminderInterval(context);
|
long lastReminderInterval = TextSecurePreferences.getRegistrationLockNextReminderInterval(context);
|
||||||
long nextReminderInterval;
|
long nextReminderInterval;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if (INTERVAL_PROGRESSION.containsKey(lastReminderInterval)) nextReminderInterval = INTERVAL_PROGRESSION.get(lastReminderInterval);
|
if (lastReminderInterval <= TimeUnit.HOURS.toMillis(6)) nextReminderInterval = TimeUnit.HOURS.toMillis(12);
|
||||||
else nextReminderInterval = INTERVAL_PROGRESSION.get(TimeUnit.HOURS.toMillis(6));
|
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);
|
||||||
} else {
|
} else {
|
||||||
if (INTERVAL_REGRESSION.containsKey(lastReminderInterval)) nextReminderInterval = INTERVAL_REGRESSION.get(lastReminderInterval);
|
if (lastReminderInterval >= TimeUnit.DAYS.toMillis(7)) nextReminderInterval = TimeUnit.DAYS.toMillis(3);
|
||||||
else nextReminderInterval = INTERVAL_REGRESSION.get(TimeUnit.HOURS.toMillis(12));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
|
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user