This commit is contained in:
Milos Kozak 2020-03-10 20:38:50 +01:00
commit 72a8bbfc75
8 changed files with 289 additions and 228 deletions

View file

@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.dexcom.cgm.EXTERNAL_PERMISSION" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
@ -264,6 +265,8 @@
<activity
android:name=".plugins.pump.insight.activities.InsightAlertActivity"
android:label="@string/pump_alert"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:theme="@style/InsightAlertDialog" />
<activity
android:name=".plugins.pump.insight.activities.InsightPairingInformationActivity"

View file

@ -1,25 +1,26 @@
package info.nightscout.androidaps.plugins.pump.insight;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Vibrator;
import android.text.Html;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.lifecycle.MutableLiveData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity;
import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage;
@ -32,19 +33,21 @@ import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType;
import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException;
import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException;
import info.nightscout.androidaps.plugins.pump.insight.utils.AlertUtilsKt;
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
public class InsightAlertService extends Service implements InsightConnectionService.StateCallback {
private static final int NOTIFICATION_ID = 31345;
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
private LocalBinder localBinder = new LocalBinder();
private boolean connectionRequested;
private final Object $alertLock = new Object[0];
private Alert alert;
private Alert alert = null;
private MutableLiveData<Alert> alertLiveData = new MutableLiveData<>();
private Thread thread;
private InsightAlertActivity alertActivity;
private Ringtone ringtone;
private Vibrator vibrator;
private boolean vibrating;
private InsightConnectionService connectionService;
@ -65,27 +68,6 @@ public class InsightAlertService extends Service implements InsightConnectionSer
}
};
private void retrieveRingtone() {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ringtone = RingtoneManager.getRingtone(this, uri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ringtone.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
.setLegacyStreamType(AudioManager.STREAM_RING).build());
} else ringtone.setStreamType(AudioManager.STREAM_RING);
}
public Alert getAlert() {
synchronized ($alertLock) {
return alert;
}
}
public void setAlertActivity(InsightAlertActivity alertActivity) {
this.alertActivity = alertActivity;
}
public void ignore(AlertType alertType) {
synchronized ($alertLock) {
if (alertType == null) {
@ -98,6 +80,10 @@ public class InsightAlertService extends Service implements InsightConnectionSer
}
}
public MutableLiveData<Alert> getAlertLiveData() {
return alertLiveData;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
@ -108,6 +94,7 @@ public class InsightAlertService extends Service implements InsightConnectionSer
public void onCreate() {
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE);
alertLiveData.setValue(null);
}
@Override
@ -118,6 +105,12 @@ public class InsightAlertService extends Service implements InsightConnectionSer
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ("mute".equals(intent.getStringExtra("command"))) {
mute();
} else if ("confirm".equals(intent.getStringExtra("command"))) {
dismissNotification();
confirm();
}
return START_STICKY;
}
@ -127,25 +120,47 @@ public class InsightAlertService extends Service implements InsightConnectionSer
thread = new Thread(this::queryActiveAlert);
thread.start();
} else if (thread != null) thread.interrupt();
} else {
dismissNotification();
if (thread != null) thread.interrupt();
}
}
private void queryActiveAlert() {
while (!Thread.currentThread().isInterrupted()) {
try {
Alert alert = connectionService.requestMessage(new GetActiveAlertMessage()).await().getAlert();
if (Thread.currentThread().isInterrupted()) {
connectionService.withdrawConnectionRequest(thread);
break;
}
synchronized ($alertLock) {
if ((this.alert == null && alert != null)
Alert alert = connectionService.requestMessage(new GetActiveAlertMessage()).await().getAlert();
if (alert == null || (alert.getAlertType() == ignoreType && System.currentTimeMillis() - ignoreTimestamp < 10000)) {
if (connectionRequested) {
connectionService.withdrawConnectionRequest(this);
connectionRequested = false;
}
this.alertLiveData.postValue(null);
this.alert = null;
dismissNotification();
stopAlerting();
} else if (!alert.equals(this.alert)) {
if (!connectionRequested) {
connectionService.requestConnection(this);
connectionRequested = true;
}
showNotification(alert);
this.alertLiveData.postValue(alert);
this.alert = alert;
if (alert.getAlertStatus() == AlertStatus.SNOOZED) stopAlerting();
else alert();
}
/*if ((this.alert == null && alert != null)
|| (this.alert != null && alert == null)
|| (this.alert != null && alert != null && !this.alert.equals(alert))) {
if (this.alert != null && (alert == null || this.alert.getAlertId() != alert.getAlertId())) stopAlerting();
this.alert = alert;
if (alertActivity != null && alert != null)
new Handler(Looper.getMainLooper()).post(() -> alertActivity.update(alert));
if (alert != null)
new Handler(Looper.getMainLooper()).post(() -> {
//showNotification(alert);
//alertActivity.update(alert);
});
}
if (alert == null) {
stopAlerting();
@ -153,8 +168,10 @@ public class InsightAlertService extends Service implements InsightConnectionSer
connectionService.withdrawConnectionRequest(this);
connectionRequested = false;
}
if (alertActivity != null)
new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish());
new Handler(Looper.getMainLooper()).post(() -> {
//dismissNotification();
//alertActivity.finish();
});
} else if (!(alert.getAlertType() == ignoreType && System.currentTimeMillis() - ignoreTimestamp < 10000)) {
if (alert.getAlertStatus() == AlertStatus.ACTIVE) alert();
else stopAlerting();
@ -162,12 +179,12 @@ public class InsightAlertService extends Service implements InsightConnectionSer
connectionService.requestConnection(this);
connectionRequested = true;
}
if (alertActivity == null) {
/*if (alertActivity == null) {
Intent intent = new Intent(InsightAlertService.this, InsightAlertActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
new Handler(Looper.getMainLooper()).post(() -> startActivity(intent));
}
}
}*/
//}
}
} catch (InterruptedException ignored) {
connectionService.withdrawConnectionRequest(thread);
@ -189,21 +206,18 @@ public class InsightAlertService extends Service implements InsightConnectionSer
connectionService.withdrawConnectionRequest(thread);
connectionRequested = false;
}
if (alertActivity != null)
new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish());
stopAlerting();
alertLiveData.postValue(null);
this.alert = null;
dismissNotification();
thread = null;
}
private void alert() {
if (!vibrating) {
vibrator.vibrate(new long[] {0, 1000, 1000}, 0);
vibrator.vibrate(new long[]{0, 1000, 1000}, 0);
vibrating = true;
}
if (ringtone == null || !ringtone.isPlaying()) {
retrieveRingtone();
ringtone.play();
}
}
private void stopAlerting() {
@ -211,15 +225,21 @@ public class InsightAlertService extends Service implements InsightConnectionSer
vibrator.cancel();
vibrating = false;
}
if (ringtone != null && ringtone.isPlaying()) ringtone.stop();
}
public void mute() {
new Thread(() -> {
try {
SnoozeAlertMessage snoozeAlertMessage = new SnoozeAlertMessage();
snoozeAlertMessage.setAlertID(alert.getAlertId());
connectionService.requestMessage(snoozeAlertMessage).await();
synchronized ($alertLock) {
if (alert == null) return;
alert.setAlertStatus(AlertStatus.SNOOZED);
alertLiveData.postValue(alert);
stopAlerting();
showNotification(alert);
SnoozeAlertMessage snoozeAlertMessage = new SnoozeAlertMessage();
snoozeAlertMessage.setAlertID(alert.getAlertId());
connectionService.requestMessage(snoozeAlertMessage).await();
}
} catch (AppLayerErrorException e) {
log.info("Exception while muting alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
ExceptionTranslator.makeToast(InsightAlertService.this, e);
@ -236,9 +256,16 @@ public class InsightAlertService extends Service implements InsightConnectionSer
public void confirm() {
new Thread(() -> {
try {
ConfirmAlertMessage confirmAlertMessage = new ConfirmAlertMessage();
confirmAlertMessage.setAlertID(alert.getAlertId());
connectionService.requestMessage(confirmAlertMessage).await();
synchronized ($alertLock) {
if (alert == null) return;
stopAlerting();
alertLiveData.postValue(null);
dismissNotification();
ConfirmAlertMessage confirmAlertMessage = new ConfirmAlertMessage();
confirmAlertMessage.setAlertID(alert.getAlertId());
connectionService.requestMessage(confirmAlertMessage).await();
this.alert = null;
}
} catch (AppLayerErrorException e) {
log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
ExceptionTranslator.makeToast(InsightAlertService.this, e);
@ -252,6 +279,48 @@ public class InsightAlertService extends Service implements InsightConnectionSer
}).start();
}
private void showNotification(Alert alert) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, LocalInsightPlugin.ALERT_CHANNEL_ID);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
notificationBuilder.setCategory(NotificationCompat.CATEGORY_ALARM);
notificationBuilder.setVibrate(new long[0]);
notificationBuilder.setShowWhen(false);
notificationBuilder.setOngoing(true);
notificationBuilder.setOnlyAlertOnce(true);
notificationBuilder.setAutoCancel(false);
notificationBuilder.setSmallIcon(AlertUtilsKt.getAlertIcon(alert.getAlertCategory()));
notificationBuilder.setContentTitle(AlertUtilsKt.getAlertCode(alert.getAlertType()) + " " + AlertUtilsKt.getAlertTitle(alert.getAlertType()));
String description = AlertUtilsKt.getAlertDescription(alert);
if (description != null)
notificationBuilder.setContentText(Html.fromHtml(description).toString());
Intent fullScreenIntent = new Intent(this, InsightAlertActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true);
switch (alert.getAlertStatus()) {
case ACTIVE:
Intent muteIntent = new Intent(this, InsightAlertService.class).putExtra("command", "mute");
PendingIntent mutePendingIntent = PendingIntent.getService(this, 1, muteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(0, MainApp.gs(R.string.mute_alert), mutePendingIntent);
case SNOOZED:
Intent confirmIntent = new Intent(this, InsightAlertService.class).putExtra("command", "confirm");
PendingIntent confirmPendingIntent = PendingIntent.getService(this, 2, confirmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(0, MainApp.gs(R.string.confirm), confirmPendingIntent);
}
Notification notification = notificationBuilder.build();
NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification);
startForeground(NOTIFICATION_ID, notification);
}
private void dismissNotification() {
NotificationManagerCompat.from(this).cancel(NOTIFICATION_ID);
stopForeground(true);
}
public class LocalBinder extends Binder {
public InsightAlertService getService() {
return InsightAlertService.this;

View file

@ -1,9 +1,12 @@
package info.nightscout.androidaps.plugins.pump.insight;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@ -132,6 +135,8 @@ import info.nightscout.androidaps.utils.SP;
public class LocalInsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface, InsightConnectionService.StateCallback {
public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert";
private static LocalInsightPlugin instance = null;
private Logger log = LoggerFactory.getLogger(L.PUMP);
@ -245,6 +250,16 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
super.onStart();
MainApp.instance().bindService(new Intent(MainApp.instance(), InsightConnectionService.class), serviceConnection, Context.BIND_AUTO_CREATE);
MainApp.instance().bindService(new Intent(MainApp.instance(), InsightAlertService.class), serviceConnection, Context.BIND_AUTO_CREATE);
createNotificationChannel();
}
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(ALERT_CHANNEL_ID, MainApp.gs(R.string.insight_alert_notification_channel), NotificationManager.IMPORTANCE_HIGH);
channel.setSound(null, null);
notificationManager.createNotificationChannel(channel);
}
}
@Override
@ -647,8 +662,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
cancelBolusMessage.setBolusID(bolusID);
connectionService.requestMessage(cancelBolusMessage).await();
bolusCancelled = true;
confirmAlert(AlertType.WARNING_38);
alertService.ignore(null);
}
confirmAlert(AlertType.WARNING_38);
} catch (AppLayerErrorException e) {
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
} catch (InsightException e) {

View file

@ -12,19 +12,18 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import java.text.DecimalFormat;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService;
import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert;
import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus;
import info.nightscout.androidaps.plugins.pump.insight.utils.AlertUtilsKt;
public class InsightAlertActivity extends NoSplashAppCompatActivity {
public class InsightAlertActivity extends AppCompatActivity {
private Alert alert;
private InsightAlertService alertService;
private ImageView icon;
@ -38,10 +37,10 @@ public class InsightAlertActivity extends NoSplashAppCompatActivity {
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
alertService = ((InsightAlertService.LocalBinder) binder).getService();
alertService.setAlertActivity(InsightAlertActivity.this);
alert = alertService.getAlert();
if (alert == null) finish();
else update(alert);
alertService.getAlertLiveData().observe(InsightAlertActivity.this, alert -> {
if (alert == null) finish();
else update(alert);
});
}
@Override
@ -70,174 +69,22 @@ public class InsightAlertActivity extends NoSplashAppCompatActivity {
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = 1.0F;
getWindow().setAttributes(layoutParams);
}
@Override
protected void onDestroy() {
alertService.setAlertActivity(null);
unbindService(serviceConnection);
super.onDestroy();
}
public void update(Alert alert) {
this.alert = alert;
mute.setEnabled(true);
mute.setVisibility(alert.getAlertStatus() == AlertStatus.SNOOZED ? View.GONE : View.VISIBLE);
confirm.setEnabled(true);
int icon = 0;
int code = 0;
int title = 0;
String description = null;
switch (alert.getAlertCategory()) {
case ERROR:
icon = R.drawable.ic_error;
break;
case MAINTENANCE:
icon = R.drawable.ic_maintenance;
break;
case WARNING:
icon = R.drawable.ic_warning;
break;
case REMINDER:
icon = R.drawable.ic_reminder;
break;
}
DecimalFormat decimalFormat = new DecimalFormat("##0.00");
int hours = alert.getTBRDuration() / 60;
int minutes = alert.getTBRDuration() - hours * 60;
switch (alert.getAlertType()) {
case REMINDER_01:
code = R.string.alert_r1_code;
title = R.string.alert_r1_title;
break;
case REMINDER_02:
code = R.string.alert_r2_code;
title = R.string.alert_r2_title;
break;
case REMINDER_03:
code = R.string.alert_r3_code;
title = R.string.alert_r3_title;
break;
case REMINDER_04:
code = R.string.alert_r4_code;
title = R.string.alert_r4_title;
break;
case REMINDER_07:
code = R.string.alert_r7_code;
title = R.string.alert_r7_title;
description = getString(R.string.alert_r7_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes));
break;
case WARNING_31:
code = R.string.alert_w31_code;
title = R.string.alert_w31_title;
description = getString(R.string.alert_w31_description, decimalFormat.format(alert.getCartridgeAmount()));
break;
case WARNING_32:
code = R.string.alert_w32_code;
title = R.string.alert_w32_title;
description = getString(R.string.alert_w32_description);
break;
case WARNING_33:
code = R.string.alert_w33_code;
title = R.string.alert_w33_title;
description = getString(R.string.alert_w33_description);
break;
case WARNING_34:
code = R.string.alert_w34_code;
title = R.string.alert_w34_title;
description = getString(R.string.alert_w34_description);
break;
case WARNING_36:
code = R.string.alert_w36_code;
title = R.string.alert_w36_title;
description = getString(R.string.alert_w36_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes));
break;
case WARNING_38:
code = R.string.alert_w38_code;
title = R.string.alert_w38_title;
description = getString(R.string.alert_w38_description, decimalFormat.format(alert.getProgrammedBolusAmount()), decimalFormat.format(alert.getDeliveredBolusAmount()));
break;
case WARNING_39:
code = R.string.alert_w39_code;
title = R.string.alert_w39_title;
break;
case MAINTENANCE_20:
code = R.string.alert_m20_code;
title = R.string.alert_m20_title;
description = getString(R.string.alert_m20_description);
break;
case MAINTENANCE_21:
code = R.string.alert_m21_code;
title = R.string.alert_m21_title;
description = getString(R.string.alert_m21_description);
break;
case MAINTENANCE_22:
code = R.string.alert_m22_code;
title = R.string.alert_m22_title;
description = getString(R.string.alert_m22_description);
break;
case MAINTENANCE_23:
code = R.string.alert_m23_code;
title = R.string.alert_m23_title;
description = getString(R.string.alert_m23_description);
break;
case MAINTENANCE_24:
code = R.string.alert_m24_code;
title = R.string.alert_m24_title;
description = getString(R.string.alert_m24_description);
break;
case MAINTENANCE_25:
code = R.string.alert_m25_code;
title = R.string.alert_m25_title;
description = getString(R.string.alert_m25_description);
break;
case MAINTENANCE_26:
code = R.string.alert_m26_code;
title = R.string.alert_m26_title;
description = getString(R.string.alert_m26_description);
break;
case MAINTENANCE_27:
code = R.string.alert_m27_code;
title = R.string.alert_m27_title;
description = getString(R.string.alert_m27_description);
break;
case MAINTENANCE_28:
code = R.string.alert_m28_code;
title = R.string.alert_m28_title;
description = getString(R.string.alert_m28_description);
break;
case MAINTENANCE_29:
code = R.string.alert_m29_code;
title = R.string.alert_m29_title;
description = getString(R.string.alert_m29_description);
break;
case MAINTENANCE_30:
code = R.string.alert_m30_code;
title = R.string.alert_m30_title;
description = getString(R.string.alert_m30_description);
break;
case ERROR_6:
code = R.string.alert_e6_code;
title = R.string.alert_e6_title;
description = getString(R.string.alert_e6_description);
break;
case ERROR_10:
code = R.string.alert_e10_code;
title = R.string.alert_e10_title;
description = getString(R.string.alert_e10_description);
break;
case ERROR_13:
code = R.string.alert_e13_code;
title = R.string.alert_e13_title;
description = getString(R.string.alert_e13_description);
break;
}
this.icon.setImageDrawable(ContextCompat.getDrawable(this, icon));
this.errorCode.setText(code);
this.errorTitle.setText(title);
this.icon.setImageDrawable(ContextCompat.getDrawable(this, AlertUtilsKt.getAlertIcon(alert.getAlertCategory())));
this.errorCode.setText(AlertUtilsKt.getAlertCode(alert.getAlertType()));
this.errorTitle.setText(AlertUtilsKt.getAlertTitle(alert.getAlertType()));
String description = AlertUtilsKt.getAlertDescription(alert);
if (description == null) this.errorDescription.setVisibility(View.GONE);
else {
this.errorDescription.setVisibility(View.VISIBLE);

View file

@ -83,4 +83,24 @@ public class Alert {
public double getCartridgeAmount() {
return cartridgeAmount;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Alert alert = (Alert) o;
if (alertId != alert.alertId) return false;
if (tbrAmount != alert.tbrAmount) return false;
if (tbrDuration != alert.tbrDuration) return false;
if (Double.compare(alert.programmedBolusAmount, programmedBolusAmount) != 0)
return false;
if (Double.compare(alert.deliveredBolusAmount, deliveredBolusAmount) != 0)
return false;
if (Double.compare(alert.cartridgeAmount, cartridgeAmount) != 0) return false;
if (alertCategory != alert.alertCategory) return false;
if (alertType != alert.alertType) return false;
return alertStatus == alert.alertStatus;
}
}

View file

@ -0,0 +1,107 @@
package info.nightscout.androidaps.plugins.pump.insight.utils
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert
import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertCategory
import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType
import java.text.DecimalFormat
fun getAlertCode(alertType: AlertType) = MainApp.gs(when (alertType) {
AlertType.REMINDER_01 -> R.string.alert_r1_code
AlertType.REMINDER_02 -> R.string.alert_r2_code
AlertType.REMINDER_03 -> R.string.alert_r3_code
AlertType.REMINDER_04 -> R.string.alert_r4_code
AlertType.REMINDER_07 -> R.string.alert_r7_code
AlertType.WARNING_31 -> R.string.alert_w31_code
AlertType.WARNING_32 -> R.string.alert_w32_code
AlertType.WARNING_33 -> R.string.alert_w33_code
AlertType.WARNING_34 -> R.string.alert_w34_code
AlertType.WARNING_36 -> R.string.alert_w36_code
AlertType.WARNING_38 -> R.string.alert_w38_code
AlertType.WARNING_39 -> R.string.alert_w39_code
AlertType.MAINTENANCE_20 -> R.string.alert_m20_code
AlertType.MAINTENANCE_21 -> R.string.alert_m21_code
AlertType.MAINTENANCE_22 -> R.string.alert_m22_code
AlertType.MAINTENANCE_23 -> R.string.alert_m23_code
AlertType.MAINTENANCE_24 -> R.string.alert_m24_code
AlertType.MAINTENANCE_25 -> R.string.alert_m25_code
AlertType.MAINTENANCE_26 -> R.string.alert_m26_code
AlertType.MAINTENANCE_27 -> R.string.alert_m27_code
AlertType.MAINTENANCE_28 -> R.string.alert_m28_code
AlertType.MAINTENANCE_29 -> R.string.alert_m29_code
AlertType.MAINTENANCE_30 -> R.string.alert_m30_code
AlertType.ERROR_6 -> R.string.alert_e6_code
AlertType.ERROR_10 -> R.string.alert_e10_code
AlertType.ERROR_13 -> R.string.alert_e13_code
})
fun getAlertTitle(alertType: AlertType) = MainApp.gs(when (alertType) {
AlertType.REMINDER_01 -> R.string.alert_r1_title
AlertType.REMINDER_02 -> R.string.alert_r2_title
AlertType.REMINDER_03 -> R.string.alert_r3_title
AlertType.REMINDER_04 -> R.string.alert_r4_title
AlertType.REMINDER_07 -> R.string.alert_r7_title
AlertType.WARNING_31 -> R.string.alert_w31_title
AlertType.WARNING_32 -> R.string.alert_w32_title
AlertType.WARNING_33 -> R.string.alert_w33_title
AlertType.WARNING_34 -> R.string.alert_w34_title
AlertType.WARNING_36 -> R.string.alert_w36_title
AlertType.WARNING_38 -> R.string.alert_w38_title
AlertType.WARNING_39 -> R.string.alert_w39_title
AlertType.MAINTENANCE_20 -> R.string.alert_m20_title
AlertType.MAINTENANCE_21 -> R.string.alert_m21_title
AlertType.MAINTENANCE_22 -> R.string.alert_m22_title
AlertType.MAINTENANCE_23 -> R.string.alert_m23_title
AlertType.MAINTENANCE_24 -> R.string.alert_m24_title
AlertType.MAINTENANCE_25 -> R.string.alert_m25_title
AlertType.MAINTENANCE_26 -> R.string.alert_m26_title
AlertType.MAINTENANCE_27 -> R.string.alert_m27_title
AlertType.MAINTENANCE_28 -> R.string.alert_m28_title
AlertType.MAINTENANCE_29 -> R.string.alert_m29_title
AlertType.MAINTENANCE_30 -> R.string.alert_m30_title
AlertType.ERROR_6 -> R.string.alert_e6_title
AlertType.ERROR_10 -> R.string.alert_e10_title
AlertType.ERROR_13 -> R.string.alert_e13_title
})
fun getAlertDescription(alert: Alert): String? {
val decimalFormat = DecimalFormat("##0.00")
val hours = alert.tbrDuration / 60
val minutes = alert.tbrDuration - hours * 60
return when (alert.alertType!!) {
AlertType.REMINDER_01 -> null
AlertType.REMINDER_02 -> null
AlertType.REMINDER_03 -> null
AlertType.REMINDER_04 -> null
AlertType.REMINDER_07 -> MainApp.gs(R.string.alert_r7_description, alert.tbrAmount, DecimalFormat("#0").format(hours.toLong()) + ":" + DecimalFormat("00").format(minutes.toLong()))
AlertType.WARNING_31 -> MainApp.gs(R.string.alert_w31_description, decimalFormat.format(alert.cartridgeAmount))
AlertType.WARNING_32 -> MainApp.gs(R.string.alert_w32_description)
AlertType.WARNING_33 -> MainApp.gs(R.string.alert_w33_description)
AlertType.WARNING_34 -> MainApp.gs(R.string.alert_w34_description)
AlertType.WARNING_36 -> MainApp.gs(R.string.alert_w36_description, alert.tbrAmount, DecimalFormat("#0").format(hours.toLong()) + ":" + DecimalFormat("00").format(minutes.toLong()))
AlertType.WARNING_38 -> MainApp.gs(R.string.alert_w38_description, decimalFormat.format(alert.programmedBolusAmount), decimalFormat.format(alert.deliveredBolusAmount))
AlertType.WARNING_39 -> null
AlertType.MAINTENANCE_20 -> MainApp.gs(R.string.alert_m20_description)
AlertType.MAINTENANCE_21 -> MainApp.gs(R.string.alert_m21_description)
AlertType.MAINTENANCE_22 -> MainApp.gs(R.string.alert_m22_description)
AlertType.MAINTENANCE_23 -> MainApp.gs(R.string.alert_m23_description)
AlertType.MAINTENANCE_24 -> MainApp.gs(R.string.alert_m24_description)
AlertType.MAINTENANCE_25 -> MainApp.gs(R.string.alert_m25_description)
AlertType.MAINTENANCE_26 -> MainApp.gs(R.string.alert_m26_description)
AlertType.MAINTENANCE_27 -> MainApp.gs(R.string.alert_m27_description)
AlertType.MAINTENANCE_28 -> MainApp.gs(R.string.alert_m28_description)
AlertType.MAINTENANCE_29 -> MainApp.gs(R.string.alert_m29_description)
AlertType.MAINTENANCE_30 -> MainApp.gs(R.string.alert_m30_description)
AlertType.ERROR_6 -> MainApp.gs(R.string.alert_e6_description)
AlertType.ERROR_10 -> MainApp.gs(R.string.alert_e10_description)
AlertType.ERROR_13 -> MainApp.gs(R.string.alert_e13_description)
}
}
fun getAlertIcon(alertCategory: AlertCategory) = when (alertCategory) {
AlertCategory.ERROR -> R.drawable.ic_error
AlertCategory.MAINTENANCE -> R.drawable.ic_maintenance
AlertCategory.WARNING -> R.drawable.ic_warning
AlertCategory.REMINDER -> R.drawable.ic_reminder
}

View file

@ -1698,5 +1698,6 @@
<string name="loop_smbexecution_time_label">SMB execution time</string>
<string name="loop_tbrrequest_time_label">Temp basal request time</string>
<string name="loop_tbrexecution_time_label">Temp basal execution time</string>
<string name="insight_alert_notification_channel">Insight Pump Alerts</string>
</resources>

View file

@ -27,12 +27,10 @@
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
<style name="InsightAlertDialog" parent="Theme.AppCompat.Dialog">
<style name="InsightAlertDialog" parent="Theme.AppCompat.Dialog.MinWidth">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowMinWidthMajor">96%</item>
<item name="android:windowMinWidthMinor">96%</item>
</style>
<style name="Theme.AppCompat.NoTitle" parent="Theme.AppCompat.NoActionBar">