diff --git a/app/build.gradle b/app/build.gradle index b1da089c05..f800902ecd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { minSdkVersion 21 targetSdkVersion 23 versionCode 1500 - version "1.5e" + version "1.5f" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 74271acb90..7d792556b7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,16 +56,6 @@ android:enabled="true" android:exported="true"> - - - - - - - - - - @@ -76,20 +66,6 @@ - - - - - - - - - - - @@ -120,14 +96,6 @@ - - - - - pluginsList = null; + private static DataReceiver dataReceiver = new DataReceiver(); + private static NSAlarmReceiver alarmReciever = new NSAlarmReceiver(); + private static AckAlarmReceiver ackAlarmReciever = new AckAlarmReceiver(); + private LocalBroadcastManager lbm; + @Override public void onCreate() { super.onCreate(); @@ -93,6 +104,8 @@ public class MainApp extends Application { sInstance = this; sResources = getResources(); + registerLocalBroadcastReceiver(); + if (pluginsList == null) { pluginsList = new ArrayList<>(); // Register all tabs in app here @@ -157,6 +170,29 @@ public class MainApp extends Application { } }); t.start(); + + } + + private void registerLocalBroadcastReceiver() { + lbm = LocalBroadcastManager.getInstance(this); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL)); + + //register alarms + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ALARM)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ANNOUNCEMENT)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_CLEAR_ALARM)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_URGENT_ALARM)); + + //register ack alarm + lbm.registerReceiver(ackAlarmReciever, new IntentFilter(Intents.ACTION_ACK_ALARM)); } private void startKeepAliveService() { 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 40cbbf3c52..3b04c30d94 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -506,7 +506,7 @@ public class DataService extends IntentService { MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(trJson); } - if (trJson.getString("eventType").equals(CareportalEvent.ANNOUNCEMENT)) { + if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.ANNOUNCEMENT)) { long date = trJson.getLong("mills"); long now = System.currentTimeMillis(); if (date > now - 15 * 60 * 1000L && trJson.has("notes")) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index c401c47574..a624310b10 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -296,17 +296,17 @@ public class TemporaryBasal implements Interval { Profile profile = MainApp.getConfigBuilder().getProfile(); Double currentBasalRate = profile.getBasal(); double rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); - return DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" + + return getCalcuatedPercentageIfNeeded() + DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } else if (isAbsolute) { return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } else { // percent return percentRate + "% @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } } @@ -337,6 +337,31 @@ public class TemporaryBasal implements Interval { } } + private String getCalcuatedPercentageIfNeeded(){ + if (isAbsolute || isFakeExtended) { + + double rate = 0d; + if (isFakeExtended) { + Profile profile = MainApp.getConfigBuilder().getProfile(); + Double currentBasalRate = profile.getBasal(); + rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); + } else if (isAbsolute){ + rate = absoluteRate; + } + + if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){ + Profile profile = MainApp.getConfigBuilder().getProfile(); + if(profile != null) { + double basal = profile.getBasal(); + if(basal != 0){ + return Math.round(rate*100d/basal) + "% "; + } + } + } + } + return ""; + } + public String toStringVeryShort() { if (isAbsolute || isFakeExtended) { diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index dbbdec2ce1..bb78ea1d0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -34,7 +34,9 @@ public interface PumpInterface { PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes); PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes); PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes); - PumpEnactResult cancelTempBasal(); + //some pumps might set a very short temp close to 100% as canecelling a temp can be noisy + //when the cancel request is requested by the user, the pump should always do a real cancel + PumpEnactResult cancelTempBasal(boolean userRequested); PumpEnactResult cancelExtendedBolus(); // Status to be passed to NS 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 b62674c5ae..c6b278955f 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 @@ -20,6 +20,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -49,6 +50,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL Button extendedBolus; Button extendedBolusCancel; Button tempBasal; + Button tempBasalCancel; Button fill; private static Handler sHandler; @@ -74,6 +76,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel); tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); + tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal); fill = (Button) view.findViewById(R.id.actions_fill); profileSwitch.setOnClickListener(this); @@ -81,6 +84,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL extendedBolus.setOnClickListener(this); extendedBolusCancel.setOnClickListener(this); tempBasal.setOnClickListener(this); + tempBasalCancel.setOnClickListener(this); fill.setOnClickListener(this); updateGUI(); @@ -114,33 +118,59 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL activity.runOnUiThread(new Runnable() { @Override public void run() { - if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() == null) + if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() == null) { + tempTarget.setVisibility(View.GONE); + profileSwitch.setVisibility(View.GONE); + extendedBolus.setVisibility(View.GONE); + extendedBolusCancel.setVisibility(View.GONE); + tempBasal.setVisibility(View.GONE); + tempBasalCancel.setVisibility(View.GONE); + fill.setVisibility(View.GONE); return; + } boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1; if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !allowProfileSwitch) profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) + + + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) { extendedBolus.setVisibility(View.GONE); - else { - extendedBolus.setVisibility(View.VISIBLE); - } - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) extendedBolusCancel.setVisibility(View.GONE); - else { - extendedBolusCancel.setVisibility(View.VISIBLE); - ExtendedBolus running = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); - extendedBolusCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + running.toString()); + } else { + if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + extendedBolus.setVisibility(View.GONE); + extendedBolusCancel.setVisibility(View.VISIBLE); + ExtendedBolus running = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + extendedBolusCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + running.toString()); + } else { + extendedBolus.setVisibility(View.VISIBLE); + extendedBolusCancel.setVisibility(View.GONE); + } } - if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isTempBasalInProgress()) + + + if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) { tempBasal.setVisibility(View.GONE); - else - tempBasal.setVisibility(View.VISIBLE); + tempBasalCancel.setVisibility(View.GONE); + } else { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasal.setVisibility(View.GONE); + tempBasalCancel.setVisibility(View.VISIBLE); + final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); + } else { + tempBasal.setVisibility(View.VISIBLE); + tempBasalCancel.setVisibility(View.GONE); + } + } + if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) fill.setVisibility(View.GONE); else fill.setVisibility(View.VISIBLE); + if (!Config.APS) tempTarget.setVisibility(View.GONE); else @@ -184,6 +214,17 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL }); } break; + case R.id.actions_canceltempbasal: + if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { + sHandler.post(new Runnable() { + @Override + public void run() { + pump.cancelTempBasal(true); + Answers.getInstance().logCustom(new CustomEvent("CancelTemp")); + } + }); + } + break; case R.id.actions_settempbasal: NewTempBasalDialog newTempDialog = new NewTempBasalDialog(); newTempDialog.show(manager, "NewTempDialog"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 51effccb86..0a379a904d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.data.Profile; +import info.nightscout.utils.NumberPicker; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -35,14 +36,14 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi RadioButton percentRadio; RadioButton absoluteRadio; RadioGroup basalTypeRadioGroup; - RelativeLayout typeSelectorLayout; + LinearLayout typeSelectorLayout; LinearLayout percentLayout; LinearLayout absoluteLayout; - PlusMinusEditText basalPercent; - PlusMinusEditText basalAbsolute; - PlusMinusEditText duration; + NumberPicker basalPercent; + NumberPicker basalAbsolute; + NumberPicker duration; Handler mHandler; public static HandlerThread mHandlerThread; @@ -65,22 +66,24 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi percentRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_percent_radio); basalTypeRadioGroup = (RadioGroup) view.findViewById(R.id.overview_newtempbasal_radiogroup); absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio); - typeSelectorLayout = (RelativeLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout); + typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout); PumpDescription pumpDescription = MainApp.getConfigBuilder().getPumpDescription(); - basalPercent = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalpercentinput, R.id.overview_newtempbasal_basalpercent_plus, R.id.overview_newtempbasal_basalpercent_minus, - 100d, 0d, (double) pumpDescription.maxTempPercent, (double) pumpDescription.tempPercentStep, new DecimalFormat("0"), true); + basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput); + double maxTempPercent = pumpDescription.maxTempPercent; + double tempPercentStep = pumpDescription.tempPercentStep; + basalPercent.setParams(100d, 0d, maxTempPercent, tempPercentStep, new DecimalFormat("0"), true); Profile profile = MainApp.getConfigBuilder().getProfile(); - Double currentBasal = profile.getBasal(); - basalAbsolute = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalabsoluteinput, R.id.overview_newtempbasal_basalabsolute_plus, R.id.overview_newtempbasal_basalabsolute_minus, - currentBasal, 0d, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, new DecimalFormat("0.00"), true); + Double currentBasal = profile != null ? profile.getBasal() : 0d; + basalAbsolute = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalabsoluteinput); + basalAbsolute.setParams(currentBasal, 0d, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, new DecimalFormat("0.00"), true); - double tempDurationStep = MainApp.getConfigBuilder().getPumpDescription().tempDurationStep; - double tempMaxDuration = MainApp.getConfigBuilder().getPumpDescription().tempMaxDuration; - duration = new PlusMinusEditText(view, R.id.overview_newtempbasal_duration, R.id.overview_newtempbasal_duration_plus, R.id.overview_newtempbasal_duration_minus, - tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, new DecimalFormat("0"), false); + double tempDurationStep = pumpDescription.tempDurationStep; + double tempMaxDuration = pumpDescription.tempMaxDuration; + duration = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_duration); + duration.setParams(tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, new DecimalFormat("0"), false); if ((pumpDescription.tempBasalStyle & PumpDescription.PERCENT) == PumpDescription.PERCENT && (pumpDescription.tempBasalStyle & PumpDescription.ABSOLUTE) == PumpDescription.ABSOLUTE) { // Both allowed @@ -107,13 +110,6 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi return view; } - @Override - public void onResume() { - super.onResume(); - if (getDialog() != null) - getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - } - @Override public void onClick(View view) { switch (view.getId()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 31907f16dc..ea995d2b6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -509,8 +509,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } @Override - public PumpEnactResult cancelTempBasal() { - PumpEnactResult result = activePump.cancelTempBasal(); + public PumpEnactResult cancelTempBasal(boolean userRequested) { + PumpEnactResult result = activePump.cancelTempBasal(userRequested); if (Config.logCongigBuilderActions) log.debug("cancelTempBasal success: " + result.success + " enacted: " + result.enacted); return result; @@ -559,7 +559,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (isTempBasalInProgress()) { if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: cancelTempBasal()"); - result = cancelTempBasal(); + result = cancelTempBasal(false); } else { result = new PumpEnactResult(); result.absolute = request.rate; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java index 827023f5b3..b33d1cb2c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java @@ -159,7 +159,7 @@ public class NSClientInternalPlugin implements PluginBase { MainApp.bus().post(new EventNSClientUpdateGUI()); } - void clearLog() { + synchronized void clearLog() { handler.post(new Runnable() { @Override public void run() { @@ -169,7 +169,7 @@ public class NSClientInternalPlugin implements PluginBase { }); } - private void addToLog(final EventNSClientNewLog ev) { + private synchronized void addToLog(final EventNSClientNewLog ev) { handler.post(new Runnable() { @Override public void run() { @@ -183,7 +183,7 @@ public class NSClientInternalPlugin implements PluginBase { }); } - static void updateLog() { + static synchronized void updateLog() { try { StringBuilder newTextLog = new StringBuilder(); List temporaryList = new ArrayList<>(listLog); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java index 35789a426c..216fa3d19a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java @@ -4,12 +4,15 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; import info.nightscout.utils.SP; @@ -22,7 +25,7 @@ public class BroadcastAckAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class); public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putInt("level", originalAlarm.getLevel()); bundle.putString("group", originalAlarm.getGroup()); @@ -30,7 +33,18 @@ public class BroadcastAckAlarm { Intent intent = new Intent(Intents.ACTION_ACK_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putInt("level", originalAlarm.getLevel()); + bundle.putString("group", originalAlarm.getGroup()); + bundle.putLong("silenceTime", silenceTimeInMsec); + intent = new Intent(Intents.ACTION_ACK_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java index 03fe04f8fe..0fee6600bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +24,20 @@ public class BroadcastAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class); public static void handleAlarm(JSONObject alarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", alarm.toString()); Intent intent = new Intent(Intents.ACTION_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("data", alarm.toString()); + intent = new Intent(Intents.ACTION_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java index 3f9a43a14a..9b133c2551 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.json.JSONObject; @@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -22,14 +25,20 @@ public class BroadcastAnnouncement { private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class); public static void handleAnnouncement(JSONObject announcement, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", announcement.toString()); Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("data", announcement.toString()); + intent = new Intent(Intents.ACTION_ANNOUNCEMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java index 7a7772357c..7580a00088 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.slf4j.Logger; @@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -22,14 +25,22 @@ public class BroadcastCals { public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("cals", cals.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_CAL); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("cals", cals.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_CAL); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java index 4f2716cf85..23406837a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +24,20 @@ public class BroadcastClearAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class); public static void handleClearAlarm(JSONObject clearalarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", clearalarm.toString()); Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("data", clearalarm.toString()); + intent = new Intent(Intents.ACTION_CLEAR_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java index 9053c6becb..a912fc5d3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.json.JSONObject; @@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -26,14 +29,20 @@ public class BroadcastDeviceStatus { Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("devicestatus", status.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - - List splitted = BroadcastTreatment.splitArray(statuses); for (JSONArray part: splitted) { Bundle bundle = new Bundle(); @@ -42,7 +51,20 @@ public class BroadcastDeviceStatus { Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + } + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + splitted = BroadcastTreatment.splitArray(statuses); + for (JSONArray part : splitted) { + Bundle bundle = new Bundle(); + bundle.putString("devicestatuses", part.toString()); + bundle.putBoolean("delta", isDelta); + Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java index f45ade6b32..a715747791 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.slf4j.Logger; @@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -22,14 +25,22 @@ public class BroadcastMbgs { public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("mbgs", mbgs.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_MBG); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("mbgs", mbgs.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_MBG); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java index ec62ccbf6f..3802b09657 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java @@ -4,12 +4,15 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.utils.SP; @@ -23,15 +26,23 @@ public class BroadcastProfile { public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("profile", profile.getData().toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_PROFILE); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("profile", profile.getData().toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_PROFILE); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java index eedeb4574d..abc49be18a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -14,7 +15,7 @@ import info.nightscout.utils.SP; public class BroadcastQueueStatus { public static void handleNewStatus(int size, Context context) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + if(!SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) return; PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java index 29e2031869..d4193f3cb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.json.JSONObject; @@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -23,15 +26,23 @@ public class BroadcastSgvs { public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("sgv", sgv.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("sgv", sgv.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_SGV); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) { @@ -41,7 +52,17 @@ public class BroadcastSgvs { Intent intent = new Intent(Intents.ACTION_NEW_SGV); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("sgvs", sgvs.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_SGV); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java index 026658afc0..7c6862cb14 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; @@ -25,8 +27,6 @@ public class BroadcastStatus { public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); try { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); @@ -41,6 +41,24 @@ public class BroadcastStatus { Intent intent = new Intent(Intents.ACTION_NEW_STATUS); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + try { + bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); + bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName); + bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode); + bundle.putString("status", status.getData().toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_STATUS); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 60540d7613..0d998a2bcd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.TransactionTooLargeException; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.json.JSONException; @@ -15,9 +16,12 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; import info.nightscout.utils.SP; +import info.nightscout.utils.ToastUtils; /** * Created by mike on 20.02.2016. @@ -27,21 +31,27 @@ public class BroadcastTreatment { public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.getData().toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("treatment", treatment.getData().toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - List splitted = splitArray(treatments); for (JSONArray part: splitted) { Bundle bundle = new Bundle(); @@ -50,42 +60,73 @@ public class BroadcastTreatment { Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + } + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)){ + splitted = splitArray(treatments); + for (JSONArray part: splitted) { + Bundle bundle = new Bundle(); + bundle.putString("treatments", part.toString()); + bundle.putBoolean("delta", isDelta); + Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - } + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); - public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - - List splitted = splitArray(treatments); - for (JSONArray part: splitted) { - Bundle bundle = new Bundle(); - bundle.putString("treatments", part.toString()); + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("treatment", treatment.toString()); bundle.putBoolean("delta", isDelta); - Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); + intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); context.sendBroadcast(intent); } } - public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) { + public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + List splitted = splitArray(treatments); + for (JSONArray part : splitted) { + Bundle bundle = new Bundle(); + bundle.putString("treatments", part.toString()); + bundle.putBoolean("delta", isDelta); + Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + } + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + splitted = splitArray(treatments); + for (JSONArray part : splitted) { + Bundle bundle = new Bundle(); + bundle.putString("treatments", part.toString()); + bundle.putBoolean("delta", isDelta); + Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } + } + } + + public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) { Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.toString()); @@ -93,20 +134,40 @@ public class BroadcastTreatment { Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("treatment", treatment.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("treatments", treatments.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("treatments", treatments.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java index 442eb729c0..c332be03af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +24,20 @@ public class BroadcastUrgentAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class); public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", urgentalarm.toString()); Intent intent = new Intent(Intents.ACTION_URGENT_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { + bundle = new Bundle(); + bundle.putString("data", urgentalarm.toString()); + intent = new Intent(Intents.ACTION_URGENT_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 5d57f3caf1..c68bbb19d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -313,6 +313,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } + pump.cancelTempBasal(true); result = pump.setTempBasalAbsolute(0d, 120); if (!result.success) { OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 71f205551e..7e33d1ff8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -175,7 +175,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, LinearLayoutManager llm; LinearLayout acceptTempLayout; - Button cancelTempButton; Button treatmentButton; Button wizardButton; Button calibrationButton; @@ -269,9 +268,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); - cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton); - if (cancelTempButton != null) - cancelTempButton.setOnClickListener(this); treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); treatmentButton.setOnClickListener(this); wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); @@ -415,7 +411,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -436,7 +432,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -450,7 +446,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -464,7 +460,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -478,7 +474,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -492,7 +488,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -506,6 +502,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 30); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -520,6 +517,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -534,6 +532,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 2 * 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -548,6 +547,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 3 * 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -583,18 +583,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(); treatmentDialogFragment.show(manager, "TreatmentDialog"); break; - case R.id.overview_canceltempbutton: - final PumpInterface pump = MainApp.getConfigBuilder(); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - sHandler.post(new Runnable() { - @Override - public void run() { - pump.cancelTempBasal(); - Answers.getInstance().logCustom(new CustomEvent("CancelTemp")); - } - }); - } - break; case R.id.overview_pumpstatus: if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized()) sHandler.post(new Runnable() { @@ -1016,15 +1004,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); - if (cancelTempButton != null) { - if (activeTemp != null) { - cancelTempButton.setVisibility(View.VISIBLE); - cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); - } else { - cancelTempButton.setVisibility(View.GONE); - } - } - String basalText = ""; if (shorttextmode) { if (activeTemp != null) { @@ -1053,6 +1032,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)"; } } + if (activeTemp != null) { + baseBasalView.setTextColor(MainApp.sResources.getColor(R.color.basal)); + } else { + baseBasalView.setTextColor(Color.WHITE); + + } + baseBasalView.setText(basalText); final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 3a7f448309..2625b4699b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -18,7 +18,6 @@ import android.support.v4.app.NotificationCompat; import com.squareup.otto.Subscribe; -import org.json.JSONException; import org.json.JSONObject; import org.monkey.d.ruffy.ruffy.driver.IRuffyService; import org.slf4j.Logger; @@ -195,11 +194,14 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public void onServiceConnected(ComponentName name, IBinder service) { ruffyScripter = new RuffyScripter(IRuffyService.Stub.asInterface(service)); + ruffyScripter.start(); log.debug("ruffy serivce connected"); } @Override public void onServiceDisconnected(ComponentName name) { + ruffyScripter.stop(); + ruffyScripter = null; log.debug("ruffy service disconnected"); } }; @@ -485,22 +487,27 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min"); - if (percent % 10 != 0) { - int rounded = percent; - while (rounded % 10 != 0) rounded = rounded - 1; - log.debug("Rounded requested percentage from " + percent + " to " + rounded); - percent = rounded; + + int adjustedPercent = percent; + + if (adjustedPercent > pumpDescription.maxTempPercent) { + log.debug("Reducing requested TBR to the maximum support by the pump: " + percent + " -> " + pumpDescription.maxTempPercent); + adjustedPercent = pumpDescription.maxTempPercent; } - percent = percent > pumpDescription.maxTempPercent ? pumpDescription.maxTempPercent : percent; + if (adjustedPercent % 10 != 0) { + Long rounded = Math.round(adjustedPercent / 10d) * 10; + log.debug("Rounded requested percentage:" + adjustedPercent + " -> " + rounded); + adjustedPercent = rounded.intValue(); + } - CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes)); + CommandResult commandResult = runCommand(new SetTbrCommand(adjustedPercent, durationInMinutes)); if (commandResult.enacted) { TemporaryBasal tempStart = new TemporaryBasal(commandResult.completionTime); // TODO commandResult.state.tbrRemainingDuration might already display 29 if 30 was set, since 29:59 is shown as 29 ... // we should check this, but really ... something must be really screwed up if that number was anything different tempStart.durationInMinutes = durationInMinutes; - tempStart.percentRate = percent; + tempStart.percentRate = adjustedPercent; tempStart.isAbsolute = false; tempStart.source = Source.USER; ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder(); @@ -514,7 +521,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { pumpEnactResult.isPercent = true; // Combo would have bailed if this wasn't set properly. Maybe we should // have the command return this anyways ... - pumpEnactResult.percent = percent; + pumpEnactResult.percent = adjustedPercent; pumpEnactResult.duration = durationInMinutes; return pumpEnactResult; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 7ee13df40c..7ed4345093 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -566,7 +566,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index c3bd70c155..e3b6bf3598 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -570,7 +570,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 7a0eca5da3..bb944b1165 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -340,7 +340,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); - return cancelTempBasal(); + return cancelTempBasal(false); } result.success = true; result.enacted = false; @@ -507,7 +507,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { PumpEnactResult result = new PumpEnactResult(); if (pump.isTempBasalInProgress) { sExecutionService.tempBasalStop(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index b51a0bb66e..ddd05a2e0b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -196,7 +196,7 @@ public class MDIPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { PumpEnactResult result = new PumpEnactResult(); result.success = false; result.comment = MainApp.instance().getString(R.string.pumperror); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java index 2dfaefe482..b479183b80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java @@ -57,7 +57,6 @@ public class VirtualPumpFragment extends SubscriberFragment { batteryView = (TextView) view.findViewById(R.id.virtualpump_battery); reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir); - updateGUI(); return view; } @@ -73,8 +72,8 @@ public class VirtualPumpFragment extends SubscriberFragment { activity.runOnUiThread(new Runnable() { @Override public void run() { - - basaBasalRateView.setText(VirtualPumpPlugin.getInstance().getBaseBasalRate() + "U"); + VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getInstance(); + basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); } else { @@ -85,8 +84,8 @@ public class VirtualPumpFragment extends SubscriberFragment { } else { extendedBolusView.setText(""); } - batteryView.setText(VirtualPumpPlugin.getInstance().batteryPercent + "%"); - reservoirView.setText(VirtualPumpPlugin.getInstance().reservoirInUnits + "U"); + batteryView.setText(virtualPump.batteryPercent + "%"); + reservoirView.setText(virtualPump.reservoirInUnits + "U"); } }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index b42d1abfd6..7337859c47 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -204,7 +204,11 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public double getBaseBasalRate() { - return MainApp.getConfigBuilder().getProfile().getBasal(); + Profile profile = MainApp.getConfigBuilder().getProfile(); + if (profile != null) + return profile.getBasal(); + else + return 0d; } @Override @@ -282,7 +286,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - result = cancelTempBasal(); + result = cancelTempBasal(false); if (!result.success) return result; } @@ -333,7 +337,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); result.success = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index ad8679beee..8e5e3bde46 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -272,7 +272,7 @@ public class SmsCommunicatorPlugin implements PluginBase { LoopPlugin loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) { loopPlugin.setFragmentEnabled(PluginBase.LOOP, false); - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled)+ " " + MainApp.sResources.getString(result.success?R.string.smscommunicator_tempbasalcanceled:R.string.smscommunicator_tempbasalcancelfailed); @@ -506,7 +506,7 @@ public class SmsCommunicatorPlugin implements PluginBase { PumpInterface pumpInterface = MainApp.getConfigBuilder(); if (pumpInterface != null) { danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); - PumpEnactResult result = pumpInterface.cancelTempBasal(); + PumpEnactResult result = pumpInterface.cancelTempBasal(true); if (result.success) { reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled); if (danaRPlugin != null) @@ -535,7 +535,7 @@ public class SmsCommunicatorPlugin implements PluginBase { suspendWaitingForConfirmation.processed = true; final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/Events/EventNewSMS.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/Events/EventNewSMS.java rename to app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/Events/EventSmsCommunicatorUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/Events/EventSmsCommunicatorUpdateGui.java rename to app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java 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 02ee924923..bca65dd4b5 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 @@ -189,6 +189,7 @@ public class ActionStringHandler { boolean useBG = Boolean.parseBoolean(act[2]); boolean useBolusIOB = Boolean.parseBoolean(act[3]); boolean useBasalIOB = Boolean.parseBoolean(act[4]); + int percentage = Integer.parseInt(act[5]); Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) { @@ -203,7 +204,7 @@ public class ActionStringHandler { } DecimalFormat format = new DecimalFormat("0.00"); BolusWizard bolusWizard = new BolusWizard(); - bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, useBolusIOB, useBasalIOB, false, false); + bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin); if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { @@ -233,6 +234,9 @@ public class ActionStringHandler { rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U"; if (useBasalIOB) rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U"; + if(percentage != 100){ + rMessage += "\nPercentage: " +format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U"; + } lastBolusWizard = bolusWizard; diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index e5af535759..f4eb4907ef 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -47,9 +47,14 @@ public class BolusWizard { // Result public Double calculatedTotalInsulin = 0d; + public Double totalBeforePercentageAdjustment = 0d; public Double carbsEquivalent = 0d; public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { + return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend); + } + + public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { this.specificProfile = specificProfile; this.carbs = carbs; this.bg = bg; @@ -103,7 +108,13 @@ public class BolusWizard { } // Total - calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; + calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; + + //percentage + if(totalBeforePercentageAdjustment > 0){ + calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d; + } + if (calculatedTotalInsulin < 0) { carbsEquivalent = -calculatedTotalInsulin * ic; diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 4fa5a0d5e2..aeb1f7181d 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -49,7 +49,6 @@ public class NSUpload { data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.absoluteRate + "u/h " + temporaryBasal.durationInMinutes + " min"); // ECOR if (originalExtendedAmount != null) data.put("originalExtendedAmount", originalExtendedAmount); // for back synchronization Bundle bundle = new Bundle(); @@ -88,7 +87,6 @@ public class NSUpload { data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.percentRate + "% " + temporaryBasal.durationInMinutes + " min"); // ECOR Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); bundle.putString("collection", "treatments"); @@ -111,7 +109,6 @@ public class NSUpload { data.put("eventType", CareportalEvent.TEMPBASAL); data.put("created_at", DateUtil.toISOString(time)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR if (isFakedTempBasal) data.put("isFakedTempBasal", isFakedTempBasal); if (pumpId != 0) diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index e24f69124d..bc8f416770 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -52,6 +52,19 @@ android:drawableTop="@drawable/icon_actions_starttempbasal" android:text="@string/overview_tempbasal_button" /> +