2017-06-11 17:22:54 +02:00
|
|
|
package info.nightscout.androidaps.receivers;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2017-08-20 11:17:05 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2017-06-11 17:22:54 +02:00
|
|
|
|
|
|
|
import info.nightscout.androidaps.MainApp;
|
|
|
|
import info.nightscout.androidaps.Services.Intents;
|
|
|
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
|
2017-11-28 21:48:46 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
2017-06-11 17:22:54 +02:00
|
|
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
|
|
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
|
|
|
|
|
|
public class NSAlarmReceiver extends BroadcastReceiver {
|
2017-08-20 11:17:05 +02:00
|
|
|
private static Logger log = LoggerFactory.getLogger(NSAlarmReceiver.class);
|
2017-06-11 17:22:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent == null)
|
|
|
|
return;
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
String data = bundle.getString("data");
|
|
|
|
JSONObject json = null;
|
|
|
|
try {
|
|
|
|
json = new JSONObject(data);
|
|
|
|
} catch (JSONException e) {
|
2017-08-20 11:17:05 +02:00
|
|
|
log.error("Unhandled exception", e);
|
2017-06-11 17:22:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSAlarm nsAlarm = new NSAlarm(json);
|
|
|
|
switch (intent.getAction()) {
|
|
|
|
case Intents.ACTION_ANNOUNCEMENT:
|
|
|
|
case Intents.ACTION_ALARM:
|
|
|
|
case Intents.ACTION_URGENT_ALARM:
|
|
|
|
Notification notification = new Notification(nsAlarm);
|
2017-06-21 07:28:04 +02:00
|
|
|
if (notification.isEnabled())
|
|
|
|
MainApp.bus().post(new EventNewNotification(notification));
|
2017-06-11 17:22:54 +02:00
|
|
|
break;
|
|
|
|
case Intents.ACTION_CLEAR_ALARM:
|
|
|
|
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
|
|
|
|
MainApp.bus().post(new EventDismissNotification(Notification.NSURGENTALARM));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|