mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
reschedule daily and weekly recurring notifications at the notif
This commit is contained in:
parent
234691b0ed
commit
71161651f4
@ -156,21 +156,13 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Event getEvent(int id) {
|
public Event getEvent(int id) {
|
||||||
final String[] projection = {COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES};
|
final String selection = MAIN_TABLE_NAME + "." + COL_ID + " = ?";
|
||||||
final String selection = COL_ID + " = ?";
|
|
||||||
final String[] selectionArgs = {String.valueOf(id)};
|
final String[] selectionArgs = {String.valueOf(id)};
|
||||||
final Cursor cursor = mDb.query(MAIN_TABLE_NAME, projection, selection, selectionArgs, null, null, null);
|
final Cursor cursor = getEventsCursor(selection, selectionArgs);
|
||||||
if (cursor != null) {
|
final List<Event> events = fillEvents(cursor);
|
||||||
if (cursor.moveToFirst()) {
|
if (!events.isEmpty())
|
||||||
final int startTS = cursor.getInt(cursor.getColumnIndex(COL_START_TS));
|
return events.get(0);
|
||||||
final int endTS = cursor.getInt(cursor.getColumnIndex(COL_END_TS));
|
|
||||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
|
||||||
final String description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION));
|
|
||||||
final int reminderMinutes = cursor.getInt(cursor.getColumnIndex(COL_REMINDER_MINUTES));
|
|
||||||
cursor.close();
|
|
||||||
return new Event(id, startTS, endTS, title, description, reminderMinutes, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +200,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||||||
newEvents.addAll(getEvents(selection, ts));
|
newEvents.addAll(getEvents(selection, ts));
|
||||||
|
|
||||||
// get yearly events
|
// get yearly events
|
||||||
selection = COL_REPEAT_INTERVAL + " = " + Constants.YEAR + " AND " + COL_REPEAT_MONTH + " = " + dateTime.getMonthOfYear() + " AND " +
|
selection = COL_REPEAT_INTERVAL + " = " + Constants.YEAR + " AND " + COL_REPEAT_MONTH + " = " + dateTime.getMonthOfYear() +
|
||||||
COL_REPEAT_DAY + " = " + dateTime.getDayOfMonth() + " AND " + COL_REPEAT_START + " <= " + dayEnd;
|
" AND " + COL_REPEAT_DAY + " = " + dateTime.getDayOfMonth() + " AND " + COL_REPEAT_START + " <= " + dayEnd;
|
||||||
newEvents.addAll(getEvents(selection, ts));
|
newEvents.addAll(getEvents(selection, ts));
|
||||||
|
|
||||||
return newEvents;
|
return newEvents;
|
||||||
|
@ -30,19 +30,26 @@ public class Utils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long delayFromNow = (long) event.getStartTS() * 1000 - event.getReminderMinutes() * 60000 - System.currentTimeMillis();
|
scheduleEventIn(context, event.getStartTS(), event);
|
||||||
if (delayFromNow < 0) {
|
}
|
||||||
|
|
||||||
|
public static void scheduleEventIn(Context context, int notifTS, Event event) {
|
||||||
|
final long delayFromNow = (long) notifTS * 1000 - event.getReminderMinutes() * 60000 - System.currentTimeMillis();
|
||||||
|
if (delayFromNow < 0)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
final long notifInMs = SystemClock.elapsedRealtime() + delayFromNow;
|
final long notifInMs = SystemClock.elapsedRealtime() + delayFromNow;
|
||||||
final Intent intent = new Intent(context, NotificationReceiver.class);
|
final PendingIntent pendingIntent = getNotificationIntent(context, event.getId());
|
||||||
intent.putExtra(NotificationReceiver.EVENT_ID, event.getId());
|
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, event.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, notifInMs, pendingIntent);
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, notifInMs, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PendingIntent getNotificationIntent(Context context, int eventId) {
|
||||||
|
final Intent intent = new Intent(context, NotificationReceiver.class);
|
||||||
|
intent.putExtra(NotificationReceiver.EVENT_ID, eventId);
|
||||||
|
return PendingIntent.getBroadcast(context, eventId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
public static int[] getLetterIDs() {
|
public static int[] getLetterIDs() {
|
||||||
return new int[]{R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
|
return new int[]{R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
|
||||||
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter};
|
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter};
|
||||||
|
@ -13,6 +13,7 @@ import com.simplemobiletools.calendar.Constants;
|
|||||||
import com.simplemobiletools.calendar.DBHelper;
|
import com.simplemobiletools.calendar.DBHelper;
|
||||||
import com.simplemobiletools.calendar.Formatter;
|
import com.simplemobiletools.calendar.Formatter;
|
||||||
import com.simplemobiletools.calendar.R;
|
import com.simplemobiletools.calendar.R;
|
||||||
|
import com.simplemobiletools.calendar.Utils;
|
||||||
import com.simplemobiletools.calendar.activities.EventActivity;
|
import com.simplemobiletools.calendar.activities.EventActivity;
|
||||||
import com.simplemobiletools.calendar.models.Event;
|
import com.simplemobiletools.calendar.models.Event;
|
||||||
|
|
||||||
@ -35,6 +36,20 @@ public class NotificationReceiver extends BroadcastReceiver {
|
|||||||
final String title = event.getTitle();
|
final String title = event.getTitle();
|
||||||
final Notification notification = getNotification(context, pendingIntent, startTime + " - " + endTime + " " + title);
|
final Notification notification = getNotification(context, pendingIntent, startTime + " - " + endTime + " " + title);
|
||||||
notificationManager.notify(id, notification);
|
notificationManager.notify(id, notification);
|
||||||
|
|
||||||
|
if (event.getRepeatInterval() != 0)
|
||||||
|
scheduleNextEvent(context, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleNextEvent(Context context, Event event) {
|
||||||
|
if (event.getRepeatInterval() == Constants.DAY || event.getRepeatInterval() == Constants.WEEK) {
|
||||||
|
int startTS = event.getStartTS();
|
||||||
|
while (startTS < System.currentTimeMillis() / 1000 + 5) {
|
||||||
|
startTS += event.getRepeatInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.scheduleEventIn(context, startTS, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent getPendingIntent(Context context, Event event) {
|
private PendingIntent getPendingIntent(Context context, Event event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user