Marshall and unmarshall Timers passed to TimerNotificationService.
This commit is contained in:
parent
92fac3eb34
commit
fb67a28e34
@ -30,6 +30,7 @@ import com.philliphsu.clock2.chronometer.ChronometerNotificationService;
|
|||||||
import com.philliphsu.clock2.timers.data.AsyncTimersTableUpdateHandler;
|
import com.philliphsu.clock2.timers.data.AsyncTimersTableUpdateHandler;
|
||||||
import com.philliphsu.clock2.timers.data.TimerCursor;
|
import com.philliphsu.clock2.timers.data.TimerCursor;
|
||||||
import com.philliphsu.clock2.util.ContentIntentUtils;
|
import com.philliphsu.clock2.util.ContentIntentUtils;
|
||||||
|
import com.philliphsu.clock2.util.ParcelableUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the notification for an active Timer.
|
* Handles the notification for an active Timer.
|
||||||
@ -59,7 +60,7 @@ public class TimerNotificationService extends ChronometerNotificationService {
|
|||||||
*/
|
*/
|
||||||
public static void showNotification(Context context, Timer timer) {
|
public static void showNotification(Context context, Timer timer) {
|
||||||
Intent intent = new Intent(context, TimerNotificationService.class);
|
Intent intent = new Intent(context, TimerNotificationService.class);
|
||||||
intent.putExtra(EXTRA_TIMER, timer);
|
intent.putExtra(EXTRA_TIMER, ParcelableUtil.marshall(timer));
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +157,8 @@ public class TimerNotificationService extends ChronometerNotificationService {
|
|||||||
Intent intent = new Intent(
|
Intent intent = new Intent(
|
||||||
/*TimerNotificationService.this,
|
/*TimerNotificationService.this,
|
||||||
TimerNotificationService.class*/);
|
TimerNotificationService.class*/);
|
||||||
intent.putExtra(EXTRA_TIMER, cursor.getItem());
|
final Timer timer = cursor.getItem();
|
||||||
|
intent.putExtra(EXTRA_TIMER, ParcelableUtil.marshall(timer));
|
||||||
// TODO: Should we startService() instead?
|
// TODO: Should we startService() instead?
|
||||||
handleDefaultAction(intent, 0, 0);
|
handleDefaultAction(intent, 0, 0);
|
||||||
}
|
}
|
||||||
@ -168,10 +170,11 @@ public class TimerNotificationService extends ChronometerNotificationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleDefaultAction(Intent intent, int flags, int startId) {
|
protected void handleDefaultAction(Intent intent, int flags, int startId) {
|
||||||
final Timer timer = intent.getParcelableExtra(EXTRA_TIMER);
|
final byte[] bytes = intent.getByteArrayExtra(EXTRA_TIMER);
|
||||||
if (timer == null) {
|
if (bytes == null) {
|
||||||
throw new IllegalStateException("Cannot start TimerNotificationService without a Timer");
|
throw new IllegalStateException("Cannot start TimerNotificationService without a Timer");
|
||||||
}
|
}
|
||||||
|
final Timer timer = ParcelableUtil.unmarshall(bytes, Timer.CREATOR);
|
||||||
final long id = timer.getId();
|
final long id = timer.getId();
|
||||||
boolean updateChronometer = false;
|
boolean updateChronometer = false;
|
||||||
Timer oldTimer = mTimers.put(id, timer);
|
Timer oldTimer = mTimers.put(id, timer);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user