Merge remote-tracking branch 'origin/dev' into smb060
* origin/dev: Actions tab: show profile switch button for single profile too. Old NS-Version non-urgent Add SP to imports refactor cancelAlarm back to KeepAliveReceiver push next alert on read status G5 upload to xdrip fake Esel new file fake Esel Apply bolus constraint before applying. Rv2,RS: always load last 45 min remove wear-overview notifications as replaced by system notifications Remove missed reference to pref in NSProfilePlugin. Remove 'sync to profile' pref. # Conflicts: # app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
This commit is contained in:
commit
57944fb4b5
|
@ -1,7 +1,6 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemClock;
|
||||
|
@ -25,7 +24,6 @@ import info.nightscout.androidaps.Services.Intents;
|
|||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
|
@ -52,13 +50,9 @@ import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
|||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||
|
@ -175,7 +169,7 @@ public class MainApp extends Application {
|
|||
else
|
||||
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
||||
|
||||
new Thread(new Runnable() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemClock.sleep(5000);
|
||||
|
@ -221,7 +215,7 @@ public class MainApp extends Application {
|
|||
|
||||
public void stopKeepAliveService() {
|
||||
if (keepAliveReceiver != null)
|
||||
keepAliveReceiver.cancelAlarm(this);
|
||||
KeepAliveReceiver.cancelAlarm(this);
|
||||
}
|
||||
|
||||
public static Bus bus() {
|
||||
|
|
|
@ -151,10 +151,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||
|
||||
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||
addPreferencesFromResource(R.xml.pref_profile);
|
||||
}
|
||||
|
||||
if (Config.DANAR) {
|
||||
addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP);
|
||||
addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP);
|
||||
|
|
|
@ -228,6 +228,9 @@ public class DataService extends IntentService {
|
|||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||
NSUpload.uploadBg(bgReading);
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
|
@ -298,7 +301,7 @@ public class DataService extends IntentService {
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) {
|
||||
Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.URGENT);
|
||||
Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS));
|
||||
|
|
|
@ -159,12 +159,16 @@ public class Profile {
|
|||
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
||||
for (Integer index = 0; index < array.length(); index++) {
|
||||
try {
|
||||
JSONObject o = array.getJSONObject(index);
|
||||
final JSONObject o = array.getJSONObject(index);
|
||||
long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds"));
|
||||
Double value = o.getDouble("value") * multiplier;
|
||||
sparse.put(tas, value);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
try {
|
||||
log.error(array.getJSONObject(index).toString());
|
||||
} catch (JSONException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,8 +127,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
|||
return;
|
||||
}
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
|
||||
if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended() || !allowProfileSwitch)
|
||||
if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended())
|
||||
profileSwitch.setVisibility(View.GONE);
|
||||
else
|
||||
profileSwitch.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -69,11 +69,6 @@ public class NotificationStore {
|
|||
}
|
||||
}
|
||||
|
||||
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
||||
if (wearPlugin != null && wearPlugin.isEnabled()) {
|
||||
wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text);
|
||||
}
|
||||
|
||||
Collections.sort(store, new NotificationComparator());
|
||||
}
|
||||
|
||||
|
|
|
@ -182,9 +182,6 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
if (timeshift < 0 || timeshift > 23) {
|
||||
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
||||
}
|
||||
if (!SP.getBoolean("syncprofiletopump", false)) {
|
||||
msg += MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
||||
}
|
||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (profile == null || profile.getBasal() == null) {
|
||||
|
|
|
@ -120,19 +120,17 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
|||
profile = new ProfileStore(newProfile.getData());
|
||||
storeNSProfile();
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
if (SP.getBoolean("syncprofiletopump", false)) {
|
||||
ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (result.enacted) {
|
||||
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
|
||||
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
|
||||
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
|
||||
}
|
||||
ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (result.enacted) {
|
||||
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
|
||||
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
|
||||
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void storeNSProfile() {
|
||||
|
|
|
@ -185,7 +185,7 @@ public class DanaRSService extends Service {
|
|||
while (!msg.done && bleComm.isConnected()) {
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min
|
||||
log.debug("Events loaded");
|
||||
return new PumpEnactResult().success(true);
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ public class DanaRv2ExecutionService extends Service {
|
|||
waitMsec(100);
|
||||
}
|
||||
waitMsec(200);
|
||||
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
||||
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min;
|
||||
return new PumpEnactResult().success(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -579,9 +579,6 @@ public class ActionStringHandler {
|
|||
if (timeshift < 0 || timeshift > 23) {
|
||||
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
||||
}
|
||||
if (!SP.getBoolean("syncprofiletopump", false)) {
|
||||
msg += MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
||||
}
|
||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (profile == null || profile.getBasal() == null) {
|
||||
|
|
|
@ -155,6 +155,10 @@ public class CommandQueue {
|
|||
// remove all unfinished boluses
|
||||
removeAll(type);
|
||||
|
||||
// apply constraints
|
||||
detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin);
|
||||
detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
||||
|
||||
// add new command to queue
|
||||
if (detailedBolusInfo.isSMB)
|
||||
add(new CommandSMBBolus(detailedBolusInfo, callback));
|
||||
|
@ -167,12 +171,8 @@ public class CommandQueue {
|
|||
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
||||
|
||||
// Bring up bolus progress dialog
|
||||
detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin);
|
||||
detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
||||
|
||||
BolusProgressDialog bolusProgressDialog;
|
||||
if (detailedBolusInfo.context != null) {
|
||||
bolusProgressDialog = new BolusProgressDialog();
|
||||
BolusProgressDialog bolusProgressDialog = new BolusProgressDialog();
|
||||
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
||||
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
||||
} else {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package info.nightscout.androidaps.queue.commands;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.utils.LocalAlertUtils;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -20,6 +20,7 @@ public class CommandReadStatus extends Command {
|
|||
@Override
|
||||
public void execute() {
|
||||
ConfigBuilderPlugin.getActivePump().getPumpStatus();
|
||||
LocalAlertUtils.notifyPumpStatusRead();
|
||||
if (callback != null)
|
||||
callback.result(null).run();
|
||||
}
|
||||
|
|
|
@ -16,61 +16,39 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.utils.LocalAlertUtils;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class KeepAliveReceiver extends BroadcastReceiver {
|
||||
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);
|
||||
public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L;
|
||||
|
||||
// TODO consider moving this into an Alarms plugin that works offline and can be configured
|
||||
// (e.g. override silent mode at night only)
|
||||
|
||||
private static int missedReadingsThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_missed_bg_readings_threshold), 30) * 60 * 1000;
|
||||
public static void cancelAlarm(Context context) {
|
||||
Intent intent = new Intent(context, KeepAliveReceiver.class);
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
alarmManager.cancel(sender);
|
||||
}
|
||||
|
||||
private static int pumpUnreachableThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_pump_unreachable_threshold), 30) * 60 * 1000;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent rIntent) {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
|
||||
wl.acquire();
|
||||
|
||||
shortenSnoozeInterval();
|
||||
checkBg();
|
||||
LocalAlertUtils.shortenSnoozeInterval();
|
||||
LocalAlertUtils.checkStaleBGAlert();
|
||||
checkPump();
|
||||
|
||||
log.debug("KeepAlive received");
|
||||
wl.release();
|
||||
}
|
||||
|
||||
private void checkBg() {
|
||||
BgReading bgReading = DatabaseHelper.lastBg();
|
||||
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_missed_bg_readings_alert), false)
|
||||
&& bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis()
|
||||
&& SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
|
||||
Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.sResources.getString(R.string.missed_bg_readings), Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPump() {
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
@ -79,18 +57,9 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis();
|
||||
boolean isBasalOutdated = Math.abs(profile.getBasal() - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep;
|
||||
|
||||
boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis();
|
||||
boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis();
|
||||
LocalAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated);
|
||||
|
||||
if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true)
|
||||
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !ConfigBuilderPlugin.getActiveLoop().isDisconnected()) {
|
||||
Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
}
|
||||
|
||||
if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) {
|
||||
if (!pump.isThisProfileSet(profile)) {
|
||||
MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null);
|
||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||
|
@ -103,8 +72,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
//called by MainApp at first app start
|
||||
public void setAlarm(Context context) {
|
||||
|
||||
shortenSnoozeInterval();
|
||||
presnoozeAlarms();
|
||||
LocalAlertUtils.shortenSnoozeInterval();
|
||||
LocalAlertUtils.presnoozeAlarms();
|
||||
|
||||
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent i = new Intent(context, KeepAliveReceiver.class);
|
||||
|
@ -117,33 +86,4 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.keepAliveMsecs, pi);
|
||||
}
|
||||
|
||||
/*Presnoozes the alarms with 5 minutes if no snooze exists.
|
||||
* Call only at startup!
|
||||
*/
|
||||
public void presnoozeAlarms() {
|
||||
if (SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
|
||||
}
|
||||
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis()) {
|
||||
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelAlarm(Context context) {
|
||||
Intent intent = new Intent(context, KeepAliveReceiver.class);
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
alarmManager.cancel(sender);
|
||||
}
|
||||
|
||||
static void shortenSnoozeInterval() {
|
||||
//shortens alarm times in case of setting changes or future data
|
||||
long nextMissedReadingsAlarm = SP.getLong("nextMissedReadingsAlarm", 0L);
|
||||
nextMissedReadingsAlarm = Math.min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm);
|
||||
SP.putLong("nextMissedReadingsAlarm", nextMissedReadingsAlarm);
|
||||
|
||||
long nextPumpDisconnectedAlarm = SP.getLong("nextPumpDisconnectedAlarm", 0L);
|
||||
nextPumpDisconnectedAlarm = Math.min(System.currentTimeMillis() + pumpUnreachableThreshold(), nextPumpDisconnectedAlarm);
|
||||
SP.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm);
|
||||
}
|
||||
}
|
||||
|
|
96
app/src/main/java/info/nightscout/utils/LocalAlertUtils.java
Normal file
96
app/src/main/java/info/nightscout/utils/LocalAlertUtils.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package info.nightscout.utils;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||
|
||||
/**
|
||||
* Created by adrian on 17/12/17.
|
||||
*/
|
||||
|
||||
public class LocalAlertUtils {
|
||||
public static int missedReadingsThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_missed_bg_readings_threshold), 30) * 60 * 1000;
|
||||
}
|
||||
|
||||
private static int pumpUnreachableThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_pump_unreachable_threshold), 30) * 60 * 1000;
|
||||
}
|
||||
|
||||
public static void checkPumpUnreachableAlarm(Date lastConnection, boolean isStatusOutdated) {
|
||||
boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis();
|
||||
boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis();
|
||||
|
||||
if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true)
|
||||
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !ConfigBuilderPlugin.getActiveLoop().isDisconnected()) {
|
||||
Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
}
|
||||
}
|
||||
|
||||
/*Presnoozes the alarms with 5 minutes if no snooze exists.
|
||||
* Call only at startup!
|
||||
*/
|
||||
public static void presnoozeAlarms() {
|
||||
if (SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
|
||||
}
|
||||
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis()) {
|
||||
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shortenSnoozeInterval() {
|
||||
//shortens alarm times in case of setting changes or future data
|
||||
long nextMissedReadingsAlarm = SP.getLong("nextMissedReadingsAlarm", 0L);
|
||||
nextMissedReadingsAlarm = Math.min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm);
|
||||
SP.putLong("nextMissedReadingsAlarm", nextMissedReadingsAlarm);
|
||||
|
||||
long nextPumpDisconnectedAlarm = SP.getLong("nextPumpDisconnectedAlarm", 0L);
|
||||
nextPumpDisconnectedAlarm = Math.min(System.currentTimeMillis() + pumpUnreachableThreshold(), nextPumpDisconnectedAlarm);
|
||||
SP.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm);
|
||||
}
|
||||
|
||||
public static void notifyPumpStatusRead(){
|
||||
//TODO: persist the actual time the pump is read and simplify the whole logic when to alarm
|
||||
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (pump != null && profile != null && profile.getBasal() != null) {
|
||||
Date lastConnection = pump.lastDataTime();
|
||||
long earliestAlarmTime = lastConnection.getTime() + pumpUnreachableThreshold();
|
||||
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < earliestAlarmTime) {
|
||||
SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkStaleBGAlert() {
|
||||
BgReading bgReading = DatabaseHelper.lastBg();
|
||||
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_missed_bg_readings_alert), false)
|
||||
&& bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis()
|
||||
&& SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
|
||||
Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.sResources.getString(R.string.missed_bg_readings), Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,33 +3,37 @@ package info.nightscout.utils;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA;
|
||||
|
||||
|
@ -440,4 +444,44 @@ public class NSUpload {
|
|||
|
||||
}
|
||||
|
||||
public static void sendToXdrip(BgReading bgReading) {
|
||||
final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
|
||||
|
||||
try {
|
||||
final JSONArray entriesBody = new JSONArray();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("sgv", bgReading.value);
|
||||
if (bgReading.direction == null) {
|
||||
json.put("direction", "NONE");
|
||||
} else {
|
||||
json.put("direction", bgReading.direction);
|
||||
}
|
||||
json.put("device", "G5");
|
||||
json.put("type", "sgv");
|
||||
json.put("date", bgReading.date);
|
||||
json.put("dateString", format.format(bgReading.date));
|
||||
entriesBody.put(json);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString("action", "add");
|
||||
bundle.putString("collection", "entries");
|
||||
bundle.putString("data", entriesBody.toString());
|
||||
final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR);
|
||||
intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
MainApp.instance().sendBroadcast(intent);
|
||||
List<ResolveInfo> receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (receivers.size() < 1) {
|
||||
log.debug("No xDrip receivers found. ");
|
||||
} else {
|
||||
log.debug(receivers.size() + " xDrip receivers");
|
||||
}
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -212,7 +212,6 @@
|
|||
<string name="connecting">Свързване</string>
|
||||
<string name="connected">Свързана</string>
|
||||
<string name="disconnected">Не е сврзана</string>
|
||||
<string name="syncprofiletopump_title">Синхронизирай помпата с профила</string>
|
||||
<string name="danar_pump_settings">DanaR настройки</string>
|
||||
<string name="nightscout">Nightscout</string>
|
||||
<string name="end_user_license_agreement">End User License Agreement</string>
|
||||
|
|
|
@ -192,7 +192,6 @@
|
|||
<string name="disconnected">Odpojeno</string>
|
||||
<string name="danar_bt_name_title">DanaR Bluetooth zařízení</string>
|
||||
<string name="danar_pump_settings">DanaR nastavení</string>
|
||||
<string name="syncprofiletopump_title">Synchronizovat profil do pumpy</string>
|
||||
<string name="nightscout">Nightscout</string>
|
||||
<string name="absolute">Absolutní</string>
|
||||
<string name="comment">Komentář</string>
|
||||
|
|
|
@ -226,7 +226,6 @@
|
|||
<string name="hoursago">vor h </string>
|
||||
<string name="smscommunicator">SMS Kommunikator</string>
|
||||
<string name="smscommunicator_allowednumbers">erlaubte Telefonnummern</string>
|
||||
<string name="syncprofiletopump_title">Profil zur Pumpe synchronisieren</string>
|
||||
<string name="waitingforpumpresult">auf Pumpenergebnis warten</string>
|
||||
<string name="nobtadapter">Kein Bluetoothadapter gefunden</string>
|
||||
<string name="smscommunicator_remotebolusnotallowed">Remote Bolus ist nicht erlaubt</string>
|
||||
|
|
|
@ -201,7 +201,6 @@
|
|||
<string name="connecting">Conectando</string>
|
||||
<string name="connected">Conectado</string>
|
||||
<string name="disconnected">Desconectado</string>
|
||||
<string name="syncprofiletopump_title">Sincronizar perfil a bomba</string>
|
||||
<string name="danar_pump_settings">Ajustes de la bomba DanaR</string>
|
||||
<string name="nightscout">Nightscout</string>
|
||||
<string name="end_user_license_agreement">Acuerdo de licencia de usuario final</string>
|
||||
|
|
|
@ -372,7 +372,6 @@
|
|||
<string name="suspendloopfor1h">Sospendi loop per 1h</string>
|
||||
<string name="suspendloopfor2h">Sospendi loop per 2h</string>
|
||||
<string name="suspendloopfor3h">Sospendi loop per 3h</string>
|
||||
<string name="syncprofiletopump_title">Sincronizza profilo sul micro</string>
|
||||
<string name="target_range">Target range:</string>
|
||||
<string name="teenage">Adolescente</string>
|
||||
<string name="tempbasals_iob_label_string">IOB:</string>
|
||||
|
|
|
@ -213,7 +213,6 @@
|
|||
<string name="connecting">연결중</string>
|
||||
<string name="connected">연결됨</string>
|
||||
<string name="disconnected">연결 끊김</string>
|
||||
<string name="syncprofiletopump_title">프로파일을 펌프에 동기화하기</string>
|
||||
<string name="danar_pump_settings">다나R 펌프 설정</string>
|
||||
<string name="nightscout">Nightscout</string>
|
||||
<string name="end_user_license_agreement">최종 사용자 라이선스 동의서</string>
|
||||
|
|
|
@ -626,7 +626,6 @@
|
|||
<string name="openapsama_bolussnooze_dia_divisor_summary">Standaard waarde: 2 Bolus snooze is actief nadat je een maaltijd bolus toegediend hebt, zodat de loop geen tegenvoorstel met een verlaagd tijdelijk basaal doet nadat je gegeten hebt. Het voorbeeld hier van van standaard 2; dus een 3 u DIA betekent dat de bolus snooze gemiddeld 1.5u actief is (3DIA/2).</string>
|
||||
<string name="openapsama_current_basal_safety_multiplier_summary">Standaard waarde: 4 Dit is een combinatie van enerzijds het OpenAPS veiligheid limieten en anderzijds van “3 x max dagelijks basaal ; 4x actueel”. Dit betekent dat het basaal niet hoger kan ingesteld worden dan het ingestelde nummer keer het actueel basaal waarbij de limiet in de pomp geen invloed heeft.Dit is een veiligheidsmaatregel om te vermijden dat patiënten in gevaarlijke laag bereik komen zonder te snappen hoe het algoritme werkt. Nogmaals de standaard waarde is 4x; de meeste zullen deze waarde nooit moeten aanpassen maar zullen eerder andere waardes moeten aanpassen als ze tegen een limiet aanstoten.</string>
|
||||
<string name="objectives_5_gate">Gedurende 1 week succesvol closed loop met KH ingave</string>
|
||||
<string name="syncprofiletopump_title">Synchroniseer profiel met de pomp</string>
|
||||
<string name="careportal_activity_label">ACTIVITIJD & FEEDBACK</string>
|
||||
<string name="danar_model" formatted="false">Model: %02X Protokoll: %02X Code: %02X</string>
|
||||
<string name="danar_history_connectingfor">Verbonden gedurende %d s</string>
|
||||
|
|
|
@ -486,7 +486,6 @@
|
|||
<string name="suspendloopfor1h">приостановить цикл на 1 час</string>
|
||||
<string name="suspendloopfor2h">приостановить цикл на 2 часа</string>
|
||||
<string name="suspendloopfor3h">приостановить цикл на 3 часа</string>
|
||||
<string name="syncprofiletopump_title">синхронизировать профиль с помпой</string>
|
||||
<string name="target_range">целевой диапазон</string>
|
||||
<string name="teenage">подросток</string>
|
||||
<string name="tempbasaldeliveryerror">ошибка доставки врем базала</string>
|
||||
|
|
|
@ -362,7 +362,6 @@
|
|||
<string name="teenage">Tonåring</string>
|
||||
<string name="targetmissing">Mål saknas i profil. Använder grundinställning</string>
|
||||
<string name="target_range">Mål gränser:</string>
|
||||
<string name="syncprofiletopump_title">Uppdatera profil till pump</string>
|
||||
<string name="suspendloopfor3h">Stäng av loop i 3 h</string>
|
||||
<string name="suspendloopfor2h">Stäng av loop i 2 h</string>
|
||||
<string name="suspendloopfor1h">Stäng av loop i 1 h</string>
|
||||
|
|
|
@ -223,7 +223,6 @@
|
|||
<string name="connecting">Connecting</string>
|
||||
<string name="connected">Connected</string>
|
||||
<string name="disconnected">Disconnected</string>
|
||||
<string name="syncprofiletopump_title">Sync profile to pump</string>
|
||||
<string name="danar_pump_settings">DanaR pump settings</string>
|
||||
<string name="nightscout">Nightscout</string>
|
||||
<string name="end_user_license_agreement">End User License Agreement</string>
|
||||
|
@ -796,5 +795,8 @@
|
|||
<string name="smbmaxminutes_summary">Max minutes of basal to limit SMB to</string>
|
||||
<string name="key_smbmaxminutes" translatable="false">smbmaxminutes</string>
|
||||
<string name="unsupportedfirmware">Unsupported pump firmware</string>
|
||||
<string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string>
|
||||
<string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string>
|
||||
<string name="dexcomg5_xdripupload_summary">In xDrip+ select 640g/Eversense data source</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
android:key="@string/key_dexcomg5_nsupload"
|
||||
android:title="@string/dexcomg5_nsupload_title" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_dexcomg5_xdripupload"
|
||||
android:summary="@string/dexcomg5_xdripupload_summary"
|
||||
android:title="@string/dexcomg5_xdripupload_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:key="profile"
|
||||
android:title="@string/profile">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="syncprofiletopump"
|
||||
android:title="@string/syncprofiletopump_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue