diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index c68897521..87accd564 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -209,6 +209,12 @@ + + + + + + diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java new file mode 100644 index 000000000..f6019b8e8 --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java @@ -0,0 +1,24 @@ +package com.todoroo.astrid.reminders; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.todoroo.andlib.utility.Preferences; + +public class ReengagementReceiver extends BroadcastReceiver { + + + + @Override + public void onReceive(Context context, Intent intent) { + + int reengagementReminders = Preferences.getInt(ReengagementService.PREF_REENGAGEMENT_COUNT, 1); + Preferences.setInt(ReengagementService.PREF_REENGAGEMENT_COUNT, reengagementReminders + 1); + + // TODO: show dialog + + ReengagementService.scheduleReengagementAlarm(context); + } + +} diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementService.java new file mode 100644 index 000000000..6b6a1cde5 --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementService.java @@ -0,0 +1,41 @@ +package com.todoroo.astrid.reminders; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; + +import com.todoroo.andlib.utility.DateUtilities; +import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.utility.Constants; + +public final class ReengagementService { + + private static final int REQUEST_CODE = 10; + + public static final String PREF_REENGAGEMENT_COUNT = "pref_reengagement_count"; //$NON-NLS-1$ + + public static final String BROADCAST_SHOW_REENGAGEMENT = Constants.PACKAGE + ".SHOW_REENGAGEMENT"; //$NON-NLS-1$ + + public static void scheduleReengagementAlarm(Context context) { + AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(BROADCAST_SHOW_REENGAGEMENT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0); + am.cancel(pendingIntent); + + long time = getNextReminderTime(); + am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); + } + + private static long getNextReminderTime() { + int reengagementReminders = Preferences.getInt(PREF_REENGAGEMENT_COUNT, 1); + int days; + if (reengagementReminders >= 4) + days = 12; + else + days = 3 * reengagementReminders; + + return DateUtilities.now() + DateUtilities.ONE_DAY * days; + } + +}