|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.timsu.astrid.utilities;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
|
@ -25,6 +26,13 @@ import com.timsu.astrid.data.task.TaskIdentifier;
|
|
|
|
|
*/
|
|
|
|
|
public class LocaleReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
/** minimum amount of time between two notifications */
|
|
|
|
|
private static final long MIN_NOTIFY_INTERVAL = 8*3600*1000L;
|
|
|
|
|
|
|
|
|
|
/** hash map of times we've notified */
|
|
|
|
|
private static final HashMap<Long, Long> notifyTimes =
|
|
|
|
|
new HashMap<Long, Long>();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
/** Called when the system is started up */
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
@ -37,6 +45,13 @@ public class LocaleReceiver extends BroadcastReceiver {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if we've already made a notification recently
|
|
|
|
|
if(notifyTimes.containsKey(tagId)) {
|
|
|
|
|
if(System.currentTimeMillis() - notifyTimes.get(tagId) <
|
|
|
|
|
MIN_NOTIFY_INTERVAL)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find out if we have active tasks with this tag
|
|
|
|
|
TaskController taskController = new TaskController(context);
|
|
|
|
|
taskController.open();
|
|
|
|
@ -52,6 +67,7 @@ public class LocaleReceiver extends BroadcastReceiver {
|
|
|
|
|
String reminder = r.getString(R.string.notif_tagNotification,
|
|
|
|
|
r.getQuantityString(R.plurals.Ntasks, count, count), tagName);
|
|
|
|
|
Notifications.showTagNotification(context, tagId, reminder);
|
|
|
|
|
notifyTimes.put(tagId, System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
taskController.close();
|
|
|
|
@ -59,7 +75,7 @@ public class LocaleReceiver extends BroadcastReceiver {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e("astrid-localerx", "Error receiving intent", e);
|
|
|
|
|
Log.e("astrid-locale-rx", "Error receiving intent", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|