From 23874ebbd652d663cbb356dd66a496e78777394a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 5 Dec 2017 01:24:43 +0100 Subject: [PATCH 01/13] Remove 'sync to profile' pref. (cherry picked from commit 01c52e7) --- .../nightscout/androidaps/PreferencesActivity.java | 4 ---- .../CircadianPercentageProfilePlugin.java | 3 --- .../plugins/Wear/ActionStringHandler.java | 3 --- .../androidaps/receivers/KeepAliveReceiver.java | 2 +- app/src/main/res/values-bg/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-it/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 1 - app/src/main/res/values/strings.xml | 1 - app/src/main/res/xml/pref_profile.xml | 13 ------------- 15 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 app/src/main/res/xml/pref_profile.xml diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 6706e88fd9..ed201d7c97 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -149,10 +149,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); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index 949e7d1cf3..5315910899 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 6511cedbdf..dce7023afe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -582,9 +582,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) { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 38ca9ee2a1..83fa84e069 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -90,7 +90,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { 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); diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 75d2cb20c2..5d46908f57 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -212,7 +212,6 @@ Свързване Свързана Не е сврзана - Синхронизирай помпата с профила DanaR настройки Nightscout End User License Agreement diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index c619655866..1d43753930 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -192,7 +192,6 @@ Odpojeno DanaR Bluetooth zařízení DanaR nastavení - Synchronizovat profil do pumpy Nightscout Absolutní Komentář diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9a4d839fec..96e19bec97 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -226,7 +226,6 @@ vor h SMS Kommunikator erlaubte Telefonnummern - Profil zur Pumpe synchronisieren auf Pumpenergebnis warten Kein Bluetoothadapter gefunden Remote Bolus ist nicht erlaubt diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3c8450676f..a87b40330f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -201,7 +201,6 @@ Conectando Conectado Desconectado - Sincronizar perfil a bomba Ajustes de la bomba DanaR Nightscout Acuerdo de licencia de usuario final diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index f52357dd0a..5e72429865 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -372,7 +372,6 @@ Sospendi loop per 1h Sospendi loop per 2h Sospendi loop per 3h - Sincronizza profilo sul micro Target range: Adolescente IOB: diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index b4bd725ce4..538dbb2023 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -213,7 +213,6 @@ 연결중 연결됨 연결 끊김 - 프로파일을 펌프에 동기화하기 다나R 펌프 설정 Nightscout 최종 사용자 라이선스 동의서 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1bcfc2736f..a9151cde59 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -626,7 +626,6 @@ 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). 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. Gedurende 1 week succesvol closed loop met KH ingave - Synchroniseer profiel met de pomp ACTIVITIJD & FEEDBACK Model: %02X Protokoll: %02X Code: %02X Verbonden gedurende %d s diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a2084cb0cb..ba0e44644c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -486,7 +486,6 @@ приостановить цикл на 1 час приостановить цикл на 2 часа приостановить цикл на 3 часа - синхронизировать профиль с помпой целевой диапазон подросток ошибка доставки врем базала diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b7527f85ad..9b84ac7660 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -362,7 +362,6 @@ Tonåring Mål saknas i profil. Använder grundinställning Mål gränser: - Uppdatera profil till pump Stäng av loop i 3 h Stäng av loop i 2 h Stäng av loop i 1 h diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e8918979b3..a3a7b76262 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -223,7 +223,6 @@ Connecting Connected Disconnected - Sync profile to pump DanaR pump settings Nightscout End User License Agreement diff --git a/app/src/main/res/xml/pref_profile.xml b/app/src/main/res/xml/pref_profile.xml deleted file mode 100644 index e8a1289047..0000000000 --- a/app/src/main/res/xml/pref_profile.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - \ No newline at end of file From ab456d5966b52163aa80a66c896773aed514110e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 6 Dec 2017 12:05:39 +0100 Subject: [PATCH 02/13] Remove missed reference to pref in NSProfilePlugin. --- .../plugins/ProfileNS/NSProfilePlugin.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index f4b4aaabcc..d3fedfd9c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -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() { From 0013050860cdf7fbae6d9b5111512501fbfaadad Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 7 Dec 2017 12:32:14 +0100 Subject: [PATCH 03/13] remove wear-overview notifications as replaced by system notifications --- .../plugins/Overview/notifications/NotificationStore.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java index ce18c32734..1ce92249f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java @@ -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()); } From e14272c083127739e760d0414ca3eb40cca0dcb6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 12 Dec 2017 18:18:41 +0100 Subject: [PATCH 04/13] Rv2,RS: always load last 45 min --- .../androidaps/plugins/PumpDanaRS/services/DanaRSService.java | 2 +- .../plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index f927c107f1..a30e237672 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -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); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 2020e6d14d..4e5b85177a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -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); } From f6721f628cadb51bc7ce50a605daa4c71c90ae82 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 12 Dec 2017 22:30:42 +0100 Subject: [PATCH 05/13] Apply bolus constraint before applying. --- .../info/nightscout/androidaps/queue/CommandQueue.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index eea2635ae7..af768e4888 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -153,6 +153,10 @@ public class CommandQueue { // remove all unfinished boluses removeAll(Command.CommandType.BOLUS); + // apply constraints + detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin); + detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs); + // add new command to queue add(new CommandBolus(detailedBolusInfo, callback)); @@ -162,12 +166,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 = null; if (detailedBolusInfo.context != null) { - bolusProgressDialog = new BolusProgressDialog(); + BolusProgressDialog bolusProgressDialog = new BolusProgressDialog(); bolusProgressDialog.setInsulin(detailedBolusInfo.insulin); bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress"); } else { From 0151dbd496a040ac85519a632218e9e59ece8e30 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 13 Dec 2017 22:14:02 +0100 Subject: [PATCH 06/13] fake Esel --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index a0ba2a6843..71778d723a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -71,6 +71,7 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; +import info.nightscout.androidaps.plugins.XDripFakeEsel.XDripFakeEselPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -160,6 +161,7 @@ public class MainApp extends Application { pluginsList.add(WearPlugin.initPlugin(this)); pluginsList.add(StatuslinePlugin.initPlugin(this)); + pluginsList.add(XDripFakeEselPlugin.initPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalPlugin.getPlugin()); From 9602bde6a16e955b3ea592b84e6afb3a57c434c1 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 13 Dec 2017 22:39:44 +0100 Subject: [PATCH 07/13] fake Esel new file --- .../XDripFakeEsel/XDripFakeEselPlugin.java | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java new file mode 100644 index 0000000000..6c79fa8ebb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java @@ -0,0 +1,190 @@ +package info.nightscout.androidaps.plugins.XDripFakeEsel; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.os.Bundle; + +import com.squareup.otto.Subscribe; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.interfaces.PluginBase; + +/** + * Created by adrian on 13/12/17. + */ + +public class XDripFakeEselPlugin implements PluginBase { + + private static Logger log = LoggerFactory.getLogger(XDripFakeEselPlugin.class); + + public static final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; + private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); + + private boolean fragmentEnabled = false; + + private final Context ctx; + + private static XDripFakeEselPlugin thisPlugin; + + public static XDripFakeEselPlugin getPlugin() { + return thisPlugin; + } + + public static XDripFakeEselPlugin initPlugin(Context ctx) { + + if (thisPlugin == null) { + thisPlugin = new XDripFakeEselPlugin(ctx); + } + + return thisPlugin; + } + + private XDripFakeEselPlugin(Context ctx) { + this.ctx = ctx; + MainApp.bus().register(this); + } + + @Override + public int getType() { + return PluginBase.GENERAL; + } + + @Override + public String getFragmentClass() { + return null; + } + + @Override + public String getName() { + return "Fake ESEL for xDrip"; + } + + @Override + public String getNameShort() { + String name = "FakeESEL"; + if (!name.trim().isEmpty()) { + //only if translation exists + return name; + } + // use long name as fallback + return getName(); + } + + @Override + public boolean isEnabled(int type) { + return type == GENERAL && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return false; + } + + @Override + public boolean showInList(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == GENERAL) { + this.fragmentEnabled = fragmentEnabled; + } + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + // do nothing, no gui + } + + @Override + public int getPreferencesId() { + return -1; + } + + + private void sendBG() { + if (!fragmentEnabled) { + return; + } + try { + + final JSONArray entriesBody = new JSONArray(); + addLastSgvEntry(entriesBody); + + sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR); + } catch (Exception e) { + log.debug(e.getMessage()); + } + } + + @Subscribe + public void onStatusEvent(final EventNewBG ev) { + sendBG(); + } + + private static void sendBundle(String action, String collection, Object json, String intentIdAction) { + final Bundle bundle = new Bundle(); + bundle.putString("action", action); + bundle.putString("collection", collection); + bundle.putString("data", json.toString()); + final Intent intent = new Intent(intentIdAction); + intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + MainApp.instance().sendBroadcast(intent); + List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); + if (receivers.size() < 1) { + log.debug("No xDrip receivers found. "); + } else { + log.debug(receivers.size() + " xDrip receivers"); + } + } + + private static void addLastSgvEntry(JSONArray entriesArray) throws Exception { + JSONObject json = new JSONObject(); + BgReading bgReading = DatabaseHelper.lastBg(); + if(bgReading==null){ + log.debug("bgReading==null"); + } + + json.put("sgv", bgReading.value); + if (bgReading.direction == null){ + json.put("direction", "NONE"); + } else { + json.put("direction", bgReading.direction); + } + json.put("device", "ESEL"); + json.put("type", "sgv"); + json.put("date", bgReading.date); + json.put("dateString", format.format(bgReading.date)); + + entriesArray.put(json); + } + + public boolean isEnabled() { + return fragmentEnabled; + } + +} From 5f60e7cf2b476863b6829f4483c2814543f1ce52 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 14 Dec 2017 21:49:11 +0100 Subject: [PATCH 08/13] G5 upload to xdrip --- .../info/nightscout/androidaps/MainApp.java | 10 +- .../androidaps/Services/DataService.java | 3 + .../nightscout/androidaps/data/Profile.java | 6 +- .../XDripFakeEsel/XDripFakeEselPlugin.java | 190 ------------------ .../java/info/nightscout/utils/NSUpload.java | 48 ++++- app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/pref_dexcomg5.xml | 6 + 7 files changed, 64 insertions(+), 202 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 71778d723a..7eac441726 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -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; @@ -51,13 +49,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; @@ -71,7 +65,6 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; -import info.nightscout.androidaps.plugins.XDripFakeEsel.XDripFakeEselPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -161,7 +154,6 @@ public class MainApp extends Application { pluginsList.add(WearPlugin.initPlugin(this)); pluginsList.add(StatuslinePlugin.initPlugin(this)); - pluginsList.add(XDripFakeEselPlugin.initPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalPlugin.getPlugin()); @@ -175,7 +167,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); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 540df96fe8..c8d8dbe808 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 5b2db2c912..ea662e434d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -159,12 +159,16 @@ public class Profile { LongSparseArray 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) { + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java deleted file mode 100644 index 6c79fa8ebb..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java +++ /dev/null @@ -1,190 +0,0 @@ -package info.nightscout.androidaps.plugins.XDripFakeEsel; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.ResolveInfo; -import android.os.Bundle; - -import com.squareup.otto.Subscribe; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Locale; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.db.DatabaseHelper; -import info.nightscout.androidaps.events.EventNewBG; -import info.nightscout.androidaps.interfaces.PluginBase; - -/** - * Created by adrian on 13/12/17. - */ - -public class XDripFakeEselPlugin implements PluginBase { - - private static Logger log = LoggerFactory.getLogger(XDripFakeEselPlugin.class); - - public static final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; - private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); - - private boolean fragmentEnabled = false; - - private final Context ctx; - - private static XDripFakeEselPlugin thisPlugin; - - public static XDripFakeEselPlugin getPlugin() { - return thisPlugin; - } - - public static XDripFakeEselPlugin initPlugin(Context ctx) { - - if (thisPlugin == null) { - thisPlugin = new XDripFakeEselPlugin(ctx); - } - - return thisPlugin; - } - - private XDripFakeEselPlugin(Context ctx) { - this.ctx = ctx; - MainApp.bus().register(this); - } - - @Override - public int getType() { - return PluginBase.GENERAL; - } - - @Override - public String getFragmentClass() { - return null; - } - - @Override - public String getName() { - return "Fake ESEL for xDrip"; - } - - @Override - public String getNameShort() { - String name = "FakeESEL"; - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); - } - - @Override - public boolean isEnabled(int type) { - return type == GENERAL && fragmentEnabled; - } - - @Override - public boolean isVisibleInTabs(int type) { - return false; - } - - @Override - public boolean canBeHidden(int type) { - return true; - } - - @Override - public boolean hasFragment() { - return false; - } - - @Override - public boolean showInList(int type) { - return true; - } - - @Override - public void setFragmentEnabled(int type, boolean fragmentEnabled) { - if (type == GENERAL) { - this.fragmentEnabled = fragmentEnabled; - } - } - - @Override - public void setFragmentVisible(int type, boolean fragmentVisible) { - // do nothing, no gui - } - - @Override - public int getPreferencesId() { - return -1; - } - - - private void sendBG() { - if (!fragmentEnabled) { - return; - } - try { - - final JSONArray entriesBody = new JSONArray(); - addLastSgvEntry(entriesBody); - - sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR); - } catch (Exception e) { - log.debug(e.getMessage()); - } - } - - @Subscribe - public void onStatusEvent(final EventNewBG ev) { - sendBG(); - } - - private static void sendBundle(String action, String collection, Object json, String intentIdAction) { - final Bundle bundle = new Bundle(); - bundle.putString("action", action); - bundle.putString("collection", collection); - bundle.putString("data", json.toString()); - final Intent intent = new Intent(intentIdAction); - intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - MainApp.instance().sendBroadcast(intent); - List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); - if (receivers.size() < 1) { - log.debug("No xDrip receivers found. "); - } else { - log.debug(receivers.size() + " xDrip receivers"); - } - } - - private static void addLastSgvEntry(JSONArray entriesArray) throws Exception { - JSONObject json = new JSONObject(); - BgReading bgReading = DatabaseHelper.lastBg(); - if(bgReading==null){ - log.debug("bgReading==null"); - } - - json.put("sgv", bgReading.value); - if (bgReading.direction == null){ - json.put("direction", "NONE"); - } else { - json.put("direction", bgReading.direction); - } - json.put("device", "ESEL"); - json.put("type", "sgv"); - json.put("date", bgReading.date); - json.put("dateString", format.format(bgReading.date)); - - entriesArray.put(json); - } - - public boolean isEnabled() { - return fragmentEnabled; - } - -} diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index d6e8254cd6..f115358703 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -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; @@ -449,4 +453,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 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(); + } + + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 282299fdd0..7286003410 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -785,5 +785,8 @@ Show detailed delta Show delta with one more decimal place Unsupported pump firmware + Send BG data to xDrip+ + dexcomg5_xdripupload + In xDrip+ select 640g/Eversense data source diff --git a/app/src/main/res/xml/pref_dexcomg5.xml b/app/src/main/res/xml/pref_dexcomg5.xml index 75631b3b85..03c49bf624 100644 --- a/app/src/main/res/xml/pref_dexcomg5.xml +++ b/app/src/main/res/xml/pref_dexcomg5.xml @@ -9,6 +9,12 @@ android:key="@string/key_dexcomg5_nsupload" android:title="@string/dexcomg5_nsupload_title" /> + + \ No newline at end of file From 9bd0a1f1447d41ff841d8ba7209d13befc5da51e Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 17 Dec 2017 01:37:27 +0100 Subject: [PATCH 09/13] push next alert on read status --- .../info/nightscout/androidaps/MainApp.java | 3 +- .../queue/commands/CommandReadStatus.java | 3 +- .../receivers/KeepAliveReceiver.java | 80 +------------- .../nightscout/utils/LocalAlertUtils.java | 103 ++++++++++++++++++ 4 files changed, 113 insertions(+), 76 deletions(-) create mode 100644 app/src/main/java/info/nightscout/utils/LocalAlertUtils.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 7eac441726..603c74da4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.androidaps.receivers.NSAlarmReceiver; +import info.nightscout.utils.LocalAlertUtils; import info.nightscout.utils.NSUpload; import io.fabric.sdk.android.Fabric; @@ -213,7 +214,7 @@ public class MainApp extends Application { public void stopKeepAliveService() { if (keepAliveReceiver != null) - keepAliveReceiver.cancelAlarm(this); + LocalAlertUtils.cancelAlarm(this); } public static Bus bus() { diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java index d573cc44be..46c524fa29 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.java @@ -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(); } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 38ca9ee2a1..fc411372a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -16,61 +16,31 @@ 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.SP; +import info.nightscout.utils.LocalAlertUtils; 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; - } - - 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,16 +49,7 @@ 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(); - - 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)); - } + LocalAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated); if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) { MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null); @@ -103,8 +64,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 +78,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); - } } diff --git a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java new file mode 100644 index 0000000000..a872b1d9ec --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java @@ -0,0 +1,103 @@ +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 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); + } + + 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)); + } + } +} From 00f13d04793d2fa3b6086a6103db34324dec8d0f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 17 Dec 2017 01:40:27 +0100 Subject: [PATCH 10/13] refactor cancelAlarm back to KeepAliveReceiver --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 3 +-- .../nightscout/androidaps/receivers/KeepAliveReceiver.java | 7 +++++++ .../main/java/info/nightscout/utils/LocalAlertUtils.java | 7 ------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 603c74da4d..bd0ba7695e 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -69,7 +69,6 @@ import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.androidaps.receivers.NSAlarmReceiver; -import info.nightscout.utils.LocalAlertUtils; import info.nightscout.utils.NSUpload; import io.fabric.sdk.android.Fabric; @@ -214,7 +213,7 @@ public class MainApp extends Application { public void stopKeepAliveService() { if (keepAliveReceiver != null) - LocalAlertUtils.cancelAlarm(this); + KeepAliveReceiver.cancelAlarm(this); } public static Bus bus() { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index fc411372a3..44d0da2c55 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -27,6 +27,13 @@ public class KeepAliveReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class); public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L; + 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); + } + @Override public void onReceive(Context context, Intent rIntent) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); diff --git a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java index a872b1d9ec..e74818d447 100644 --- a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java @@ -57,13 +57,6 @@ public class LocalAlertUtils { } } - 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); - } - public static void shortenSnoozeInterval() { //shortens alarm times in case of setting changes or future data long nextMissedReadingsAlarm = SP.getLong("nextMissedReadingsAlarm", 0L); From 88adc31dbcbcc0597c963cdc51683637272b9d8b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 19 Dec 2017 07:16:41 +0100 Subject: [PATCH 11/13] Add SP to imports --- .../info/nightscout/androidaps/receivers/KeepAliveReceiver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 44d0da2c55..e8bc69281f 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.LocalAlertUtils; +import info.nightscout.utils.SP; public class KeepAliveReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class); From 81ca35515f265ec40a7add6ce472173198f714d9 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 20 Dec 2017 14:34:30 +0100 Subject: [PATCH 12/13] Old NS-Version non-urgent --- .../java/info/nightscout/androidaps/Services/DataService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index c8d8dbe808..70bd8d71ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -301,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)); From d1085c876e6f179ffb5c91b1c2cf51419c930841 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 20 Dec 2017 16:15:55 +0100 Subject: [PATCH 13/13] Actions tab: show profile switch button for single profile too. --- .../nightscout/androidaps/plugins/Actions/ActionsFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 18f092966e..910f032fc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -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);