|  |  | @ -6,13 +6,21 @@ import android.support.annotation.NonNull; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.util.TextSecurePreferences; |  |  |  | import org.thoughtcrime.securesms.util.TextSecurePreferences; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.HashMap; |  |  |  | import java.util.NavigableSet; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Map; |  |  |  | import java.util.TreeSet; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | import java.util.concurrent.TimeUnit; |  |  |  | import java.util.concurrent.TimeUnit; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | public class RegistrationLockReminders { |  |  |  | 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) { |  |  |  |   public static boolean needsReminder(@NonNull Context context) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (!TextSecurePreferences.isRegistrationtLockEnabled(context)) return false; |  |  |  |     if (!TextSecurePreferences.isRegistrationtLockEnabled(context)) return false; | 
			
		
	
	
		
		
			
				
					|  |  | @ -24,20 +32,16 @@ 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 nextReminderInterval; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     long nextReminderInterval; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (success) { |  |  |  |     if (success) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       if      (lastReminderInterval <= TimeUnit.HOURS.toMillis(6))  nextReminderInterval = TimeUnit.HOURS.toMillis(12); |  |  |  |       long timeSinceLastReminder = System.currentTimeMillis() - TextSecurePreferences.getRegistrationLockLastReminderTime(context); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else if (lastReminderInterval <= TimeUnit.HOURS.toMillis(12)) nextReminderInterval = TimeUnit.DAYS.toMillis(1); |  |  |  |       nextReminderInterval = INTERVALS.higher(timeSinceLastReminder); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else if (lastReminderInterval <= TimeUnit.DAYS.toMillis(1))   nextReminderInterval = TimeUnit.DAYS.toMillis(3); |  |  |  |       if (nextReminderInterval == null) nextReminderInterval = INTERVALS.last(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else if (lastReminderInterval <= TimeUnit.DAYS.toMillis(3))   nextReminderInterval = TimeUnit.DAYS.toMillis(7); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       else                                                                  nextReminderInterval = TimeUnit.DAYS.toMillis(7); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } else { |  |  |  |     } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |       if      (lastReminderInterval >= TimeUnit.DAYS.toMillis(7)) nextReminderInterval = TimeUnit.DAYS.toMillis(3); |  |  |  |       long lastReminderInterval = TextSecurePreferences.getRegistrationLockNextReminderInterval(context); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else if (lastReminderInterval >= TimeUnit.DAYS.toMillis(3)) nextReminderInterval = TimeUnit.DAYS.toMillis(1); |  |  |  |       nextReminderInterval = INTERVALS.lower(lastReminderInterval); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else if (lastReminderInterval >= TimeUnit.DAYS.toMillis(1)) nextReminderInterval = TimeUnit.HOURS.toMillis(12); |  |  |  |       if (nextReminderInterval == null) nextReminderInterval = INTERVALS.first(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       else                                                                nextReminderInterval = TimeUnit.HOURS.toMillis(6); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis()); |  |  |  |     TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis()); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |