l = insightPlugin.getStatusItems(refresh);
-
- holder.removeAllViews();
-
- for (StatusItem row : l) {
- viewAdapter.inflateStatus(row);
- }
-
- }
- });
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java
deleted file mode 100644
index c72da31fdf..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java
+++ /dev/null
@@ -1,935 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight;
-
-import android.content.DialogInterface;
-import android.os.SystemClock;
-import android.support.v4.app.FragmentActivity;
-import android.support.v7.app.AlertDialog;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-import info.nightscout.androidaps.BuildConfig;
-import info.nightscout.androidaps.Config;
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.DetailedBolusInfo;
-import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.data.PumpEnactResult;
-import info.nightscout.androidaps.db.ExtendedBolus;
-import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.db.TemporaryBasal;
-import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.interfaces.ConstraintsInterface;
-import info.nightscout.androidaps.interfaces.PluginBase;
-import info.nightscout.androidaps.interfaces.PluginDescription;
-import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.interfaces.PumpDescription;
-import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusSilentlyTaskRunner;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelTBRSilentlyTaskRunner;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
-import info.nightscout.androidaps.plugins.PumpInsight.connector.WriteBasalProfileTaskRunner;
-import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightCallback;
-import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightUpdateGui;
-import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver;
-import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
-import sugar.free.sightparser.applayer.descriptors.ActiveBolus;
-import sugar.free.sightparser.applayer.descriptors.ActiveBolusType;
-import sugar.free.sightparser.applayer.descriptors.MessagePriority;
-import sugar.free.sightparser.applayer.descriptors.PumpStatus;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock;
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.BolusMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage;
-import sugar.free.sightparser.handling.SingleMessageTaskRunner;
-import sugar.free.sightparser.handling.TaskRunner;
-import sugar.free.sightparser.pipeline.Status;
-
-import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.getRecordUniqueID;
-
-
-/**
- * Created by jamorham on 23/01/2018.
- *
- * Connects to SightRemote app service using SightParser library
- *
- * SightRemote and SightParser created by Tebbe Ubben
- *
- * Original proof of concept SightProxy by jamorham
- */
-
-@SuppressWarnings("AccessStaticViaInstance")
-public class InsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface {
- private Logger log = LoggerFactory.getLogger(L.PUMP);
-
- private static volatile InsightPlugin plugin;
-
- public static InsightPlugin getPlugin() {
- if (plugin == null) {
- plugin = new InsightPlugin();
- }
- return plugin;
- }
-
- private static final long BUSY_WAIT_TIME = 20000;
- private static Integer batteryPercent = 0;
- private static Integer reservoirInUnits = 0;
- private static boolean initialized = false;
- private static volatile boolean update_pending = false;
- private StatusTaskRunner.Result statusResult;
- private long statusResultTime = -1;
- private long lastDataTime = 0;
- private boolean fauxTBRcancel = true;
- private PumpDescription pumpDescription = new PumpDescription();
- private double basalRate = 0;
- private Connector connector;
- private volatile boolean connector_enabled = false;
- private List profileBlocks;
-
- private InsightPlugin() {
- super(new PluginDescription()
- .mainType(PluginType.PUMP)
- .fragmentClass(InsightFragment.class.getName())
- .pluginName(R.string.insightpump)
- .shortName(R.string.insightpump_shortname)
- .preferencesId(R.xml.pref_insightpump)
- .description(R.string.description_pump_insight)
- );
- if (L.isEnabled(L.PUMP))
- log.debug("InsightPlugin instantiated");
- pumpDescription.setPumpDescription(PumpType.AccuChekInsight);
- }
-
-
- private static void updateGui() {
- update_pending = false;
- MainApp.bus().post(new EventInsightUpdateGui());
- }
-
- private static void pushCallbackEvent(EventInsightCallback e) {
- MainApp.bus().post(e);
- }
-
- @Override
- protected void onStart() {
- if (!connector_enabled) {
- synchronized (this) {
- if (!connector_enabled) {
- if (L.isEnabled(L.PUMP))
- log.debug("Instantiating connector");
- connector_enabled = true;
- this.connector = Connector.get();
- this.connector.init();
- }
- }
- }
- super.onStart();
- }
-
- protected void onStop() {
- if (connector_enabled) {
- synchronized (this) {
- if (connector_enabled) {
- if (L.isEnabled(L.PUMP))
- log.debug("Shutting down connector");
- Connector.get().shutdown();
- connector_enabled = false;
- }
- }
- }
- }
-
- @Override
- public boolean isFakingTempsByExtendedBoluses() {
- return true;
- }
-
- @Override
- public PumpEnactResult loadTDDs() {
- PumpEnactResult result = new PumpEnactResult();
- result.success = true;
- return result;
- }
-
- @Override
- public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) {
- boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false);
- if (allowHardwarePump || context == null) {
- pluginSwitcher.invoke();
- } else {
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setMessage(R.string.allow_hardware_pump_text)
- .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- pluginSwitcher.invoke();
- SP.putBoolean("allow_hardware_pump", true);
- log.debug("First time HW pump allowed!");
- }
- })
- .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- pluginSwitcher.cancel();
- log.debug("User does not allow switching to HW pump!");
- }
- });
- builder.create().show();
- }
- }
-
- @Override
- public boolean isInitialized() {
- return initialized;
- }
-
- @Override
- public boolean isSuspended() {
- return !isPumpRunning();
- }
-
- @Override
- public boolean isBusy() {
- return false;
- }
-
- @Override
- public boolean isConnected() {
- return Connector.get().isPumpConnected();
- }
-
- @Override
- public boolean isConnecting() {
- return Connector.get().isPumpConnecting();
- }
-
- @Override
- public boolean isHandshakeInProgress() {
- return false;
- }
-
- @Override
- public void finishHandshaking() {
- }
-
- @Override
- public void connect(String reason) {
- if (L.isEnabled(L.PUMP))
- log.debug("InsightPlugin::connect()");
- try {
- if (!connector.isPumpConnected()) {
- if (Helpers.ratelimit("insight-connect-timer", 40)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Actually requesting a connect");
- connector.connectToPump();
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Already connected");
- }
- } catch (NullPointerException e) {
- log.error("Could not sconnect - null pointer: " + e);
- }
-
- // TODO review
- if (!Config.NSCLIENT)
- NSUpload.uploadDeviceStatus();
- }
-
- @Override
- public void disconnect(String reason) {
- if (L.isEnabled(L.PUMP))
- log.debug("InsightPlugin::disconnect()");
- try {
- if (!SP.getBoolean("insight_always_connected", false)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Requesting disconnect");
- connector.disconnectFromPump();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Not disconnecting due to preference");
- }
- } catch (NullPointerException e) {
- log.error("Could not disconnect - null pointer: " + e);
- }
- }
-
- @Override
- public void stopConnecting() {
- if (L.isEnabled(L.PUMP))
- log.debug("InsightPlugin::stopConnecting()");
- try {
- if (isConnecting()) {
- if (!SP.getBoolean("insight_always_connected", false)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Requesting disconnect");
- connector.disconnectFromPump();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Not disconnecting due to preference");
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Not currently trying to connect so not stopping connection");
- }
- } catch (NullPointerException e) {
- log.error("Could not stop connecting - null pointer: " + e);
- }
- }
-
- @Override
- public void getPumpStatus() {
- if (L.isEnabled(L.PUMP))
- log.debug("getPumpStatus");
- if (Connector.get().isPumpConnected()) {
- if (L.isEnabled(L.PUMP))
- log.debug("is connected.. requesting status");
- try {
- setStatusResult(fetchTaskRunner(new StatusTaskRunner(connector.getServiceConnector()), StatusTaskRunner.Result.class));
- if (L.isEnabled(L.PUMP))
- log.debug("GOT STATUS RESULT!!! PARTY WOOHOO!!!");
- statusResultTime = Helpers.tsl();
- processStatusResult();
- updateGui();
- connector.requestHistoryReSync();
- connector.requestHistorySync();
- } catch (Exception e) {
- log.error("StatusTaskRunner wasn't successful.");
- if (connector.getServiceConnector().isConnectedToService() && connector.getServiceConnector().getStatus() != Status.CONNECTED) {
- if (Helpers.ratelimit("insight-reconnect", 2)) {
- Connector.connectToPump();
- updateGui();
- }
- }
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("not connected.. not requesting status");
- }
- }
-
- public void setStatusResult(StatusTaskRunner.Result result) {
- this.statusResult = result;
- this.pumpDescription.basalMinimumRate = result.minimumBasalAmount;
- this.pumpDescription.basalMaximumRate = result.maximumBasalAmount;
- }
-
- @Override
- public PumpEnactResult setNewBasalProfile(Profile profile) {
- PumpEnactResult result = new PumpEnactResult();
- if (!isInitialized()) {
- log.error("setNewBasalProfile not initialized");
- Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
- MainApp.bus().post(new EventNewNotification(notification));
- result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet);
- return result;
- }
- MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
- List profileBlocks = new ArrayList<>();
- for (int i = 0; i < profile.getBasalValues().length; i++) {
- Profile.BasalValue basalValue = profile.getBasalValues()[i];
- Profile.BasalValue nextValue = null;
- if (profile.getBasalValues().length > i + 1)
- nextValue = profile.getBasalValues()[i + 1];
- profileBlocks.add(new BRProfileBlock.ProfileBlock((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60), Helpers.roundDouble(basalValue.value, 2)));
- if (L.isEnabled(L.PUMP))
- log.debug("setNewBasalProfile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
- }
- try {
- fetchTaskRunner(new WriteBasalProfileTaskRunner(connector.getServiceConnector(), profileBlocks));
- MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
- Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
- MainApp.bus().post(new EventNewNotification(notification));
- result.success = true;
- result.enacted = true;
- result.comment = "OK";
- this.profileBlocks = profileBlocks;
- } catch (Exception e) {
- Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
- MainApp.bus().post(new EventNewNotification(notification));
- result.comment = MainApp.gs(R.string.failedupdatebasalprofile);
- }
- return result;
- }
-
- @Override
- public boolean isThisProfileSet(Profile profile) {
- if (!isInitialized() || profileBlocks == null) return true;
- if (profile.getBasalValues().length != profileBlocks.size()) return false;
- for (int i = 0; i < profileBlocks.size(); i++) {
- BRProfileBlock.ProfileBlock profileBlock = profileBlocks.get(i);
- Profile.BasalValue basalValue = profile.getBasalValues()[i];
- Profile.BasalValue nextValue = null;
- if (profile.getBasalValues().length > i + 1)
- nextValue = profile.getBasalValues()[i + 1];
- if (L.isEnabled(L.PUMP))
- log.debug("isThisProfileSet - Comparing block: Pump: " + profileBlock.getAmount() + " for " + profileBlock.getDuration()
- + " Profile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
- if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds)
- return false;
- //Allow a little imprecision due to rounding errors
- if (Math.abs(profileBlock.getAmount() - Helpers.roundDouble(basalValue.value, 2)) >= 0.01D)
- return false;
- }
- return true;
- }
-
- @Override
- public long lastDataTime() {
- return lastDataTime;
- }
-
- @Override
- public double getBaseBasalRate() {
- return basalRate;
- }
-
- public String getBaseBasalRateString() {
- final DecimalFormat df = new DecimalFormat("#.##");
- return df.format(basalRate);
- }
-
- @Override
- public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
- final PumpEnactResult result = new PumpEnactResult();
- result.bolusDelivered = detailedBolusInfo.insulin;
- result.carbsDelivered = detailedBolusInfo.carbs;
- result.enacted = result.bolusDelivered > 0 || result.carbsDelivered > 0;
- result.comment = MainApp.gs(R.string.virtualpump_resultok);
-
- result.percent = 100;
-
- int bolusId = 0;
-
- // is there an insulin component to the treatment?
- if (detailedBolusInfo.insulin > 0) {
- try {
- bolusId = deliverBolus(detailedBolusInfo.insulin);
- result.success = true;
- detailedBolusInfo.pumpId = getRecordUniqueID(bolusId);
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- } else {
- result.success = true; // always true with carb only treatments
- }
-
- if (result.success) {
- if (L.isEnabled(L.PUMP))
- log.debug("Success!");
-
- Treatment t = new Treatment();
- t.isSMB = detailedBolusInfo.isSMB;
- final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
- bolusingEvent.t = t;
- bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), 0F);
- bolusingEvent.bolusId = bolusId;
- bolusingEvent.percent = 0;
- MainApp.bus().post(bolusingEvent);
- TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Failure to deliver treatment");
- }
-
- if (L.isEnabled(L.PUMP))
- log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
-
- updateGui();
- connector.tryToGetPumpStatusAgain();
-
- if (result.success) while (true) {
- try {
- Thread.sleep(500);
- final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
- ActiveBolusesMessage activeBolusesMessage = fetchSingleMessage(new ActiveBolusesMessage(), ActiveBolusesMessage.class);
- ActiveBolus activeBolus = null;
- if (activeBolusesMessage.getBolus1() != null && activeBolusesMessage.getBolus1().getBolusID() == bolusingEvent.bolusId)
- activeBolus = activeBolusesMessage.getBolus1();
- else if (activeBolusesMessage.getBolus2() != null && activeBolusesMessage.getBolus2().getBolusID() == bolusingEvent.bolusId)
- activeBolus = activeBolusesMessage.getBolus2();
- else if (activeBolusesMessage.getBolus3() != null && activeBolusesMessage.getBolus3().getBolusID() == bolusingEvent.bolusId)
- activeBolus = activeBolusesMessage.getBolus3();
- if (activeBolus == null) break;
- else {
- int percentBefore = bolusingEvent.percent;
- bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getLeftoverAmount()));
- bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), activeBolus.getInitialAmount() - activeBolus.getLeftoverAmount());
- if (percentBefore != bolusingEvent.percent) MainApp.bus().post(bolusingEvent);
- }
- } catch (Exception e) {
- break;
- }
- }
-
- connector.requestHistorySync(2000);
- return result;
- }
-
- @Override
- public void stopBolusDelivering() {
- CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
- cancelBolusMessage.setMessagePriority(MessagePriority.HIGHEST);
- cancelBolusMessage.setBolusId(EventOverviewBolusProgress.getInstance().bolusId);
- try {
- fetchSingleMessage(cancelBolusMessage);
- } catch (Exception e) {
- }
- }
-
- // Temporary Basals
-
- @Override
- public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
- if (L.isEnabled(L.PUMP))
- log.debug("Set TBR absolute: " + absoluteRate);
- if (getBaseBasalRate() == 0) {
- if (L.isEnabled(L.PUMP))
- log.debug("Base basal rate appears to be zero!");
- return pumpEnactFailure();
- }
- double percent = 100D / getBaseBasalRate() * absoluteRate;
- if (L.isEnabled(L.PUMP))
- log.debug("Calculated requested rate: " + absoluteRate + " base rate: " + getBaseBasalRate() + " percentage: " + percent + "%");
- try {
- if (percent > 250) {
- if (L.isEnabled(L.PUMP))
- log.debug("Calculated rate is above 250%, switching to emulation using extended boluses");
- cancelTempBasal(true);
- if (!setExtendedBolus((absoluteRate - getBaseBasalRate()) / 60D * ((double) durationInMinutes), durationInMinutes).success) {
- //Fallback to TBR if setting an extended bolus didn't work
- if (L.isEnabled(L.PUMP))
- log.debug("Setting an extended bolus didn't work, falling back to normal TBR");
- return setTempBasalPercent((int) percent, durationInMinutes, profile, true);
- }
- return new PumpEnactResult().success(true).enacted(true).absolute(absoluteRate).duration(durationInMinutes);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Calculated rate is below or equal to 250%, using normal TBRs");
- cancelExtendedBolus();
- return setTempBasalPercent((int) percent, durationInMinutes, profile, true);
- }
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- }
-
-
- @Override
- public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
- if (L.isEnabled(L.PUMP))
- log.debug("Set TBR %");
-
- percent = (int) Math.round(((double) percent) / 10d) * 10;
- if (percent == 100) {
- // This would cause a cancel if a tbr is in progress so treat as a cancel
- return cancelTempBasal(false);
- } else if (percent > 250) percent = 250;
-
- try {
- fetchTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), percent, durationInMinutes));
- final TemporaryBasal tempBasal = new TemporaryBasal()
- .date(System.currentTimeMillis())
- .percent(percent)
- .duration(durationInMinutes)
- .source(Source.USER);
- TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
- updateGui();
- if (L.isEnabled(L.PUMP))
- log.debug("Set temp basal " + percent + "% for " + durationInMinutes + "m");
- connector.requestHistorySync(5000);
- connector.tryToGetPumpStatusAgain();
- return new PumpEnactResult().success(true).enacted(true).percent(percent);
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- }
-
-
- @Override
- public PumpEnactResult cancelTempBasal(boolean enforceNew) {
- if (L.isEnabled(L.PUMP))
- log.debug("Cancel TBR called");
-
- try {
- cancelExtendedBolus();
- SystemClock.sleep(1100); // to be sure db records are at least 1 sec off (for NS)
- realTBRCancel();
- SystemClock.sleep(1100); // to be sure db records are at least 1 sec off (for NS)
- updateGui();
- connector.requestHistorySync(5000);
- connector.tryToGetPumpStatusAgain();
- return new PumpEnactResult().success(true).enacted(true).isTempCancel(true);
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- }
-
- private void realTBRCancel() throws Exception {
- if (fetchTaskRunner(new CancelTBRSilentlyTaskRunner(connector.getServiceConnector()), Boolean.class) && TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
- TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
- TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
- }
- }
-
-
- // Extended Boluses
-
- @Override
- public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
- if (L.isEnabled(L.PUMP))
- log.debug("Set Extended bolus " + insulin + " " + durationInMinutes);
- try {
- ExtendedBolusMessage extendedBolusMessage = new ExtendedBolusMessage();
- extendedBolusMessage.setAmount(insulin);
- extendedBolusMessage.setDuration(durationInMinutes);
- BolusMessage bolusMessage = fetchSingleMessage(extendedBolusMessage, BolusMessage.class);
- final ExtendedBolus extendedBolus = new ExtendedBolus()
- .date(System.currentTimeMillis())
- .insulin(insulin)
- .durationInMinutes(durationInMinutes)
- .source(Source.USER)
- .pumpId(getRecordUniqueID(bolusMessage.getBolusId()));
- TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
- updateGui();
- connector.requestHistorySync(30000);
- connector.tryToGetPumpStatusAgain();
- return new PumpEnactResult().success(true).enacted(true).duration(durationInMinutes).bolusDelivered(insulin);
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- }
-
- @Override
- public PumpEnactResult cancelExtendedBolus() {
- if (L.isEnabled(L.PUMP))
- log.debug("Cancel Extended bolus called");
-
- Integer bolusId = null;
-
- try {
- bolusId = fetchTaskRunner(new CancelBolusSilentlyTaskRunner(connector.getServiceConnector(), ActiveBolusType.EXTENDED), Integer.class);
- if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
- ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis());
- exStop.source = Source.USER;
- TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(exStop);
- }
- if (bolusId != null) connector.requestHistorySync(5000);
- connector.tryToGetPumpStatusAgain();
- updateGui();
- return new PumpEnactResult().success(true).enacted(bolusId != null);
- } catch (Exception e) {
- return pumpEnactFailure();
- }
- }
-
-
- private int deliverBolus(double bolusValue) throws Exception {
- if (L.isEnabled(L.PUMP))
- log.debug("DeliverBolus: " + bolusValue);
-
- final StandardBolusMessage message = new StandardBolusMessage();
- message.setAmount(bolusValue);
-
- return fetchSingleMessage(message, BolusMessage.class).getBolusId();
- }
-
- @Override
- public JSONObject getJSONStatus(Profile profile, String profileName) {
- long now = System.currentTimeMillis();
- if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) {
- if (L.isEnabled(L.PUMP))
- log.debug("getJSONStatus not returning as data likely stale");
- return null;
- }
-
- final JSONObject pump = new JSONObject();
- final JSONObject battery = new JSONObject();
- final JSONObject status = new JSONObject();
- final JSONObject extended = new JSONObject();
- try {
- battery.put("percent", batteryPercent);
- status.put("status", isSuspended() ? "suspended" : "normal");
- status.put("timestamp", DateUtil.toISOString(connector.getLastContactTime()));
- extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
- try {
- extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName());
- } catch (Exception e) {
- }
- TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now);
- if (tb != null) {
- extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
- extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
- extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
- }
- ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now);
- if (eb != null) {
- extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
- extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
- extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
- }
- extended.put("BaseBasalRate", getBaseBasalRate());
- status.put("timestamp", DateUtil.toISOString(now));
-
- pump.put("battery", battery);
- pump.put("status", status);
- pump.put("extended", extended);
- pump.put("reservoir", reservoirInUnits);
- pump.put("clock", DateUtil.toISOString(now));
- } catch (JSONException e) {
- log.error("Unhandled exception", e);
- }
- return pump;
- }
-
- @Override
- public String deviceID() {
- return "InsightPump";
- }
-
- @Override
- public PumpDescription getPumpDescription() {
- return pumpDescription;
- }
-
- @Override
- public String shortStatus(boolean veryShort) {
- String msg = gs(R.string.insightpump_shortname) + " Batt: " + batteryPercent + " Reserv: " + reservoirInUnits + " Basal: " + basalRate;
- if (LiveHistory.getStatus().length() > 0) {
- msg += LiveHistory.getStatus();
- }
- return msg;
- }
-
- private void processStatusResult() {
- if (statusResult != null) {
- batteryPercent = statusResult.battery;
- reservoirInUnits = (int) statusResult.cartridge;
- basalRate = statusResult.baseBasalRate;
- profileBlocks = statusResult.basalProfile;
- initialized = true; // basic communication test
- }
- }
-
- private String gs(int id) {
- return MainApp.gs(id);
- }
-
- private boolean isPumpRunning() {
- if (statusResult == null) return true; // assume running if we have no information
- return statusResult.pumpStatus == PumpStatus.STARTED;
- }
-
- List getStatusItems(boolean refresh) {
- final List l = new ArrayList<>();
-
- // Todo last contact time
-
- l.add(new StatusItem(gs(R.string.status_no_colon), connector.getLastStatusMessage()));
- l.add(new StatusItem(gs(R.string.changed), connector.getNiceLastStatusTime()));
-
- boolean pumpRunning;
- // also check time since received
- if (statusResult != null) {
-
- pumpRunning = isPumpRunning();
- if (pumpRunning) {
- l.add(new StatusItem(gs(R.string.pump_basebasalrate_label), getBaseBasalRateString() + "U"));
- } else {
- l.add(new StatusItem(gs(R.string.combo_warning), gs(R.string.pump_stopped_uppercase), StatusItem.Highlight.CRITICAL));
- }
- }
-
- final long offset_ms = Helpers.msSince(statusResultTime);
- final long offset_minutes = offset_ms / 60000;
-
- if (statusResult != null) {
- l.add(new StatusItem(gs(R.string.status_updated), Helpers.niceTimeScalar(Helpers.msSince(statusResultTime)) + " " + gs(R.string.ago)));
- l.add(new StatusItem(gs(R.string.pump_battery_label), batteryPercent + "%", batteryPercent < 100 ?
- (batteryPercent < 90 ?
- (batteryPercent < 70 ?
- (StatusItem.Highlight.BAD) : StatusItem.Highlight.NOTICE) : StatusItem.Highlight.NORMAL) : StatusItem.Highlight.GOOD));
- l.add(new StatusItem(gs(R.string.pump_reservoir_label), reservoirInUnits + "U"));
- try {
- if (statusResult.tbrAmount != 100) {
- l.add(new StatusItem(gs(R.string.insight_active_tbr), statusResult.tbrAmount + "% " + gs(R.string.with) + " "
- + Helpers.qs(statusResult.tbrLeftoverDuration - offset_minutes, 0)
- + " " + gs(R.string.insight_min_left), StatusItem.Highlight.NOTICE));
- }
- } catch (NullPointerException e) {
- // currentTBRMessage may be null
- }
-
- }
-
- if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
- try {
- l.add(new StatusItem(gs(R.string.pump_tempbasal_label), TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()));
- } catch (NullPointerException e) {
- //
- }
- }
-
- if (statusResult != null) {
- try {
- statusActiveBolus(statusResult.activeBolus1, offset_minutes, l);
- statusActiveBolus(statusResult.activeBolus2, offset_minutes, l);
- statusActiveBolus(statusResult.activeBolus3, offset_minutes, l);
- } catch (NullPointerException e) {
- // getActiveBolusesMessage() may be null
- }
- }
-
- if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
- try {
-
- l.add(new StatusItem(gs(R.string.virtualpump_extendedbolus_label), TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()).toString()));
- } catch (NullPointerException e) {
- //
- }
- }
-
- l.add(new StatusItem(gs(R.string.log_book), HistoryReceiver.getStatusString()));
-
- if (LiveHistory.getStatus().length() > 0) {
- l.add(new StatusItem(gs(R.string.insight_last_completed_action), LiveHistory.getStatus()));
- }
-
- final String keep_alive_status = Connector.getKeepAliveString();
- if (keep_alive_status != null) {
- l.add(new StatusItem(gs(R.string.insight_keep_alive_status), keep_alive_status));
- }
-
- final List status_statistics = connector.getStatusStatistics();
- if (status_statistics.size() > 0) {
- l.addAll(status_statistics);
- }
-
- if (Helpers.ratelimit("insight-status-ui-refresh", 10)) {
- connector.tryToGetPumpStatusAgain();
- }
- connector.requestHistorySync();
- if (refresh) scheduleGUIUpdate();
-
- return l;
- }
-
- private synchronized void scheduleGUIUpdate() {
- if (!update_pending && connector.uiFresh()) {
- update_pending = true;
- Helpers.runOnUiThreadDelayed(new Runnable() {
- @Override
- public void run() {
- updateGui();
- }
- }, 1000);
- }
- }
-
- private void statusActiveBolus(ActiveBolus activeBolus, long offset_mins, List l) {
- if (activeBolus == null) return;
- switch (activeBolus.getBolusType()) {
-
- case STANDARD:
- l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U", StatusItem.Highlight.NOTICE));
- break;
- case EXTENDED:
- l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U " + gs(R.string.insight_total_with) + " "
- + activeBolus.getLeftoverAmount() + "U " + gs(R.string.insight_remaining_over) + " " + (activeBolus.getDuration() - offset_mins) + " " + gs(R.string.insight_min), StatusItem.Highlight.NOTICE));
- break;
- case MULTIWAVE:
- l.add(new StatusItem(activeBolus.getBolusType() + " " + gs(R.string.bolus), activeBolus.getInitialAmount() + "U " + gs(R.string.insight_upfront_with) + " "
- + activeBolus.getLeftoverAmount() + "U " + gs(R.string.insight_remaining_over) + " " + (activeBolus.getDuration() - offset_mins) + " " + gs(R.string.insight_min), StatusItem.Highlight.NOTICE));
-
- break;
- default:
- log.error("ERROR: unknown bolus type! " + activeBolus.getBolusType());
- }
- }
-
- private void fetchTaskRunner(TaskRunner taskRunner) throws Exception {
- fetchTaskRunner(taskRunner, Object.class);
- }
-
- private void fetchSingleMessage(AppLayerMessage message) throws Exception {
- fetchSingleMessage(message, AppLayerMessage.class);
- }
-
- private T fetchTaskRunner(TaskRunner taskRunner, Class resultType) throws Exception {
- try {
- T result = (T) taskRunner.fetchAndWaitUsingLatch(BUSY_WAIT_TIME);
- lastDataTime = System.currentTimeMillis();
- return result;
- } catch (Exception e) {
- log.error("Error while fetching " + taskRunner.getClass().getSimpleName() + ": " + e.getClass().getSimpleName());
- throw e;
- }
- }
-
- private T fetchSingleMessage(AppLayerMessage message, Class resultType) throws Exception {
- try {
- T result = (T) new SingleMessageTaskRunner(connector.getServiceConnector(), message).fetchAndWaitUsingLatch(BUSY_WAIT_TIME);
- lastDataTime = System.currentTimeMillis();
- return result;
- } catch (Exception e) {
- log.error("Error while fetching " + message.getClass().getSimpleName() + ": " + e.getClass().getSimpleName());
- throw e;
- }
- }
-
-
- private PumpEnactResult pumpEnactFailure() {
- return new PumpEnactResult().success(false).enacted(false);
- }
-
- // Constraints
-
- @Override
- public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) {
- percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this);
- percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this);
-
- return percentRate;
- }
-
- @Override
- public Constraint applyBolusConstraints(Constraint insulin) {
- if (statusResult != null) {
- insulin.setIfSmaller(statusResult.maximumBolusAmount, String.format(MainApp.gs(R.string.limitingbolus), statusResult.maximumBolusAmount, MainApp.gs(R.string.pumplimit)), this);
- if (insulin.value() < statusResult.minimumBolusAmount) {
-
- //TODO: Add function to Constraints or use different approach
- // This only works if the interface of the InsightPlugin is called last.
- // If not, another contraint could theoretically set the value between 0 and minimumBolusAmount
-
- insulin.set(0d, String.format(MainApp.gs(R.string.limitingbolus), statusResult.minimumBolusAmount, MainApp.gs(R.string.pumplimit)), this);
- }
- }
- return insulin;
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java
deleted file mode 100644
index 7b3108602e..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import sugar.free.sightparser.applayer.descriptors.ActiveBolusType;
-import sugar.free.sightparser.applayer.descriptors.MessagePriority;
-import sugar.free.sightparser.applayer.descriptors.alerts.Warning38BolusCancelled;
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-// by Tebbe Ubben
-
-public class CancelBolusSilentlyTaskRunner extends TaskRunner {
-
- private ActiveBolusType bolusType;
- private long cancelledAt;
- private int bolusId;
-
- public CancelBolusSilentlyTaskRunner(SightServiceConnector serviceConnector, ActiveBolusType bolusType) {
- super(serviceConnector);
- this.bolusType = bolusType;
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) return new ActiveBolusesMessage();
- else if (message instanceof ActiveBolusesMessage) {
- ActiveBolusesMessage bolusesMessage = (ActiveBolusesMessage) message;
- CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
- if (bolusesMessage.getBolus1().getBolusType() == bolusType)
- bolusId = bolusesMessage.getBolus1().getBolusID();
- else if (bolusesMessage.getBolus2().getBolusType() == bolusType)
- bolusId = bolusesMessage.getBolus2().getBolusID();
- else if (bolusesMessage.getBolus3().getBolusType() == bolusType)
- bolusId = bolusesMessage.getBolus3().getBolusID();
- else finish(null);
- cancelBolusMessage.setBolusId(bolusId);
- return cancelBolusMessage;
- } else if (message instanceof CancelBolusMessage) {
- cancelledAt = System.currentTimeMillis();
- ActiveAlertMessage activeAlertMessage = new ActiveAlertMessage();
- activeAlertMessage.setMessagePriority(MessagePriority.HIGHER);
- return activeAlertMessage;
- } else if (message instanceof ActiveAlertMessage) {
- ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message;
- if (activeAlertMessage.getAlert() == null) {
- if (System.currentTimeMillis() - cancelledAt >= 10000) finish(bolusId);
- else {
- ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage();
- activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER);
- return activeAlertMessage2;
- }
- } else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(bolusId);
- else {
- DismissAlertMessage dismissAlertMessage = new DismissAlertMessage();
- dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID());
- dismissAlertMessage.setMessagePriority(MessagePriority.HIGHER);
- return dismissAlertMessage;
- }
- } else if (message instanceof DismissAlertMessage) finish(bolusId);
- return null;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java
deleted file mode 100644
index 9a3068aef9..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import sugar.free.sightparser.applayer.descriptors.MessagePriority;
-import sugar.free.sightparser.applayer.descriptors.alerts.Warning36TBRCancelled;
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage;
-import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-public class CancelTBRSilentlyTaskRunner extends TaskRunner {
-
- private long cancelledAt;
-
- public CancelTBRSilentlyTaskRunner(SightServiceConnector serviceConnector) {
- super(serviceConnector);
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) return new CurrentTBRMessage();
- else if (message instanceof CurrentTBRMessage) {
- if (((CurrentTBRMessage) message).getPercentage() == 100) finish(false);
- else return new CancelTBRMessage();
- } else if (message instanceof CancelTBRMessage) {
- ActiveAlertMessage activeAlertMessage = new ActiveAlertMessage();
- activeAlertMessage.setMessagePriority(MessagePriority.HIGHER);
- return activeAlertMessage;
- } else if (message instanceof ActiveAlertMessage) {
- ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message;
- if (activeAlertMessage.getAlert() == null) {
- if (System.currentTimeMillis() - cancelledAt >= 10000) finish(true);
- else {
- ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage();
- activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER);
- return activeAlertMessage2;
- }
- } else if (!(activeAlertMessage.getAlert() instanceof Warning36TBRCancelled)) finish(true);
- else {
- DismissAlertMessage dismissAlertMessage = new DismissAlertMessage();
- dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID());
- dismissAlertMessage.setMessagePriority(MessagePriority.HIGHER);
- return dismissAlertMessage;
- }
- } else if (message instanceof DismissAlertMessage) finish(true);
- return null;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java
deleted file mode 100644
index 4a90cd92ca..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/Connector.java
+++ /dev/null
@@ -1,574 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import android.content.Intent;
-import android.os.PowerManager;
-
-import com.squareup.otto.Subscribe;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Formatter;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.events.EventFeatureRunning;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightUpdateGui;
-import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver;
-import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
-import info.nightscout.utils.SP;
-import sugar.free.sightparser.handling.ServiceConnectionCallback;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.StatusCallback;
-import sugar.free.sightparser.pipeline.Status;
-
-import static sugar.free.sightparser.handling.HistoryBroadcast.ACTION_START_RESYNC;
-import static sugar.free.sightparser.handling.HistoryBroadcast.ACTION_START_SYNC;
-import static sugar.free.sightparser.handling.SightService.COMPATIBILITY_VERSION;
-
-/**
- * Created by jamorham on 23/01/2018.
- *
- * Connects to SightRemote app service using SightParser library
- *
- * SightRemote and SightParser created by Tebbe Ubben
- *
- * Original proof of concept SightProxy by jamorham
- */
-
-public class Connector {
- private static Logger log = LoggerFactory.getLogger(L.PUMP);
-
- // TODO connection statistics
-
- private static final String TAG = "InsightConnector";
- private static final String COMPANION_APP_PACKAGE = "sugar.free.sightremote";
- private final static long FRESH_MS = 70000;
- private static final Map statistics = new HashMap<>();
- private static volatile Connector instance;
- private static volatile HistoryReceiver historyReceiver;
- private static volatile long stayConnectedTill = -1;
- private static volatile long stayConnectedTime = 0;
- private static volatile boolean disconnect_thread_running = false;
- private volatile SightServiceConnector serviceConnector;
- private volatile Status lastStatus = null;
- private String compatabilityMessage = null;
- private volatile long lastStatusTime = -1;
- private volatile long lastContactTime = -1;
- private boolean companionAppInstalled = false;
- private int serviceReconnects = 0;
- private StatusCallback statusCallback = new StatusCallback() {
- @Override
- public synchronized void onStatusChange(Status status, long statusTime, long waitTime) {
-
- if ((status != lastStatus) || (Helpers.msSince(lastStatusTime) > 2000)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Status change: " + status);
-
- updateStatusStatistics(lastStatus, lastStatusTime);
- lastStatus = status;
- lastStatusTime = Helpers.tsl();
-
- if (status == Status.CONNECTED) {
- lastContactTime = lastStatusTime;
- extendKeepAliveIfActive();
- }
-
- MainApp.bus().post(new EventInsightUpdateGui());
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Same status as before: " + status);
- }
- }
-
- };
- private ServiceConnectionCallback connectionCallback = new ServiceConnectionCallback() {
-
- @Override
- public synchronized void onServiceConnected() {
- if (L.isEnabled(L.PUMP))
- log.debug("On service connected");
- try {
- final String remoteVersion = serviceConnector.getRemoteVersion();
- if (remoteVersion.equals(COMPATIBILITY_VERSION)) {
- serviceConnector.connect();
- } else {
- log.error("PROTOCOL VERSION MISMATCH! local: " + COMPATIBILITY_VERSION + " remote: " + remoteVersion);
- statusCallback.onStatusChange(Status.INCOMPATIBLE, 0, 0);
- compatabilityMessage = MainApp.gs(R.string.insight_incompatible_compantion_app_we_need_version) + " " + getLocalVersion();
- serviceConnector.disconnectFromService();
-
- }
- } catch (NullPointerException e) {
- log.error("ERROR: null pointer when trying to connect to pump");
- }
- statusCallback.onStatusChange(safeGetStatus(), 0, 0);
- }
-
- @Override
- public synchronized void onServiceDisconnected() {
- if (L.isEnabled(L.PUMP))
- log.debug("Disconnected from service");
- if (Helpers.ratelimit("insight-automatic-reconnect", 30)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Scheduling automatic service reconnection");
- Helpers.runOnUiThreadDelayed(new Runnable() {
- @Override
- public void run() {
- init();
- }
- }, 20000);
- }
- }
- };
-
- private Connector() {
- initializeHistoryReceiver();
- MainApp.bus().register(this);
- }
-
- public static Connector get() {
- if (instance == null) {
- init_instance();
- }
- return instance;
- }
-
- private synchronized static void init_instance() {
- if (instance == null) {
- instance = new Connector();
- }
- }
-
- private static boolean isCompanionAppInstalled() {
- return Helpers.checkPackageExists(MainApp.instance(), TAG, COMPANION_APP_PACKAGE);
- }
-
- public static void connectToPump() {
- connectToPump(0);
- }
-
- public synchronized static void connectToPump(long keep_alive) {
- if (L.isEnabled(L.PUMP))
- log.debug("Attempting to connect to pump.");
- if (keep_alive > 0 && Helpers.tsl() + keep_alive > stayConnectedTill) {
- stayConnectedTime = keep_alive;
- stayConnectedTill = Helpers.tsl() + keep_alive;
- if (L.isEnabled(L.PUMP))
- log.debug("Staying connected till: " + Helpers.dateTimeText(stayConnectedTill));
- delayedDisconnectionThread();
- }
- get().getServiceConnector().connect();
- }
-
- public static void disconnectFromPump() {
- if (Helpers.tsl() >= stayConnectedTill) {
- if (L.isEnabled(L.PUMP))
- log.debug("Requesting real pump disconnect");
- get().getServiceConnector().disconnect();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Cannot disconnect as due to keep alive till: " + Helpers.dateTimeText(stayConnectedTill));
- // TODO set a disconnection timer?
- }
- }
-
- static String getLocalVersion() {
- return COMPATIBILITY_VERSION;
- }
-
- private static String statusToString(Status status) {
- switch (status) {
-
- case EXCHANGING_KEYS:
- return MainApp.gs(R.string.connecting).toUpperCase();
- case WAITING_FOR_CODE_CONFIRMATION:
- return MainApp.gs(R.string.insight_waiting_for_code).toUpperCase();
- case CODE_REJECTED:
- return MainApp.gs(R.string.insight_code_rejected).toUpperCase();
- case APP_BINDING:
- return MainApp.gs(R.string.insight_app_binding).toUpperCase();
- case CONNECTING:
- return MainApp.gs(R.string.connecting).toUpperCase();
- case CONNECTED:
- return MainApp.gs(R.string.connected).toUpperCase();
- case DISCONNECTED:
- return MainApp.gs(R.string.disconnected).toUpperCase();
- case NOT_AUTHORIZED:
- return MainApp.gs(R.string.insight_not_authorized).toUpperCase();
- case INCOMPATIBLE:
- return MainApp.gs(R.string.insight_incompatible).toUpperCase();
-
- default:
- return status.toString();
- }
- }
-
- private static synchronized void extendKeepAliveIfActive() {
- if (keepAliveActive()) {
- if (Helpers.ratelimit("extend-insight-keepalive", 10)) {
- stayConnectedTill = Helpers.tsl() + stayConnectedTime;
- if (L.isEnabled(L.PUMP))
- log.debug("Keep-alive extended until: " + Helpers.dateTimeText(stayConnectedTill));
- }
- }
- }
-
- private static boolean keepAliveActive() {
- return Helpers.tsl() <= stayConnectedTill;
- }
-
- public static String getKeepAliveString() {
- if (keepAliveActive()) {
- return MainApp.gs(R.string.insight_keepalive_format_string,
- stayConnectedTime / 1000, Helpers.hourMinuteSecondString(stayConnectedTill));
-
- } else {
- return null;
- }
- }
-
- private static synchronized void delayedDisconnectionThread() {
- if (keepAliveActive()) {
- if (!disconnect_thread_running) {
- disconnect_thread_running = true;
- new Thread(new Runnable() {
- @Override
- public void run() {
- final PowerManager.WakeLock wl = Helpers.getWakeLock("insight-disconnection-timer", 600000);
- try {
- while (disconnect_thread_running && keepAliveActive()) {
- if (Helpers.ratelimit("insight-expiry-notice", 5)) {
- if (L.isEnabled(L.PUMP))
- log.debug("Staying connected thread expires: " + Helpers.dateTimeText(stayConnectedTill));
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //
- }
- }
-
- if (disconnect_thread_running) {
- if (L.isEnabled(L.PUMP))
- log.debug("Sending the real delayed disconnect");
- get().getServiceConnector().disconnect();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Disconnect thread already terminating");
- }
- } finally {
- Helpers.releaseWakeLock(wl);
- disconnect_thread_running = false;
- }
- }
- }).start();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Disconnect thread already running");
- }
- }
- }
-
- private static long percentage(long t, long total) {
- return (long) (Helpers.roundDouble(((double) t * 100) / total, 0));
- }
-
- public synchronized void shutdown() {
- if (instance != null) {
- if (L.isEnabled(L.PUMP))
- log.debug("Attempting to shut down connector");
- try {
- disconnect_thread_running = false;
- try {
- instance.serviceConnector.setConnectionCallback(null);
- } catch (Exception e) {
- //
- }
- try {
- instance.serviceConnector.removeStatusCallback(statusCallback);
- } catch (Exception e) {
- //
- }
- try {
- instance.serviceConnector.disconnect();
- } catch (Exception e) {
- log.error("Exception disconnecting: " + e);
- }
- try {
- instance.serviceConnector.disconnectFromService();
- } catch (Exception e) {
- log.error("Excpetion disconnecting service: " + e);
- }
- instance.serviceConnector = null;
- instance = null;
- } catch (Exception e) {
- log.error("Exception shutting down: " + e);
- }
- }
- }
-
- @SuppressWarnings("AccessStaticViaInstance")
- private synchronized void initializeHistoryReceiver() {
- if (historyReceiver == null) {
- historyReceiver = new HistoryReceiver();
- }
- historyReceiver.registerHistoryReceiver();
- }
-
- public synchronized void init() {
- if (L.isEnabled(L.PUMP))
- log.debug("Connector::init()");
- if (serviceConnector == null) {
- companionAppInstalled = isCompanionAppInstalled();
- if (companionAppInstalled) {
- serviceConnector = new SightServiceConnector(MainApp.instance());
- serviceConnector.removeStatusCallback(statusCallback);
- serviceConnector.addStatusCallback(statusCallback);
- serviceConnector.setConnectionCallback(connectionCallback);
- serviceConnector.connectToService();
- if (L.isEnabled(L.PUMP))
- log.debug("Trying to connect");
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Not trying init due to missing companion app");
- }
- } else {
- if (!serviceConnector.isConnectedToService()) {
- if (serviceReconnects > 0) {
- serviceConnector = null;
- init();
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Trying to reconnect to service (" + serviceReconnects + ")");
- serviceConnector.connectToService();
- serviceReconnects++;
- }
- } else {
- serviceReconnects = 0; // everything ok
- }
- }
- }
-
- public SightServiceConnector getServiceConnector() {
- init();
- return serviceConnector;
- }
-
- public String getCurrent() {
- init();
- return safeGetStatus().toString();
- }
-
- public Status safeGetStatus() {
- try {
- if (isConnected()) return serviceConnector.getStatus();
- return Status.DISCONNECTED;
- } catch (IllegalArgumentException e) {
- return Status.INCOMPATIBLE;
- }
- }
-
- public Status getLastStatus() {
- return lastStatus;
- }
-
- public boolean isConnected() {
- return serviceConnector != null && serviceConnector.isConnectedToService();
- }
-
- public boolean isPumpConnected() {
- return isConnected() && getLastStatus() == Status.CONNECTED;
- }
-
- public boolean isPumpConnecting() {
- return isConnected() && getLastStatus() == Status.CONNECTING;
- }
-
- public long getLastContactTime() {
- return lastContactTime;
- }
-
- public String getLastStatusMessage() {
-
- if (!companionAppInstalled) {
- return MainApp.gs(R.string.insight_companion_app_not_installed);
- }
-
- if (!isConnected()) {
- if (L.isEnabled(L.PUMP))
- log.debug("Not connected to companion");
- if (Helpers.ratelimit("insight-app-not-connected", 5)) {
- init();
- }
-
- if ((lastStatus == null) || (lastStatus != Status.INCOMPATIBLE)) {
- if (compatabilityMessage != null) {
- // if disconnected but previous state was incompatible
- return compatabilityMessage;
- } else {
- return MainApp.gs(R.string.insight_not_connected_to_companion_app);
- }
- }
- }
-
- if (lastStatus == null) {
- return MainApp.gs(R.string.unknown);
- }
-
- switch (lastStatus) {
- case CONNECTED:
- if (Helpers.msSince(lastStatusTime) > (60 * 10 * 1000)) {
- tryToGetPumpStatusAgain();
- }
- break;
- case INCOMPATIBLE:
- return statusToString(lastStatus) + " " + MainApp.gs(R.string.insight_needs) + " " + getLocalVersion();
- }
- return statusToString(lastStatus);
- }
-
- public String getNiceLastStatusTime() {
- if (lastStatusTime < 1) {
- return MainApp.gs(R.string.insight_startup_uppercase);
- } else {
- return Helpers.niceTimeScalar(Helpers.msSince(lastStatusTime)) + " " + MainApp.gs(R.string.ago);
- }
- }
-
- public boolean uiFresh() {
- // todo check other changes
-
- if (Helpers.msSince(lastStatusTime) < FRESH_MS) {
- return true;
- }
- if (Helpers.msSince(LiveHistory.getStatusTime()) < FRESH_MS) {
- return true;
- }
- return false;
- }
-
- @SuppressWarnings("AccessStaticViaInstance")
- public void tryToGetPumpStatusAgain() {
- if (Helpers.ratelimit("insight-retry-status-request", 5)) {
- try {
- ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Insight. Status missing", null);
- } catch (NullPointerException e) {
- //
- }
- }
- }
-
- public void requestHistorySync() {
- requestHistorySync(0);
- }
-
- public void requestHistoryReSync() {
- requestHistoryReSync(0);
- }
-
- public void requestHistorySync(long delay) {
- if (Helpers.ratelimit("insight-history-sync-request", 10)) {
- final Intent intent = new Intent(ACTION_START_SYNC);
- sendBroadcastToCompanion(intent, delay);
- }
- }
-
- public void requestHistoryReSync(long delay) {
- if (Helpers.ratelimit("insight-history-resync-request", 300)) {
- final Intent intent = new Intent(ACTION_START_RESYNC);
- sendBroadcastToCompanion(intent, delay);
- }
- }
-
- private void sendBroadcastToCompanion(final Intent intent, final long delay) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- final PowerManager.WakeLock wl = Helpers.getWakeLock("insight-companion-delay", 60000);
- intent.setPackage(COMPANION_APP_PACKAGE);
- intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
- try {
- if (delay > 0) {
-
- Thread.sleep(delay);
- }
- } catch (InterruptedException e) {
- //
- } finally {
- Helpers.releaseWakeLock(wl);
- }
- MainApp.instance().sendBroadcast(intent);
- }
- }).start();
- }
-
- public boolean lastStatusRecent() {
- return true; // TODO evaluate whether current
- }
-
- private void updateStatusStatistics(Status last, long since) {
- if ((last != null) && (since > 0)) {
- Long total = statistics.get(last);
- if (total == null) total = 0L;
- statistics.put(last, total + Helpers.msSince(since));
- if (L.isEnabled(L.PUMP))
- log.debug("Updated statistics for: " + last + " total: " + Helpers.niceTimeScalar(statistics.get(last)));
- // TODO persist data
- }
- }
-
- public List getStatusStatistics() {
- final List l = new ArrayList<>();
- long total = 0;
- for (Map.Entry entry : statistics.entrySet()) {
- total += getEntryTime(entry);
- }
- for (Map.Entry entry : statistics.entrySet()) {
- if ((long) entry.getValue() > 1000) {
- l.add(new StatusItem(MainApp.gs(R.string.statistics) + " " + Helpers.capitalize(entry.getKey().toString()),
- new Formatter().format("%4s %12s",
- percentage(getEntryTime(entry), total) + "%",
- Helpers.niceTimeScalar(getEntryTime(entry))).toString()));
- }
- }
- return l;
- }
-
- private long getEntryTime(Map.Entry entry) {
- return (long) entry.getValue() + (entry.getKey().equals(lastStatus) ? Helpers.msSince(lastStatusTime) : 0);
- }
-
- @Subscribe
- public void onStatusEvent(final EventFeatureRunning ev) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- if (isConnected()) {
- if (SP.getBoolean("insight_preemptive_connect", true)) {
- switch (ev.getFeature()) {
- case WIZARD:
- if (L.isEnabled(L.PUMP))
- log.debug("Wizard feature detected, preconnecting to pump");
- connectToPump(120 * 1000);
- break;
- case MAIN:
- if (L.isEnabled(L.PUMP))
- log.debug("Main feature detected, preconnecting to pump");
- connectToPump(30 * 1000);
- break;
- }
- }
- }
- }
- }).start();
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java
deleted file mode 100644
index f18bb0d487..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.ChangeTBRMessage;
-import sugar.free.sightparser.applayer.messages.remote_control.SetTBRMessage;
-import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-// from Tebbe - note this uses 1 minute duration to silently cancel existing TBR
-
-public class SetTBRTaskRunner extends TaskRunner {
-
- private int amount;
- private int duration;
-
- public SetTBRTaskRunner(SightServiceConnector serviceConnector, int amount, int duration) {
- super(serviceConnector);
- this.amount = amount;
- this.duration = duration;
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) return new CurrentTBRMessage();
- else if (message instanceof CurrentTBRMessage) {
- if (((CurrentTBRMessage) message).getPercentage() == 100) {
- SetTBRMessage setTBRMessage = new SetTBRMessage();
- setTBRMessage.setDuration(duration);
- setTBRMessage.setAmount(amount);
- return setTBRMessage;
- } else {
- ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
- changeTBRMessage.setDuration(duration);
- changeTBRMessage.setAmount(amount);
- return changeTBRMessage;
- }
- } else if (message instanceof SetTBRMessage) finish(amount);
- return null;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java
deleted file mode 100644
index 1df56be468..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/StatusTaskRunner.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import java.util.List;
-
-import sugar.free.sightparser.applayer.descriptors.ActiveBolus;
-import sugar.free.sightparser.applayer.descriptors.PumpStatus;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ActiveProfileBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile1Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile2Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile3Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile4Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile5Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.FactoryMinBRAmountBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.FactoryMinBolusAmountBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.MaxBRAmountBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.MaxBolusAmountBlock;
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.configuration.ReadConfigurationBlockMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage;
-import sugar.free.sightparser.applayer.messages.status.BatteryAmountMessage;
-import sugar.free.sightparser.applayer.messages.status.CartridgeAmountMessage;
-import sugar.free.sightparser.applayer.messages.status.CurrentBasalMessage;
-import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage;
-import sugar.free.sightparser.applayer.messages.status.PumpStatusMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-/**
- * Created by Tebbe Ubben on 12.03.2018.
- */
-
-public class StatusTaskRunner extends TaskRunner {
-
- private Result result = new Result();
-
- public StatusTaskRunner(SightServiceConnector serviceConnector) {
- super(serviceConnector);
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) return new PumpStatusMessage();
- else if (message instanceof PumpStatusMessage) {
- result.pumpStatus = ((PumpStatusMessage) message).getPumpStatus();
- if (result.pumpStatus == PumpStatus.STOPPED) return new BatteryAmountMessage();
- else return new CurrentTBRMessage();
- } else if (message instanceof CurrentTBRMessage) {
- CurrentTBRMessage currentTBRMessage = (CurrentTBRMessage) message;
- result.tbrAmount = currentTBRMessage.getPercentage();
- result.tbrInitialDuration = currentTBRMessage.getInitialTime();
- result.tbrLeftoverDuration = currentTBRMessage.getLeftoverTime();
- return new ActiveBolusesMessage();
- } else if (message instanceof ActiveBolusesMessage) {
- ActiveBolusesMessage activeBolusesMessage = (ActiveBolusesMessage) message;
- result.activeBolus1 = activeBolusesMessage.getBolus1();
- result.activeBolus2 = activeBolusesMessage.getBolus2();
- result.activeBolus3 = activeBolusesMessage.getBolus3();
- return new CurrentBasalMessage();
- } else if (message instanceof CurrentBasalMessage) {
- result.baseBasalRate = ((CurrentBasalMessage) message).getCurrentBasalAmount();
- return new BatteryAmountMessage();
- } else if (message instanceof BatteryAmountMessage) {
- result.battery = ((BatteryAmountMessage) message).getBatteryAmount();
- return new CartridgeAmountMessage();
- } else if (message instanceof CartridgeAmountMessage) {
- result.cartridge = ((CartridgeAmountMessage) message).getCartridgeAmount();
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(ActiveProfileBlock.ID);
- return readMessage;
- } else if (message instanceof ReadConfigurationBlockMessage) {
- ConfigurationBlock configurationBlock = ((ReadConfigurationBlockMessage) message).getConfigurationBlock();
- if (configurationBlock instanceof ActiveProfileBlock) {
- ActiveProfileBlock activeProfileBlock = (ActiveProfileBlock) configurationBlock;
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- switch (activeProfileBlock.getActiveProfile()) {
- case BR_PROFILE_1:
- readMessage.setConfigurationBlockID(BRProfile1Block.ID);
- break;
- case BR_PROFILE_2:
- readMessage.setConfigurationBlockID(BRProfile2Block.ID);
- break;
- case BR_PROFILE_3:
- readMessage.setConfigurationBlockID(BRProfile3Block.ID);
- break;
- case BR_PROFILE_4:
- readMessage.setConfigurationBlockID(BRProfile4Block.ID);
- break;
- case BR_PROFILE_5:
- readMessage.setConfigurationBlockID(BRProfile5Block.ID);
- break;
- }
- return readMessage;
- } else if (configurationBlock instanceof BRProfileBlock) {
- result.basalProfile = ((BRProfileBlock) configurationBlock).getProfileBlocks();
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(MaxBolusAmountBlock.ID);
- return readMessage;
- } else if (configurationBlock instanceof MaxBolusAmountBlock) {
- result.maximumBolusAmount = ((MaxBolusAmountBlock) configurationBlock).getMaximumAmount();
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(MaxBRAmountBlock.ID);
- return readMessage;
- } else if (configurationBlock instanceof MaxBRAmountBlock) {
- result.maximumBasalAmount = ((MaxBRAmountBlock) configurationBlock).getMaximumAmount();
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(FactoryMinBRAmountBlock.ID);
- return readMessage;
- } else if (configurationBlock instanceof FactoryMinBRAmountBlock) {
- result.minimumBasalAmount = ((FactoryMinBRAmountBlock) configurationBlock).getMinimumAmount();
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(FactoryMinBolusAmountBlock.ID);
- return readMessage;
- } else if (configurationBlock instanceof FactoryMinBolusAmountBlock) {
- result.minimumBolusAmount = ((FactoryMinBolusAmountBlock) configurationBlock).getMinimumAmount();
- finish(result);
- }
- }
- return null;
- }
-
- public static class Result {
- public PumpStatus pumpStatus;
- public double baseBasalRate;
- public int battery;
- public double cartridge ;
- public int tbrAmount = 100;
- public int tbrInitialDuration = 0;
- public int tbrLeftoverDuration = 0;
- public ActiveBolus activeBolus1;
- public ActiveBolus activeBolus2;
- public ActiveBolus activeBolus3;
- public List basalProfile;
- public double maximumBolusAmount;
- public double maximumBasalAmount;
- public double minimumBolusAmount;
- public double minimumBasalAmount;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java
deleted file mode 100644
index 7012d200e7..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/WriteBasalProfileTaskRunner.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import java.util.List;
-
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ActiveProfileBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile1Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile2Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile3Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile4Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile5Block;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock;
-import sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock;
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.messages.configuration.CloseWriteSessionMessage;
-import sugar.free.sightparser.applayer.messages.configuration.OpenWriteSessionMessage;
-import sugar.free.sightparser.applayer.messages.configuration.ReadConfigurationBlockMessage;
-import sugar.free.sightparser.applayer.messages.configuration.WriteConfigurationBlockMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-/**
- * Created by Tebbe Ubben on 10.03.2018.
- */
-
-public class WriteBasalProfileTaskRunner extends TaskRunner {
-
- private List profileBlocks;
- private BRProfileBlock profileBlock;
-
- public WriteBasalProfileTaskRunner(SightServiceConnector serviceConnector, List profileBlocks) {
- super(serviceConnector);
- this.profileBlocks = profileBlocks;
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) {
- ReadConfigurationBlockMessage readMessage = new ReadConfigurationBlockMessage();
- readMessage.setConfigurationBlockID(ActiveProfileBlock.ID);
- return readMessage;
- } else if (message instanceof ReadConfigurationBlockMessage) {
- ConfigurationBlock configurationBlock = ((ReadConfigurationBlockMessage) message).getConfigurationBlock();
- ActiveProfileBlock activeProfileBlock = (ActiveProfileBlock) configurationBlock;
- switch (activeProfileBlock.getActiveProfile()) {
- case BR_PROFILE_1:
- profileBlock = new BRProfile1Block();
- break;
- case BR_PROFILE_2:
- profileBlock = new BRProfile2Block();
- break;
- case BR_PROFILE_3:
- profileBlock = new BRProfile3Block();
- break;
- case BR_PROFILE_4:
- profileBlock = new BRProfile4Block();
- break;
- case BR_PROFILE_5:
- profileBlock = new BRProfile5Block();
- break;
- }
- profileBlock.setProfileBlocks(profileBlocks);
- return new OpenWriteSessionMessage();
- } else if (message instanceof OpenWriteSessionMessage) {
- WriteConfigurationBlockMessage writeMessage = new WriteConfigurationBlockMessage();
- writeMessage.setConfigurationBlock(profileBlock);
- return writeMessage;
- } else if (message instanceof WriteConfigurationBlockMessage) {
- return new CloseWriteSessionMessage();
- } else if (message instanceof CloseWriteSessionMessage) finish(null);
- return null;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java
deleted file mode 100644
index 753ac7f0e6..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightCallback.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.events;
-
-import java.util.UUID;
-
-import info.nightscout.androidaps.events.Event;
-
-/**
- * Created by jamorham on 23/01/2018.
- */
-public class EventInsightCallback extends Event {
-
- public UUID request_uuid;
- public boolean success = false;
- public String message = null;
- public Object response_object = null;
-
- public EventInsightCallback() {
- request_uuid = UUID.randomUUID();
- }
-
- @Override
- public String toString() {
- return "Event: " + request_uuid + " success: " + success + " msg: " + message + " Object: " + response_object;
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java
deleted file mode 100644
index 3741c607c4..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/events/EventInsightUpdateGui.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.events;
-
-import info.nightscout.androidaps.events.EventUpdateGui;
-
-/**
- * Created by jamorham on 23/01/2018.
- */
-public class EventInsightUpdateGui extends EventUpdateGui {
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java
deleted file mode 100644
index 49836e9f3b..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.history;
-
-import android.content.Intent;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.db.CareportalEvent;
-import info.nightscout.androidaps.db.TDD;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import sugar.free.sightparser.handling.HistoryBroadcast;
-
-import java.util.Date;
-
-import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber;
-
-/**
- * Created by jamorham on 27/01/2018.
- *
- * Parse inbound logbook intents
- */
-
-class HistoryIntentAdapter {
- private Logger log = LoggerFactory.getLogger(L.PUMP);
-
- private HistoryLogAdapter logAdapter = new HistoryLogAdapter();
-
- private static long getDateExtra(Intent intent, String name) {
- return ((Date) intent.getSerializableExtra(name)).getTime();
- }
-
- static long getRecordUniqueID(long pump_serial_number, long pump_record_id) {
- updatePumpSerialNumber(pump_serial_number);
- return (pump_serial_number * 10000000) + pump_record_id;
- }
-
- void processTBRIntent(Intent intent) {
-
- final int pump_tbr_duration = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1);
- final int pump_tbr_percent = intent.getIntExtra(HistoryBroadcast.EXTRA_TBR_AMOUNT, -1);
- long pump_record_id = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
- if (pump_record_id == -1) {
- pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
- }
- final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
- final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
-
- if ((pump_tbr_duration == -1) || (pump_tbr_percent == -1) || (pump_record_id == -1)) {
- log.error("Invalid TBR record!!!");
- return;
- }
-
- final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id);
-
- if (L.isEnabled(L.PUMP))
- log.debug("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id);
- logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id);
- }
-
- void processDeliveredBolusIntent(Intent intent) {
-
- final String bolus_type = intent.getStringExtra(HistoryBroadcast.EXTRA_BOLUS_TYPE);
- final int bolus_id = intent.getIntExtra(HistoryBroadcast.EXTRA_BOLUS_ID, -1);
- long pump_record_id = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
- if (pump_record_id == -1) {
- pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
- }
- final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
- final long event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
- final double immediate_amount = intent.getDoubleExtra(HistoryBroadcast.EXTRA_IMMEDIATE_AMOUNT, -1);
- final double extended_insulin = intent.getDoubleExtra(HistoryBroadcast.EXTRA_EXTENDED_AMOUNT, -1);
- final int extended_minutes = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1);
-
- final long record_unique_id = getRecordUniqueID(pump_serial_number, bolus_id > -1 ? bolus_id : pump_record_id);
-
- switch (bolus_type) {
- case "STANDARD":
- if (immediate_amount == -1) {
- log.error("ERROR Standard bolus fails sanity check");
- return;
- }
- LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U ", event_time);
- logAdapter.createStandardBolusRecord(start_time, immediate_amount, record_unique_id);
- break;
-
- case "EXTENDED":
- if ((extended_insulin == -1) || (extended_minutes == -1)) {
- log.error("ERROR: Extended bolus fails sanity check");
- return;
- }
- LiveHistory.setStatus(bolus_type + " BOLUS\n" + extended_insulin + "U over " + extended_minutes + " min, ", event_time);
- logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id);
- break;
-
- case "MULTIWAVE":
- if ((immediate_amount == -1) || (extended_insulin == -1) || (extended_minutes == -1)) {
- log.error("ERROR: Multiwave bolus fails sanity check");
- return;
- }
- LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U + " + extended_insulin + "U over " + extended_minutes + " min, ", event_time);
- logAdapter.createStandardBolusRecord(start_time, immediate_amount, pump_serial_number + pump_record_id);
- logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id);
- break;
- default:
- log.error("ERROR, UNKNWON BOLUS TYPE: " + bolus_type);
- }
- }
-
- void processDailyTotalIntent(Intent intent) {
- long date = getDateExtra(intent, HistoryBroadcast.EXTRA_TOTAL_DATE);
- double basal = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BASAL_TOTAL, 0D);
- double bolus = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BOLUS_TOTAL, 0D);
- TDD tdd = new TDD(date, bolus, basal, bolus + basal);
- MainApp.getDbHelper().createOrUpdateTDD(tdd);
- }
-
- void processCannulaFilledIntent(Intent intent) {
- long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- uploadCareportalEvent(date, CareportalEvent.SITECHANGE);
- }
-
- void processCartridgeInsertedIntent(Intent intent) {
- long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- uploadCareportalEvent(date, CareportalEvent.INSULINCHANGE);
- }
-
- void processBatteryInsertedIntent(Intent intent) {
- long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- uploadCareportalEvent(date, CareportalEvent.PUMPBATTERYCHANGE);
- }
-
- private void uploadCareportalEvent(long date, String event) {
- if (SP.getBoolean("insight_automatic_careportal_events", false)) {
- if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
- return;
- try {
- JSONObject data = new JSONObject();
- String enteredBy = SP.getString("careportal_enteredby", "");
- if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
- data.put("created_at", DateUtil.toISOString(date));
- data.put("eventType", event);
- NSUpload.uploadCareportalEntryToNS(data);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- void processOccurenceOfAlertIntent(Intent intent) {
- if (SP.getBoolean("insight_automatic_careportal_events", false)) {
- long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE);
- int alertText = getAlertText(alertType);
- if (alertText == 0) return;
- if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
- return;
- logNote(date, MainApp.gs(alertText));
- }
- }
-
- void processPumpStatusChangedIntent(Intent intent) {
- long newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
- if (SP.getBoolean("insight_automatic_careportal_events", false)) {
- String newStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_NEW_STATUS);
- switch (newStatus) {
- case "STARTED":
- logNote(newStatusTime, MainApp.gs(R.string.pump_started));
- break;
- case "STOPPED":
- logNote(newStatusTime, MainApp.gs(R.string.pump_stopped));
- break;
- case "PAUSED":
- logNote(newStatusTime, MainApp.gs(R.string.pump_paused));
- break;
- }
- }
- if (intent.hasExtra(HistoryBroadcast.EXTRA_OLD_STATUS_TIME)) {
- String oldStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_OLD_STATUS);
- if (oldStatus.equals("STOPPED")) {
- long oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME);
- int duration = (int) ((newStatusTime - oldStatusTime) / 60000);
-
- long serialNumber = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
- long recordId = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
- long uniqueRecordId = getRecordUniqueID(serialNumber, recordId);
-
- logAdapter.createTBRrecord(oldStatusTime, 0, duration, uniqueRecordId);
- }
- }
- }
-
- private void logNote(long date, String note) {
- try {
- if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
- return;
- JSONObject data = new JSONObject();
- String enteredBy = SP.getString("careportal_enteredby", "");
- if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
- data.put("created_at", DateUtil.toISOString(date));
- data.put("eventType", CareportalEvent.NOTE);
- data.put("notes", note);
- NSUpload.uploadCareportalEntryToNS(data);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
-
- private int getAlertText(String type) {
- if (type.equals("Error6MechanicalError")) return R.string.alert_e6;
- if (type.equals("Error7ElectronicError")) return R.string.alert_e7;
- if (type.equals("Error10RewindError")) return R.string.alert_e10;
- if (type.equals("Error13LanguageError")) return R.string.alert_e13;
- if (type.equals("Maintenance20CartridgeNotInserted")) return R.string.alert_m20;
- if (type.equals("Maintenance21CartridgeEmpty")) return R.string.alert_m21;
- if (type.equals("Maintenance22BatteryEmpty")) return R.string.alert_m22;
- if (type.equals("Maintenance23AutomaticOff")) return R.string.alert_m23;
- if (type.equals("Maintenance24Occlusion")) return R.string.alert_m24;
- if (type.equals("Maintenance25LoantimeOver")) return R.string.alert_m25;
- if (type.equals("Maintenance26CartridgeChangeNotCompleted")) return R.string.alert_m26;
- if (type.equals("Maintenance27DataDownloadFailed")) return R.string.alert_m27;
- if (type.equals("Maintenance28PauseModeTimeout")) return R.string.alert_m28;
- if (type.equals("Maintenance29BatteryTypeNotSet")) return R.string.alert_m29;
- if (type.equals("Maintenance30CartridgeTypeNotSet")) return R.string.alert_m30;
- if (type.equals("Warning31CartridgeLow")) return R.string.alert_w31;
- if (type.equals("Warning32BatteryLow")) return R.string.alert_w32;
- if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33;
- if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34;
- if (type.equals("Warning36TBRCancelled")) return 0;
- if (type.equals("Warning38BolusCancelled")) return 0;
- if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39;
- return 0;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java
deleted file mode 100644
index fc44f25418..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.history;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.data.DetailedBolusInfo;
-import info.nightscout.androidaps.db.ExtendedBolus;
-import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.db.TemporaryBasal;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.T;
-
-/**
- * Created by jamorham on 27/01/2018.
- *
- * Write to the History Log
- */
-
-class HistoryLogAdapter {
- private Logger log = LoggerFactory.getLogger(L.PUMP);
-
- private static final long MAX_TIME_DIFFERENCE = T.secs(61).msecs();
-
- void createTBRrecord(long eventDate, int percent, int duration, long record_id) {
-
- TemporaryBasal temporaryBasal = new TemporaryBasal().date(eventDate);
-
- final TemporaryBasal temporaryBasalFromHistory = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(eventDate);
-
- if (temporaryBasalFromHistory == null) {
- if (L.isEnabled(L.PUMP))
- log.debug("Create new TBR: " + eventDate + " " + percent + " " + duration);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Loaded existing TBR record: " + temporaryBasalFromHistory.toString());
- if (Math.abs(eventDate - temporaryBasalFromHistory.date) < MAX_TIME_DIFFERENCE) {
- if (temporaryBasalFromHistory.source != Source.PUMP) {
- if (temporaryBasalFromHistory.percentRate == percent) {
- if (L.isEnabled(L.PUMP))
- log.debug("Things seem to match: %" + percent);
- temporaryBasal = temporaryBasalFromHistory;
- String _id = temporaryBasal._id;
- if (NSUpload.isIdValid(_id)) {
- NSUpload.removeCareportalEntryFromNS(_id);
- } else {
- UploadQueue.removeID("dbAdd", _id);
- }
- MainApp.getDbHelper().delete(temporaryBasalFromHistory);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("This record has different percent rates: " + temporaryBasalFromHistory.percentRate + " vs us: " + percent);
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("This record is already a pump record!");
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Time difference too big! : " + (eventDate - temporaryBasalFromHistory.date));
- }
- }
-
- temporaryBasal.source(Source.PUMP)
- .pumpId(record_id)
- .percent(percent)
- .duration(duration);
-
- TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
- }
-
- void createExtendedBolusRecord(long eventDate, double insulin, int durationInMinutes, long record_id) {
-
- final ExtendedBolus extendedBolusFromHistory = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(eventDate);
-
- if (extendedBolusFromHistory == null) {
- if (L.isEnabled(L.PUMP))
- log.debug("Create new EB: " + eventDate + " " + insulin + " " + durationInMinutes);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Loaded existing EB record: " + extendedBolusFromHistory.log());
- if (Math.abs(eventDate - extendedBolusFromHistory.date) < MAX_TIME_DIFFERENCE) {
- if (extendedBolusFromHistory.source != Source.PUMP) {
- if (L.isEnabled(L.PUMP))
- log.debug("Date seem to match: " + DateUtil.dateAndTimeFullString(eventDate));
- String _id = extendedBolusFromHistory._id;
- if (NSUpload.isIdValid(_id)) {
- NSUpload.removeCareportalEntryFromNS(_id);
- } else {
- UploadQueue.removeID("dbAdd", _id);
- }
- MainApp.getDbHelper().delete(extendedBolusFromHistory);
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("This record is already a pump record!");
- }
- } else {
- if (L.isEnabled(L.PUMP))
- log.debug("Time difference too big! : " + (eventDate - extendedBolusFromHistory.date));
- }
- }
-
- // TODO trap items below minimum period
-
- // TODO (mike) find and remove ending record with Source.USER
-
- ExtendedBolus extendedBolus = new ExtendedBolus()
- .date(eventDate)
- .insulin(insulin)
- .durationInMinutes(durationInMinutes)
- .source(Source.PUMP)
- .pumpId(record_id);
-
- if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null) // actual basal rate is needed for absolute rate calculation
- TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
- }
-
- void createStandardBolusRecord(long eventDate, double insulin, long record_id) {
-
- //DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(eventDate.getTime());
-
- // TODO do we need to do the same delete + insert that we are doing for temporary basals here too?
-
- final DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
- detailedBolusInfo.date = eventDate;
- detailedBolusInfo.source = Source.PUMP;
- detailedBolusInfo.pumpId = record_id;
- detailedBolusInfo.insulin = insulin;
- TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java
deleted file mode 100644
index a66378ba54..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.history;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-
-import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.BUSY;
-import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.SYNCED;
-import static info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver.Status.SYNCING;
-import static sugar.free.sightparser.handling.HistoryBroadcast.*;
-
-/**
- * Created by jamorham on 27/01/2018.
- */
-
-public class HistoryReceiver {
-
- private static BroadcastReceiver historyReceiver;
- private volatile static Status status = Status.IDLE;
- private volatile HistoryIntentAdapter intentAdapter;
-
- public HistoryReceiver() {
- initializeHistoryReceiver();
- }
-
- public static synchronized void registerHistoryReceiver() {
- try {
- MainApp.instance().unregisterReceiver(historyReceiver);
- } catch (Exception e) {
- //
- }
-
- final IntentFilter filter = new IntentFilter();
- filter.addAction(ACTION_PUMP_STATUS_CHANGED);
- filter.addAction(ACTION_BOLUS_PROGRAMMED);
- filter.addAction(ACTION_BOLUS_DELIVERED);
- filter.addAction(ACTION_END_OF_TBR);
- filter.addAction(ACTION_DAILY_TOTAL);
- filter.addAction(ACTION_SYNC_STARTED);
- filter.addAction(ACTION_STILL_SYNCING);
- filter.addAction(ACTION_SYNC_FINISHED);
- filter.addAction(ACTION_CANNULA_FILLED);
- filter.addAction(ACTION_CARTRIDGE_INSERTED);
- filter.addAction(ACTION_BATTERY_INSERTED);
- filter.addAction(ACTION_OCCURENCE_OF_ALERT);
- filter.addAction(ACTION_PUMP_STATUS_CHANGED);
-
- MainApp.instance().registerReceiver(historyReceiver, filter);
- }
-
- // History
-
- public static String getStatusString() {
- return status.toString();
- }
-
- private synchronized void initializeHistoryReceiver() {
- historyReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, final Intent intent) {
-
- final String action = intent.getAction();
- if (action == null) return;
-
- if (intentAdapter == null) {
- synchronized (this) {
- if (intentAdapter == null) {
- intentAdapter = new HistoryIntentAdapter();
- }
- }
- }
-
- switch (action) {
- case ACTION_SYNC_STARTED:
- status = SYNCING;
- break;
- case ACTION_STILL_SYNCING:
- status = BUSY;
- break;
- case ACTION_SYNC_FINISHED:
- status = SYNCED;
- break;
- case ACTION_BOLUS_DELIVERED:
- intentAdapter.processDeliveredBolusIntent(intent);
- break;
- case ACTION_END_OF_TBR:
- intentAdapter.processTBRIntent(intent);
- break;
- case ACTION_DAILY_TOTAL:
- intentAdapter.processDailyTotalIntent(intent);
- break;
- case ACTION_CANNULA_FILLED:
- intentAdapter.processCannulaFilledIntent(intent);
- break;
- case ACTION_CARTRIDGE_INSERTED:
- intentAdapter.processCartridgeInsertedIntent(intent);
- break;
- case ACTION_BATTERY_INSERTED:
- intentAdapter.processBatteryInsertedIntent(intent);
- break;
- case ACTION_OCCURENCE_OF_ALERT:
- intentAdapter.processOccurenceOfAlertIntent(intent);
- break;
- case ACTION_PUMP_STATUS_CHANGED:
- intentAdapter.processPumpStatusChangedIntent(intent);
- break;
- }
- }
- };
- }
-
- enum Status {
- IDLE(R.string.insight_history_idle),
- SYNCING(R.string.insight_history_syncing),
- BUSY(R.string.insight_history_busy),
- SYNCED(R.string.insight_history_synced);
-
- private final int string_id;
-
- Status(int string_id) {
- this.string_id = string_id;
- }
-
- @Override
- public String toString() {
- return MainApp.gs(string_id);
- }
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java
deleted file mode 100644
index 46af6bda98..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/LiveHistory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.history;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers;
-
-/**
- * Created by jamorham on 27/01/2018.
- *
- * In memory status storage class
- */
-
-public class LiveHistory {
-
- private static String status = "";
- private static long status_time = -1;
-
- public static String getStatus() {
- if (status.equals("")) return status;
- return status + " " + Helpers.niceTimeScalar(Helpers.msSince(status_time)) + " " + MainApp.gs(R.string.ago);
- }
-
- public static long getStatusTime() {
- return status_time;
- }
-
- static void setStatus(String mystatus, long eventtime) {
- if (eventtime > status_time) {
- status_time = eventtime;
- status = mystatus;
- }
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java
deleted file mode 100644
index 9a2bcfeff5..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/PumpIdCache.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.history;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.SP;
-
-/**
- * Created by jamorham on 01/02/2018.
- */
-
-public class PumpIdCache {
- private static Logger log = LoggerFactory.getLogger(L.PUMP);
-
- private static final String INSIGHT_PUMP_ID_PREF = "insight-pump-id";
- private static long cachedPumpSerialNumber = -1;
-
- static void updatePumpSerialNumber(long pump_serial_number) {
- if (pump_serial_number != cachedPumpSerialNumber) {
- cachedPumpSerialNumber = pump_serial_number;
- if (L.isEnabled(L.PUMP))
- log.debug("Updating pump serial number: " + pump_serial_number);
- SP.putLong(INSIGHT_PUMP_ID_PREF, cachedPumpSerialNumber);
- }
- }
-
- public static long getRecordUniqueID(long record_id) {
- if (cachedPumpSerialNumber == -1) {
- cachedPumpSerialNumber = SP.getLong(INSIGHT_PUMP_ID_PREF, 0L);
- }
- return HistoryIntentAdapter.getRecordUniqueID(cachedPumpSerialNumber, record_id);
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java
deleted file mode 100644
index bfdca16588..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/Helpers.java
+++ /dev/null
@@ -1,197 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.utils;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Handler;
-import android.os.PowerManager;
-import android.util.Log;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.HashMap;
-import java.util.Map;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.logging.L;
-
-/**
- * Created by jamorham on 24/01/2018.
- *
- * Useful utility methods from xDrip+
- */
-
-public class Helpers {
- private static Logger log = LoggerFactory.getLogger(L.PUMP);
-
-
- private static final Map rateLimits = new HashMap<>();
- // singletons to avoid repeated allocation
- private static DecimalFormatSymbols dfs;
- private static DecimalFormat df;
-
- // return true if below rate limit
- public static synchronized boolean ratelimit(String name, int seconds) {
- // check if over limit
- if ((rateLimits.containsKey(name)) && (tsl() - rateLimits.get(name) < (seconds * 1000))) {
- if (L.isEnabled(L.PUMP))
- log.debug(name + " rate limited: " + seconds + " seconds");
- return false;
- }
- // not over limit
- rateLimits.put(name, tsl());
- return true;
- }
-
- public static long tsl() {
- return System.currentTimeMillis();
- }
-
- public static long msSince(long when) {
- return (tsl() - when);
- }
-
- public static long msTill(long when) {
- return (when - tsl());
- }
-
- public static boolean checkPackageExists(Context context, String TAG, String packageName) {
- try {
- final PackageManager pm = context.getPackageManager();
- final PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi.packageName.equals(packageName);
- } catch (PackageManager.NameNotFoundException e) {
- return false;
- } catch (Exception e) {
- log.error("Exception trying to determine packages! " + e);
- return false;
- }
- }
-
- public static boolean runOnUiThreadDelayed(Runnable theRunnable, long delay) {
- return new Handler(MainApp.instance().getMainLooper()).postDelayed(theRunnable, delay);
- }
-
- public static PowerManager.WakeLock getWakeLock(final String name, int millis) {
- final PowerManager pm = (PowerManager) MainApp.instance().getSystemService(Context.POWER_SERVICE);
- if (pm == null) return null;
- final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
- wl.acquire(millis);
- return wl;
- }
-
- public static void releaseWakeLock(PowerManager.WakeLock wl) {
- if (wl == null) return;
- if (wl.isHeld()) wl.release();
- }
-
- public static String niceTimeSince(long t) {
- return niceTimeScalar(msSince(t));
- }
-
- public static String niceTimeTill(long t) {
- return niceTimeScalar(-msSince(t));
- }
-
- public static String niceTimeScalar(long t) {
- String unit = MainApp.gs(R.string.second);
- t = t / 1000;
- if (t > 59) {
- unit = MainApp.gs(R.string.minute);
- t = t / 60;
- if (t > 59) {
- unit = MainApp.gs(R.string.hour);
- t = t / 60;
- if (t > 24) {
- unit = MainApp.gs(R.string.day);
- t = t / 24;
- if (t > 28) {
- unit = MainApp.gs(R.string.week);
- t = t / 7;
- }
- }
- }
- }
- if (t != 1) unit = unit + MainApp.gs(R.string.time_plural);
- return qs((double) t, 0) + " " + unit;
- }
-
- public static String qs(double x, int digits) {
-
- if (digits == -1) {
- digits = 0;
- if (((int) x != x)) {
- digits++;
- if ((((int) x * 10) / 10 != x)) {
- digits++;
- if ((((int) x * 100) / 100 != x)) digits++;
- }
- }
- }
-
- if (dfs == null) {
- final DecimalFormatSymbols local_dfs = new DecimalFormatSymbols();
- local_dfs.setDecimalSeparator('.');
- dfs = local_dfs; // avoid race condition
- }
-
- final DecimalFormat this_df;
- // use singleton if on ui thread otherwise allocate new as DecimalFormat is not thread safe
- if (Thread.currentThread().getId() == 1) {
- if (df == null) {
- final DecimalFormat local_df = new DecimalFormat("#", dfs);
- local_df.setMinimumIntegerDigits(1);
- df = local_df; // avoid race condition
- }
- this_df = df;
- } else {
- this_df = new DecimalFormat("#", dfs);
- }
-
- this_df.setMaximumFractionDigits(digits);
- return this_df.format(x);
- }
-
- public static String niceTimeScalarRedux(long t) {
- return niceTimeScalar(t).replaceFirst("^1 ", "");
- }
-
- public static String niceTimeScalarBrief(long t) {
- // TODO i18n wont work for non-latin characterset
- return niceTimeScalar(t).replaceFirst("([a-z])[a-z]*", "$1").replace(" ", "");
- }
-
- public static String hourMinuteString(long timestamp) {
- return android.text.format.DateFormat.format("kk:mm", timestamp).toString();
- }
-
- public static String hourMinuteSecondString(long timestamp) {
- return android.text.format.DateFormat.format("kk:mm:ss", timestamp).toString();
- }
-
- public static String dateTimeText(long timestamp) {
- return android.text.format.DateFormat.format("yyyy-MM-dd kk:mm:ss", timestamp).toString();
- }
-
- public static String dateText(long timestamp) {
- return android.text.format.DateFormat.format("yyyy-MM-dd", timestamp).toString();
- }
-
- public static String capitalize(String text) {
- return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase();
- }
-
- public static double roundDouble(double value, int places) {
- if (places < 0) throw new IllegalArgumentException("Invalid decimal places");
- BigDecimal bd = new BigDecimal(value);
- bd = bd.setScale(places, RoundingMode.HALF_UP);
- return bd.doubleValue();
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java
deleted file mode 100644
index 395dd51084..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/StatusItem.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.utils;
-
-/**
- * Created by jamorham on 26/01/2018.
- *
- * For representing row status items
- */
-
-public class StatusItem {
-
- public enum Highlight {
- NORMAL,
- GOOD,
- BAD,
- NOTICE,
- CRITICAL
- }
-
- public String name;
- public String value;
- public Highlight highlight;
- public String button_name;
- public Runnable runnable;
-
-
- public StatusItem(String name, String value) {
- this(name, value, Highlight.NORMAL);
- }
-
- public StatusItem() {
- this("line-break", "", Highlight.NORMAL);
- }
-
- public StatusItem(String name, Highlight highlight) {
- this("heading-break", name, highlight);
- }
-
- public StatusItem(String name, Runnable runnable) {
- this("button-break", "", Highlight.NORMAL, name, runnable);
- }
-
- public StatusItem(String name, String value, Highlight highlight) {
- this(name, value, highlight, null, null);
- }
-
- public StatusItem(String name, String value, Highlight highlight, String button_name, Runnable runnable) {
- this.name = name;
- this.value = value;
- this.highlight = highlight;
- this.button_name = button_name;
- this.runnable = runnable;
- }
-
- public StatusItem(String name, Integer value) {
- this(name, value, Highlight.NORMAL);
- }
-
- public StatusItem(String name, Integer value, Highlight highlight) {
- this.name = name;
- this.value = Integer.toString(value);
- this.highlight = highlight;
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java
deleted file mode 100644
index 87c40c19de..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/utils/ui/StatusItemViewAdapter.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.utils.ui;
-
-import android.app.Activity;
-import android.graphics.Color;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
-
-/**
- * Created by jamorham on 26/01/2018.
- *
- * Convert StatusItem to View
- */
-
-public class StatusItemViewAdapter {
-
- private final Activity activity;
- private final ViewGroup holder;
-
- public StatusItemViewAdapter(Activity activity, ViewGroup holder) {
- this.activity = activity;
- this.holder = holder;
- }
-
- public View inflateStatus(StatusItem statusItem) {
- if (activity == null) return null;
- final View child = activity.getLayoutInflater().inflate(R.layout.insightpump_statuselements, null);
- final TextView name = (TextView) child.findViewById(R.id.insightstatuslabel);
- final TextView value = (TextView)child.findViewById(R.id.insightstatusvalue);
- final TextView spacer = (TextView)child.findViewById(R.id.insightstatusspacer);
- final LinearLayout layout = (LinearLayout)child.findViewById(R.id.insightstatuslayout);
-
- if (statusItem.name.equals("line-break")) {
- spacer.setVisibility(View.GONE);
- name.setVisibility(View.GONE);
- value.setVisibility(View.GONE);
- layout.setPadding(10, 10, 10, 10);
- } else if (statusItem.name.equals("heading-break")) {
- value.setVisibility(View.GONE);
- spacer.setVisibility(View.GONE);
- name.setText(statusItem.value);
- name.setGravity(Gravity.CENTER_HORIZONTAL);
- name.setTextColor(Color.parseColor("#fff9c4"));
- } else {
- name.setText(statusItem.name);
- value.setText(statusItem.value);
- }
-
- final int this_color = getHighlightColor(statusItem);
- name.setBackgroundColor(this_color);
- value.setBackgroundColor(this_color);
- spacer.setBackgroundColor(this_color);
-
- if (this_color != Color.TRANSPARENT) {
- name.setTextColor(Color.WHITE);
- spacer.setTextColor(Color.WHITE);
- }
-
- if (holder != null) {
- holder.addView(child);
- }
- return child;
- }
-
- private static int getHighlightColor(StatusItem row) {
- switch (row.highlight) {
- case BAD:
- return Color.parseColor("#480000");
- case NOTICE:
- return Color.parseColor("#403000");
- case GOOD:
- return Color.parseColor("#003000");
- case CRITICAL:
- return Color.parseColor("#770000");
- default:
- return Color.TRANSPARENT;
- }
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java
deleted file mode 100644
index 3f218063ef..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorFragment.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package info.nightscout.androidaps.plugins.SmsCommunicator;
-
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.text.Html;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.squareup.otto.Subscribe;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.Comparator;
-
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-
-/**
- * A simple {@link Fragment} subclass.
- */
-public class SmsCommunicatorFragment extends SubscriberFragment {
- private static Logger log = LoggerFactory.getLogger(SmsCommunicatorFragment.class);
-
- TextView logView;
-
- public SmsCommunicatorFragment() {
- super();
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- try {
- View view = inflater.inflate(R.layout.smscommunicator_fragment, container, false);
-
- logView = (TextView) view.findViewById(R.id.smscommunicator_log);
-
- updateGUI();
- return view;
- } catch (Exception e) {
- FabricPrivacy.logException(e);
- }
-
- return null;
- }
-
- @Subscribe
- public void onStatusEvent(final EventSmsCommunicatorUpdateGui ev) {
- updateGUI();
- }
-
-
- @Override
- protected void updateGUI() {
- Activity activity = getActivity();
- if (activity != null)
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- class CustomComparator implements Comparator {
- public int compare(SmsCommunicatorPlugin.Sms object1, SmsCommunicatorPlugin.Sms object2) {
- return (int) (object1.date - object2.date);
- }
- }
- Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator());
- int messagesToShow = 40;
-
- int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().messages.size() - messagesToShow);
-
- String logText = "";
- for (int x = start; x < SmsCommunicatorPlugin.getPlugin().messages.size(); x++) {
- SmsCommunicatorPlugin.Sms sms = SmsCommunicatorPlugin.getPlugin().messages.get(x);
- if (sms.received) {
- logText += DateUtil.timeString(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
";
- } else if (sms.sent) {
- logText += DateUtil.timeString(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
";
- }
- }
- logView.setText(Html.fromHtml(logText));
- }
- });
- }
-}
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
deleted file mode 100644
index e5e1a6c18e..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java
+++ /dev/null
@@ -1,606 +0,0 @@
-package info.nightscout.androidaps.plugins.SmsCommunicator;
-
-import android.content.Intent;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.os.SystemClock;
-import android.telephony.SmsManager;
-import android.telephony.SmsMessage;
-
-import com.crashlytics.android.answers.CustomEvent;
-import com.squareup.otto.Subscribe;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.text.Normalizer;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import info.nightscout.androidaps.Constants;
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.services.Intents;
-import info.nightscout.androidaps.data.DetailedBolusInfo;
-import info.nightscout.androidaps.data.GlucoseStatus;
-import info.nightscout.androidaps.data.IobTotal;
-import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.androidaps.db.DatabaseHelper;
-import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.events.EventPreferenceChange;
-import info.nightscout.androidaps.events.EventRefreshOverview;
-import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.interfaces.PluginBase;
-import info.nightscout.androidaps.interfaces.PluginDescription;
-import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.T;
-import info.nightscout.utils.XdripCalibrations;
-
-/**
- * Created by mike on 05.08.2016.
- */
-public class SmsCommunicatorPlugin extends PluginBase {
- private static Logger log = LoggerFactory.getLogger(SmsCommunicatorPlugin.class);
-
- private static SmsCommunicatorPlugin smsCommunicatorPlugin;
-
- public static SmsCommunicatorPlugin getPlugin() {
-
- if (smsCommunicatorPlugin == null) {
- smsCommunicatorPlugin = new SmsCommunicatorPlugin();
- }
- return smsCommunicatorPlugin;
- }
-
- private List allowedNumbers = new ArrayList<>();
-
- class Sms {
- String phoneNumber;
- String text;
- long date;
- boolean received = false;
- boolean sent = false;
- boolean processed = false;
-
- String confirmCode;
- double bolusRequested = 0d;
- double tempBasal = 0d;
- double calibrationRequested = 0d;
- int duration = 0;
-
- Sms(SmsMessage message) {
- phoneNumber = message.getOriginatingAddress();
- text = message.getMessageBody();
- date = message.getTimestampMillis();
- received = true;
- }
-
- Sms(String phoneNumber, String text, long date) {
- this.phoneNumber = phoneNumber;
- this.text = text;
- this.date = date;
- sent = true;
- }
-
- Sms(String phoneNumber, String text, long date, String confirmCode) {
- this.phoneNumber = phoneNumber;
- this.text = text;
- this.date = date;
- this.confirmCode = confirmCode;
- sent = true;
- }
-
- public String toString() {
- return "SMS from " + phoneNumber + ": " + text;
- }
- }
-
- private Sms cancelTempBasalWaitingForConfirmation = null;
- private Sms tempBasalWaitingForConfirmation = null;
- private Sms bolusWaitingForConfirmation = null;
- private Sms calibrationWaitingForConfirmation = null;
- private Sms suspendWaitingForConfirmation = null;
- private Date lastRemoteBolusTime = new Date(0);
-
- ArrayList messages = new ArrayList<>();
-
- private SmsCommunicatorPlugin() {
- super(new PluginDescription()
- .mainType(PluginType.GENERAL)
- .fragmentClass(SmsCommunicatorFragment.class.getName())
- .pluginName(R.string.smscommunicator)
- .shortName(R.string.smscommunicator_shortname)
- .preferencesId(R.xml.pref_smscommunicator)
- .description(R.string.description_sms_communicator)
- );
- processSettings(null);
- }
-
- @Override
- protected void onStart() {
- MainApp.bus().register(this);
- super.onStart();
- }
-
- @Override
- protected void onStop() {
- MainApp.bus().unregister(this);
- }
-
- @Subscribe
- public void processSettings(final EventPreferenceChange ev) {
- if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
- String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
-
- String pattern = ";";
-
- String[] substrings = settings.split(pattern);
- for (String number : substrings) {
- String cleaned = number.replaceAll("\\s+", "");
- allowedNumbers.add(cleaned);
- log.debug("Found allowed number: " + cleaned);
- }
- }
- }
-
- private boolean isAllowedNumber(String number) {
- for (String num : allowedNumbers) {
- if (num.equals(number)) return true;
- }
- return false;
- }
-
- public void handleNewData(Intent intent) {
- Bundle bundle = intent.getExtras();
- if (bundle == null) return;
-
- Object[] pdus = (Object[]) bundle.get("pdus");
- if (pdus != null) {
- // For every SMS message received
- for (Object pdu : pdus) {
- SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu);
- processSms(new Sms(message));
- }
- }
- }
-
- private void processSms(final Sms receivedSms) {
- if (!isEnabled(PluginType.GENERAL)) {
- log.debug("Ignoring SMS. Plugin disabled.");
- return;
- }
- if (!isAllowedNumber(receivedSms.phoneNumber)) {
- log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed");
- return;
- }
-
- String reply = "";
-
- messages.add(receivedSms);
- log.debug(receivedSms.toString());
-
- String[] splited = receivedSms.text.split("\\s+");
- Double amount;
- Double tempBasal;
- int duration = 0;
- String passCode;
- boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
-
- if (splited.length > 0) {
- switch (splited[0].toUpperCase()) {
- case "BG":
- BgReading actualBG = DatabaseHelper.actualBg();
- BgReading lastBG = DatabaseHelper.lastBg();
-
- String units = ProfileFunctions.getInstance().getProfileUnits();
-
- if (actualBG != null) {
- reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
- } else if (lastBG != null) {
- Long agoMsec = System.currentTimeMillis() - lastBG.date;
- int agoMin = (int) (agoMsec / 60d / 1000d);
- reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", ";
- }
- GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
- if (glucoseStatus != null)
- reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
-
- TreatmentsPlugin.getPlugin().updateTotalIOBTreatments();
- IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round();
- TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
- IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
-
- reply += MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
- + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
- + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
-
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bg"));
- break;
- case "LOOP":
- if (splited.length > 1)
- switch (splited[1].toUpperCase()) {
- case "DISABLE":
- case "STOP":
- LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
- if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) {
- loopPlugin.setPluginEnabled(PluginType.LOOP, false);
- ConfigBuilderPlugin.getPlugin().storeSettings("SMS_LOOP_STOP");
- ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
- @Override
- public void run() {
- MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
- String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " +
- MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- });
- }
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop"));
- break;
- case "ENABLE":
- case "START":
- loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
- if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
- loopPlugin.setPluginEnabled(PluginType.LOOP, true);
- ConfigBuilderPlugin.getPlugin().storeSettings("SMS_LOOP_START");
- reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
- }
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Start"));
- break;
- case "STATUS":
- loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
- if (loopPlugin != null) {
- if (loopPlugin.isEnabled(PluginType.LOOP)) {
- if (loopPlugin.isSuspended())
- reply = String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend());
- else
- reply = MainApp.gs(R.string.smscommunicator_loopisenabled);
- } else {
- reply = MainApp.gs(R.string.smscommunicator_loopisdisabled);
- }
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
- break;
- case "RESUME":
- LoopPlugin.getPlugin().suspendTo(0);
- MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME"));
- NSUpload.uploadOpenAPSOffline(0);
- reply = MainApp.gs(R.string.smscommunicator_loopresumed);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
- break;
- case "SUSPEND":
- if (splited.length >= 3)
- duration = SafeParse.stringToInt(splited[2]);
- duration = Math.max(0, duration);
- duration = Math.min(180, duration);
- if (duration == 0) {
- reply = MainApp.gs(R.string.smscommunicator_wrongduration);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else if (remoteCommandsAllowed) {
- passCode = generatePasscode();
- reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
- receivedSms.processed = true;
- resetWaitingMessages();
- sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
- suspendWaitingForConfirmation.duration = duration;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend"));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- break;
- }
- break;
- case "TREATMENTS":
- if (splited.length > 1)
- switch (splited[1].toUpperCase()) {
- case "REFRESH":
- Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
- TreatmentsPlugin.getPlugin().getService().resetTreatments();
- MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
- List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
- reply = "TERATMENTS REFRESH " + q.size() + " receivers";
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Treatments_Refresh"));
- break;
- }
- break;
- case "NSCLIENT":
- if (splited.length > 1)
- switch (splited[1].toUpperCase()) {
- case "RESTART":
- Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
- MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
- List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
- reply = "NSCLIENT RESTART " + q.size() + " receivers";
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Nsclient_Restart"));
- break;
- }
- break;
- case "PUMP":
- case "DANAR":
- ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() {
- @Override
- public void run() {
- PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (result.success) {
- if (pump != null) {
- String reply = pump.shortStatus(true);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- } else {
- String reply = MainApp.gs(R.string.readstatusfailed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- });
- receivedSms.processed = true;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Pump"));
- break;
- case "BASAL":
- if (splited.length > 1) {
- if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
- if (remoteCommandsAllowed) {
- passCode = generatePasscode();
- reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
- receivedSms.processed = true;
- resetWaitingMessages();
- sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- } else {
- tempBasal = SafeParse.stringToDouble(splited[1]);
- Profile profile = ProfileFunctions.getInstance().getProfile();
- if (profile == null) {
- reply = MainApp.gs(R.string.noprofile);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
- if (remoteCommandsAllowed) {
- passCode = generatePasscode();
- reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
- receivedSms.processed = true;
- resetWaitingMessages();
- sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
- tempBasalWaitingForConfirmation.tempBasal = tempBasal;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- }
- }
- break;
- case "BOLUS":
- if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
- reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) {
- reply = MainApp.gs(R.string.pumpsuspended);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else if (splited.length > 1) {
- amount = SafeParse.stringToDouble(splited[1]);
- amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
- if (amount > 0d && remoteCommandsAllowed) {
- passCode = generatePasscode();
- reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
- receivedSms.processed = true;
- resetWaitingMessages();
- sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
- bolusWaitingForConfirmation.bolusRequested = amount;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus"));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- break;
- case "CAL":
- if (splited.length > 1) {
- amount = SafeParse.stringToDouble(splited[1]);
- if (amount > 0d && remoteCommandsAllowed) {
- passCode = generatePasscode();
- reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
- receivedSms.processed = true;
- resetWaitingMessages();
- sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
- calibrationWaitingForConfirmation.calibrationRequested = amount;
- FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal"));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- break;
- default: // expect passCode here
- if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
- bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
- bolusWaitingForConfirmation.processed = true;
- DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
- detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
- detailedBolusInfo.source = Source.USER;
- ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() {
- @Override
- public void run() {
- PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (result.success) {
- SystemClock.sleep(T.secs(15).msecs()); // wait some time to get history
- String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
- if (pump != null)
- reply += "\n" + pump.shortStatus(true);
- lastRemoteBolusTime = new Date();
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- SystemClock.sleep(T.secs(60).msecs()); // wait some time to get history
- String reply = MainApp.gs(R.string.smscommunicator_bolusfailed);
- if (pump != null)
- reply += "\n" + pump.shortStatus(true);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- });
- } else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
- tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
- tempBasalWaitingForConfirmation.processed = true;
- Profile profile = ProfileFunctions.getInstance().getProfile();
- if (profile != null)
- ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30, true, profile, new Callback() {
- @Override
- public void run() {
- if (result.success) {
- String reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
- reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
- reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- });
- } else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
- cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
- cancelTempBasalWaitingForConfirmation.processed = true;
- ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
- @Override
- public void run() {
- if (result.success) {
- String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled);
- reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
- reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- });
- } else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed &&
- calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
- calibrationWaitingForConfirmation.processed = true;
- boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
- if (result) {
- reply = MainApp.gs(R.string.smscommunicator_calibrationsent);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- reply = MainApp.gs(R.string.smscommunicator_calibrationfailed);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
- suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
- suspendWaitingForConfirmation.processed = true;
- ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
- @Override
- public void run() {
- if (result.success) {
- LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
- NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
- MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
- String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
- MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
- sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- } else {
- String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
- reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
- sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
- }
- }
- });
- } else {
- sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand), System.currentTimeMillis()));
- }
- resetWaitingMessages();
- break;
- }
- }
-
- MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
- }
-
- public void sendNotificationToAllNumbers(String text) {
- for (int i = 0; i < allowedNumbers.size(); i++) {
- Sms sms = new Sms(allowedNumbers.get(i), text, System.currentTimeMillis());
- sendSMS(sms);
- }
- }
-
- private void sendSMSToAllNumbers(Sms sms) {
- for (String number : allowedNumbers) {
- sms.phoneNumber = number;
- sendSMS(sms);
- }
- }
-
- private void sendSMS(Sms sms) {
- SmsManager smsManager = SmsManager.getDefault();
- sms.text = stripAccents(sms.text);
- if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
- try {
- log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text);
- smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
- messages.add(sms);
- } catch (IllegalArgumentException e) {
- Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);
- MainApp.bus().post(new EventNewNotification(notification));
- } catch (java.lang.SecurityException e) {
- Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL);
- MainApp.bus().post(new EventNewNotification(notification));
- }
- }
-
- private String generatePasscode() {
- int startChar1 = 'A'; // on iphone 1st char is uppercase :)
- String passCode = Character.toString((char) (startChar1 + Math.random() * ('z' - 'a' + 1)));
- int startChar2 = Math.random() > 0.5 ? 'a' : 'A';
- passCode += Character.toString((char) (startChar2 + Math.random() * ('z' - 'a' + 1)));
- int startChar3 = Math.random() > 0.5 ? 'a' : 'A';
- passCode += Character.toString((char) (startChar3 + Math.random() * ('z' - 'a' + 1)));
- return passCode;
- }
-
- private void resetWaitingMessages() {
- tempBasalWaitingForConfirmation = null;
- cancelTempBasalWaitingForConfirmation = null;
- bolusWaitingForConfirmation = null;
- calibrationWaitingForConfirmation = null;
- suspendWaitingForConfirmation = null;
- }
-
- private static String stripAccents(String s) {
- s = Normalizer.normalize(s, Normalizer.Form.NFD);
- s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
- return s;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java
deleted file mode 100644
index 460e550b8e..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package info.nightscout.androidaps.plugins.Source;
-
-import android.content.Intent;
-import android.os.Bundle;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import info.nightscout.androidaps.Config;
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.androidaps.interfaces.BgSourceInterface;
-import info.nightscout.androidaps.interfaces.PluginBase;
-import info.nightscout.androidaps.interfaces.PluginDescription;
-import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
-
-/**
- * Created by mike on 28.11.2017.
- */
-
-public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterface {
- private static Logger log = LoggerFactory.getLogger(L.BGSOURCE);
-
- private static SourceDexcomG5Plugin plugin = null;
-
- public static SourceDexcomG5Plugin getPlugin() {
- if (plugin == null)
- plugin = new SourceDexcomG5Plugin();
- return plugin;
- }
-
- private SourceDexcomG5Plugin() {
- super(new PluginDescription()
- .mainType(PluginType.BGSOURCE)
- .fragmentClass(BGSourceFragment.class.getName())
- .pluginName(R.string.DexcomG5)
- .shortName(R.string.dexcomG5_shortname)
- .preferencesId(R.xml.pref_dexcomg5)
- .description(R.string.description_source_dexcom_g5)
- );
- }
-
- @Override
- public boolean advancedFilteringSupported() {
- return true;
- }
-
- @Override
- public void handleNewData(Intent intent) {
- // onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
-
- if (!isEnabled(PluginType.BGSOURCE)) return;
-
- Bundle bundle = intent.getExtras();
- if (bundle == null) return;
-
- BgReading bgReading = new BgReading();
-
- String data = bundle.getString("data");
- if (L.isEnabled(L.BGSOURCE))
- log.debug("Received Dexcom Data", data);
-
- if (data == null) return;
-
- try {
- JSONArray jsonArray = new JSONArray(data);
- if (L.isEnabled(L.BGSOURCE))
- log.debug("Received Dexcom Data size:" + jsonArray.length());
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject json = jsonArray.getJSONObject(i);
- bgReading.value = json.getInt("m_value");
- bgReading.direction = json.getString("m_trend");
- bgReading.date = json.getLong("m_time") * 1000L;
- bgReading.raw = 0;
- boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
- 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) {
- log.error("Exception: ", e);
- }
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java
deleted file mode 100644
index 02c74defca..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/SendToDataLayerThread.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package info.nightscout.androidaps.plugins.Wear.wearintegration;
-
-import android.os.AsyncTask;
-import android.util.Log;
-
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.wearable.DataApi;
-import com.google.android.gms.wearable.DataMap;
-import com.google.android.gms.wearable.Node;
-import com.google.android.gms.wearable.NodeApi;
-import com.google.android.gms.wearable.PutDataMapRequest;
-import com.google.android.gms.wearable.PutDataRequest;
-import com.google.android.gms.wearable.Wearable;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by emmablack on 12/26/14.
- */
-class SendToDataLayerThread extends AsyncTask {
- private GoogleApiClient googleApiClient;
- private static final String TAG = "SendDataThread";
- String path;
-
- SendToDataLayerThread(String path, GoogleApiClient pGoogleApiClient) {
- this.path = path;
- googleApiClient = pGoogleApiClient;
- }
-
- @Override
- protected Void doInBackground(DataMap... params) {
- try {
- final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
- for (Node node : nodes.getNodes()) {
- for (DataMap dataMap : params) {
- PutDataMapRequest putDMR = PutDataMapRequest.create(path);
- putDMR.getDataMap().putAll(dataMap);
- PutDataRequest request = putDMR.asPutDataRequest();
- DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
- if (result.getStatus().isSuccess()) {
- Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
- } else {
- Log.d(TAG, "ERROR: failed to send DataMap");
- }
- }
- }
- } catch (Exception e) {
- Log.e(TAG, "Got exception sending data to wear: " + e.toString());
- }
- return null;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java
index 5135c6b87b..b3b0c091d5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop;
+package info.nightscout.androidaps.plugins.aps.loop;
import android.text.Html;
import android.text.Spanned;
@@ -22,11 +22,11 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 09.06.2016.
@@ -307,6 +307,11 @@ public class APSResult {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
Profile profile = ProfileFunctions.getInstance().getProfile();
+ if (profile == null) {
+ log.error("FALSE: No Profile");
+ return false;
+ }
+
if (usePercent) {
if (activeTemp == null && percent == 100) {
if (L.isEnabled(L.APS))
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java
index 2c2bb1a2ee..69afe3d8e7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop;
+package info.nightscout.androidaps.plugins.aps.loop;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java
index 0c0e31fb03..0b11dd0ac3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop;
+package info.nightscout.androidaps.plugins.aps.loop;
import android.app.Activity;
@@ -13,19 +13,16 @@ import android.widget.TextView;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
-import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
-import info.nightscout.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui;
+import info.nightscout.androidaps.utils.FabricPrivacy;
public class LoopFragment extends SubscriberFragment {
@BindView(R.id.loop_run)
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java
index ac5076be72..91bbccc515 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop;
+package info.nightscout.androidaps.plugins.aps.loop;
import android.annotation.SuppressLint;
import android.app.Notification;
@@ -34,6 +34,7 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG;
+import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase;
@@ -43,24 +44,24 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
-import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
-import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by mike on 05.08.2016.
@@ -175,6 +176,14 @@ public class LoopPlugin extends PluginBase {
return loopSuspendedTill;
}
+ @Subscribe
+ public void onStatusEvent(final EventTempTargetChange ev) {
+ new Thread(() -> invoke("EventTempTargetChange", true)).start();
+ FabricPrivacy.getInstance().logCustom(new CustomEvent("TT_Loop_Run"));
+ }
+
+
+
public void suspendTo(long endTime) {
loopSuspendedTill = endTime;
isSuperBolus = false;
@@ -409,8 +418,10 @@ public class LoopPlugin extends PluginBase {
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH)
.setCategory(Notification.CATEGORY_ALARM)
- .setVisibility(Notification.VISIBILITY_PUBLIC)
- .setLocalOnly(true);
+ .setVisibility(Notification.VISIBILITY_PUBLIC);
+ if (SP.getBoolean("wearcontrol", false)) {
+ builder.setLocalOnly(true);
+ }
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java
index 988d08fb84..e3a64dbece 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/ScriptReader.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/ScriptReader.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop;
+package info.nightscout.androidaps.plugins.aps.loop;
import android.content.Context;
import android.content.res.AssetManager;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java
index 1ef5dc4c94..0d2a45f528 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopSetLastRunGui.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop.events;
+package info.nightscout.androidaps.plugins.aps.loop.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java
index d4417dbb12..f746dfb0a0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventLoopUpdateGui.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop.events;
+package info.nightscout.androidaps.plugins.aps.loop.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java
similarity index 71%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java
index 001d11661e..6a0a4dc0cf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/events/EventNewOpenLoopNotification.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Loop.events;
+package info.nightscout.androidaps.plugins.aps.loop.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java
index 50e79d1e37..7eb9a2d81d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSAMA;
+package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import org.json.JSONArray;
import org.json.JSONException;
@@ -26,12 +26,12 @@ import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.SP;
public class DetermineBasalAdapterAMAJS {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java
index 77c8d8a860..46f1057e27 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalResultAMA.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSAMA;
+package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import org.json.JSONException;
import org.json.JSONObject;
@@ -7,8 +7,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.utils.DateUtil;
public class DetermineBasalResultAMA extends APSResult {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java
index 1874816ddc..f73a66bbfe 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSAMA;
+package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import android.app.Activity;
import android.os.Bundle;
@@ -19,12 +19,12 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.JSONFormatter;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java
index 3bf1301416..3447c7c4f4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSAMA;
+package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import org.json.JSONException;
import org.slf4j.Logger;
@@ -11,27 +11,26 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.Profiler;
-import info.nightscout.utils.Round;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.Round;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java
index 1574665dc4..4baabf22ab 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA;
+package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.json.JSONException;
import org.json.JSONObject;
@@ -23,9 +23,9 @@ import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.SP;
public class DetermineBasalAdapterMAJS {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java
index d3e1869f87..bbbcf7f893 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalResultMA.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA;
+package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.json.JSONException;
import org.json.JSONObject;
@@ -7,7 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
public class DetermineBasalResultMA extends APSResult {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java
index 8907166951..30ce388f5d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/LoggerCallback.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/LoggerCallback.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA;
+package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.mozilla.javascript.ScriptableObject;
import org.slf4j.Logger;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java
index 12d7988a16..257a4abcb2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA;
+package info.nightscout.androidaps.plugins.aps.openAPSMA;
import android.app.Activity;
import android.os.Bundle;
@@ -12,12 +12,12 @@ import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.JSONFormatter;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClickListener {
Button run;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java
index 5b59252ea1..24b4cb7929 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA;
+package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.json.JSONException;
import org.slf4j.Logger;
@@ -11,27 +11,26 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.Profiler;
-import info.nightscout.utils.Round;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.Round;
-import static info.nightscout.utils.HardLimits.checkOnlyHardLimits;
-import static info.nightscout.utils.HardLimits.verifyHardLimits;
+import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits;
+import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java
similarity index 71%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java
index 40f3c31973..de4292025d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateGui.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA.events;
+package info.nightscout.androidaps.plugins.aps.openAPSMA.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java
index 177133f155..fb5ea7e78f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/events/EventOpenAPSUpdateResultGui.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSMA.events;
+package info.nightscout.androidaps.plugins.aps.openAPSMA.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java
index f974ff472e..bfff43f9d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSSMB;
+package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.json.JSONArray;
import org.json.JSONException;
@@ -26,12 +26,12 @@ import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
public class DetermineBasalAdapterSMBJS {
private static Logger log = LoggerFactory.getLogger(L.APS);
@@ -211,6 +211,7 @@ public class DetermineBasalAdapterSMBJS {
double autosensDataRatio,
boolean tempTargetSet,
boolean microBolusAllowed,
+ boolean uamAllowed,
boolean advancedFiltering
) throws JSONException {
@@ -247,14 +248,16 @@ public class DetermineBasalAdapterSMBJS {
// mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
//}
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
- mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
+ mProfile.put("enableUAM", uamAllowed);
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
- mProfile.put("enableSMB_with_COB", SP.getBoolean(R.string.key_enableSMB_with_COB, false));
- mProfile.put("enableSMB_with_temptarget", SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
- mProfile.put("allowSMB_with_high_temptarget", SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
- mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
- mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
- mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes));
+
+ boolean smbEnabled = SP.getBoolean(MainApp.gs(R.string.key_use_smb), false);
+ mProfile.put("enableSMB_with_COB", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false));
+ mProfile.put("enableSMB_with_temptarget", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
+ mProfile.put("allowSMB_with_high_temptarget", smbEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
+ mProfile.put("enableSMB_always", smbEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
+ mProfile.put("enableSMB_after_carbs", smbEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
+ mProfile.put("maxSMBBasalMinutes", SP.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes));
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
mProfile.put("current_basal", basalrate);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java
index 364731bea5..9d0bd22557 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalResultSMB.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSSMB;
+package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.json.JSONException;
import org.json.JSONObject;
@@ -6,8 +6,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.utils.DateUtil;
public class DetermineBasalResultSMB extends APSResult {
private static final Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java
index d27f8b31d0..87572e2ad6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSSMB;
+package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import android.app.Activity;
import android.os.Bundle;
@@ -22,12 +22,12 @@ import butterknife.OnClick;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.JSONFormatter;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSSMBFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(L.APS);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java
index d42ca9e89f..73914662d7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java
@@ -1,11 +1,9 @@
-package info.nightscout.androidaps.plugins.OpenAPSSMB;
+package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
@@ -13,35 +11,35 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint;
+import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.ScriptReader;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.Profiler;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by mike on 05.08.2016.
*/
-public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
+public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(L.APS);
private static OpenAPSSMBPlugin openAPSSMBPlugin;
@@ -150,7 +148,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
if (L.isEnabled(L.APS))
Profiler.log(log, "getMealData()", startPart);
- double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
+ Constraint maxIOBAllowedConstraint = MainApp.getConstraintChecker().getMaxIOBAllowed();
+ inputConstraints.copyReasons(maxIOBAllowedConstraint);
+ double maxIob = maxIOBAllowedConstraint.value();
minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
@@ -198,6 +198,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering);
inputConstraints.copyReasons(advancedFiltering);
+ Constraint uam = new Constraint<>(true);
+ MainApp.getConstraintChecker().isUAMEnabled(uam);
+ inputConstraints.copyReasons(uam);
+
if (L.isEnabled(L.APS))
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
if (L.isEnabled(L.APS))
@@ -209,6 +213,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
lastAutosensResult.ratio, //autosensDataRatio
isTempTarget,
smbAllowed.value(),
+ uam.value(),
advancedFiltering.value()
);
} catch (JSONException e) {
@@ -264,4 +269,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
return newvalue;
}
+ public Constraint isSuperBolusEnabled(Constraint value) {
+ value.set(false);
+ return value;
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java
index 0ce8d2bb94..f6b8f20233 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/SMBDefaults.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/SMBDefaults.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.OpenAPSSMB;
+package info.nightscout.androidaps.plugins.aps.openAPSSMB;
/**
* Created by mike on 10.12.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java
index fabd83f0ea..3ac877b42d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/common/SubscriberFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Common;
+package info.nightscout.androidaps.plugins.common;
import android.support.v4.app.Fragment;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java
index 3df78c9a28..b374c78413 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConfigBuilder;
+package info.nightscout.androidaps.plugins.configBuilder;
import android.content.Intent;
@@ -39,13 +39,14 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.SensitivityInterface;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
-import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
-import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.PasswordProtection;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
+import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
+
+import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.PasswordProtection;
public class ConfigBuilderFragment extends SubscriberFragment {
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
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java
index 588ba2ac93..3c3531da86 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
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConfigBuilder;
+package info.nightscout.androidaps.plugins.configBuilder;
import android.support.annotation.Nullable;
@@ -20,11 +20,11 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
-import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref0Plugin;
+import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
+import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
import info.nightscout.androidaps.queue.CommandQueue;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java
index 9b4e1d0a28..b19948fc5e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/DetailedBolusInfoStorage.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConfigBuilder;
+package info.nightscout.androidaps.plugins.configBuilder;
import android.support.annotation.Nullable;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java
similarity index 65%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java
index 312c0cd9ae..6b9b353979 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConfigBuilder;
+package info.nightscout.androidaps.plugins.configBuilder;
import android.content.Intent;
import android.support.annotation.Nullable;
@@ -16,15 +16,16 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.ProfileSwitch;
+import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.FabricPrivacy;
public class ProfileFunctions {
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
@@ -139,4 +140,44 @@ public class ProfileFunctions {
return null;
}
+ public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) {
+ ProfileSwitch profileSwitch = new ProfileSwitch();
+ profileSwitch.date = date;
+ profileSwitch.source = Source.USER;
+ profileSwitch.profileName = profileName;
+ profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
+ profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
+ profileSwitch.durationInMinutes = duration;
+ profileSwitch.isCPP = percentage != 100 || timeshift != 0;
+ profileSwitch.timeshift = timeshift;
+ profileSwitch.percentage = percentage;
+ return profileSwitch;
+ }
+
+ public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
+ ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis());
+ TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
+ FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
+ }
+
+ public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
+ ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis());
+ if (profileSwitch != null) {
+ profileSwitch = new ProfileSwitch();
+ profileSwitch.date = System.currentTimeMillis();
+ profileSwitch.source = Source.USER;
+ profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false);
+ profileSwitch.profileJson = getInstance().getProfile().getData().toString();
+ profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
+ profileSwitch.durationInMinutes = duration;
+ profileSwitch.isCPP = percentage != 100 || timeshift != 0;
+ profileSwitch.timeshift = timeshift;
+ profileSwitch.percentage = percentage;
+ TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
+ FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
+ } else {
+ log.error("No profile switch existing");
+ }
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java
new file mode 100644
index 0000000000..2862cc3d7a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java
@@ -0,0 +1,125 @@
+package info.nightscout.androidaps.plugins.constraints.dstHelper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Calendar;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.Constraint;
+import info.nightscout.androidaps.interfaces.ConstraintsInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PluginDescription;
+import info.nightscout.androidaps.interfaces.PluginType;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.utils.T;
+
+/**
+ * Created by Rumen on 31.10.2018.
+ */
+public class DstHelperPlugin extends PluginBase implements ConstraintsInterface {
+ private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
+ private int minutesToChange = 0;
+
+ static DstHelperPlugin plugin = null;
+
+ public static DstHelperPlugin getPlugin() {
+ if (plugin == null)
+ plugin = new DstHelperPlugin();
+ return plugin;
+ }
+
+ public DstHelperPlugin() {
+ super(new PluginDescription()
+ .mainType(PluginType.CONSTRAINTS)
+ .neverVisible(true)
+ .alwaysEnabled(true)
+ .showInList(false)
+ .pluginName(R.string.dst_plugin_name)
+ );
+ }
+
+ public int dstTest(Calendar c) throws Exception {
+// c = Calendar.getInstance(TimeZone.getDefault());
+// c = Calendar.getInstance(TimeZone.getTimeZone("Australia/Lord_Howe"));
+// c.setTimeInMillis(DateUtil.fromISODateString("2018-10-07T01:00:00Z").getTime());
+ long zoneOffset = c.get(Calendar.ZONE_OFFSET);
+ long d1 = c.getTimeInMillis() - zoneOffset;
+ c.setTimeInMillis(d1);
+ int offset1 = c.get(Calendar.DST_OFFSET);
+
+ c.add(Calendar.DATE, 1);
+ long d2 = c.getTimeInMillis();
+
+ int diffInHours = (int) ((d1 - d2) / -T.hours(1).msecs());
+ long offsetDetectedTime = 0;
+ // comparing millis because change can be < 1 hour
+// log.debug("Starting from: "+startTimeString + " to "+endTimeString);
+// log.debug("start "+offset1+" end "+c.get(Calendar.DST_OFFSET));
+ if (offset1 != c.get(Calendar.DST_OFFSET)) {
+ //we have a time change in next 24 hours, but when exactly
+// log.debug("Daylight saving time detected between " + startTimeString + " and " + endTimeString);
+// log.debug("Diff in hours is: "+diffInHours);
+ c.setTimeInMillis(d1 - zoneOffset);
+ offset1 = c.get(Calendar.DST_OFFSET);
+ for (int i = 0; i <= diffInHours * 4; i++) {
+
+ if (offset1 != c.get(Calendar.DST_OFFSET)) {
+ log.debug("Detected offset in " + ((i / 4) - zoneOffset / T.hours(1).msecs()) + " hours value is " + (offset1 - c.get(Calendar.DST_OFFSET)) / T.mins(1).msecs() + " minutes");
+ offsetDetectedTime = c.getTimeInMillis() - d1;
+ break;
+ }
+ c.add(Calendar.MINUTE, 15);
+
+ }
+ }
+ int minutesLeft = (int) ((offsetDetectedTime / T.mins(1).msecs()));
+ /*log.debug("zoneoffset(minutes):"+zoneOffset/T.mins(1).msecs());
+ log.debug("Start offset: "+offset1/T.mins(1).msecs());
+ log.debug("End offset :" + c.get(Calendar.DST_OFFSET)/T.mins(1).msecs());
+ log.debug("Now is:"+startTimeString);
+ log.debug("Detected in(min): "+(offsetDetectedTime/T.mins(1).msecs()));
+ log.debug("Returning value of: " + minutesLeft); */
+ minutesToChange = minutesLeft;
+ return minutesLeft;
+
+ }
+
+ //Return false if time to DST change is less than 91 and positive
+ @Override
+ public Constraint isLoopInvocationAllowed(Constraint value) {
+ try {
+ this.dstTest(Calendar.getInstance());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (this.minutesToChange <= 90 && minutesToChange > 0 && value.value()) {
+ try {
+ LoopPlugin loopPlugin = LoopPlugin.getPlugin();
+ if (loopPlugin.suspendedTo() == 0L) {
+// loopPlugin.suspendTo(System.currentTimeMillis() + minutesToChange * T.mins(1).msecs());
+ warnUser(Notification.DST_LOOP_DISABLED, MainApp.gs(R.string.dst_loop_disabled_warning));
+ } else
+ log.debug("Loop already suspended");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ value.set(false, "DST in 90 minutes or less", this);
+ } else if (minutesToChange <= 24 * T.hours(1).mins() && minutesToChange > 0) {
+ warnUser(Notification.DST_IN_24H, MainApp.gs(R.string.dst_in_24h_warning));
+ }
+ return value;
+ }
+
+ // display warning
+ void warnUser(int id, String warningText) {
+ Notification notification = new Notification(id, warningText, Notification.LOW);
+ MainApp.bus().post(new EventNewNotification(notification));
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java
index 3dcec0920f..b943571089 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives;
+package info.nightscout.androidaps.plugins.constraints.objectives;
import android.app.Activity;
import android.os.Bundle;
@@ -22,9 +22,9 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective;
-import info.nightscout.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective;
+import info.nightscout.androidaps.utils.FabricPrivacy;
public class ObjectivesFragment extends SubscriberFragment {
RecyclerView recyclerView;
@@ -120,6 +120,7 @@ public class ObjectivesFragment extends SubscriberFragment {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position);
holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1));
+ holder.revert.setVisibility(View.INVISIBLE);
if (objective.getObjective() != 0) {
holder.objective.setVisibility(View.VISIBLE);
holder.objective.setText(MainApp.gs(objective.getObjective()));
@@ -145,6 +146,9 @@ public class ObjectivesFragment extends SubscriberFragment {
holder.verify.setVisibility(View.VISIBLE);
holder.verify.setEnabled(objective.isCompleted() || enableFake.isChecked());
holder.start.setVisibility(View.GONE);
+ if(objective.isRevertable()) {
+ holder.revert.setVisibility(View.VISIBLE);
+ }
holder.progress.setVisibility(View.VISIBLE);
holder.progress.removeAllViews();
for (Objective.Task task : objective.getTasks()) {
@@ -169,8 +173,20 @@ public class ObjectivesFragment extends SubscriberFragment {
scrollToCurrentObjective();
startUpdateTimer();
});
+ holder.revert.setOnClickListener((view) -> {
+ objective.setAccomplishedOn(null);
+ objective.setStartedOn(null);
+ if (position > 0) {
+ Objective prevObj = ObjectivesPlugin.getPlugin().getObjectives().get(position - 1);
+ prevObj.setAccomplishedOn(null);
+ }
+ notifyDataSetChanged();
+ scrollToCurrentObjective();
+ });
}
+
+
@Override
public int getItemCount() {
return ObjectivesPlugin.getPlugin().getObjectives().size();
@@ -185,6 +201,7 @@ public class ObjectivesFragment extends SubscriberFragment {
public LinearLayout progress;
public Button verify;
public Button start;
+ public Button revert;
public ViewHolder(View itemView) {
super(itemView);
@@ -195,6 +212,7 @@ public class ObjectivesFragment extends SubscriberFragment {
progress = itemView.findViewById(R.id.objective_progress);
verify = itemView.findViewById(R.id.objective_verify);
start = itemView.findViewById(R.id.objective_start);
+ revert = itemView.findViewById(R.id.objective_back);
}
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java
index cc50189346..1d18cd14b4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives;
+package info.nightscout.androidaps.plugins.constraints.objectives;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -16,18 +16,18 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.events.EventObjectivesSaved;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective1;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective2;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective3;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective4;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective5;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective6;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective7;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives.Objective8;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesSaved;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective1;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective2;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective3;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective4;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective6;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective7;
+import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective8;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java
similarity index 57%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java
index 1822368cf9..d4dbb0251d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/events/EventObjectivesSaved.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.events;
+package info.nightscout.androidaps.plugins.constraints.objectives.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java
index 5127f64b34..83abe15688 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import android.support.annotation.StringRes;
@@ -8,8 +8,8 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
public abstract class Objective {
@@ -42,6 +42,10 @@ public abstract class Objective {
return true;
}
+ public boolean isRevertable() {
+ return false;
+ }
+
public boolean isAccomplished() {
return accomplishedOn != null;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java
index 39127c4d45..65a716abab 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
@@ -7,14 +7,14 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
-import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
+import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
public class Objective1 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java
index ac5485f953..6f97bfdd95 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
+import info.nightscout.androidaps.utils.T;
public class Objective2 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java
similarity index 71%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java
index 8a84e3c83c..4924d9434c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective3.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import info.nightscout.androidaps.R;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java
similarity index 73%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java
index 4cac10e514..1bbb4ef7c2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
+import info.nightscout.androidaps.utils.T;
public class Objective4 extends Objective {
@@ -25,4 +25,9 @@ public class Objective4 extends Objective {
}
});
}
+
+ @Override
+ public boolean isRevertable() {
+ return true;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java
index 8472f26c6c..b04062655a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.T;
public class Objective5 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java
similarity index 74%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java
index 7867b28e70..284dfa3ab0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.T;
public class Objective6 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java
similarity index 73%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java
index 670cffe746..f90411ecfb 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.T;
public class Objective7 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java
similarity index 74%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java
index 9ac4f9b6d7..7148f5e5ad 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives;
+package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.T;
public class Objective8 extends Objective {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
similarity index 80%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
index 9229164eb0..65dc119c6a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java
@@ -1,5 +1,6 @@
-package info.nightscout.androidaps.plugins.ConstraintsSafety;
+package info.nightscout.androidaps.plugins.constraints.safety;
+import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ConstraintChecker;
@@ -12,16 +13,17 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
-import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
@@ -94,6 +96,17 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
return value;
}
+ @Override
+ public Constraint isUAMEnabled(Constraint value) {
+ boolean enabled = SP.getBoolean(R.string.key_use_uam, false);
+ if (!enabled)
+ value.set(false, MainApp.gs(R.string.uamdisabledinpreferences), this);
+ boolean oref1Enabled = SensitivityOref1Plugin.getPlugin().isEnabled(PluginType.SENSITIVITY);
+ if (!oref1Enabled)
+ value.set(false, MainApp.gs(R.string.uamdisabledoref1notselected), this);
+ return value;
+ }
+
@Override
public Constraint isAdvancedFilteringEnabled(Constraint value) {
BgSourceInterface bgSource = ConfigBuilderPlugin.getPlugin().getActiveBgSource();
@@ -110,17 +123,19 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
absoluteRate.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingbasalratio), 0d, MainApp.gs(R.string.itmustbepositivevalue)), this);
- double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d);
- absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this);
+ if (Config.APS) {
+ double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d);
+ absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this);
- // Check percentRate but absolute rate too, because we know real current basal in pump
- Double maxBasalMult = SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d);
- double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100;
- absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier)), this);
+ // Check percentRate but absolute rate too, because we know real current basal in pump
+ Double maxBasalMult = SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d);
+ double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100;
+ absoluteRate.setIfSmaller(maxFromBasalMult, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromBasalMult, MainApp.gs(R.string.maxbasalmultiplier)), this);
- Double maxBasalFromDaily = SP.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d);
- double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100;
- absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier)), this);
+ Double maxBasalFromDaily = SP.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d);
+ double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100;
+ absoluteRate.setIfSmaller(maxFromDaily, String.format(MainApp.gs(R.string.limitingbasalratio), maxFromDaily, MainApp.gs(R.string.maxdailybasalmultiplier)), this);
+ }
absoluteRate.setIfSmaller(HardLimits.maxBasal(), String.format(MainApp.gs(R.string.limitingbasalratio), HardLimits.maxBasal(), MainApp.gs(R.string.hardlimit)), this);
@@ -187,7 +202,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
return insulin;
}
- @Override
+ @Override
public Constraint applyExtendedBolusConstraints(Constraint insulin) {
insulin.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingextendedbolus), 0d, MainApp.gs(R.string.itmustbepositivevalue)), this);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java
new file mode 100644
index 0000000000..197fd5c17a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java
@@ -0,0 +1,76 @@
+package info.nightscout.androidaps.plugins.constraints.storage;
+
+import android.os.Environment;
+import android.os.StatFs;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.Constraint;
+import info.nightscout.androidaps.interfaces.ConstraintsInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PluginDescription;
+import info.nightscout.androidaps.interfaces.PluginType;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+
+/**
+ * Created by Rumen on 06.03.2019.
+ */
+public class StorageConstraintPlugin extends PluginBase implements ConstraintsInterface {
+ private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
+ static StorageConstraintPlugin plugin = null;
+
+ public static StorageConstraintPlugin getPlugin() {
+ if (plugin == null)
+ plugin = new StorageConstraintPlugin();
+ return plugin;
+ }
+
+ public StorageConstraintPlugin() {
+ super(new PluginDescription()
+ .mainType(PluginType.CONSTRAINTS)
+ .neverVisible(true)
+ .alwaysEnabled(true)
+ .showInList(false)
+ .pluginName(R.string.storage)
+ );
+ }
+
+ /**
+ * Constraints interface
+ **/
+
+ @Override
+ public Constraint isClosedLoopAllowed(Constraint value) {
+ long diskfree = getAvailableInternalMemorySize();
+ if (L.isEnabled(L.CONSTRAINTS))
+ log.debug("Internal storage free (Mb):" + diskfree);
+ if (diskfree < Constants.MINIMUM_FREE_SPACE) {
+ value.set(false, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this);
+ Notification notification = new Notification(Notification.DISKFULL, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
+ } else {
+ MainApp.bus().post(new EventDismissNotification(Notification.DISKFULL));
+ }
+
+ return value;
+ }
+
+ public static long getAvailableInternalMemorySize() {
+ File path = Environment.getDataDirectory();
+ StatFs stat = new StatFs(path.getPath());
+ long blockSize = stat.getBlockSizeLong();
+ long blocksAvailable = stat.getAvailableBlocksLong();
+ int size = 1048576; // blocksize of 1 Mb
+ return ((blocksAvailable * blockSize) / size);
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java
index a71b447d82..02ff6e6b5c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java
@@ -1,18 +1,25 @@
-package info.nightscout.androidaps.plugins.Actions;
+package info.nightscout.androidaps.plugins.general.actions;
import android.app.Activity;
import android.content.Intent;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.LinearLayout;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.activities.HistoryBrowseActivity;
import info.nightscout.androidaps.MainApp;
@@ -25,18 +32,21 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
-import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
-import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog;
-import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.SingleClickButton;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
+import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog;
+import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog;
+import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog;
+import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.SingleClickButton;
+
/**
* A simple {@link Fragment} subclass.
@@ -49,6 +59,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
return actionsPlugin;
}
+ View actionsFragmentView;
SingleClickButton profileSwitch;
SingleClickButton tempTarget;
SingleClickButton extendedBolus;
@@ -59,6 +70,9 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
SingleClickButton tddStats;
SingleClickButton history;
+ private Map pumpCustomActions = new HashMap<>();
+ private List pumpCustomButtons = new ArrayList<>();
+
public ActionsFragment() {
super();
}
@@ -90,6 +104,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
history.setOnClickListener(this);
tddStats.setOnClickListener(this);
+ actionsFragmentView = view;
+
updateGUI();
return view;
} catch (Exception e) {
@@ -192,13 +208,87 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
else
tempTarget.setVisibility(View.VISIBLE);
- if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE);
- else tddStats.setVisibility(View.VISIBLE);
+ if (!pump.getPumpDescription().supportsTDDs)
+ tddStats.setVisibility(View.GONE);
+ else
+ tddStats.setVisibility(View.VISIBLE);
+
+ checkPumpCustomActions();
+
}
});
}
+ View.OnClickListener pumpCustomActionsListener = v -> {
+
+ SingleClickButton btn = (SingleClickButton)v;
+
+ CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString());
+
+ ConfigBuilderPlugin.getPlugin().getActivePump().executeCustomAction(customAction.getCustomActionType());
+
+ };
+
+
+ private void checkPumpCustomActions() {
+
+ PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
+
+ removePumpCustomActions();
+
+ if (activePump == null) {
+ return;
+ }
+
+ List customActions = activePump.getCustomActions();
+
+ if (customActions != null && customActions.size()>0) {
+
+ LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
+
+ for (CustomAction customAction : customActions) {
+
+ SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle);
+ btn.setText(MainApp.gs(customAction.getName()));
+
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f);
+ layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3
+
+ btn.setLayoutParams(layoutParams);
+ btn.setOnClickListener(pumpCustomActionsListener);
+
+ Drawable top = getResources().getDrawable(customAction.getIconResourceId());
+ btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null);
+
+ ll.addView(btn);
+
+ this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction);
+ this.pumpCustomButtons.add(btn);
+
+ }
+ }
+
+ }
+
+
+ private void removePumpCustomActions() {
+
+ if (pumpCustomActions.size()==0)
+ return;
+
+ LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
+
+ for (SingleClickButton customButton : pumpCustomButtons) {
+ ll.removeView(customButton);
+ }
+
+ pumpCustomButtons.clear();
+ pumpCustomActions.clear();
+ }
+
+
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java
index ff6275c9c9..5d47206e5c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Actions;
+package info.nightscout.androidaps.plugins.general.actions;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java
new file mode 100644
index 0000000000..e5e119baad
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java
@@ -0,0 +1,47 @@
+package info.nightscout.androidaps.plugins.general.actions.defs;
+
+import info.nightscout.androidaps.R;
+
+/**
+ * Created by andy on 9/20/18.
+ */
+
+public class CustomAction {
+
+ private int name;
+ private String iconName;
+ private CustomActionType customActionType;
+ private int iconResourceId;
+
+
+ public CustomAction(int nameResourceId, CustomActionType actionType) {
+ this.name = nameResourceId;
+ this.customActionType = actionType;
+ this.iconResourceId = R.drawable.icon_actions_profileswitch;
+ }
+
+ public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId) {
+ this.name = nameResourceId;
+ this.customActionType = actionType;
+ this.iconResourceId = iconResourceId;
+ }
+
+
+ public int getName() {
+
+ return name;
+ }
+
+
+
+
+ public CustomActionType getCustomActionType() {
+
+ return customActionType;
+ }
+
+
+ public int getIconResourceId() {
+ return iconResourceId;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java
new file mode 100644
index 0000000000..74ecf3c0e3
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java
@@ -0,0 +1,11 @@
+package info.nightscout.androidaps.plugins.general.actions.defs;
+
+/**
+ * Created by andy on 9/20/18.
+ */
+
+public interface CustomActionType {
+
+ String getKey();
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java
index 880bee86a8..45333040e1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Actions.dialogs;
+package info.nightscout.androidaps.plugins.general.actions.dialogs;
import android.content.Context;
import android.content.Intent;
@@ -34,18 +34,18 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.ToastUtils;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
public class FillDialog extends DialogFragment implements OnClickListener {
private static Logger log = LoggerFactory.getLogger(FillDialog.class);
@@ -185,7 +185,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
confirmMessage.add(MainApp.gs(R.string.fillwarning));
confirmMessage.add("");
confirmMessage.add(MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + "");
- if (!insulinAfterConstraints.equals(insulin))
+ if (Math.abs(insulinAfterConstraints - insulin) > 0.01d)
confirmMessage.add("" + MainApp.gs(R.string.bolusconstraintapplied) + "");
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java
index 710874a790..3ba1ff3177 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewExtendedBolusDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Actions.dialogs;
+package info.nightscout.androidaps.plugins.general.actions.dialogs;
import android.content.Context;
import android.content.DialogInterface;
@@ -12,7 +12,6 @@ import android.view.ViewGroup;
import com.crashlytics.android.answers.CustomEvent;
-import org.mozilla.javascript.tools.jsc.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,12 +20,12 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SafeParse;
public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java
index 95abf173db..ae8ca782d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/NewTempBasalDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Actions.dialogs;
+package info.nightscout.androidaps.plugins.general.actions.dialogs;
import android.content.DialogInterface;
import android.content.Intent;
@@ -24,13 +24,13 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpDescription;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SafeParse;
public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(NewTempBasalDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java
index c0de76ee37..96cf65fc93 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.java
@@ -1,16 +1,75 @@
package info.nightscout.androidaps.plugins.general.automation;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.plugins.general.automation.actions.Action;
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
public class AutomationEvent {
- Trigger trigger;
- List actions = new ArrayList<>();
+ private Trigger trigger = new TriggerConnector();
+ private List actions = new ArrayList<>();
+ private String title;
- AutomationEvent() {
+ public void setTitle(String title) { this.title = title; }
+
+ public void setTrigger(Trigger trigger) { this.trigger = trigger; }
+
+ public Trigger getTrigger() {
+ return trigger;
+ }
+
+ public List getActions() {
+ return actions;
+ }
+
+ public void addAction(Action action) { actions.add(action); }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String toJSON() {
+ JSONObject o = new JSONObject();
+ try {
+ // title
+ o.put("title", title);
+ // trigger
+ o.put("trigger", trigger.toJSON());
+ // actions
+ JSONArray array = new JSONArray();
+ for (Action a : actions) {
+ array.put(a.toJSON());
+ }
+ o.put("actions", array);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return o.toString();
+ }
+
+ public AutomationEvent fromJSON(String data) {
+ try {
+ JSONObject d = new JSONObject(data);
+ // title
+ title = d.optString("title", "");
+ // trigger
+ trigger = Trigger.instantiate(d.getString("trigger"));
+ // actions
+ JSONArray array = d.getJSONArray("actions");
+ actions.clear();
+ for (int i = 0; i < array.length(); i++) {
+ actions.add(Action.instantiate(new JSONObject(array.getString(i))));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return this;
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java
index 0e9eccd84e..ea3d4a8e7d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java
@@ -1,24 +1,400 @@
package info.nightscout.androidaps.plugins.general.automation;
+import android.app.Activity;
+import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.DrawableRes;
+import android.support.annotation.NonNull;
+import android.support.v4.app.FragmentManager;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+import java.util.HashSet;
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.general.automation.actions.Action;
+import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog;
+import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog;
+import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog;
+import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
public class AutomationFragment extends SubscriberFragment {
+ @BindView(R.id.eventListView)
+ RecyclerView mEventListView;
+
+ private EventListAdapter mEventListAdapter;
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+
View view = inflater.inflate(R.layout.automation_fragment, container, false);
+ unbinder = ButterKnife.bind(this, view);
+
+ final AutomationPlugin plugin = AutomationPlugin.getPlugin();
+ mEventListAdapter = new EventListAdapter(plugin.getAutomationEvents(), getFragmentManager());
+ mEventListView.setLayoutManager(new LinearLayoutManager(getContext()));
+ mEventListView.setAdapter(mEventListAdapter);
+
+ EditEventDialog.setOnClickListener(event -> mEventListAdapter.notifyDataSetChanged());
+
+ updateGUI();
+
return view;
}
@Override
- protected void updateGUI() {
-
+ public void updateGUI() {
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.runOnUiThread(() -> mEventListAdapter.notifyDataSetChanged());
}
+
+ @OnClick(R.id.fabAddEvent)
+ void onClickAddEvent(View v) {
+ EditEventDialog dialog = EditEventDialog.newInstance(new AutomationEvent(), true);
+ dialog.show(getFragmentManager(), "EditEventDialog");
+ }
+
+ /**
+ * RecyclerViewAdapter to display event lists.
+ */
+ public static class EventListAdapter extends RecyclerView.Adapter {
+ private final List mEventList;
+ private final FragmentManager mFragmentManager;
+
+ public EventListAdapter(List events, FragmentManager fragmentManager) {
+ this.mEventList = events;
+ this.mFragmentManager = fragmentManager;
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_event_item, parent, false);
+ return new ViewHolder(v, parent.getContext());
+ }
+
+ private void addImage(@DrawableRes int res, Context context, LinearLayout layout) {
+ ImageView iv = new ImageView(context);
+ iv.setImageResource(res);
+ iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24)));
+ layout.addView(iv);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
+ final AutomationEvent event = mEventList.get(position);
+ holder.eventTitle.setText(event.getTitle());
+ holder.iconLayout.removeAllViews();
+
+ // trigger icons
+ HashSet triggerIcons = new HashSet<>();
+ TriggerConnector.fillIconSet((TriggerConnector)event.getTrigger(), triggerIcons);
+ for(int res : triggerIcons) {
+ addImage(res, holder.context, holder.iconLayout);
+ }
+
+ // arrow icon
+ ImageView iv = new ImageView(holder.context);
+ iv.setImageResource(R.drawable.ic_arrow_forward_white_24dp);
+ iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24)));
+ iv.setPadding(MainApp.dpToPx(4), 0, MainApp.dpToPx(4), 0);
+ holder.iconLayout.addView(iv);
+
+ // action icons
+ HashSet actionIcons = new HashSet<>();
+ for(Action action : event.getActions()) {
+ if (action.icon().isPresent())
+ actionIcons.add(action.icon().get());
+ }
+ for(int res : actionIcons) {
+ addImage(res, holder.context, holder.iconLayout);
+ }
+
+ // remove event
+ holder.iconTrash.setOnClickListener(v -> {
+ mEventList.remove(event);
+ notifyDataSetChanged();
+ });
+
+ // edit event
+ holder.rootLayout.setOnClickListener(v -> {
+ EditEventDialog dialog = EditEventDialog.newInstance(event, false);
+ dialog.show(mFragmentManager, "EditEventDialog");
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return mEventList.size();
+ }
+
+ static class ViewHolder extends RecyclerView.ViewHolder {
+ final RelativeLayout rootLayout;
+ final LinearLayout iconLayout;
+ final TextView eventTitle;
+ final Context context;
+ final ImageView iconTrash;
+
+ public ViewHolder(View view, Context context) {
+ super(view);
+ this.context = context;
+ eventTitle = view.findViewById(R.id.viewEventTitle);
+ rootLayout = view.findViewById(R.id.rootLayout);
+ iconLayout = view.findViewById(R.id.iconLayout);
+ iconTrash = view.findViewById(R.id.iconTrash);
+ }
+ }
+ }
+
+ /**
+ * RecyclerViewAdapter to display action lists.
+ */
+ public static class ActionListAdapter extends RecyclerView.Adapter {
+ private final List mActionList;
+ private final FragmentManager mFragmentManager;
+
+ public ActionListAdapter(FragmentManager manager, List events) {
+ this.mActionList = events;
+ this.mFragmentManager = manager;
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_action_item, parent, false);
+ return new ViewHolder(v);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
+ final Action action = mActionList.get(position);
+ holder.actionTitle.setText(action.friendlyName());
+ holder.layoutText.setOnClickListener(v -> {
+ if (action.hasDialog()) {
+ EditActionDialog dialog = EditActionDialog.newInstance(action);
+ dialog.show(mFragmentManager, "EditActionDialog");
+ }
+ });
+ holder.iconTrash.setOnClickListener(v -> {
+ mActionList.remove(action);
+ notifyDataSetChanged();
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return mActionList.size();
+ }
+
+ static class ViewHolder extends RecyclerView.ViewHolder {
+ TextView actionTitle;
+ TextView actionDescription;
+ LinearLayout layoutText;
+ ImageView iconTrash;
+
+ public ViewHolder(View view) {
+ super(view);
+ layoutText = view.findViewById(R.id.layoutText);
+ actionTitle = view.findViewById(R.id.viewActionTitle);
+ actionDescription = view.findViewById(R.id.viewActionDescription);
+ iconTrash = view.findViewById(R.id.iconTrash);
+ }
+ }
+ }
+
+ /**
+ * Custom Adapter to display triggers dynamically with nested linear layouts.
+ */
+ public static class TriggerListAdapter {
+ private final LinearLayout mRootLayout;
+ private final Context mContext;
+ private final TriggerConnector mRootConnector;
+ private final FragmentManager mFragmentManager;
+
+ public TriggerListAdapter(Context context, FragmentManager fragmentManager, LinearLayout rootLayout, TriggerConnector rootTrigger) {
+ mRootLayout = rootLayout;
+ mContext = context;
+ mFragmentManager = fragmentManager;
+ mRootConnector = rootTrigger;
+ build();
+ }
+
+ public Context getContext() {
+ return mContext;
+ }
+
+ public LinearLayout getRootLayout() {
+ return mRootLayout;
+ }
+
+ public FragmentManager getFragmentManager() {
+ return mFragmentManager;
+ }
+
+ public void destroy() {
+ mRootLayout.removeAllViews();
+ }
+
+ private void build() {
+ for(int i = 0; i < mRootConnector.size(); ++i) {
+ final Trigger trigger = mRootConnector.get(i);
+
+ // spinner
+ if (i > 0) {
+ createSpinner(trigger);
+ }
+
+ // trigger layout
+ mRootLayout.addView(trigger.createView(mContext, mFragmentManager));
+
+ // buttons
+ createButtons(trigger);
+ }
+
+ if (mRootConnector.size() == 0) {
+ Button buttonAdd = new Button(mContext);
+ buttonAdd.setText("Add New");
+ buttonAdd.setOnClickListener(v -> {
+ ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance();
+ dialog.setOnClickListener(newTriggerObject -> {
+ mRootConnector.add(newTriggerObject);
+ rebuild();
+ });
+ dialog.show(mFragmentManager, "ChooseTriggerDialog");
+ });
+ mRootLayout.addView(buttonAdd);
+ }
+ }
+
+ private Spinner createSpinner() {
+ Spinner spinner = new Spinner(mContext);
+ ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, TriggerConnector.Type.labels());
+ spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(spinnerArrayAdapter);
+ return spinner;
+ }
+
+ private void createSpinner(Trigger trigger) {
+ final TriggerConnector connector = trigger.getConnector();
+ final int initialPosition = connector.getConnectorType().ordinal();
+ Spinner spinner = createSpinner();
+ spinner.setSelection(initialPosition);
+ spinner.setBackgroundColor(MainApp.gc(R.color.black_overlay));
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ );
+ params.setMargins(0, MainApp.dpToPx(8), 0, MainApp.dpToPx(8));
+ spinner.setLayoutParams(params);
+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ if (position != initialPosition) {
+ // conector type changed
+ changeConnector(trigger, connector, TriggerConnector.Type.values()[position]);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) { }
+ });
+ mRootLayout.addView(spinner);
+ }
+
+ private void createButtons(Trigger trigger) {
+ // do not create buttons for TriggerConnector
+ if (trigger instanceof TriggerConnector) {
+ return;
+ }
+
+ // Button Layout
+ LinearLayout buttonLayout = new LinearLayout(mContext);
+ buttonLayout.setOrientation(LinearLayout.HORIZONTAL);
+ buttonLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ mRootLayout.addView(buttonLayout);
+
+ // Button [-]
+ Button buttonRemove = new Button(mContext);
+ buttonRemove.setText("del");
+ buttonRemove.setOnClickListener(v -> {
+ final TriggerConnector connector = trigger.getConnector();
+ connector.remove(trigger);
+ connector.simplify().rebuildView();
+ });
+ buttonLayout.addView(buttonRemove);
+
+ // Button [+]
+ Button buttonAdd = new Button(mContext);
+ buttonAdd.setText("add");
+ buttonAdd.setOnClickListener(v -> {
+ ChooseTriggerDialog dialog = ChooseTriggerDialog.newInstance();
+ dialog.show(mFragmentManager, "ChooseTriggerDialog");
+ dialog.setOnClickListener(newTriggerObject -> {
+ TriggerConnector connector = trigger.getConnector();
+ connector.add(connector.pos(trigger)+1, newTriggerObject);
+ connector.simplify().rebuildView();
+ });
+ });
+ buttonLayout.addView(buttonAdd);
+
+ // Button [*]
+ Button buttonCopy = new Button(mContext);
+ buttonCopy.setText("copy");
+ buttonCopy.setOnClickListener(v -> {
+ TriggerConnector connector = trigger.getConnector();
+ connector.add(connector.pos(trigger)+1, trigger.duplicate());
+ connector.simplify().rebuildView();
+ });
+ buttonLayout.addView(buttonCopy);
+ }
+
+ public static void changeConnector(final Trigger trigger, final TriggerConnector connector, final TriggerConnector.Type newConnectorType) {
+ if (connector.size() > 2) {
+ // split connector
+ int pos = connector.pos(trigger) - 1;
+
+ TriggerConnector newConnector = new TriggerConnector(newConnectorType);
+
+ // move trigger from pos and pos+1 into new connector
+ for(int i = 0; i < 2; ++i) {
+ Trigger t = connector.get(pos);
+ newConnector.add(t);
+ connector.remove(t);
+ }
+
+ connector.add(pos, newConnector);
+ } else {
+ connector.changeConnectorType(newConnectorType);
+ }
+
+ connector.simplify().rebuildView();
+ }
+
+ public void rebuild() {
+ destroy();
+ build();
+ }
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java
index 22526a50df..a65c4fee4b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.java
@@ -18,7 +18,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.services.LocationService;
public class AutomationPlugin extends PluginBase {
@@ -31,10 +31,10 @@ public class AutomationPlugin extends PluginBase {
return plugin;
}
- List automationEvents = new ArrayList<>();
- EventLocationChange eventLocationChange;
- EventChargingState eventChargingState;
- EventNetworkChange eventNetworkChange;
+ private final List automationEvents = new ArrayList<>();
+ private EventLocationChange eventLocationChange;
+ private EventChargingState eventChargingState;
+ private EventNetworkChange eventNetworkChange;
private AutomationPlugin() {
super(new PluginDescription()
@@ -64,6 +64,22 @@ public class AutomationPlugin extends PluginBase {
MainApp.bus().unregister(this);
}
+ public List getAutomationEvents() {
+ return automationEvents;
+ }
+
+ public EventLocationChange getEventLocationChange() {
+ return eventLocationChange;
+ }
+
+ public EventChargingState getEventChargingState() {
+ return eventChargingState;
+ }
+
+ public EventNetworkChange getEventNetworkChange() {
+ return eventNetworkChange;
+ }
+
@Subscribe
public void onEventPreferenceChange(EventPreferenceChange e) {
if (e.isChanged(R.string.key_location)) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java
index b74243326e..546cc6b272 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java
@@ -1,9 +1,62 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import android.widget.LinearLayout;
+
+import com.google.common.base.Optional;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
import info.nightscout.androidaps.queue.Callback;
public abstract class Action {
- abstract int friendlyName();
+ public abstract int friendlyName();
+
abstract void doAction(Callback callback);
+
+ public void generateDialog(LinearLayout root) { }
+
+ public boolean hasDialog() { return false; }
+
+ public String toJSON() {
+ JSONObject o = new JSONObject();
+ try {
+ o.put("type", this.getClass().getName());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return o.toString();
+ }
+
+ public abstract Optional icon();
+
+ public Action fromJSON(String data) {
+ return this;
+ }
+
+ public static Action instantiate(JSONObject object) {
+ try {
+ String type = object.getString("type");
+ JSONObject data = object.optJSONObject("data");
+ Class clazz = Class.forName(type);
+ return ((Action) clazz.newInstance()).fromJSON(data != null ? data.toString() : "");
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public void apply(Action a) {
+ try {
+ JSONObject object = new JSONObject(a.toJSON());
+ String type = object.getString("type");
+ JSONObject data = object.getJSONObject("data");
+ if (type.equals(getClass().getName())) {
+ fromJSON(data.toString());
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java
index 059bdacaf3..794d4a31ce 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java
@@ -1,17 +1,19 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import com.google.common.base.Optional;
+
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.queue.Callback;
public class ActionLoopDisable extends Action {
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.disableloop;
}
@@ -33,4 +35,9 @@ public class ActionLoopDisable extends Action {
callback.result(new PumpEnactResult().success(true).comment(R.string.alreadydisabled)).run();
}
}
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.ic_stop_24dp);
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java
index 1ef1ec81a6..6e8839f353 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java
@@ -1,17 +1,19 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import com.google.common.base.Optional;
+
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.queue.Callback;
public class ActionLoopEnable extends Action {
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.enableloop;
}
@@ -28,4 +30,9 @@ public class ActionLoopEnable extends Action {
callback.result(new PumpEnactResult().success(true).comment(R.string.alreadyenabled)).run();
}
}
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.ic_play_circle_outline_24dp);
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java
index 71244c70f4..c734acd541 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java
@@ -1,18 +1,19 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import com.google.common.base.Optional;
+
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventRefreshOverview;
-import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.queue.Callback;
public class ActionLoopResume extends Action {
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.resumeloop;
}
@@ -30,4 +31,9 @@ public class ActionLoopResume extends Action {
callback.result(new PumpEnactResult().success(true).comment(R.string.notsuspended)).run();
}
}
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.ic_replay_24dp);
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java
index eb9ddfd79c..4938a6939d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java
@@ -1,18 +1,20 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import com.google.common.base.Optional;
+
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventRefreshOverview;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.queue.Callback;
public class ActionLoopSuspend extends Action {
- int minutes;
+ private int minutes;
@Override
- int friendlyName() {
- return R.string.disableloop;
+ public int friendlyName() {
+ return R.string.suspendloop;
}
@Override
@@ -27,4 +29,9 @@ public class ActionLoopSuspend extends Action {
callback.result(new PumpEnactResult().success(true).comment(R.string.alreadysuspended)).run();
}
}
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.ic_pause_circle_outline_24dp);
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java
index 8cd8db0f4e..f033e3b679 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java
@@ -1,33 +1,101 @@
package info.nightscout.androidaps.plugins.general.automation.actions;
+import android.widget.LinearLayout;
+
+import com.google.common.base.Optional;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
+import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
+import info.nightscout.androidaps.plugins.general.automation.elements.Label;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.JsonHelper;
public class ActionStartTempTarget extends Action {
+ private String reason = "";
+ private InputBg value;
+ private InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
- double value;
- int durationInMinutes;
- String reason;
- String units = Constants.MGDL;
+ public ActionStartTempTarget() {
+ value = new InputBg(Constants.MGDL);
+ }
+
+ public ActionStartTempTarget(String units) {
+ value = new InputBg(units);
+ }
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.starttemptarget;
}
@Override
void doAction(Callback callback) {
- double converted = Profile.toMgdl(value, units);
- TempTarget tempTarget = new TempTarget().date(DateUtil.now()).duration(durationInMinutes).reason(reason).source(Source.USER).low(converted).high(converted);
+ TempTarget tempTarget = new TempTarget().date(DateUtil.now()).duration((int)duration.getMinutes()).reason(reason).source(Source.USER).low(value.getMgdl()).high(value.getMgdl());
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
if (callback != null)
callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run();
}
+
+ @Override
+ public void generateDialog(LinearLayout root) {
+ int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol;
+
+ new LayoutBuilder()
+ .add(new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value))
+ .add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration))
+ .build(root);
+ }
+
+ @Override
+ public boolean hasDialog() {
+ return true;
+ }
+
+ @Override
+ public String toJSON() {
+ JSONObject o = new JSONObject();
+ try {
+ o.put("type", ActionStartTempTarget.class.getName());
+ JSONObject data = new JSONObject();
+ data.put("reason", reason);
+ data.put("valueInMg", value.getMgdl());
+ data.put("units", value.getUnits());
+ data.put("durationInMinutes", duration.getMinutes());
+ o.put("data", data);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return o.toString();
+ }
+
+ @Override
+ public Action fromJSON(String data) {
+ try {
+ JSONObject d = new JSONObject(data);
+ reason = JsonHelper.safeGetString(d, "reason");
+ value.setUnits(JsonHelper.safeGetString(d, "units"));
+ value.setMgdl(JsonHelper.safeGetInt(d, "valueInMg"));
+ duration.setMinutes(JsonHelper.safeGetDouble(d, "durationInMinutes"));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return this;
+ }
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.icon_cp_cgm_target);
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java
new file mode 100644
index 0000000000..12956dd108
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.java
@@ -0,0 +1,139 @@
+package info.nightscout.androidaps.plugins.general.automation.dialogs;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import butterknife.Unbinder;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.actions.Action;
+import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopDisable;
+import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable;
+import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopResume;
+import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopSuspend;
+import info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget;
+
+public class ChooseActionDialog extends DialogFragment {
+
+ public interface OnClickListener {
+ void onClick(Action newActionObject);
+ }
+
+ private static OnClickListener mClickListener = null;
+
+ private static final List actionDummyObjects = new ArrayList() {{
+ add(new ActionLoopDisable());
+ add(new ActionLoopEnable());
+ add(new ActionLoopResume());
+ add(new ActionLoopSuspend());
+ add(new ActionStartTempTarget());
+ }};
+
+ private Unbinder mUnbinder;
+
+ @BindView(R.id.radioGroup)
+ RadioGroup mRadioGroup;
+
+ public static ChooseActionDialog newInstance() {
+ Bundle args = new Bundle();
+
+ ChooseActionDialog fragment = new ChooseActionDialog();
+ fragment.setArguments(args);
+
+ return fragment;
+ }
+
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.automation_dialog_choose_action, container, false);
+ mUnbinder = ButterKnife.bind(this, view);
+
+ for(Action a : actionDummyObjects) {
+ RadioButton radioButton = new RadioButton(getContext());
+ radioButton.setText(a.friendlyName());
+ radioButton.setTag(a);
+ mRadioGroup.addView(radioButton);
+ }
+
+ // restore checked radio button
+ int checkedIndex = 0;
+ if (savedInstanceState != null) {
+ checkedIndex = savedInstanceState.getInt("checkedIndex");
+ }
+
+ ((RadioButton)mRadioGroup.getChildAt(checkedIndex)).setChecked(true);
+
+ return view;
+ }
+
+ private int getCheckedIndex() {
+ for(int i = 0; i < mRadioGroup.getChildCount(); ++i) {
+ if (((RadioButton)mRadioGroup.getChildAt(i)).isChecked())
+ return i;
+ }
+ return -1;
+ }
+
+ private Class getActionClass() {
+ int radioButtonID = mRadioGroup.getCheckedRadioButtonId();
+ RadioButton radioButton = mRadioGroup.findViewById(radioButtonID);
+ if (radioButton != null) {
+ Object tag = radioButton.getTag();
+ if (tag instanceof Action)
+ return tag.getClass();
+ }
+ return null;
+ }
+
+ private Action instantiateAction() {
+ Class actionClass = getActionClass();
+ if (actionClass != null) {
+ try {
+ return (Action) actionClass.newInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+
+ public static void setOnClickListener(OnClickListener clickListener) {
+ mClickListener = clickListener;
+ }
+
+ @Override
+ public void onDestroyView() {
+ mUnbinder.unbind();
+ super.onDestroyView();
+ }
+
+ @OnClick(R.id.ok)
+ public void onButtonOk(View view) {
+ if (mClickListener != null)
+ mClickListener.onClick(instantiateAction());
+
+ dismiss();
+ }
+
+ @OnClick(R.id.cancel)
+ public void onButtonCancel(View view) {
+ dismiss();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ bundle.putInt("checkedIndex", getCheckedIndex());
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java
new file mode 100644
index 0000000000..cdb6b0739f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.java
@@ -0,0 +1,132 @@
+package info.nightscout.androidaps.plugins.general.automation.dialogs;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import butterknife.Unbinder;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime;
+
+public class ChooseTriggerDialog extends DialogFragment {
+
+ public interface OnClickListener {
+ void onClick(Trigger newTriggerObject);
+ }
+
+ private static final List triggerDummyObjects = new ArrayList() {{
+ add(new TriggerBg());
+ add(new TriggerTime());
+ }};
+
+ private Unbinder mUnbinder;
+ private OnClickListener mClickListener = null;
+
+ @BindView(R.id.radioGroup)
+ RadioGroup mRadioGroup;
+
+ public static ChooseTriggerDialog newInstance() {
+ Bundle args = new Bundle();
+
+ ChooseTriggerDialog fragment = new ChooseTriggerDialog();
+ fragment.setArguments(args);
+
+ return fragment;
+ }
+
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.automation_dialog_choose_trigger, container, false);
+ mUnbinder = ButterKnife.bind(this, view);
+
+ for(Trigger t : triggerDummyObjects) {
+ RadioButton radioButton = new RadioButton(getContext());
+ radioButton.setText(t.friendlyName());
+ radioButton.setTag(t);
+ mRadioGroup.addView(radioButton);
+ }
+
+ // restore checked radio button
+ int checkedIndex = 0;
+ if (savedInstanceState != null) {
+ checkedIndex = savedInstanceState.getInt("checkedIndex");
+ }
+
+ ((RadioButton)mRadioGroup.getChildAt(checkedIndex)).setChecked(true);
+
+ return view;
+ }
+
+ private int getCheckedIndex() {
+ for(int i = 0; i < mRadioGroup.getChildCount(); ++i) {
+ if (((RadioButton)mRadioGroup.getChildAt(i)).isChecked())
+ return i;
+ }
+ return -1;
+ }
+
+ private Class getTriggerClass() {
+ int radioButtonID = mRadioGroup.getCheckedRadioButtonId();
+ RadioButton radioButton = mRadioGroup.findViewById(radioButtonID);
+ if (radioButton != null) {
+ Object tag = radioButton.getTag();
+ if (tag instanceof Trigger)
+ return tag.getClass();
+ }
+ return null;
+ }
+
+ private Trigger instantiateTrigger() {
+ Class triggerClass = getTriggerClass();
+ if (triggerClass != null) {
+ try {
+ return (Trigger) triggerClass.newInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+
+ public void setOnClickListener(OnClickListener clickListener) {
+ mClickListener = clickListener;
+ }
+
+ @Override
+ public void onDestroyView() {
+ mUnbinder.unbind();
+ super.onDestroyView();
+ }
+
+ @OnClick(R.id.ok)
+ public void onButtonOk(View view) {
+ if (mClickListener != null)
+ mClickListener.onClick(instantiateTrigger());
+
+ dismiss();
+ }
+
+ @OnClick(R.id.cancel)
+ public void onButtonCancel(View view) {
+ dismiss();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ bundle.putInt("checkedIndex", getCheckedIndex());
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java
new file mode 100644
index 0000000000..f0338afbfe
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.java
@@ -0,0 +1,94 @@
+package info.nightscout.androidaps.plugins.general.automation.dialogs;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import butterknife.Unbinder;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.actions.Action;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
+
+public class EditActionDialog extends DialogFragment {
+ private static Action resultAction;
+
+ private Unbinder mUnbinder;
+ private Action mAction;
+
+ @BindView(R.id.layout_root)
+ LinearLayout mRootLayout;
+
+ @BindView(R.id.viewActionTitle)
+ TextView mViewActionTitle;
+
+ public static EditActionDialog newInstance(Action action) {
+ Bundle args = new Bundle();
+ EditActionDialog fragment = new EditActionDialog();
+ fragment.setArguments(args);
+ resultAction = action;
+
+ return fragment;
+ }
+
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.automation_dialog_action, container, false);
+ mUnbinder = ButterKnife.bind(this, view);
+
+ // get json data for action
+ String actionData = null;
+ if (savedInstanceState != null) {
+ actionData = savedInstanceState.getString("action");
+ }
+ if (actionData == null) {
+ actionData = resultAction.toJSON();
+ }
+
+ // create action from json
+ try {
+ mAction = Action.instantiate(new JSONObject(actionData));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+
+ mViewActionTitle.setText(mAction.friendlyName());
+ mRootLayout.removeAllViews();
+ mAction.generateDialog(mRootLayout);
+
+ return view;
+ }
+
+ @Override
+ public void onDestroyView() {
+ mUnbinder.unbind();
+ super.onDestroyView();
+ }
+
+ @OnClick(R.id.ok)
+ public void onButtonOk(View view) {
+ resultAction.apply(mAction);
+ dismiss();
+ }
+
+ @OnClick(R.id.cancel)
+ public void onButtonCancel(View view) {
+ dismiss();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ bundle.putString("action", mAction.toJSON());
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java
new file mode 100644
index 0000000000..535aee578a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.java
@@ -0,0 +1,175 @@
+package info.nightscout.androidaps.plugins.general.automation.dialogs;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.design.widget.TextInputEditText;
+import android.support.v4.app.DialogFragment;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import butterknife.Unbinder;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.AutomationEvent;
+import info.nightscout.androidaps.plugins.general.automation.AutomationFragment;
+import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
+import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
+
+public class EditEventDialog extends DialogFragment {
+ public interface OnClickListener {
+ void onClick(AutomationEvent event);
+ }
+
+ private static OnClickListener mClickListener = null;
+ private static AutomationEvent staticEvent;
+
+ public static void setOnClickListener(OnClickListener clickListener) {
+ mClickListener = clickListener;
+ }
+
+ @BindView(R.id.inputEventTitle)
+ TextInputEditText mEditEventTitle;
+
+ @BindView(R.id.editTrigger)
+ TextView mEditTrigger;
+
+ @BindView(R.id.editAction)
+ TextView mEditAction;
+
+ @BindView(R.id.triggerDescription)
+ TextView mTriggerDescription;
+
+ @BindView(R.id.actionListView)
+ RecyclerView mActionListView;
+
+ private Unbinder mUnbinder;
+ private AutomationFragment.ActionListAdapter mActionListAdapter;
+ private AutomationEvent mEvent;
+ private boolean mAddNew;
+
+ public static EditEventDialog newInstance(AutomationEvent event, boolean addNew) {
+ staticEvent = event;
+
+ Bundle args = new Bundle();
+ EditEventDialog fragment = new EditEventDialog();
+ fragment.setArguments(args);
+ // clone event
+ try {
+ fragment.mEvent = new AutomationEvent().fromJSON(event.toJSON());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ fragment.mAddNew = addNew;
+ return fragment;
+ }
+
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.automation_dialog_event, container, false);
+ mUnbinder = ButterKnife.bind(this, view);
+
+ // load data from bundle
+ if (savedInstanceState != null) {
+ String eventData = savedInstanceState.getString("event");
+ if (eventData != null) mEvent = new AutomationEvent().fromJSON(eventData);
+ mAddNew = savedInstanceState.getBoolean("addNew");
+ } else if (mAddNew) {
+ mEvent.setTrigger(new TriggerConnector(TriggerConnector.Type.OR));
+ }
+
+ // event title
+ mEditEventTitle.setText(mEvent.getTitle());
+
+ // display root trigger
+ mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription());
+
+ // setup trigger click event listener
+ EditTriggerDialog.setOnClickListener(trigger -> {
+ mEvent.setTrigger(trigger);
+ mTriggerDescription.setText(mEvent.getTrigger().friendlyDescription());
+ });
+ mEditTrigger.setOnClickListener(v -> {
+ EditTriggerDialog dialog = EditTriggerDialog.newInstance(mEvent.getTrigger());
+ dialog.show(getFragmentManager(), "EditTriggerDialog");
+ });
+
+ // setup action list view
+ mActionListAdapter = new AutomationFragment.ActionListAdapter(getFragmentManager(), mEvent.getActions());
+ mActionListView.setLayoutManager(new LinearLayoutManager(getContext()));
+ mActionListView.setAdapter(mActionListAdapter);
+
+ // setup action click event listener
+ ChooseActionDialog.setOnClickListener(newActionObject -> {
+ mEvent.addAction(newActionObject);
+ mActionListAdapter.notifyDataSetChanged();
+ });
+ mEditAction.setOnClickListener(v -> {
+ ChooseActionDialog dialog = ChooseActionDialog.newInstance();
+ dialog.show(getFragmentManager(), "ChooseActionDialog");
+ });
+
+
+ return view;
+ }
+
+ @Override
+ public void onDestroyView() {
+ mUnbinder.unbind();
+ super.onDestroyView();
+ }
+
+ @OnClick(R.id.ok)
+ public void onButtonOk(View view) {
+ // check for title
+ String title = mEditEventTitle.getText().toString();
+ if (title.isEmpty()) {
+ Toast.makeText(getContext(), R.string.automation_missing_task_name, Toast.LENGTH_LONG).show();
+ return;
+ }
+ mEvent.setTitle(title);
+
+ // check for at least one trigger
+ TriggerConnector con = (TriggerConnector) mEvent.getTrigger();
+ if (con.size() == 0) {
+ Toast.makeText(getContext(), R.string.automation_missing_trigger, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ // check for at least one action
+ if (mEvent.getActions().isEmpty()) {
+ Toast.makeText(getContext(), R.string.automation_missing_action, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ // apply changes
+ staticEvent.fromJSON(mEvent.toJSON());
+
+ // add new
+ if (mAddNew) {
+ final AutomationPlugin plugin = AutomationPlugin.getPlugin();
+ plugin.getAutomationEvents().add(mEvent);
+ }
+
+ if (mClickListener != null) mClickListener.onClick(mEvent);
+ dismiss();
+ }
+
+ @OnClick(R.id.cancel)
+ public void onButtonCancel(View view) {
+ dismiss();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ bundle.putString("event", mEvent.toJSON());
+ bundle.putBoolean("addNew", mAddNew);
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java
new file mode 100644
index 0000000000..a22ed1380c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.java
@@ -0,0 +1,85 @@
+package info.nightscout.androidaps.plugins.general.automation.dialogs;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import butterknife.Unbinder;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
+
+public class EditTriggerDialog extends DialogFragment {
+
+ public interface OnClickListener {
+ void onClick(Trigger newTriggerObject);
+ }
+
+ private static OnClickListener mClickListener = null;
+
+ @BindView(R.id.layoutTrigger)
+ LinearLayout mLayoutTrigger;
+
+ private Trigger mTrigger;
+ private Unbinder mUnbinder;
+
+ public static EditTriggerDialog newInstance(Trigger trigger) {
+ Bundle args = new Bundle();
+ args.putString("trigger", trigger.toJSON());
+ EditTriggerDialog fragment = new EditTriggerDialog();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.automation_dialog_edit_trigger, container, false);
+ mUnbinder = ButterKnife.bind(this, view);
+
+ // load data from bundle
+ Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments();
+ if (bundle != null) {
+ String triggerData = bundle.getString("trigger");
+ if (triggerData != null) mTrigger = Trigger.instantiate(triggerData);
+ }
+
+ // display root trigger
+ mLayoutTrigger.addView(mTrigger.createView(getContext(), getFragmentManager()));
+
+ return view;
+ }
+
+ public static void setOnClickListener(OnClickListener clickListener) {
+ mClickListener = clickListener;
+ }
+
+ @Override
+ public void onDestroyView() {
+ mUnbinder.unbind();
+ super.onDestroyView();
+ }
+
+ @OnClick(R.id.ok)
+ public void onButtonOk(View view) {
+ if (mClickListener != null)
+ mClickListener.onClick(mTrigger);
+
+ dismiss();
+ }
+
+ @OnClick(R.id.cancel)
+ public void onButtonCancel(View view) {
+ dismiss();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ bundle.putString("trigger", mTrigger.toJSON());
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java
new file mode 100644
index 0000000000..bc9f49625a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java
@@ -0,0 +1,7 @@
+package info.nightscout.androidaps.plugins.general.automation.elements;
+
+import android.widget.LinearLayout;
+
+public class Element {
+ public void addToLayout(LinearLayout root) { }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java
new file mode 100644
index 0000000000..5118528611
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java
@@ -0,0 +1,87 @@
+package info.nightscout.androidaps.plugins.general.automation.elements;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.LinearLayout;
+
+import java.text.DecimalFormat;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.utils.NumberPicker;
+
+public class InputBg extends Element {
+ final private TextWatcher textWatcher = new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ // TODO: validate inputs
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+ };
+
+ private String units;
+ private double value;
+ private final double minValue, maxValue, step;
+ private final DecimalFormat decimalFormat;
+
+ public InputBg(String units) {
+ this.units = units;
+
+ // set default initial value
+ if (units.equals(Constants.MMOL)) {
+ // mmol
+ value = 5.5;
+ minValue = 2;
+ maxValue = 30;
+ step = 0.1;
+ decimalFormat = new DecimalFormat("0.0");
+ } else {
+ // mg/dL
+ value = 100;
+ minValue = 36;
+ maxValue = 540;
+ step = 1;
+ decimalFormat = new DecimalFormat("0");
+ }
+ }
+
+ @Override
+ public void addToLayout(LinearLayout root) {
+ NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
+ numberPicker.setParams(0d, minValue, maxValue, step, decimalFormat, false, textWatcher);
+ numberPicker.setValue(value);
+ numberPicker.setOnValueChangedListener(value -> this.value = value);
+ root.addView(numberPicker);
+ }
+
+ public String getUnits() {
+ return units;
+ }
+
+ public void setUnits(String units) {
+ if (!this.units.equals(units)) {
+ String previousUnits = this.units;
+ this.units = units;
+ value = Profile.toUnits(Profile.toMgdl(value, previousUnits), Profile.toMmol(value, previousUnits), units);
+ }
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public int getMgdl() {
+ return (int)Profile.toMgdl(value, units);
+ }
+
+ public void setMgdl(int value) {
+ this.value = Profile.fromMgdlToUnits(value, units);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java
new file mode 100644
index 0000000000..79dd19c6cd
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java
@@ -0,0 +1,61 @@
+package info.nightscout.androidaps.plugins.general.automation.elements;
+
+import android.widget.LinearLayout;
+
+import java.text.DecimalFormat;
+
+import info.nightscout.androidaps.utils.NumberPicker;
+
+public class InputDuration extends Element {
+ public enum TimeUnit {
+ MINUTES,
+ HOURS
+ }
+
+ private TimeUnit unit;
+ private double value;
+
+ public InputDuration(double value, TimeUnit unit) {
+ this.unit = unit;
+ this.value = value;
+ }
+
+ @Override
+ public void addToLayout(LinearLayout root) {
+ NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
+ if (unit.equals(TimeUnit.MINUTES)) {
+ // Minutes
+ numberPicker.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false);
+ } else {
+ // Hours
+ numberPicker.setParams(0d, 0d, 24d, 1d, new DecimalFormat("0"), false);
+ }
+ numberPicker.setValue(value);
+ numberPicker.setOnValueChangedListener(value -> this.value = value);
+ root.addView(numberPicker);
+ }
+
+ public TimeUnit getUnit() {
+ return unit;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setMinutes(double value) {
+ if (unit.equals(TimeUnit.MINUTES)) {
+ this.value = value;
+ } else {
+ this.value = value / 60d;
+ }
+ }
+
+ public double getMinutes() {
+ if (unit.equals(TimeUnit.MINUTES)) {
+ return value;
+ } else {
+ return value * 60d;
+ }
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java
new file mode 100644
index 0000000000..45defc218e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Label.java
@@ -0,0 +1,59 @@
+package info.nightscout.androidaps.plugins.general.automation.elements;
+
+import android.graphics.Typeface;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import info.nightscout.androidaps.MainApp;
+
+public class Label extends Element {
+ private final Element element;
+ private final String textPre;
+ private final String textPost;
+
+ public Label(String textPre, String textPost, Element element) {
+ this.element = element;
+ this.textPre = textPre;
+ this.textPost = textPost;
+ }
+
+ @Override
+ public void addToLayout(LinearLayout root) {
+ // container layout
+ LinearLayout layout = new LinearLayout(root.getContext());
+ layout.setOrientation(LinearLayout.HORIZONTAL);
+ layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+
+ // text view pre element
+ int px = MainApp.dpToPx(10);
+ TextView textViewPre = new TextView(root.getContext());
+ textViewPre.setText(textPre);
+ textViewPre.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+ textViewPre.setWidth(MainApp.dpToPx(120));
+ textViewPre.setPadding(px, px, px, px);
+ textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD);
+ layout.addView(textViewPre);
+
+ // add element to layout
+ element.addToLayout(layout);
+
+ // text view post element
+ if (textPost != null) {
+ px = MainApp.dpToPx(5);
+ TextView textViewPost = new TextView(root.getContext());
+ textViewPost.setText(textPost);
+ textViewPost.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+ textViewPost.setWidth(MainApp.dpToPx(45));
+ textViewPost.setPadding(px, px, px, px);
+ textViewPost.setTypeface(textViewPost.getTypeface(), Typeface.BOLD);
+ layout.addView(textViewPost);
+ }
+
+ // add layout to root layout
+ root.addView(layout);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java
new file mode 100644
index 0000000000..c41a5ee79a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.java
@@ -0,0 +1,22 @@
+package info.nightscout.androidaps.plugins.general.automation.elements;
+
+import android.widget.LinearLayout;
+
+import java.util.ArrayList;
+
+public class LayoutBuilder {
+ private ArrayList mElements = new ArrayList<>();
+
+ public LayoutBuilder add(Element element) {
+ mElements.add(element);
+ return this;
+ }
+
+ public void build(LinearLayout layout) {
+ layout.removeAllViews();
+ for(Element e : mElements) {
+ e.addToLayout(layout);
+ }
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java
index 8cfa2156d9..876db6099c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java
@@ -1,64 +1,142 @@
package info.nightscout.androidaps.plugins.general.automation.triggers;
+import android.support.v4.app.FragmentManager;
+import android.content.Context;
+import android.support.annotation.StringRes;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.google.common.base.Optional;
+
import org.json.JSONException;
import org.json.JSONObject;
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public abstract class Trigger {
- protected static final int ISLOWER = -2;
- protected static final int ISEQUALORLOWER = -1;
- protected static final int ISEQUAL = 0;
- protected static final int ISEQUALORGREATER = 1;
- protected static final int ISGREATER = 2;
+ public enum Comparator {
+ IS_LESSER,
+ IS_EQUAL_OR_LESSER,
+ IS_EQUAL,
+ IS_EQUAL_OR_GREATER,
+ IS_GREATER,
+ IS_NOT_AVAILABLE;
- protected static final int ISNOTAVAILABLE = 10;
+ public @StringRes int getStringRes() {
+ switch (this) {
+ case IS_LESSER:
+ return R.string.islesser;
+ case IS_EQUAL_OR_LESSER:
+ return R.string.isequalorlesser;
+ case IS_EQUAL:
+ return R.string.isequal;
+ case IS_EQUAL_OR_GREATER:
+ return R.string.isequalorgreater;
+ case IS_GREATER:
+ return R.string.isgreater;
+ case IS_NOT_AVAILABLE:
+ return R.string.isnotavailable;
+ default:
+ return R.string.unknown;
+ }
+ }
+
+ public boolean check(T obj1, T obj2) {
+ if (obj1 == null || obj2 == null)
+ return this.equals(Comparator.IS_NOT_AVAILABLE);
+
+ int comparison = obj1.compareTo(obj2);
+ switch (this) {
+ case IS_LESSER:
+ return comparison < 0;
+ case IS_EQUAL_OR_LESSER:
+ return comparison <= 0;
+ case IS_EQUAL:
+ return comparison == 0;
+ case IS_EQUAL_OR_GREATER:
+ return comparison >= 0;
+ case IS_GREATER:
+ return comparison > 0;
+ default:
+ return false;
+ }
+ }
+
+ public static List labels() {
+ List list = new ArrayList<>();
+ for(Comparator c : values()) {
+ list.add(MainApp.gs(c.getStringRes()));
+ }
+ return list;
+ }
+ }
+
+ protected TriggerConnector connector = null;
Trigger() {
}
- abstract boolean shouldRun();
+ public TriggerConnector getConnector() {
+ return connector;
+ }
- abstract String toJSON();
+ public abstract boolean shouldRun();
- abstract Trigger fromJSON(String data);
+ public abstract String toJSON();
- abstract int friendlyName();
+ /*package*/ abstract Trigger fromJSON(String data);
- abstract String friendlyDescription();
+ public abstract int friendlyName();
+
+ public abstract String friendlyDescription();
+
+ public abstract Optional icon();
void notifyAboutRun(long time) {
}
- static Trigger instantiate(JSONObject object) {
+ public abstract Trigger duplicate();
+
+ public static Trigger instantiate(String json) {
+ try {
+ return instantiate(new JSONObject(json));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static Trigger instantiate(JSONObject object) {
try {
String type = object.getString("type");
- String data = object.getString("data");
+ JSONObject data = object.getJSONObject("data");
Class clazz = Class.forName(type);
- return ((Trigger) clazz.newInstance()).fromJSON(data);
+ return ((Trigger) clazz.newInstance()).fromJSON(data.toString());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
e.printStackTrace();
}
return null;
-
}
- public static int toComparatorString(int comparator) {
- switch (comparator) {
- case ISLOWER:
- return R.string.islower;
- case ISEQUALORLOWER:
- return R.string.isequalorlower;
- case ISEQUAL:
- return R.string.isequal;
- case ISEQUALORGREATER:
- return R.string.isequalorgreater;
- case ISGREATER:
- return R.string.isgreater;
- case ISNOTAVAILABLE:
- return R.string.isnotavailable;
- }
- return R.string.unknown;
+ public View createView(Context context, FragmentManager fragmentManager) {
+ final int padding = MainApp.dpToPx(4);
+
+ LinearLayout root = new LinearLayout(context);
+ root.setPadding(padding, padding, padding, padding);
+ root.setOrientation(LinearLayout.VERTICAL);
+ root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ TextView title = new TextView(context);
+ title.setText(friendlyName());
+ root.addView(title);
+
+ return root;
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java
deleted file mode 100644
index 3e791afcc7..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAnd.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package info.nightscout.androidaps.plugins.general.automation.triggers;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import info.nightscout.androidaps.R;
-
-public class TriggerAnd extends Trigger {
-
- private List list = new ArrayList<>();
-
- @Override
- synchronized boolean shouldRun() {
- boolean result = true;
-
- for (Trigger t : list) {
- result = result && t.shouldRun();
- }
- return result;
- }
-
- @Override
- synchronized String toJSON() {
- JSONObject o = new JSONObject();
- try {
- o.put("type", TriggerAnd.class.getName());
- JSONArray array = new JSONArray();
- for (Trigger t : list) {
- array.put(t.toJSON());
- }
- o.put("data", array.toString());
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return o.toString();
- }
-
- @Override
- Trigger fromJSON(String data) {
- try {
- JSONArray array = new JSONArray(data);
- for (int i = 0; i < array.length(); i++) {
- Trigger newItem = instantiate(new JSONObject(array.getString(i)));
- list.add(newItem);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return this;
- }
-
- @Override
- int friendlyName() {
- return R.string.and;
- }
-
- @Override
- String friendlyDescription() {
- int counter = 0;
- StringBuilder result = new StringBuilder();
- for (Trigger t : list) {
- if (counter++ > 0) result.append(R.string.and);
- result.append(t.friendlyDescription());
- }
- return result.toString();
- }
-
- synchronized void add(Trigger t) {
- list.add(t);
- }
-
- synchronized boolean remove(Trigger t) {
- return list.remove(t);
- }
-
- int size() {
- return list.size();
- }
-
- Trigger get(int i) {
- return list.get(i);
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java
index 5939502163..cd3217b414 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java
@@ -1,55 +1,99 @@
package info.nightscout.androidaps.plugins.general.automation.triggers;
+import android.support.v4.app.FragmentManager;
+import android.content.Context;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import com.google.common.base.Optional;
+
import org.json.JSONException;
import org.json.JSONObject;
+import java.text.DecimalFormat;
+
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.utils.JsonHelper;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.utils.JsonHelper;
+import info.nightscout.androidaps.utils.NumberPicker;
public class TriggerBg extends Trigger {
- double threshold;
- int comparator = ISEQUAL;
- String units = ProfileFunctions.getInstance().getProfileUnits();
+ private double threshold = 100.0; // FIXME
+ private Comparator comparator = Comparator.IS_EQUAL;
+ private String units = ProfileFunctions.getInstance().getProfileUnits();
+
+ final private TextWatcher textWatcher = new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ // TODO: validate inputs
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+ };
+
+ public TriggerBg() {
+ super();
+ }
+
+ private TriggerBg(TriggerBg triggerBg) {
+ super();
+ comparator = triggerBg.comparator;
+ units = triggerBg.units;
+ threshold = triggerBg.threshold;
+ }
+
+ public double getThreshold() {
+ return threshold;
+ }
+
+ public Comparator getComparator() {
+ return comparator;
+ }
+
+ public String getUnits() {
+ return units;
+ }
@Override
- synchronized boolean shouldRun() {
+ public synchronized boolean shouldRun() {
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
- if (glucoseStatus == null && comparator == ISNOTAVAILABLE)
+ if (glucoseStatus == null && comparator.equals(Comparator.IS_NOT_AVAILABLE))
return true;
if (glucoseStatus == null)
return false;
- switch (comparator) {
- case ISLOWER:
- return glucoseStatus.glucose < Profile.toMgdl(threshold, units);
- case ISEQUALORLOWER:
- return glucoseStatus.glucose <= Profile.toMgdl(threshold, units);
- case ISEQUAL:
- return glucoseStatus.glucose == Profile.toMgdl(threshold, units);
- case ISEQUALORGREATER:
- return glucoseStatus.glucose >= Profile.toMgdl(threshold, units);
- case ISGREATER:
- return glucoseStatus.glucose > Profile.toMgdl(threshold, units);
- }
- return false;
+ return comparator.check(glucoseStatus.glucose, Profile.toMgdl(threshold, units));
}
@Override
- synchronized String toJSON() {
+ public synchronized String toJSON() {
JSONObject o = new JSONObject();
try {
o.put("type", TriggerBg.class.getName());
JSONObject data = new JSONObject();
data.put("threshold", threshold);
- data.put("comparator", comparator);
+ data.put("comparator", comparator.toString());
data.put("units", units);
- o.put("data", data.toString());
+ o.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
@@ -61,7 +105,7 @@ public class TriggerBg extends Trigger {
try {
JSONObject d = new JSONObject(data);
threshold = JsonHelper.safeGetDouble(d, "threshold");
- comparator = JsonHelper.safeGetInt(d, "comparator");
+ comparator = Comparator.valueOf(JsonHelper.safeGetString(d, "comparator"));
units = JsonHelper.safeGetString(d, "units");
} catch (JSONException e) {
e.printStackTrace();
@@ -70,16 +114,26 @@ public class TriggerBg extends Trigger {
}
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.glucose;
}
@Override
- String friendlyDescription() {
- if (comparator == Trigger.ISNOTAVAILABLE)
+ public String friendlyDescription() {
+ if (comparator.equals(Comparator.IS_NOT_AVAILABLE))
return MainApp.gs(R.string.glucoseisnotavailable);
else
- return MainApp.gs(R.string.glucosecompared, Trigger.toComparatorString(comparator), threshold, units);
+ return MainApp.gs(R.string.glucosecompared, MainApp.gs(comparator.getStringRes()), threshold, units);
+ }
+
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.icon_cp_bgcheck);
+ }
+
+ @Override
+ public Trigger duplicate() {
+ return new TriggerBg(this);
}
TriggerBg threshold(double threshold) {
@@ -87,7 +141,7 @@ public class TriggerBg extends Trigger {
return this;
}
- TriggerBg comparator(int comparator) {
+ TriggerBg comparator(Comparator comparator) {
this.comparator = comparator;
return this;
}
@@ -96,4 +150,59 @@ public class TriggerBg extends Trigger {
this.units = units;
return this;
}
+
+ @Override
+ public View createView(Context context, FragmentManager fragmentManager) {
+ LinearLayout root = (LinearLayout) super.createView(context, fragmentManager);
+
+ // spinner for comparator
+ Spinner spinner = new Spinner(context);
+ ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, Comparator.labels());
+ spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(spinnerArrayAdapter);
+ LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ );
+ spinnerParams.setMargins(0, MainApp.dpToPx(4), 0, MainApp.dpToPx(4));
+ spinner.setLayoutParams(spinnerParams);
+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ comparator = Comparator.values()[position];
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) { }
+ });
+ spinner.setSelection(comparator.ordinal());
+ root.addView(spinner);
+
+ // horizontal layout
+ LinearLayout layout = new LinearLayout(context);
+ layout.setOrientation(LinearLayout.HORIZONTAL);
+ layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ root.addView(layout);
+
+ // input field for threshold
+ NumberPicker numberPicker = new NumberPicker(context, null);
+ numberPicker.setParams(0d, 0d, (double) 500, 1d, new DecimalFormat("0"), false, textWatcher);
+ numberPicker.setValue(threshold);
+ numberPicker.setOnValueChangedListener(value -> threshold = value);
+ layout.addView(numberPicker);
+
+ // text view for unit
+ TextView tvUnits = new TextView(context);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.MATCH_PARENT
+ );
+ params.setMargins(MainApp.dpToPx(6), 0, 0, 0);
+ tvUnits.setLayoutParams(params);
+ tvUnits.setText(units);
+ tvUnits.setGravity(Gravity.CENTER_VERTICAL);
+ layout.addView(tvUnits);
+
+ return root;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java
new file mode 100644
index 0000000000..28ee9b0705
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java
@@ -0,0 +1,262 @@
+package info.nightscout.androidaps.plugins.general.automation.triggers;
+
+import android.support.v4.app.FragmentManager;
+import android.content.Context;
+import android.support.annotation.StringRes;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import com.google.common.base.Optional;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.general.automation.AutomationFragment;
+import info.nightscout.androidaps.utils.JsonHelper;
+
+public class TriggerConnector extends Trigger {
+ public enum Type {
+ AND,
+ OR,
+ XOR;
+
+ public boolean apply(boolean a, boolean b) {
+ switch (this) {
+ case AND:
+ return a && b;
+ case OR:
+ return a || b;
+ case XOR:
+ return a ^ b;
+ }
+ return false;
+ }
+
+ public @StringRes int getStringRes() {
+ switch (this) {
+ case OR:
+ return R.string.or;
+ case XOR:
+ return R.string.xor;
+
+ default:
+ case AND:
+ return R.string.and;
+ }
+ }
+
+ public static List labels() {
+ List list = new ArrayList<>();
+ for(Type t : values()) {
+ list.add(MainApp.gs(t.getStringRes()));
+ }
+ return list;
+ }
+ }
+
+ public static void fillIconSet(TriggerConnector connector, HashSet set) {
+ for(Trigger t : connector.list) {
+ if (t instanceof TriggerConnector) {
+ fillIconSet((TriggerConnector) t, set);
+ } else {
+ Optional icon = t.icon();
+ if (icon.isPresent()) {
+ set.add(icon.get());
+ }
+ }
+ }
+ }
+
+ protected List list = new ArrayList<>();
+ private Type connectorType;
+
+ public TriggerConnector() {
+ connectorType = Type.AND;
+ }
+
+ public TriggerConnector(Type connectorType) {
+ this.connectorType = connectorType;
+ }
+
+ public void changeConnectorType(Type type) { this.connectorType = type; }
+
+ public Type getConnectorType() { return connectorType; }
+
+ public synchronized void add(Trigger t) {
+ list.add(t);
+ t.connector = this;
+ }
+
+ public synchronized void add(int pos, Trigger t) {
+ list.add(pos, t);
+ t.connector = this;
+ }
+
+ public synchronized boolean remove(Trigger t) {
+ return list.remove(t);
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ public Trigger get(int i) {
+ return list.get(i);
+ }
+
+ public int pos(Trigger trigger) {
+ for(int i = 0; i < list.size(); ++i) {
+ if (list.get(i) == trigger) return i;
+ }
+ return -1;
+ }
+
+ @Override
+ public synchronized boolean shouldRun() {
+ boolean result = true;
+
+ // check first trigger
+ if (list.size() > 0)
+ result = list.get(0).shouldRun();
+
+ // check all others
+ for (int i = 1; i < list.size(); ++i) {
+ result = connectorType.apply(result, list.get(i).shouldRun());
+ }
+
+ return result;
+ }
+
+ @Override
+ public synchronized String toJSON() {
+ JSONObject o = new JSONObject();
+ try {
+ o.put("type", TriggerConnector.class.getName());
+ JSONObject data = new JSONObject();
+ data.put("connectorType", connectorType.toString());
+ JSONArray array = new JSONArray();
+ for (Trigger t : list) {
+ array.put(t.toJSON());
+ }
+ data.put("triggerList", array);
+ o.put("data", data);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return o.toString();
+ }
+
+ @Override
+ Trigger fromJSON(String data) {
+ try {
+ JSONObject d = new JSONObject(data);
+ connectorType = Type.valueOf(JsonHelper.safeGetString(d, "connectorType"));
+ JSONArray array = d.getJSONArray("triggerList");
+ list.clear();
+ for (int i = 0; i < array.length(); i++) {
+ Trigger newItem = instantiate(new JSONObject(array.getString(i)));
+ add(newItem);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return this;
+ }
+
+ @Override
+ public int friendlyName() {
+ return connectorType.getStringRes();
+ }
+
+ @Override
+ public String friendlyDescription() {
+ int counter = 0;
+ StringBuilder result = new StringBuilder();
+ for (Trigger t : list) {
+ if (counter++ > 0) result.append(" " + MainApp.gs(friendlyName()) + " ");
+ result.append(t.friendlyDescription());
+ }
+ return result.toString();
+ }
+
+ @Override
+ public Optional icon() {
+ return Optional.absent();
+ }
+
+ @Override
+ public Trigger duplicate() {
+ return null;
+ }
+
+ private AutomationFragment.TriggerListAdapter adapter;
+
+ public void rebuildView() {
+ if (adapter != null)
+ adapter.rebuild();
+ }
+
+ @Override
+ public View createView(Context context, FragmentManager fragmentManager) {
+ final int padding = MainApp.dpToPx(5);
+
+ LinearLayout root = new LinearLayout(context);
+ root.setOrientation(LinearLayout.VERTICAL);
+ root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ root.setPadding(padding,padding,padding,padding);
+ root.setBackgroundResource(R.drawable.border_automation_unit);
+
+ LinearLayout triggerListLayout = new LinearLayout(context);
+ triggerListLayout.setOrientation(LinearLayout.VERTICAL);
+ triggerListLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ root.addView(triggerListLayout);
+
+ adapter = new AutomationFragment.TriggerListAdapter(context, fragmentManager, triggerListLayout, this);
+
+ return root;
+ }
+
+ public TriggerConnector simplify() {
+ // simplify children
+ for(int i = 0; i < size(); ++i) {
+ if (get(i) instanceof TriggerConnector) {
+ TriggerConnector t = (TriggerConnector) get(i);
+ t.simplify();
+ }
+ }
+
+ // drop connector with only 1 element
+ if (size() == 1 && get(0) instanceof TriggerConnector) {
+ TriggerConnector c = (TriggerConnector) get(0);
+ remove(c);
+ changeConnectorType(c.getConnectorType());
+ for (Trigger t : c.list) {
+ add(t);
+ }
+ c.list.clear();
+ return simplify();
+ }
+
+ // merge connectors
+ if (connector != null && (connector.getConnectorType().equals(connectorType) || size() == 1)) {
+ final int pos = connector.pos(this);
+ connector.remove(this);
+ // move triggers of child connector into parent connector
+ for (int i = size()-1; i >= 0; --i) {
+ connector.add(pos, get(i));
+ }
+ list.clear();
+ return connector.simplify();
+ }
+
+ return this;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java
deleted file mode 100644
index 309838b25f..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerOr.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package info.nightscout.androidaps.plugins.general.automation.triggers;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import info.nightscout.androidaps.R;
-
-public class TriggerOr extends Trigger {
-
- private List list = new ArrayList<>();
-
- @Override
- synchronized boolean shouldRun() {
- boolean result = false;
-
- for (Trigger t : list) {
- result = result || t.shouldRun();
- }
- return result;
- }
-
- @Override
- synchronized String toJSON() {
- JSONObject o = new JSONObject();
- try {
- o.put("type", TriggerOr.class.getName());
- JSONArray array = new JSONArray();
- for (Trigger t : list) {
- array.put(t.toJSON());
- }
- o.put("data", array.toString());
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return o.toString();
- }
-
- @Override
- Trigger fromJSON(String data) {
- try {
- JSONArray array = new JSONArray(data);
- for (int i = 0; i < array.length(); i++) {
- Trigger newItem = instantiate(new JSONObject(array.getString(i)));
- list.add(newItem);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return this;
- }
-
- @Override
- int friendlyName() {
- return R.string.or;
- }
-
- @Override
- String friendlyDescription() {
- int counter = 0;
- StringBuilder result = new StringBuilder();
- for (Trigger t : list) {
- if (counter++ > 0) result.append(R.string.or);
- result.append(t.friendlyDescription());
- }
- return result.toString();
- }
-
- synchronized void add(Trigger t) {
- list.add(t);
- }
-
- synchronized boolean remove(Trigger t) {
- return list.remove(t);
- }
-
- int size() {
- return list.size();
- }
-
- Trigger get(int i) {
- return list.get(i);
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java
index b5f0e6e072..faeeafcb1d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java
@@ -1,39 +1,152 @@
package info.nightscout.androidaps.plugins.general.automation.triggers;
+import android.support.v4.app.FragmentManager;
+import android.content.Context;
+import android.support.annotation.StringRes;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import com.dpro.widgets.WeekdaysPicker;
+import com.google.common.base.Optional;
+
import org.json.JSONException;
import org.json.JSONObject;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.JsonHelper;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.JsonHelper;
+import info.nightscout.androidaps.utils.T;
public class TriggerTime extends Trigger {
- long lastRun;
+ public enum DayOfWeek {
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY,
+ SUNDAY;
+
+ private static final int[] calendarInts = new int[] {
+ Calendar.MONDAY,
+ Calendar.TUESDAY,
+ Calendar.WEDNESDAY,
+ Calendar.THURSDAY,
+ Calendar.FRIDAY,
+ Calendar.SATURDAY,
+ Calendar.SUNDAY
+ };
+
+ private static final int[] fullNames = new int[] {
+ R.string.weekday_monday,
+ R.string.weekday_tuesday,
+ R.string.weekday_wednesday,
+ R.string.weekday_thursday,
+ R.string.weekday_friday,
+ R.string.weekday_saturday,
+ R.string.weekday_sunday
+ };
+
+ private static final int[] shortNames = new int[] {
+ R.string.weekday_monday_short,
+ R.string.weekday_tuesday_short,
+ R.string.weekday_wednesday_short,
+ R.string.weekday_thursday_short,
+ R.string.weekday_friday_short,
+ R.string.weekday_saturday_short,
+ R.string.weekday_sunday_short
+ };
+
+ public int toCalendarInt() {
+ return calendarInts[ordinal()];
+ }
+
+ public static DayOfWeek fromCalendarInt(int day) {
+ for(int i = 0; i < calendarInts.length; ++i) {
+ if (calendarInts[i] == day)
+ return values()[i];
+ }
+ return null;
+ }
+
+ public @StringRes int getFullName() {
+ return fullNames[ordinal()];
+ }
+
+ public @StringRes int getShortName() {
+ return shortNames[ordinal()];
+ }
+ }
+
+ private final boolean[] weekdays = new boolean[DayOfWeek.values().length];
+
+ private long lastRun;
// Single execution
- long runAt;
+ private long runAt;
// Recurring
- boolean recurring;
- boolean monday = true;
- boolean tuesday = true;
- boolean wednesday = true;
- boolean thursday = true;
- boolean friday = true;
- boolean saturday = true;
- boolean sunday = true;
- int hour;
- int minute;
+ private boolean recurring;
+ private int hour;
+ private int minute;
- long validTo;
+ private long validTo;
+
+ public TriggerTime() {
+ super();
+ setAll(false);
+ }
+
+ private TriggerTime(TriggerTime triggerTime) {
+ super();
+ lastRun = triggerTime.lastRun;
+ runAt = triggerTime.runAt;
+ recurring = triggerTime.recurring;
+ hour = triggerTime.hour;
+ minute = triggerTime.minute;
+ validTo = triggerTime.validTo;
+
+ for(int i = 0; i < weekdays.length; ++i) {
+ weekdays[i] = triggerTime.weekdays[i];
+ }
+ }
+
+ public void setAll(boolean value) {
+ for(DayOfWeek day : DayOfWeek.values()) {
+ set(day, value);
+ }
+ }
+
+ public TriggerTime set(DayOfWeek day, boolean value) {
+ weekdays[day.ordinal()] = value;
+ return this;
+ }
+
+ public boolean isSet(DayOfWeek day) {
+ return weekdays[day.ordinal()];
+ }
+
+ public long getLastRun() {
+ return lastRun;
+ }
+
+ public long getRunAt() {
+ return runAt;
+ }
+
+ public boolean isRecurring() {
+ return recurring;
+ }
@Override
- boolean shouldRun() {
+ public boolean shouldRun() {
if (recurring) {
if (validTo != 0 && DateUtil.now() > validTo)
return false;
@@ -46,13 +159,7 @@ public class TriggerTime extends Trigger {
scheduledCal.set(Calendar.SECOND, 0);
long scheduled = scheduledCal.getTimeInMillis();
- if (monday && scheduledDayOfWeek == Calendar.MONDAY ||
- tuesday && scheduledDayOfWeek == Calendar.TUESDAY ||
- wednesday && scheduledDayOfWeek == Calendar.WEDNESDAY ||
- thursday && scheduledDayOfWeek == Calendar.THURSDAY ||
- friday && scheduledDayOfWeek == Calendar.FRIDAY ||
- saturday && scheduledDayOfWeek == Calendar.SATURDAY ||
- sunday && scheduledDayOfWeek == Calendar.SUNDAY) {
+ if (isSet(DayOfWeek.fromCalendarInt(scheduledDayOfWeek))) {
if (DateUtil.now() >= scheduled && DateUtil.now() - scheduled < T.mins(5).msecs()) {
if (lastRun < scheduled)
return true;
@@ -68,25 +175,21 @@ public class TriggerTime extends Trigger {
}
@Override
- String toJSON() {
+ public String toJSON() {
JSONObject object = new JSONObject();
JSONObject data = new JSONObject();
try {
data.put("lastRun", lastRun);
data.put("runAt", runAt);
data.put("recurring", recurring);
- data.put("monday", monday);
- data.put("tuesday", tuesday);
- data.put("wednesday", wednesday);
- data.put("thursday", thursday);
- data.put("friday", friday);
- data.put("saturday", saturday);
- data.put("sunday", sunday);
+ for(int i = 0; i < weekdays.length; ++i) {
+ data.put(DayOfWeek.values()[i].name(), weekdays[i]);
+ }
data.put("hour", hour);
data.put("minute", minute);
data.put("validTo", validTo);
object.put("type", TriggerTime.class.getName());
- object.put("data", data.toString());
+ object.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
@@ -101,13 +204,9 @@ public class TriggerTime extends Trigger {
lastRun = JsonHelper.safeGetLong(o, "lastRun");
runAt = JsonHelper.safeGetLong(o, "runAt");
recurring = JsonHelper.safeGetBoolean(o, "recurring");
- monday = JsonHelper.safeGetBoolean(o, "monday");
- tuesday = JsonHelper.safeGetBoolean(o, "tuesday");
- wednesday = JsonHelper.safeGetBoolean(o, "wednesday");
- thursday = JsonHelper.safeGetBoolean(o, "thursday");
- friday = JsonHelper.safeGetBoolean(o, "friday");
- saturday = JsonHelper.safeGetBoolean(o, "saturday");
- sunday = JsonHelper.safeGetBoolean(o, "sunday");
+ for(int i = 0; i < weekdays.length; ++i) {
+ weekdays[i] = JsonHelper.safeGetBoolean(o, DayOfWeek.values()[i].name());
+ }
hour = JsonHelper.safeGetInt(o, "hour");
minute = JsonHelper.safeGetInt(o, "minute");
validTo = JsonHelper.safeGetLong(o, "validTo");
@@ -118,12 +217,12 @@ public class TriggerTime extends Trigger {
}
@Override
- int friendlyName() {
+ public int friendlyName() {
return R.string.time;
}
@Override
- String friendlyDescription() {
+ public String friendlyDescription() {
if (recurring) {
// TODO
return "Every ";
@@ -132,11 +231,21 @@ public class TriggerTime extends Trigger {
}
}
+ @Override
+ public Optional icon() {
+ return Optional.of(R.drawable.ic_access_alarm_24dp);
+ }
+
@Override
void notifyAboutRun(long time) {
lastRun = time;
}
+ @Override
+ public Trigger duplicate() {
+ return new TriggerTime(this);
+ }
+
TriggerTime lastRun(long lastRun) {
this.lastRun = lastRun;
return this;
@@ -152,41 +261,6 @@ public class TriggerTime extends Trigger {
return this;
}
- TriggerTime monday(boolean monday) {
- this.monday = monday;
- return this;
- }
-
- TriggerTime tuesday(boolean tuesday) {
- this.tuesday = tuesday;
- return this;
- }
-
- TriggerTime wednesday(boolean wednesday) {
- this.wednesday = wednesday;
- return this;
- }
-
- TriggerTime thursday(boolean thursday) {
- this.thursday = thursday;
- return this;
- }
-
- TriggerTime friday(boolean friday) {
- this.friday = friday;
- return this;
- }
-
- TriggerTime saturday(boolean saturday) {
- this.saturday = saturday;
- return this;
- }
-
- TriggerTime sunday(boolean sunday) {
- this.sunday = sunday;
- return this;
- }
-
TriggerTime validTo(long validTo) {
this.validTo = validTo;
return this;
@@ -202,4 +276,28 @@ public class TriggerTime extends Trigger {
return this;
}
+ private List getSelectedDays() {
+ List selectedDays = new ArrayList<>();
+ for(int i = 0; i < weekdays.length; ++i) {
+ DayOfWeek day = DayOfWeek.values()[i];
+ boolean selected = weekdays[i];
+ if (selected) selectedDays.add(day.toCalendarInt());
+ }
+ return selectedDays;
+ }
+
+ @Override
+ public View createView(Context context, FragmentManager fragmentManager) {
+ LinearLayout root = (LinearLayout) super.createView(context, fragmentManager);
+
+ // TODO: Replace external tool WeekdaysPicker with a self-made GUI element
+ WeekdaysPicker weekdaysPicker = new WeekdaysPicker(context);
+ weekdaysPicker.setEditable(true);
+ weekdaysPicker.setSelectedDays(getSelectedDays());
+ weekdaysPicker.setOnWeekdaysChangeListener((view, i, list) -> set(DayOfWeek.fromCalendarInt(i), list.contains(i)));
+ weekdaysPicker.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+
+ root.addView(weekdaysPicker);
+ return root;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java
index e39480691e..991fc962ee 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Careportal;
+package info.nightscout.androidaps.plugins.general.careportal;
import android.app.Activity;
@@ -22,12 +22,12 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.events.EventCareportalEventChange;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
-import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
-import info.nightscout.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
+import info.nightscout.androidaps.utils.FabricPrivacy;
public class CareportalFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(CareportalFragment.class);
@@ -229,8 +229,8 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
handleAge(sage, CareportalEvent.SENSORCHANGE, sageWarn, sageUrgent);
- double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
- double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
+ double pbageUrgent = nsSettings.getExtendedWarnValue("bage", "urgent", 360);
+ double pbageWarn = nsSettings.getExtendedWarnValue("bage", "warn", 240);
handleAge(pbage, CareportalEvent.PUMPBATTERYCHANGE, pbageWarn, pbageUrgent);
}
);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java
index 22aa4686b2..fa8f87ef46 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalPlugin.java
@@ -1,6 +1,5 @@
-package info.nightscout.androidaps.plugins.Careportal;
+package info.nightscout.androidaps.plugins.general.careportal;
-import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
index 2a169dc4f3..e4eccd18d9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Careportal.Dialogs;
+package info.nightscout.androidaps.plugins.general.careportal.Dialogs;
import android.app.Activity;
@@ -48,20 +48,20 @@ import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DefaultValueHelper;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.JsonHelper;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.Translator;
+import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DefaultValueHelper;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.JsonHelper;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.Translator;
public class NewNSTreatmentDialog extends DialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
private static Logger log = LoggerFactory.getLogger(NewNSTreatmentDialog.class);
@@ -270,7 +270,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
if (profile == null) {
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
- } else if (profile.getUnits().equals(Constants.MMOL)) {
+ } else if (units.equals(Constants.MMOL)) {
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
} else {
@@ -279,7 +279,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
}
sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
- Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits());
+ Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) {
editBg.setValue(savedInstanceState.getDouble("editBg"));
} else {
@@ -459,7 +459,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
if ((data.size() > 0) &&
(data.get(0).date > millis - 7 * 60 * 1000L) &&
(data.get(0).date < millis + 7 * 60 * 1000L)) {
- editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, profile != null ? profile.getUnits() : Constants.MGDL));
+ editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, units));
}
}
@@ -722,7 +722,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
public void createNSTreatment(JSONObject data) {
if (options.executeProfileSwitch) {
if (data.has("profile")) {
- doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift"));
+ ProfileFunctions.doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift"));
}
} else if (options.executeTempTarget) {
final int duration = JsonHelper.safeGetInt(data, "duration");
@@ -736,8 +736,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
.reason(reason)
.source(Source.USER);
if (tempTarget.durationInMinutes != 0) {
- tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits()))
- .high(Profile.toMgdl(targetTop, profile.getUnits()));
+ tempTarget.low(Profile.toMgdl(targetBottom, units))
+ .high(Profile.toMgdl(targetTop, units));
} else {
tempTarget.low(0).high(0);
}
@@ -746,7 +746,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
}
} else {
if (JsonHelper.safeGetString(data, "eventType").equals(CareportalEvent.PROFILESWITCH)) {
- ProfileSwitch profileSwitch = prepareProfileSwitch(
+ ProfileSwitch profileSwitch = ProfileFunctions.prepareProfileSwitch(
profileStore,
JsonHelper.safeGetString(data, "profile"),
JsonHelper.safeGetInt(data, "duration"),
@@ -762,46 +762,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
}
}
- public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) {
- ProfileSwitch profileSwitch = new ProfileSwitch();
- profileSwitch.date = date;
- profileSwitch.source = Source.USER;
- profileSwitch.profileName = profileName;
- profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
- profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
- profileSwitch.durationInMinutes = duration;
- profileSwitch.isCPP = percentage != 100 || timeshift != 0;
- profileSwitch.timeshift = timeshift;
- profileSwitch.percentage = percentage;
- return profileSwitch;
- }
-
- public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
- ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis());
- TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
- FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
- }
-
- public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
- ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis());
- if (profileSwitch != null) {
- profileSwitch = new ProfileSwitch();
- profileSwitch.date = System.currentTimeMillis();
- profileSwitch.source = Source.USER;
- profileSwitch.profileName = ProfileFunctions.getInstance().getProfileName(System.currentTimeMillis(), false);
- profileSwitch.profileJson = ProfileFunctions.getInstance().getProfile().getData().toString();
- profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
- profileSwitch.durationInMinutes = duration;
- profileSwitch.isCPP = percentage != 100 || timeshift != 0;
- profileSwitch.timeshift = timeshift;
- profileSwitch.percentage = percentage;
- TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
- FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
- } else {
- log.error("No profile switch existing");
- }
- }
-
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString("notesEdit", notesEdit.getText().toString());
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java
index cbdbe38940..08f65a967f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/OptionsToShow.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/OptionsToShow.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Careportal;
+package info.nightscout.androidaps.plugins.general.careportal;
/**
* Created by mike on 05.11.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java
index 49da1d6ac5..2396fc9e3d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/Food.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/Food.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Food;
+package info.nightscout.androidaps.plugins.general.food;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
@@ -8,7 +8,7 @@ import org.json.JSONObject;
import java.util.Objects;
-import info.nightscout.utils.JsonHelper;
+import info.nightscout.androidaps.utils.JsonHelper;
/**
* Created by mike on 20.09.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java
index 677fac5fb2..6eb55db266 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Food;
+package info.nightscout.androidaps.plugins.general.food;
import android.app.Activity;
import android.content.DialogInterface;
@@ -31,10 +31,10 @@ import java.util.Set;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SpinnerHelper;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.utils.SpinnerHelper;
/**
* Created by mike on 16.10.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java
index 84996f1a37..e5548417a2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Food;
+package info.nightscout.androidaps.plugins.general.food;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java
index b2e23dfd69..2d8d5f847b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Food;
+package info.nightscout.androidaps.plugins.general.food;
import android.content.Intent;
import android.os.Bundle;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java
index d108382c92..67bf604f41 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.java
@@ -1,10 +1,9 @@
-package info.nightscout.androidaps.plugins.Maintenance;
+package info.nightscout.androidaps.plugins.general.maintenance;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Environment;
@@ -29,9 +28,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.utils.OKDialog;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.OKDialog;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by mike on 03.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java
index fc1cc0362a..29eeabdf5f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Maintenance;
+package info.nightscout.androidaps.plugins.general.maintenance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java
index f9c00d56c7..e0e9b58253 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenanceFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Maintenance;
+package info.nightscout.androidaps.plugins.general.maintenance;
import android.content.Intent;
import android.os.Bundle;
@@ -10,9 +10,9 @@ import android.view.ViewGroup;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Food.FoodPlugin;
-import info.nightscout.androidaps.plugins.Maintenance.activities.LogSettingActivity;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.food.FoodPlugin;
+import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
/**
*
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java
index 09ab7feee1..bd5e67345d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Maintenance;
+package info.nightscout.androidaps.plugins.general.maintenance;
import android.content.Context;
import android.content.Intent;
@@ -28,8 +28,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.utils.SP;
public class MaintenancePlugin extends PluginBase {
@@ -73,8 +73,8 @@ public class MaintenancePlugin extends PluginBase {
}
public void sendLogs() {
- String recipient = SP.getString("key_maintenance_logs_email", "logs@androidaps.org");
- int amount = SP.getInt("key_maintenance_logs_amount", 2);
+ String recipient = SP.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org");
+ int amount = SP.getInt(R.string.key_maintenance_logs_amount, 2);
String logDirectory = LoggerUtils.getLogDirectory();
List logs = this.getLogfiles(logDirectory, amount);
@@ -103,7 +103,7 @@ public class MaintenancePlugin extends PluginBase {
Arrays.sort(files, (f1, f2) -> f1.getName().compareTo(f2.getName()));
List delFiles = Arrays.asList(files);
- int amount = SP.getInt("key_logshipper_amount", 2);
+ int amount = SP.getInt(R.string.key_logshipper_amount, 2);
int keepIndex = amount - 1;
if (keepIndex < delFiles.size()) {
@@ -213,6 +213,10 @@ public class MaintenancePlugin extends PluginBase {
builder.append("ADD TIME OF EVENT HERE: " + System.lineSeparator());
builder.append("ADD ISSUE DESCRIPTION OR GITHUB ISSUE REFERENCE NUMBER: " + System.lineSeparator());
builder.append("-------------------------------------------------------" + System.lineSeparator());
+ builder.append("(Please remember this will send only very recent logs." + System.lineSeparator());
+ builder.append("If you want to provide logs for event older than a few hours," + System.lineSeparator());
+ builder.append("you have to do it manually)" + System.lineSeparator());
+ builder.append("-------------------------------------------------------" + System.lineSeparator());
builder.append(MainApp.gs(R.string.app_name) + " " + BuildConfig.VERSION + System.lineSeparator());
if (Config.NSCLIENT)
builder.append("NSCLIENT" + System.lineSeparator());
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java
index 7d21d561b9..9d7681ae38 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/activities/LogSettingActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Maintenance.activities;
+package info.nightscout.androidaps.plugins.general.maintenance.activities;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java
index 9eff2ca84c..dc384a7378 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal;
+package info.nightscout.androidaps.plugins.general.nsclient;
import android.app.Activity;
@@ -20,18 +20,14 @@ import android.widget.TextView;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.events.EventPreferenceChange;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.SP;
public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private TextView logTextView;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java
index 69de5934f8..1947c5911d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal;
+package info.nightscout.androidaps.plugins.general.nsclient;
import android.content.ComponentName;
import android.content.Context;
@@ -30,12 +30,12 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.ToastUtils;
public class NSClientPlugin extends PluginBase {
private Logger log = LoggerFactory.getLogger(L.NSCLIENT);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java
index 8f3f31f6e7..40a411694b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal;
+package info.nightscout.androidaps.plugins.general.nsclient;
import android.content.Context;
import android.content.Intent;
@@ -25,7 +25,7 @@ import java.util.Locale;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.services.Intents;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile;
@@ -35,14 +35,14 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
-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.utils.BatteryLevel;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.data.DbLogger;
+import info.nightscout.androidaps.utils.BatteryLevel;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.05.2017.
@@ -470,14 +470,14 @@ public class NSUpload {
DbLogger.dbAdd(intent, data.toString());
}
- public static void uploadBg(BgReading reading) {
+ public static void uploadBg(BgReading reading, String source) {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "entries");
JSONObject data = new JSONObject();
try {
- data.put("device", "AndroidAPS-DexcomG5");
+ data.put("device", source);
data.put("date", reading.date);
data.put("dateString", DateUtil.toISOString(reading.date));
data.put("sgv", reading.value);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java
index ba6ec2c80b..8eeee8c43c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NsClientReceiverDelegate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal;
+package info.nightscout.androidaps.plugins.general.nsclient;
import android.content.Context;
import android.content.Intent;
@@ -15,7 +15,7 @@ import info.nightscout.androidaps.events.EventNetworkChange;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
class NsClientReceiverDelegate {
@@ -48,9 +48,7 @@ class NsClientReceiverDelegate {
bus.post(event);
context.registerReceiver(chargingStateReceiver,
- new IntentFilter(Intent.ACTION_POWER_CONNECTED));
- context.registerReceiver(chargingStateReceiver,
- new IntentFilter(Intent.ACTION_POWER_DISCONNECTED));
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
EventChargingState eventChargingState = chargingStateReceiver.grabChargingState(context);
if (eventChargingState != null)
@@ -97,7 +95,7 @@ class NsClientReceiverDelegate {
}
void processStateChange() {
- boolean newAllowedState = allowedChargingState && allowedNetworkState;
+ boolean newAllowedState = allowedChargingState && allowedNetworkState;
if (newAllowedState != allowed) {
allowed = newAllowedState;
bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
@@ -109,7 +107,9 @@ class NsClientReceiverDelegate {
boolean newAllowedState = true;
- if (!ev.isCharging && chargingOnly) newAllowedState = false;
+ if (!ev.isCharging && chargingOnly) {
+ newAllowedState = false;
+ }
return newAllowedState;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java
index 9c0284029c..c2bb0d21ab 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal;
+package info.nightscout.androidaps.plugins.general.nsclient;
import android.content.Context;
import android.content.Intent;
@@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
/**
* Created by mike on 21.02.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java
index ed9c4c3013..ead373d61d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.acks;
+package info.nightscout.androidaps.plugins.general.nsclient.acks;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
import io.socket.client.Ack;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java
index 56055351d9..62c1cf7f5d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAuthAck.java
@@ -1,10 +1,9 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.acks;
+package info.nightscout.androidaps.plugins.general.nsclient.acks;
import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.Event;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import io.socket.client.Ack;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java
index 42534387b2..68ce3d9a37 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.acks;
+package info.nightscout.androidaps.plugins.general.nsclient.acks;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java
index f94f9e51aa..6873b59515 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAckAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -8,8 +8,8 @@ import android.support.v4.content.LocalBroadcastManager;
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;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSAlarm;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 11.06.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java
index 8f75d92365..9c1e3e7ae2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java
index 5e1b01f225..b26c055851 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastAnnouncement.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java
index 4e49785f82..7d5dcddadc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastCals.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONArray;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java
index e6fec32ffa..fe9a194ca2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastClearAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java
index 4915608673..412c321817 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastDeviceStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -12,7 +12,7 @@ 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;
+import info.nightscout.androidaps.utils.SP;
public class BroadcastDeviceStatus {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java
index f38141ec6d..0a8c21251b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastFood.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastFood.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -12,7 +12,7 @@ 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;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 20.02.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java
index e91c3e2fd6..9c059ae8a2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastMbgs.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONArray;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java
index 6bd6bbc81a..9411ed6e9e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -9,7 +9,7 @@ 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;
+import info.nightscout.androidaps.utils.SP;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java
index dea4cf8713..04e957811d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastSgvs.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -12,7 +12,7 @@ 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;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 22.02.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java
index a0e8607efc..c037acc9bb 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -13,9 +13,9 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 24.02.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java
index 4f36d85348..e4ca7b577f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastTreatment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Intent;
import android.os.Bundle;
@@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 20.02.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java
index c8988141d7..676dbe909d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/broadcasts/BroadcastUrgentAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
+package info.nightscout.androidaps.plugins.general.nsclient.broadcasts;
import android.content.Context;
import android.content.Intent;
@@ -10,7 +10,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.services.Intents;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java
index 109331b34b..06fc06e943 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/AlarmAck.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/AlarmAck.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
/**
* Created by mike on 11.06.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java
index ec31141002..3aaf4ccac4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/DbLogger.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DbLogger.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import android.content.Intent;
import android.content.pm.ResolveInfo;
@@ -11,7 +11,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by mike on 02.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java
index 7ad82220da..305a09d560 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java
index 83fe44073e..b3e59d9448 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSCal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java
index b48319f979..b2539a716e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import android.content.Intent;
import android.os.Bundle;
@@ -18,12 +18,12 @@ import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
+import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.logging.BundleLogger;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 25.06.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java
index cd4cd9cdba..9e3475c27e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java
index dc3c9f742e..8511247e42 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -17,10 +17,10 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.logging.BundleLogger;
/*
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java
index 2212884a3e..391b363d99 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java
index d4ee20e2a1..39491445a0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.data;
+package info.nightscout.androidaps.plugins.general.nsclient.data;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java
index 82b11a812d..121085cb94 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientNewLog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.events;
+package info.nightscout.androidaps.plugins.general.nsclient.events;
import java.text.SimpleDateFormat;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java
similarity index 69%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java
index b968878da8..b5481ce741 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientRestart.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.events;
+package info.nightscout.androidaps.plugins.general.nsclient.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java
index 977c0e31fc..c3bf74321c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.events;
+package info.nightscout.androidaps.plugins.general.nsclient.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java
index dd78d2cd28..60d74a249d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/events/EventNSClientUpdateGUI.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.events;
+package info.nightscout.androidaps.plugins.general.nsclient.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java
index f23533e9ab..7185072692 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AckAlarmReceiver.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+package info.nightscout.androidaps.plugins.general.nsclient.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -13,10 +13,10 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.data.AlarmAck;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
+import info.nightscout.androidaps.utils.SP;
public class AckAlarmReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(L.NSCLIENT);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java
similarity index 75%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java
index dd5d3330ab..e91e203175 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AutoStartReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/AutoStartReceiver.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+package info.nightscout.androidaps.plugins.general.nsclient.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
public class AutoStartReceiver extends BroadcastReceiver {
public AutoStartReceiver() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java
index 896382d818..4d8b7eba2a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/DBAccessReceiver.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+package info.nightscout.androidaps.plugins.general.nsclient.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -17,11 +17,11 @@ import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.BundleLogger;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastTreatment;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
public class DBAccessReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(L.NSCLIENT);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java
similarity index 73%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java
index a38ca842f9..0b221ee456 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/RestartReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/receivers/RestartReceiver.java
@@ -1,13 +1,12 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
+package info.nightscout.androidaps.plugins.general.nsclient.receivers;
-import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
-import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
+import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
public class RestartReceiver extends WakefulBroadcastReceiver {
public RestartReceiver() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java
index 2066aaa423..359c224158 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.NSClientInternal.services;
+package info.nightscout.androidaps.plugins.general.nsclient.services;
import android.app.Service;
import android.content.Context;
@@ -35,39 +35,39 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
-import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck;
-import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAuthAck;
-import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSUpdateAck;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAlarm;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAnnouncement;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastClearAlarm;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastFood;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
-import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.JsonHelper;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
+import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
+import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAddAck;
+import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAuthAck;
+import info.nightscout.androidaps.plugins.general.nsclient.acks.NSUpdateAck;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAlarm;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAnnouncement;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastCals;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastClearAlarm;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastDeviceStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastFood;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastMbgs;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastProfile;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastSgvs;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastTreatment;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastUrgentAlarm;
+import info.nightscout.androidaps.plugins.general.nsclient.data.AlarmAck;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSTreatment;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.JsonHelper;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java
index 1baac9a694..6cb5a1bc82 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.app.Activity;
@@ -21,9 +21,9 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
public class BolusProgressDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(L.UI);
@@ -107,9 +107,9 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
@Override
public void onPause() {
+ running = false;
super.onPause();
MainApp.unsubscribe(this);
- running = false;
if (L.isEnabled(L.UI))
log.debug("onPause");
}
@@ -173,10 +173,12 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(() -> {
- if (L.isEnabled(L.UI))
- log.debug("executing");
try {
- dismiss();
+ if (running) {
+ if (L.isEnabled(L.UI))
+ log.debug("executing");
+ dismiss();
+ }
} catch (Exception e) {
log.error("Unhandled exception", e);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java
index 6fddc218ac..b0bc7e96f5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressHelperActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/BolusProgressHelperActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java
index f1f62c0bc4..b950414237 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/CalibrationDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.content.Context;
@@ -19,15 +19,14 @@ import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
-import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.XdripCalibrations;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.XdripCalibrations;
public class CalibrationDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java
index 50de25b656..053337e356 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/EditQuickWizardDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.os.Bundle;
@@ -22,10 +22,10 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.QuickWizard;
import info.nightscout.androidaps.data.QuickWizardEntry;
-import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SafeParse;
public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java
index dc4fa21aca..549653f400 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.content.Intent;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java
index c556a6c844..1107cf1a9f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/ErrorHelperActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/ErrorHelperActivity.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.utils.SP;
public class ErrorHelperActivity extends AppCompatActivity {
public ErrorHelperActivity() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java
index 40450adf77..44d13fa570 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewCarbsDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.os.Bundle;
import android.os.HandlerThread;
@@ -21,8 +21,8 @@ import android.widget.RadioButton;
import com.google.common.base.Joiner;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,16 +40,16 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.DefaultValueHelper;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.plugins.treatments.CarbsGenerator;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.DefaultValueHelper;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.ToastUtils;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
public class NewCarbsDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java
index 8545858d4e..f326805ba2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewInsulinDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.content.Context;
import android.content.Intent;
@@ -40,20 +40,20 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.T;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.T;
+import info.nightscout.androidaps.utils.ToastUtils;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
public class NewInsulinDialog extends DialogFragment implements OnClickListener {
private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java
index b1a8bf172a..b5e7b1dd74 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/NewTreatmentDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.content.Context;
import android.content.DialogInterface;
@@ -32,14 +32,14 @@ import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.ToastUtils;
public class NewTreatmentDialog extends DialogFragment implements OnClickListener {
private static Logger log = LoggerFactory.getLogger(NewTreatmentDialog.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java
index 1b6a4f2ff8..33b3019668 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/Dialogs/WizardDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.Dialogs;
+package info.nightscout.androidaps.plugins.general.overview.Dialogs;
import android.app.Activity;
import android.content.Context;
@@ -51,27 +51,26 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventFeatureRunning;
-import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.BolusWizard;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.BolusWizard;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.ToastUtils;
public class WizardDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener, Spinner.OnItemSelectedListener {
private static Logger log = LoggerFactory.getLogger(WizardDialog.class);
@@ -165,18 +164,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
}
- @Subscribe
- public void onStatusEvent(final EventNewBG e) {
- Activity activity = getActivity();
- if (activity != null)
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- calculateInsulin();
- }
- });
- }
-
@Subscribe
public void onStatusEvent(final EventAutosensCalculationFinished e) {
Activity activity = getActivity();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
index a414d38310..59d3e50728 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
@@ -1,8 +1,9 @@
-package info.nightscout.androidaps.plugins.Overview;
+package info.nightscout.androidaps.plugins.general.overview;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.NotificationManager;
+import android.arch.core.util.Function;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
@@ -82,50 +83,52 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
-import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.NewCarbsDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.NewInsulinDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
-import info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity;
-import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
-import info.nightscout.androidaps.plugins.Overview.notifications.NotificationRecyclerViewAdapter;
-import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
-import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
-import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
-import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
+import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.CalibrationDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewCarbsDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewInsulinDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.NewTreatmentDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.WizardDialog;
+import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity;
+import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData;
+import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationRecyclerViewAdapter;
+import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore;
+import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin;
+import info.nightscout.androidaps.plugins.source.SourceDexcomG6Plugin;
+import info.nightscout.androidaps.plugins.source.SourceXdripPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.treatments.fragments.ProfileViewerDialog;
+import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.BolusWizard;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.DefaultValueHelper;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.OKDialog;
-import info.nightscout.utils.Profiler;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SingleClickButton;
-import info.nightscout.utils.T;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.BolusWizard;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.DefaultValueHelper;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.OKDialog;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SingleClickButton;
+import info.nightscout.androidaps.utils.T;
+import info.nightscout.androidaps.utils.ToastUtils;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(L.OVERVIEW);
@@ -162,6 +165,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
TextView sage;
TextView pbage;
+ TextView iageView;
+ TextView cageView;
+ TextView reservoirView;
+ TextView sageView;
+ TextView batteryView;
+ LinearLayout statuslightsLayout;
+
RecyclerView notificationsView;
LinearLayoutManager llm;
@@ -258,8 +268,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
- bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
- iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
+ iageView = (TextView) view.findViewById(R.id.overview_insulinage);
+ cageView = (TextView) view.findViewById(R.id.overview_canulaage);
+ reservoirView = (TextView) view.findViewById(R.id.overview_reservoirlevel);
+ sageView = (TextView) view.findViewById(R.id.overview_sensorage);
+ batteryView = (TextView) view.findViewById(R.id.overview_batterylevel);
+ statuslightsLayout = (LinearLayout) view.findViewById(R.id.overview_statuslights);
+
+ bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
+ iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton);
treatmentButton.setOnClickListener(this);
@@ -446,7 +463,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
super.onCreateContextMenu(menu, v, menuInfo);
if (v == apsModeView) {
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
- final PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription();
+ final PumpDescription pumpDescription =
+ ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription();
if (!ProfileFunctions.getInstance().isProfileValid("ContexMenuCreation"))
return;
menu.setHeaderTitle(MainApp.gs(R.string.loop));
@@ -457,19 +475,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.gs(R.string.suspendloopfor2h));
menu.add(MainApp.gs(R.string.suspendloopfor3h));
menu.add(MainApp.gs(R.string.suspendloopfor10h));
- if (pumpDescription.tempDurationStep15mAllowed)
- menu.add(MainApp.gs(R.string.disconnectpumpfor15m));
- if (pumpDescription.tempDurationStep30mAllowed)
- menu.add(MainApp.gs(R.string.disconnectpumpfor30m));
- menu.add(MainApp.gs(R.string.disconnectpumpfor1h));
- menu.add(MainApp.gs(R.string.disconnectpumpfor2h));
- menu.add(MainApp.gs(R.string.disconnectpumpfor3h));
- } else {
- menu.add(MainApp.gs(R.string.resume));
+ } else {
+ if (!loopPlugin.isDisconnected()) {
+ menu.add(MainApp.gs(R.string.resume));
+ }
}
}
- if (!loopPlugin.isEnabled(PluginType.LOOP))
+
+ if (!loopPlugin.isEnabled(PluginType.LOOP)) {
menu.add(MainApp.gs(R.string.enableloop));
+ }
+
+ if (!loopPlugin.isDisconnected()) {
+ showSuspendtPump(menu, pumpDescription);
+ } else {
+ menu.add(MainApp.gs(R.string.reconnect));
+ }
+
} else if (v == activeProfileView) {
menu.setHeaderTitle(MainApp.gs(R.string.profile));
menu.add(MainApp.gs(R.string.danar_viewprofile));
@@ -488,6 +510,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
}
+ private void showSuspendtPump(ContextMenu menu,
+ PumpDescription pumpDescription) {
+ if (pumpDescription.tempDurationStep15mAllowed)
+ menu.add(MainApp.gs(R.string.disconnectpumpfor15m));
+ if (pumpDescription.tempDurationStep30mAllowed)
+ menu.add(MainApp.gs(R.string.disconnectpumpfor30m));
+ menu.add(MainApp.gs(R.string.disconnectpumpfor1h));
+ menu.add(MainApp.gs(R.string.disconnectpumpfor2h));
+ menu.add(MainApp.gs(R.string.disconnectpumpfor3h));
+ }
+
@Override
public boolean onContextItemSelected(MenuItem item) {
final Profile profile = ProfileFunctions.getInstance().getProfile();
@@ -516,7 +549,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
updateGUI("suspendmenu");
NSUpload.uploadOpenAPSOffline(0);
return true;
- } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) {
+ } else if (item.getTitle().equals(MainApp.gs(R.string.resume)) ||
+ item.getTitle().equals(MainApp.gs(R.string.reconnect))) {
loopPlugin.suspendTo(0L);
updateGUI("suspendmenu");
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
@@ -631,6 +665,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void onClick(View v) {
boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE);
boolean g5 = SourceDexcomG5Plugin.getPlugin().isEnabled(PluginType.BGSOURCE);
+ boolean g6 = SourceDexcomG6Plugin.getPlugin().isEnabled(PluginType.BGSOURCE);
String units = ProfileFunctions.getInstance().getProfileUnits();
FragmentManager manager = getFragmentManager();
@@ -653,7 +688,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (xdrip) {
CalibrationDialog calibrationDialog = new CalibrationDialog();
calibrationDialog.show(manager, "CalibrationDialog");
- } else if (g5) {
+ } else if (g5 || g6) {
try {
Intent i = new Intent("com.dexcom.cgm.activities.MeterEntryActivity");
startActivity(i);
@@ -669,6 +704,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
openCgmApp("com.dexcom.cgm.region5.mgdl");
else if (g5 && units.equals(Constants.MMOL))
openCgmApp("com.dexcom.cgm.region5.mmol");
+ else if (g6 && units.equals(Constants.MGDL))
+ openCgmApp("com.dexcom.g6.region3.mgdl");
+ else if (g6 && units.equals(Constants.MMOL))
+ openCgmApp("com.dexcom.g6.region3.mmol");
break;
case R.id.overview_treatmentbutton:
NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog();
@@ -784,7 +823,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
- if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
+ if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror));
builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
@@ -808,7 +847,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return;
}
accepted = true;
- if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
+ if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || finalCarbsAfterConstraints > 0) {
if (wizard.superBolus) {
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(PluginType.LOOP)) {
@@ -1088,25 +1127,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (Config.APS && pump.getPumpDescription().isTempBasalCapable) {
apsModeView.setVisibility(View.VISIBLE);
- apsModeView.setBackgroundColor(MainApp.gc(R.color.loopenabled));
- apsModeView.setTextColor(Color.BLACK);
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuperBolus()) {
- apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended));
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend()));
- apsModeView.setTextColor(Color.WHITE);
- } else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isDisconnected()) {
- apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended));
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
+ } else if (loopPlugin.isDisconnected()) {
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonCritical));
apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend()));
- apsModeView.setTextColor(Color.WHITE);
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextCritical));
} else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuspended()) {
- apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended));
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()));
- apsModeView.setTextColor(Color.WHITE);
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
} else if (pump.isSuspended()) {
- apsModeView.setBackgroundColor(MainApp.gc(R.color.looppumpsuspended));
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
apsModeView.setText(MainApp.gs(R.string.pumpsuspended));
- apsModeView.setTextColor(Color.WHITE);
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
} else if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (closedLoopEnabled.value()) {
apsModeView.setText(MainApp.gs(R.string.closedloop));
@@ -1114,9 +1153,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
apsModeView.setText(MainApp.gs(R.string.openloop));
}
} else {
- apsModeView.setBackgroundColor(MainApp.gc(R.color.loopdisabled));
+ apsModeView.setBackgroundColor(MainApp.gc(R.color.ribbonCritical));
apsModeView.setText(MainApp.gs(R.string.disabledloop));
- apsModeView.setTextColor(Color.WHITE);
+ apsModeView.setTextColor(MainApp.gc(R.color.ribbonTextCritical));
}
} else {
apsModeView.setVisibility(View.GONE);
@@ -1125,13 +1164,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// temp target
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory();
if (tempTarget != null) {
- tempTargetView.setTextColor(Color.BLACK);
- tempTargetView.setBackgroundColor(MainApp.gc(R.color.tempTargetBackground));
+ tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
+ tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
tempTargetView.setVisibility(View.VISIBLE);
tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end()));
} else {
- tempTargetView.setTextColor(Color.WHITE);
- tempTargetView.setBackgroundColor(MainApp.gc(R.color.tempTargetDisabledBackground));
+ tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
+ tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
tempTargetView.setVisibility(View.VISIBLE);
}
@@ -1230,7 +1269,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
activeProfileView.setText(ProfileFunctions.getInstance().getProfileName());
- activeProfileView.setBackgroundColor(Color.GRAY);
+ if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) {
+ activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
+ activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
+ } else {
+ activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
+ activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
+ }
// QuickWizard button
QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
@@ -1335,6 +1380,56 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobView.setText(cobText);
}
+ if (statuslightsLayout != null) {
+ if (SP.getBoolean(R.string.key_show_statuslights, false)) {
+ CareportalEvent careportalEvent;
+ NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
+ double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 96);
+ double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 72);
+ double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72);
+ double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48);
+ double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166);
+ double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
+ //double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
+ //double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
+ double batUrgent = SP.getDouble(R.string.key_statuslights_bat_critical, 5.0);
+ double batWarn = SP.getDouble(R.string.key_statuslights_bat_warning, 25.0);
+ double resUrgent = SP.getDouble(R.string.key_statuslights_res_critical, 10.0);
+ double resWarn = SP.getDouble(R.string.key_statuslights_res_warning, 80.0);
+
+ if (cageView != null) {
+ careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
+ double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
+ applyStatuslight(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE, true);
+ }
+
+ if (iageView != null) {
+ careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
+ double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
+ applyStatuslight(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE, true);
+ }
+
+ if (reservoirView != null) {
+ double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
+ applyStatuslight(reservoirView, "RES", reservoirLevel, resWarn, resUrgent, -1, false);
+ }
+
+ if (sageView != null) {
+ careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
+ double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
+ applyStatuslight(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE, true);
+ }
+
+ if (batteryView != null) {
+ double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
+ applyStatuslight(batteryView, "BAT", batteryLevel, batWarn, batUrgent, -1, false);
+ }
+ statuslightsLayout.setVisibility(View.VISIBLE);
+ } else {
+ statuslightsLayout.setVisibility(View.GONE);
+ }
+ }
+
boolean predictionsAvailable;
if (Config.APS)
predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
@@ -1364,7 +1459,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// Sensitivity
if (sensitivityView != null) {
- AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("Overview");
+ AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Overview");
if (autosensData != null)
sensitivityView.setText(String.format("%.0f%%", autosensData.autosensResult.ratio * 100));
else
@@ -1525,4 +1620,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
}
+ public static void applyStatuslight(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) {
+ Function check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold;
+ if (value != invalid) {
+ view.setText(text);
+ if (check.apply(urgentThreshold)) {
+ view.setTextColor(MainApp.gc(R.color.ribbonCritical));
+ } else if (check.apply(warnThreshold)) {
+ view.setTextColor(MainApp.gc(R.color.ribbonWarning));
+ } else {
+ view.setTextColor(MainApp.gc(R.color.ribbonDefault));
+ }
+ view.setVisibility(View.VISIBLE);
+ } else {
+ view.setVisibility(View.GONE);
+ }
+
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java
index b184201908..b0981cc6ce 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview;
+package info.nightscout.androidaps.plugins.general.overview;
import com.squareup.otto.Subscribe;
@@ -16,11 +16,11 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java
index 237575c328..0bea854c19 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.activities;
+package info.nightscout.androidaps.plugins.general.overview.activities;
import android.app.Activity;
import android.os.Bundle;
@@ -18,11 +18,11 @@ import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.QuickWizard;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog;
-import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.EditQuickWizardDialog;
+import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
public class QuickWizardListActivity extends AppCompatActivity implements View.OnClickListener {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java
index af336cd74c..2022a4d74b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissBolusprogressIfRunning.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.events;
+package info.nightscout.androidaps.plugins.general.overview.events;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java
similarity index 77%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java
index 1fa71febbe..bc13c93970 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.events;
+package info.nightscout.androidaps.plugins.general.overview.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java
similarity index 63%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java
index 2a669d26d2..f6b62b7f83 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java
@@ -1,7 +1,7 @@
-package info.nightscout.androidaps.plugins.Overview.events;
+package info.nightscout.androidaps.plugins.general.overview.events;
import info.nightscout.androidaps.events.Event;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
/**
* Created by mike on 03.12.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java
similarity index 78%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java
index 18e8ff91bc..3a7c50faac 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventOverviewBolusProgress.java
@@ -1,9 +1,6 @@
-package info.nightscout.androidaps.plugins.Overview.events;
+package info.nightscout.androidaps.plugins.general.overview.events;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.events.Event;
public class EventOverviewBolusProgress extends Event {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java
similarity index 68%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java
index b72c2548e2..7b070d160e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventQuickWizardChange.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.events;
+package info.nightscout.androidaps.plugins.general.overview.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java
index a4b3fc597a..c081567a4c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphData;
+package info.nightscout.androidaps.plugins.general.overview.graphData;
import android.graphics.Color;
import android.graphics.DashPathEffect;
@@ -28,24 +28,24 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
-import info.nightscout.androidaps.plugins.IobCobCalculator.BasalData;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.Round;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.FixedLineGraphSeries;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.ScaledDataPoint;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.TimeAsXAxisLabelFormatter;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.Round;
/**
* Created by mike on 18.10.2017.
@@ -78,6 +78,8 @@ public class GraphData {
if (bgReadingsArray == null || bgReadingsArray.size() == 0) {
if (L.isEnabled(L.OVERVIEW))
log.debug("No BG data.");
+ maxY = 10;
+ minY = 0;
return;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java
index 08da836210..21f0039860 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/AreaGraphSeries.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java
@@ -17,7 +17,7 @@
* with the "Linking Exception" along with this program; if not,
* write to the author Jonas Gehring .
*/
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -26,7 +26,6 @@ import android.graphics.Path;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.BaseSeries;
-import com.jjoe64.graphview.series.DataPointInterface;
import java.util.Iterator;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java
index 20d478692a..60f8266a8e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DataPointWithLabelInterface.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
/**
* GraphView
* Copyright (C) 2014 Jonas Gehring
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java
index 5ac5224c65..b7094be44c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DoubleDataPoint.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/DoubleDataPoint.java
@@ -1,9 +1,8 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
import com.jjoe64.graphview.series.DataPointInterface;
import java.io.Serializable;
-import java.util.Date;
/**
* Created by mike on 21.04.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java
index 922ac3a85b..1ccbcd85cf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/FixedLineGraphSeries.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
/**
* Created by mike on 24.04.2017.
@@ -15,15 +15,6 @@ import com.jjoe64.graphview.series.DataPointInterface;
import java.util.Iterator;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Path;
-
-import com.jjoe64.graphview.GraphView;
-
-import java.util.Iterator;
-
/**
* Series to plot the data as line.
* The line can be styled with many options.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java
index 4a87a8508e..aaa38359a0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/PointsWithLabelGraphSeries.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
/**
* GraphView
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java
index 4aa1271679..21af9d4390 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/Scale.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
/**
* Created by mike on 18.10.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java
index 61f4102a30..ac63790a71 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/ScaledDataPoint.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
import com.jjoe64.graphview.series.DataPointInterface;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java
index 323751e4c8..c5e5441470 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/TimeAsXAxisLabelFormatter.java
@@ -1,12 +1,9 @@
-package info.nightscout.androidaps.plugins.Overview.graphExtensions;
-
-import android.content.Context;
+package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
import com.jjoe64.graphview.DefaultLabelFormatter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
/**
* Created by mike on 09.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java
index ad102bdc11..a8d6fca1ba 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/DismissNotificationService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.notifications;
+package info.nightscout.androidaps.plugins.general.overview.notifications;
import android.app.IntentService;
import android.app.PendingIntent;
@@ -6,7 +6,7 @@ import android.content.Intent;
import android.support.annotation.Nullable;
import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
public class DismissNotificationService extends IntentService {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java
index 23e9ec9643..3b6bcf615d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java
@@ -1,17 +1,14 @@
-package info.nightscout.androidaps.plugins.Overview.notifications;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package info.nightscout.androidaps.plugins.general.overview.notifications;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSAlarm;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
+import info.nightscout.androidaps.utils.SP;
// Added by Rumen for debugging
@@ -68,6 +65,15 @@ public class Notification {
public static final int NSMALFUNCTION = 40;
public static final int NEWVERSIONDETECTED = 41;
public static final int SENDLOGFILES = 42;
+ public static final int DEVICENOTPAIRED = 43;
+ public static final int MEDTRONIC_PUMP_ALARM = 44;
+ public static final int RILEYLINK_CONNECTION = 45;
+ public static final int PERMISSION_PHONESTATE = 46;
+ public static final int INSIGHT_DATE_TIME_UPDATED = 47;
+ public static final int INSIGHT_TIMEOUT_DURING_HANDSHAKE = 48;
+ public static final int DST_LOOP_DISABLED = 49;
+ public static final int DST_IN_24H = 50;
+ public static final int DISKFULL = 51;
public int id;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java
index 9af6be3be3..de35e4bc8c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationRecyclerViewAdapter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.notifications;
+package info.nightscout.androidaps.plugins.general.overview.notifications;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
@@ -18,11 +18,11 @@ import java.util.Objects;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAckAlarm;
-import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAckAlarm;
+import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter {
private static Logger log = LoggerFactory.getLogger(L.NOTIFICATION);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java
index 7c4469521d..8d327bf29f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.notifications;
+package info.nightscout.androidaps.plugins.general.overview.notifications;
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
@@ -26,7 +26,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.services.AlarmSoundService;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 03.12.2016.
@@ -126,12 +126,8 @@ public class NotificationStore {
private void raiseSystemNotification(Notification n) {
Context context = MainApp.instance().getApplicationContext();
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.blueowl);
- int smallIcon = R.drawable.ic_notification;
- if (Config.NSCLIENT) {
- largeIcon = BitmapFactory.decodeResource(MainApp.instance().getResources(), R.mipmap.yellowowl);
- smallIcon = R.drawable.nsclient_smallicon;
- }
+ Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), MainApp.getIcon());
+ int smallIcon = MainApp.getNotificationIcon();
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context, CHANNEL_ID)
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java
index 6248231a59..2ff61b63c8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationWithAction.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Overview.notifications;
+package info.nightscout.androidaps.plugins.general.overview.notifications;
public class NotificationWithAction extends Notification {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java
index 56b3a2cd09..863046c0c4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/DummyService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Persistentnotification;
+package info.nightscout.androidaps.plugins.general.persistentNotification;
import android.app.Notification;
import android.app.Service;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java
similarity index 64%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java
index cd69e88210..0287c21260 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Persistentnotification;
+package info.nightscout.androidaps.plugins.general.persistentNotification;
import android.annotation.SuppressLint;
import android.app.Notification;
@@ -11,11 +11,11 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
import com.squareup.otto.Subscribe;
-import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
@@ -27,7 +27,6 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventInitializationChanged;
-import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
@@ -36,11 +35,12 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
/**
* Created by adrian on 23/12/16.
@@ -60,6 +60,18 @@ public class PersistentNotificationPlugin extends PluginBase {
public static final int ONGOING_NOTIFICATION_ID = 4711;
private final Context ctx;
+ /// For Android Auto
+ /// Intents are not declared in manifest and not consumed, this is intentionally because actually we can't do anything with
+ private static final String PACKAGE = "info.nightscout";
+ private static final String READ_ACTION =
+ "info.nightscout.androidaps.ACTION_MESSAGE_READ";
+ private static final String REPLY_ACTION =
+ "info.nightscout.androidaps.ACTION_MESSAGE_REPLY";
+ private static final String CONVERSATION_ID = "conversation_id";
+ private static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
+ /// End Android Auto
+
+
public PersistentNotificationPlugin(Context ctx) {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
@@ -107,7 +119,8 @@ public class PersistentNotificationPlugin extends PluginBase {
return null;
}
- String line1 = "";
+ String line1;
+ String line1_aa;
if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() == null || !ProfileFunctions.getInstance().isProfileValid("Notificiation"))
return null;
@@ -118,22 +131,25 @@ public class PersistentNotificationPlugin extends PluginBase {
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
if (lastBG != null) {
- line1 = lastBG.valueToUnitsToString(units);
+ line1 = line1_aa = lastBG.valueToUnitsToString(units);
if (glucoseStatus != null) {
line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units)
+ " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units);
+ line1_aa += " " + lastBG.directionToSymbol();
} else {
line1 += " " +
MainApp.gs(R.string.old_data) +
" ";
+ line1_aa += line1 + ".";
}
} else {
- line1 = MainApp.gs(R.string.missed_bg_readings);
+ line1 = line1_aa = MainApp.gs(R.string.missed_bg_readings);
}
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
line1 += " " + activeTemp.toStringShort();
+ line1_aa += " " + activeTemp.toStringShort() + ".";
}
//IOB
@@ -143,30 +159,72 @@ public class PersistentNotificationPlugin extends PluginBase {
IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
- String line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob)+": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString();;
-
+ String line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString();
+ String line2_aa = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U. " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString() + ".";
+
+
String line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h";
+ String line3_aa = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h.";
line3 += " - " + ProfileFunctions.getInstance().getProfileName();
+ line3_aa += " - " + ProfileFunctions.getInstance().getProfileName() + ".";
+
+ /// For Android Auto
+ Intent msgReadIntent = new Intent()
+ .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
+ .setAction(READ_ACTION)
+ .putExtra(CONVERSATION_ID, ONGOING_NOTIFICATION_ID)
+ .setPackage(PACKAGE);
+
+ PendingIntent msgReadPendingIntent =
+ PendingIntent.getBroadcast(ctx,
+ ONGOING_NOTIFICATION_ID,
+ msgReadIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ Intent msgReplyIntent = new Intent()
+ .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
+ .setAction(REPLY_ACTION)
+ .putExtra(CONVERSATION_ID, ONGOING_NOTIFICATION_ID)
+ .setPackage(PACKAGE);
+
+ PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(
+ ctx,
+ ONGOING_NOTIFICATION_ID,
+ msgReplyIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Build a RemoteInput for receiving voice input from devices
+ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();
+
+ // Create the UnreadConversation
+ NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder =
+ new NotificationCompat.CarExtender.UnreadConversation.Builder(line1_aa + "\n" + line2_aa)
+ .setLatestTimestamp(System.currentTimeMillis())
+ .setReadPendingIntent(msgReadPendingIntent)
+ .setReplyAction(msgReplyPendingIntent, remoteInput);
+
+ /// Add dot to produce a "more natural sounding result"
+ unreadConversationBuilder.addMessage(line3_aa);
+ /// End Android Auto
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID);
builder.setOngoing(true);
builder.setOnlyAlertOnce(true);
builder.setCategory(NotificationCompat.CATEGORY_STATUS);
- if (Config.NSCLIENT){
- builder.setSmallIcon(R.drawable.nsclient_smallicon);
- Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.yellowowl);
- builder.setLargeIcon(largeIcon);
- } else {
- builder.setSmallIcon(R.drawable.ic_notification);
- Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.blueowl);
- builder.setLargeIcon(largeIcon);
- }
+ builder.setSmallIcon(MainApp.getNotificationIcon());
+ Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), MainApp.getIcon());
+ builder.setLargeIcon(largeIcon);
builder.setContentTitle(line1);
builder.setContentText(line2);
builder.setSubText(line3);
+ /// Android Auto
+ builder.extend(new NotificationCompat.CarExtender()
+ .setUnreadConversation(unreadConversationBuilder.build()));
+ /// End Android Auto
+
Intent resultIntent = new Intent(ctx, MainActivity.class);
@@ -225,7 +283,7 @@ public class PersistentNotificationPlugin extends PluginBase {
}
@Subscribe
- public void onStatusEvent(final EventNewBG ev) {
+ public void onStatusEvent(final EventAutosensCalculationFinished ev) {
triggerNotificationUpdate();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java
new file mode 100644
index 0000000000..4b05072eb1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java
@@ -0,0 +1,59 @@
+package info.nightscout.androidaps.plugins.general.smsCommunicator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.utils.DateUtil;
+
+class AuthRequest {
+ private static Logger log = LoggerFactory.getLogger(L.SMS);
+
+ Sms requester;
+ String confirmCode;
+ private Runnable action;
+
+ private long date;
+
+ private boolean processed;
+ private SmsCommunicatorPlugin plugin;
+
+ AuthRequest(SmsCommunicatorPlugin plugin, Sms requester, String requestText, String confirmCode, SmsAction action) {
+ this.requester = requester;
+ this.confirmCode = confirmCode;
+ this.action = action;
+ this.plugin = plugin;
+
+ this.date = DateUtil.now();
+
+ plugin.sendSMS(new Sms(requester.phoneNumber, requestText));
+ }
+
+ void action(String codeReceived) {
+ if (processed) {
+ if (L.isEnabled(L.SMS))
+ log.debug("Already processed");
+ return;
+ }
+ if (!confirmCode.equals(codeReceived)) {
+ processed = true;
+ if (L.isEnabled(L.SMS))
+ log.debug("Wrong code");
+ plugin.sendSMS(new Sms(requester.phoneNumber, R.string.sms_wrongcode));
+ return;
+ }
+ if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) {
+ processed = true;
+ if (L.isEnabled(L.SMS))
+ log.debug("Processing confirmed SMS: " + requester.text);
+ if (action != null)
+ action.run();
+ return;
+ }
+ if (L.isEnabled(L.SMS))
+ log.debug("Timed out SMS: " + requester.text);
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java
new file mode 100644
index 0000000000..2eedfa0a51
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java
@@ -0,0 +1,42 @@
+package info.nightscout.androidaps.plugins.general.smsCommunicator;
+
+import android.telephony.SmsMessage;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.utils.DateUtil;
+
+class Sms {
+ String phoneNumber;
+ String text;
+ long date;
+ boolean received = false;
+ boolean sent = false;
+ boolean processed = false;
+ boolean ignored = false;
+
+ Sms(SmsMessage message) {
+ phoneNumber = message.getOriginatingAddress();
+ text = message.getMessageBody();
+ date = message.getTimestampMillis();
+ received = true;
+ }
+
+ Sms(String phoneNumber, String text) {
+ this.phoneNumber = phoneNumber;
+ this.text = text;
+ this.date = DateUtil.now();
+ sent = true;
+ }
+
+ Sms(String phoneNumber, int textId) {
+ this.phoneNumber = phoneNumber;
+ this.text = MainApp.gs(textId);
+ this.date = DateUtil.now();
+ sent = true;
+ }
+
+ public String toString() {
+ return "SMS from " + phoneNumber + ": " + text;
+ }
+}
+
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java
new file mode 100644
index 0000000000..6b5d5b8747
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java
@@ -0,0 +1,33 @@
+package info.nightscout.androidaps.plugins.general.smsCommunicator;
+
+abstract class SmsAction implements Runnable {
+ Double aDouble;
+ Integer anInteger;
+ Integer secondInteger;
+ String aString;
+
+ SmsAction() {}
+
+ SmsAction(Double aDouble) {
+ this.aDouble = aDouble;
+ }
+
+ SmsAction(Double aDouble, Integer secondInteger) {
+ this.aDouble = aDouble;
+ this.secondInteger = secondInteger;
+ }
+
+ SmsAction(String aString, Integer secondInteger) {
+ this.aString = aString;
+ this.secondInteger = secondInteger;
+ }
+
+ SmsAction(Integer anInteger) {
+ this.anInteger = anInteger;
+ }
+
+ SmsAction(Integer anInteger, Integer secondInteger) {
+ this.anInteger = anInteger;
+ this.secondInteger = secondInteger;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java
new file mode 100644
index 0000000000..d1c4adf5fe
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.java
@@ -0,0 +1,73 @@
+package info.nightscout.androidaps.plugins.general.smsCommunicator;
+
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.text.Html;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.squareup.otto.Subscribe;
+
+import java.util.Collections;
+import java.util.Comparator;
+
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui;
+import info.nightscout.androidaps.utils.DateUtil;
+
+public class SmsCommunicatorFragment extends SubscriberFragment {
+ TextView logView;
+
+ public SmsCommunicatorFragment() {
+ super();
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.smscommunicator_fragment, container, false);
+
+ logView = (TextView) view.findViewById(R.id.smscommunicator_log);
+
+ return view;
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventSmsCommunicatorUpdateGui ev) {
+ updateGUI();
+ }
+
+ @Override
+ protected void updateGUI() {
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.runOnUiThread(() -> {
+ class CustomComparator implements Comparator {
+ public int compare(Sms object1, Sms object2) {
+ return (int) (object1.date - object2.date);
+ }
+ }
+ Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator());
+ int messagesToShow = 40;
+
+ int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().messages.size() - messagesToShow);
+
+ String logText = "";
+ for (int x = start; x < SmsCommunicatorPlugin.getPlugin().messages.size(); x++) {
+ Sms sms = SmsCommunicatorPlugin.getPlugin().messages.get(x);
+ if (sms.ignored) {
+ logText += DateUtil.timeString(sms.date) + " <<< " + "░ " + sms.phoneNumber + " " + sms.text + "
";
+ } else if (sms.received) {
+ logText += DateUtil.timeString(sms.date) + " <<< " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
";
+ } else if (sms.sent) {
+ logText += DateUtil.timeString(sms.date) + " >>> " + (sms.processed ? "● " : "○ ") + sms.phoneNumber + " " + sms.text + "
";
+ }
+ }
+ logView.setText(Html.fromHtml(logText));
+ });
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java
new file mode 100644
index 0000000000..e4ec65df11
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java
@@ -0,0 +1,795 @@
+package info.nightscout.androidaps.plugins.general.smsCommunicator;
+
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.telephony.SmsManager;
+import android.telephony.SmsMessage;
+
+import com.squareup.otto.Subscribe;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.Normalizer;
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.data.DetailedBolusInfo;
+import info.nightscout.androidaps.data.GlucoseStatus;
+import info.nightscout.androidaps.data.IobTotal;
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.data.ProfileStore;
+import info.nightscout.androidaps.db.BgReading;
+import info.nightscout.androidaps.db.DatabaseHelper;
+import info.nightscout.androidaps.db.Source;
+import info.nightscout.androidaps.events.EventPreferenceChange;
+import info.nightscout.androidaps.events.EventRefreshOverview;
+import info.nightscout.androidaps.interfaces.Constraint;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PluginDescription;
+import info.nightscout.androidaps.interfaces.PluginType;
+import info.nightscout.androidaps.interfaces.ProfileInterface;
+import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.queue.Callback;
+import info.nightscout.androidaps.services.Intents;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.XdripCalibrations;
+
+/**
+ * Created by mike on 05.08.2016.
+ */
+public class SmsCommunicatorPlugin extends PluginBase {
+ private static Logger log = LoggerFactory.getLogger(L.SMS);
+
+ private static SmsCommunicatorPlugin smsCommunicatorPlugin;
+
+ public static SmsCommunicatorPlugin getPlugin() {
+
+ if (smsCommunicatorPlugin == null) {
+ smsCommunicatorPlugin = new SmsCommunicatorPlugin();
+ }
+ return smsCommunicatorPlugin;
+ }
+
+ List allowedNumbers = new ArrayList<>();
+
+ AuthRequest messageToConfirm = null;
+
+ long lastRemoteBolusTime = 0;
+
+ ArrayList messages = new ArrayList<>();
+
+ SmsCommunicatorPlugin() {
+ super(new PluginDescription()
+ .mainType(PluginType.GENERAL)
+ .fragmentClass(SmsCommunicatorFragment.class.getName())
+ .pluginName(R.string.smscommunicator)
+ .shortName(R.string.smscommunicator_shortname)
+ .preferencesId(R.xml.pref_smscommunicator)
+ .description(R.string.description_sms_communicator)
+ );
+ processSettings(null);
+ }
+
+ @Override
+ protected void onStart() {
+ MainApp.bus().register(this);
+ super.onStart();
+ }
+
+ @Override
+ protected void onStop() {
+ MainApp.bus().unregister(this);
+ }
+
+ @Subscribe
+ public void processSettings(final EventPreferenceChange ev) {
+ if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
+ String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
+
+ String pattern = ";";
+
+ String[] substrings = settings.split(pattern);
+ for (String number : substrings) {
+ String cleaned = number.replaceAll("\\s+", "");
+ allowedNumbers.add(cleaned);
+ log.debug("Found allowed number: " + cleaned);
+ }
+ }
+ }
+
+ boolean isCommand(String command, String number) {
+ switch(command.toUpperCase()) {
+ case "BG":
+ case "LOOP":
+ case "TREATMENTS":
+ case "NSCLIENT":
+ case "PUMP":
+ case "BASAL":
+ case "BOLUS":
+ case "EXTENDED":
+ case "CAL":
+ case "PROFILE":
+ return true;
+ }
+ if (messageToConfirm != null && messageToConfirm.requester.phoneNumber.equals(number))
+ return true;
+ return false;
+ }
+
+ boolean isAllowedNumber(String number) {
+ for (String num : allowedNumbers) {
+ if (num.equals(number)) return true;
+ }
+ return false;
+ }
+
+ public void handleNewData(Intent intent) {
+ Bundle bundle = intent.getExtras();
+ if (bundle == null) return;
+
+ Object[] pdus = (Object[]) bundle.get("pdus");
+ if (pdus != null) {
+ // For every SMS message received
+ for (Object pdu : pdus) {
+ SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu);
+ processSms(new Sms(message));
+ }
+ }
+ }
+
+ void processSms(final Sms receivedSms) {
+ if (!isEnabled(PluginType.GENERAL)) {
+ log.debug("Ignoring SMS. Plugin disabled.");
+ return;
+ }
+ if (!isAllowedNumber(receivedSms.phoneNumber)) {
+ log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed");
+ receivedSms.ignored = true;
+ messages.add(receivedSms);
+ MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
+ return;
+ }
+
+ messages.add(receivedSms);
+ log.debug(receivedSms.toString());
+
+ String[] splitted = receivedSms.text.split("\\s+");
+ boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
+
+ if (splitted.length > 0 && isCommand(splitted[0].toUpperCase(), receivedSms.phoneNumber)) {
+ switch (splitted[0].toUpperCase()) {
+ case "BG":
+ processBG(splitted, receivedSms);
+ break;
+ case "LOOP":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2 || splitted.length == 3)
+ processLOOP(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "TREATMENTS":
+ if (splitted.length == 2)
+ processTREATMENTS(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "NSCLIENT":
+ if (splitted.length == 2)
+ processNSCLIENT(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "PUMP":
+ processPUMP(splitted, receivedSms);
+ break;
+ case "PROFILE":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2 || splitted.length == 3)
+ processPROFILE(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "BASAL":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2 || splitted.length == 3)
+ processBASAL(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "EXTENDED":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2 || splitted.length == 3)
+ processEXTENDED(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "BOLUS":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2 && DateUtil.now() - lastRemoteBolusTime < Constants.remoteBolusMinDistance)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotebolusnotallowed));
+ else if (splitted.length == 2 && ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended())
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.pumpsuspended));
+ else if (splitted.length == 2)
+ processBOLUS(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ case "CAL":
+ if (!remoteCommandsAllowed)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
+ else if (splitted.length == 2)
+ processCAL(splitted, receivedSms);
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ default: // expect passCode here
+ if (messageToConfirm != null && messageToConfirm.requester.phoneNumber.equals(receivedSms.phoneNumber)) {
+ messageToConfirm.action(splitted[0]);
+ messageToConfirm = null;
+ } else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand));
+ break;
+ }
+ }
+
+ MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
+ }
+
+ @SuppressWarnings("unused")
+ private void processBG(String[] splitted, Sms receivedSms) {
+ BgReading actualBG = DatabaseHelper.actualBg();
+ BgReading lastBG = DatabaseHelper.lastBg();
+
+ String reply = "";
+
+ String units = ProfileFunctions.getInstance().getProfileUnits();
+
+ if (actualBG != null) {
+ reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
+ } else if (lastBG != null) {
+ Long agoMsec = System.currentTimeMillis() - lastBG.date;
+ int agoMin = (int) (agoMsec / 60d / 1000d);
+ reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", ";
+ }
+ GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
+ if (glucoseStatus != null)
+ reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
+
+ TreatmentsPlugin.getPlugin().updateTotalIOBTreatments();
+ IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round();
+ TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
+ IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
+
+ String cobText = MainApp.gs(R.string.value_unavailable_short);
+ CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "SMS COB");
+
+ reply += MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U), "
+ + MainApp.gs(R.string.cob) + ": " + cobInfo.generateCOBString();
+
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ receivedSms.processed = true;
+ }
+
+ private void processLOOP(String[] splitted, Sms receivedSms) {
+ String reply;
+ switch (splitted[1].toUpperCase()) {
+ case "DISABLE":
+ case "STOP":
+ LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
+ if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) {
+ loopPlugin.setPluginEnabled(PluginType.LOOP, false);
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
+ @Override
+ public void run() {
+ MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
+ String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " +
+ MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ });
+ } else {
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisdisabled));
+ }
+ receivedSms.processed = true;
+ break;
+ case "ENABLE":
+ case "START":
+ loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
+ if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
+ loopPlugin.setPluginEnabled(PluginType.LOOP, true);
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loophasbeenenabled));
+ MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
+ } else {
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisenabled));
+ }
+ receivedSms.processed = true;
+ break;
+ case "STATUS":
+ loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
+ if (loopPlugin != null) {
+ if (loopPlugin.isEnabled(PluginType.LOOP)) {
+ if (loopPlugin.isSuspended())
+ reply = String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend());
+ else
+ reply = MainApp.gs(R.string.smscommunicator_loopisenabled);
+ } else {
+ reply = MainApp.gs(R.string.smscommunicator_loopisdisabled);
+ }
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ receivedSms.processed = true;
+ break;
+ case "RESUME":
+ LoopPlugin.getPlugin().suspendTo(0);
+ MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME"));
+ NSUpload.uploadOpenAPSOffline(0);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopresumed));
+ break;
+ case "SUSPEND":
+ int duration = 0;
+ if (splitted.length == 3)
+ duration = SafeParse.stringToInt(splitted[2]);
+ duration = Math.max(0, duration);
+ duration = Math.min(180, duration);
+ if (duration == 0) {
+ receivedSms.processed = true;
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_wrongduration));
+ return;
+ } else {
+ String passCode = generatePasscode();
+ reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(duration) {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger * 60L * 1000);
+ NSUpload.uploadOpenAPSOffline(anInteger * 60);
+ MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
+ String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
+ MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+
+ }
+ });
+ }
+ break;
+ default:
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ break;
+ }
+ }
+
+ private void processTREATMENTS(String[] splitted, Sms receivedSms) {
+ if (splitted[1].toUpperCase().equals("REFRESH")) {
+ Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
+ TreatmentsPlugin.getPlugin().getService().resetTreatments();
+ MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
+ List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
+ String reply = "TREATMENTS REFRESH " + q.size() + " receivers";
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ receivedSms.processed = true;
+ } else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ }
+
+ private void processNSCLIENT(String[] splitted, Sms receivedSms) {
+ if (splitted[1].toUpperCase().equals("RESTART")) {
+ Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
+ MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
+ List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
+ String reply = "NSCLIENT RESTART " + q.size() + " receivers";
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ receivedSms.processed = true;
+ } else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ }
+
+ @SuppressWarnings("unused")
+ private void processPUMP(String[] splitted, Sms receivedSms) {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() {
+ @Override
+ public void run() {
+ PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
+ if (result.success) {
+ if (pump != null) {
+ String reply = pump.shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ } else {
+ String reply = MainApp.gs(R.string.readstatusfailed);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ receivedSms.processed = true;
+ }
+
+ private void processPROFILE(String[] splitted, Sms receivedSms) {
+ // load profiles
+ ProfileInterface anInterface = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
+ if (anInterface == null) {
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured));
+ receivedSms.processed = true;
+ return;
+ }
+ ProfileStore store = anInterface.getProfile();
+ if (store == null) {
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured));
+ receivedSms.processed = true;
+ return;
+ }
+ final ArrayList list = store.getProfileList();
+
+ if (splitted[1].toUpperCase().equals("STATUS")) {
+ sendSMS(new Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().getProfileName()));
+ } else if (splitted[1].toUpperCase().equals("LIST")) {
+ if (list.isEmpty())
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.invalidprofile));
+ else {
+ String reply = "";
+ for (int i = 0; i < list.size(); i++) {
+ if (i > 0)
+ reply += "\n";
+ reply += (i + 1) + ". ";
+ reply += list.get(i);
+ }
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ } else {
+
+ int pindex = SafeParse.stringToInt(splitted[1]);
+ int percentage = 100;
+ if (splitted.length > 2)
+ percentage = SafeParse.stringToInt(splitted[2]);
+
+ if (pindex > list.size())
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else if (percentage == 0)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else if (pindex == 0)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else {
+ final Profile profile = store.getSpecificProfile((String) list.get(pindex - 1));
+ if (profile == null)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
+ else {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_profilereplywithcode), list.get(pindex - 1), percentage, passCode);
+ receivedSms.processed = true;
+ int finalPercentage = percentage;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction((String) list.get(pindex - 1), finalPercentage) {
+ @Override
+ public void run() {
+ ProfileFunctions.doProfileSwitch(store, (String) list.get(pindex - 1), 0, finalPercentage, 0);
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.profileswitchcreated));
+ }
+ });
+ }
+ }
+ }
+ receivedSms.processed = true;
+ }
+
+ private void processBASAL(String[] splitted, Sms receivedSms) {
+ if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ } else if (splitted[1].endsWith("%")) {
+ int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splitted[1], "%"));
+ int duration = 30;
+ if (splitted.length > 2)
+ duration = SafeParse.stringToInt(splitted[2]);
+ final Profile profile = ProfileFunctions.getInstance().getProfile();
+
+ if (profile == null)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
+ else if (tempBasalPct == 0 && !splitted[1].equals("0%"))
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else if (duration == 0)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else {
+ tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value();
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, duration, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct, duration) {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, secondInteger, true, profile, new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ String reply;
+ if (result.isPercent)
+ reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration);
+ else
+ reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ }
+ } else {
+ Double tempBasal = SafeParse.stringToDouble(splitted[1]);
+ int duration = 30;
+ if (splitted.length > 2)
+ duration = SafeParse.stringToInt(splitted[2]);
+ final Profile profile = ProfileFunctions.getInstance().getProfile();
+ if (profile == null)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
+ else if (tempBasal == 0 && !splitted[1].equals("0"))
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else if (duration == 0)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else {
+ tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, duration, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal, duration) {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, secondInteger, true, profile, new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ String reply;
+ if (result.isPercent)
+ reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration);
+ else
+ reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+ }
+
+ private void processEXTENDED(String[] splitted, Sms receivedSms) {
+ if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelExtended(new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ String reply = MainApp.gs(R.string.smscommunicator_extendedcanceled);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_extendedcancelfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ } else if (splitted.length != 3) {
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ } else {
+ Double extended = SafeParse.stringToDouble(splitted[1]);
+ int duration = SafeParse.stringToInt(splitted[2]);
+ extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value();
+ if (extended == 0 || duration == 0)
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ else {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) {
+ @Override
+ public void run() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().extendedBolus(aDouble, secondInteger, new Callback() {
+ @Override
+ public void run() {
+ if (result.success) {
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_extendedfailed);
+ reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+ }
+
+
+ private void processBOLUS(String[] splitted, Sms receivedSms) {
+ Double bolus = SafeParse.stringToDouble(splitted[1]);
+ bolus = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolus)).value();
+ if (bolus > 0d) {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), bolus, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(bolus) {
+ @Override
+ public void run() {
+ DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
+ detailedBolusInfo.insulin = aDouble;
+ detailedBolusInfo.source = Source.USER;
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(detailedBolusInfo, new Callback() {
+ @Override
+ public void run() {
+ final boolean resultSuccess = result.success;
+ final double resultBolusDelivered = result.bolusDelivered;
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() {
+ @Override
+ public void run() {
+ PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
+ if (resultSuccess) {
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), resultBolusDelivered);
+ if (pump != null)
+ reply += "\n" + pump.shortStatus(true);
+ lastRemoteBolusTime = DateUtil.now();
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
+ } else {
+ String reply = MainApp.gs(R.string.smscommunicator_bolusfailed);
+ if (pump != null)
+ reply += "\n" + pump.shortStatus(true);
+ sendSMS(new Sms(receivedSms.phoneNumber, reply));
+ }
+ }
+ });
+ }
+ });
+ }
+ });
+ } else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ }
+
+ private void processCAL(String[] splitted, Sms receivedSms) {
+ Double cal = SafeParse.stringToDouble(splitted[1]);
+ if (cal > 0d) {
+ String passCode = generatePasscode();
+ String reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), cal, passCode);
+ receivedSms.processed = true;
+ messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
+ @Override
+ public void run() {
+ boolean result = XdripCalibrations.sendIntent(aDouble);
+ if (result)
+ sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationsent));
+ else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationfailed));
+ }
+ });
+ } else
+ sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
+ }
+
+ public void sendNotificationToAllNumbers(String text) {
+ for (int i = 0; i < allowedNumbers.size(); i++) {
+ Sms sms = new Sms(allowedNumbers.get(i), text);
+ sendSMS(sms);
+ }
+ }
+
+ private void sendSMSToAllNumbers(Sms sms) {
+ for (String number : allowedNumbers) {
+ sms.phoneNumber = number;
+ sendSMS(sms);
+ }
+ }
+
+ void sendSMS(Sms sms) {
+ SmsManager smsManager = SmsManager.getDefault();
+ sms.text = stripAccents(sms.text);
+ if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
+ try {
+ if (L.isEnabled(L.SMS))
+ log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text);
+ smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
+ messages.add(sms);
+ } catch (IllegalArgumentException e) {
+ Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
+ } catch (java.lang.SecurityException e) {
+ Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
+ }
+ MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
+ }
+
+ private String generatePasscode() {
+ int startChar1 = 'A'; // on iphone 1st char is uppercase :)
+ String passCode = Character.toString((char) (startChar1 + Math.random() * ('z' - 'a' + 1)));
+ int startChar2 = Math.random() > 0.5 ? 'a' : 'A';
+ passCode += Character.toString((char) (startChar2 + Math.random() * ('z' - 'a' + 1)));
+ int startChar3 = Math.random() > 0.5 ? 'a' : 'A';
+ passCode += Character.toString((char) (startChar3 + Math.random() * ('z' - 'a' + 1)));
+ passCode.replace('l', 'k').replace('I', 'J');
+ return passCode;
+ }
+
+ private static String stripAccents(String s) {
+ s = Normalizer.normalize(s, Normalizer.Form.NFD);
+ s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
+ return s;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java
similarity index 69%
rename from app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java
index 02956a5d67..7e50671c45 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/events/EventSmsCommunicatorUpdateGui.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.SmsCommunicator.events;
+package info.nightscout.androidaps.plugins.general.smsCommunicator.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
index 5245921922..b92410d67f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Wear;
+package info.nightscout.androidaps.plugins.general.wear;
import android.app.NotificationManager;
import android.content.Context;
@@ -31,31 +31,31 @@ import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
-import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
-import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
-import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.aps.loop.APSResult;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
+import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
+import info.nightscout.androidaps.plugins.treatments.CarbsGenerator;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.BolusWizard;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.HardLimits;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.BolusWizard;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.HardLimits;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by adrian on 09/02/17.
@@ -232,8 +232,8 @@ public class ActionStringHandler {
0d, percentage, useBolusIOB, useBasalIOB, false, useTrend);
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolusWizard.calculatedTotalInsulin)).value();
- if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) {
- sendError("Insulin contraint violation!" +
+ if (Math.abs(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) {
+ sendError("Insulin constraint violation!" +
"\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) + "!");
return;
}
@@ -452,7 +452,7 @@ public class ActionStringHandler {
PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class);
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
- PumpInterface insight = MainApp.getSpecificPlugin(InsightPlugin.class);
+ PumpInterface insight = MainApp.getSpecificPlugin(LocalInsightPlugin.class);
boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight;
@@ -693,7 +693,7 @@ public class ActionStringHandler {
//send profile to pumpe
new NewNSTreatmentDialog(); //init
- NewNSTreatmentDialog.doProfileSwitch(0, percentage, timeshift);
+ ProfileFunctions.doProfileSwitch(0, percentage, timeshift);
}
private static void generateTempTarget(int duration, double low, double high) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java
index b1b47a4ae2..701784e9d9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearFragment.java
@@ -1,6 +1,5 @@
-package info.nightscout.androidaps.plugins.Wear;
+package info.nightscout.androidaps.plugins.general.wear;
-import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java
index 72b2397213..2d7f13f221 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.java
@@ -1,7 +1,8 @@
-package info.nightscout.androidaps.plugins.Wear;
+package info.nightscout.androidaps.plugins.general.wear;
import android.content.Context;
import android.content.Intent;
+import android.util.Log;
import com.squareup.otto.Subscribe;
@@ -9,7 +10,6 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventBolusRequested;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
-import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
@@ -18,12 +18,13 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by adrian on 17/11/16.
@@ -35,6 +36,8 @@ public class WearPlugin extends PluginBase {
private final Context ctx;
private static WearPlugin wearPlugin;
+ private static String TAG = "WearPlugin";
+
public static WearPlugin getPlugin() {
return wearPlugin;
@@ -76,7 +79,10 @@ public class WearPlugin extends PluginBase {
}
private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) {
- if (isEnabled(getType())) { //only start service when this plugin is enabled
+
+ //Log.d(TAG, "WR: WearPlugin:sendDataToWatch (status=" + status + ",basals=" + basals + ",bgValue=" + bgValue + ")");
+
+ if (isEnabled(getType())) { // only start service when this plugin is enabled
if (bgValue) {
ctx.startService(new Intent(ctx, WatchUpdaterService.class));
@@ -93,15 +99,20 @@ public class WearPlugin extends PluginBase {
}
void resendDataToWatch() {
+ //Log.d(TAG, "WR: WearPlugin:resendDataToWatch");
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND));
}
void openSettings() {
+ //Log.d(TAG, "WR: WearPlugin:openSettings");
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
}
void requestNotificationCancel(String actionstring) {
- Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION);
+ //Log.d(TAG, "WR: WearPlugin:requestNotificationCancel");
+
+ Intent intent = new Intent(ctx, WatchUpdaterService.class)
+ .setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION);
intent.putExtra("actionstring", actionstring);
ctx.startService(intent);
}
@@ -136,7 +147,7 @@ public class WearPlugin extends PluginBase {
}
@Subscribe
- public void onStatusEvent(final EventNewBG ev) {
+ public void onStatusEvent(final EventAutosensCalculationFinished ev) {
sendDataToWatch(true, true, true);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java
new file mode 100644
index 0000000000..aa6498563d
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/SendToDataLayerThread.java
@@ -0,0 +1,139 @@
+package info.nightscout.androidaps.plugins.general.wear.wearintegration;
+
+import android.os.AsyncTask;
+import android.util.Log;
+
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Created by emmablack on 12/26/14.
+ */
+class SendToDataLayerThread extends AsyncTask {
+ private GoogleApiClient googleApiClient;
+ private static final String TAG = "SendToDataLayerThread";
+ private String path;
+ private String logPrefix = ""; // "WR: ";
+ private static int concurrency = 0;
+ private static int state = 0;
+ private static final ReentrantLock lock = new ReentrantLock();
+ private static long lastlock = 0;
+ private static final boolean testlockup = false; // always false in production
+
+
+ SendToDataLayerThread(String path, GoogleApiClient pGoogleApiClient) {
+ // Log.d(TAG, logPrefix + "SendToDataLayerThread: " + path);
+ this.path = path;
+ googleApiClient = pGoogleApiClient;
+ }
+
+
+ @Override
+ protected void onPreExecute() {
+ concurrency++;
+ if ((concurrency > 12) || ((concurrency > 3 && (lastlock != 0) && (tsl() - lastlock) > 300000))) {
+ // error if 9 concurrent threads or lock held for >5 minutes with concurrency of 4
+ final String err = "Wear Integration deadlock detected!! " + ((lastlock != 0) ? "locked" : "") + " state:"
+ + state + " @" + hourMinuteString(tsl());
+ // Home.toaststaticnext(err);
+ Log.e(TAG, logPrefix + err);
+ }
+ if (concurrency < 0)
+ Log.d(TAG, logPrefix + "Wear Integration impossible concurrency!!");
+
+ Log.d(TAG, logPrefix + "SendDataToLayerThread pre-execute concurrency: " + concurrency);
+ }
+
+
+ @Override
+ protected Void doInBackground(DataMap... params) {
+ if (testlockup) {
+ try {
+ Log.e(TAG, logPrefix + "WARNING RUNNING TEST LOCK UP CODE - NEVER FOR PRODUCTION");
+ Thread.sleep(1000000); // DEEEBBUUGGGG
+ } catch (Exception e) {
+ }
+ }
+ sendToWear(params);
+ concurrency--;
+ Log.d(TAG, logPrefix + "SendDataToLayerThread post-execute concurrency: " + concurrency);
+ return null;
+ }
+
+
+ // Debug function to expose where it might be locking up
+ private synchronized void sendToWear(final DataMap... params) {
+ if (!lock.tryLock()) {
+ Log.d(TAG, logPrefix + "Concurrent access - waiting for thread unlock");
+ lock.lock(); // enforce single threading
+ Log.d(TAG, logPrefix + "Thread unlocked - proceeding");
+ }
+ lastlock = tsl();
+ try {
+ if (state != 0) {
+ Log.e(TAG, logPrefix + "WEAR STATE ERROR: state=" + state);
+ }
+ state = 1;
+ final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15,
+ TimeUnit.SECONDS);
+
+ Log.d(TAG, logPrefix + "Nodes: " + nodes);
+
+ state = 2;
+ for (Node node : nodes.getNodes()) {
+ state = 3;
+ for (DataMap dataMap : params) {
+ state = 4;
+ PutDataMapRequest putDMR = PutDataMapRequest.create(path);
+ state = 5;
+ putDMR.getDataMap().putAll(dataMap);
+ putDMR.setUrgent();
+ state = 6;
+ PutDataRequest request = putDMR.asPutDataRequest();
+ state = 7;
+ DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15,
+ TimeUnit.SECONDS);
+ state = 8;
+ if (result.getStatus().isSuccess()) {
+ Log.d(TAG, logPrefix + "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
+ } else {
+ Log.e(TAG, logPrefix + "ERROR: failed to send DataMap");
+ result = Wearable.DataApi.putDataItem(googleApiClient, request).await(30, TimeUnit.SECONDS);
+ if (result.getStatus().isSuccess()) {
+ Log.d(TAG, logPrefix + "DataMap retry: " + dataMap + " sent to: " + node.getDisplayName());
+ } else {
+ Log.e(TAG, logPrefix + "ERROR on retry: failed to send DataMap: "
+ + result.getStatus().toString());
+ }
+ }
+ state = 9;
+ }
+ }
+ state = 0;
+ } catch (Exception e) {
+ Log.e(TAG, logPrefix + "Got exception in sendToWear: " + e.toString());
+ } finally {
+ lastlock = 0;
+ lock.unlock();
+ }
+ }
+
+
+ private static long tsl() {
+ return System.currentTimeMillis();
+ }
+
+
+ private static String hourMinuteString(long timestamp) {
+ return android.text.format.DateFormat.format("kk:mm", timestamp).toString();
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java
index 8007e03164..52dbeed75c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java
@@ -1,9 +1,17 @@
-package info.nightscout.androidaps.plugins.Wear.wearintegration;
+package info.nightscout.androidaps.plugins.general.wear.wearintegration;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.os.AsyncTask;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
@@ -14,8 +22,11 @@ import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.CapabilityApi;
+import com.google.android.gms.wearable.CapabilityInfo;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.PutDataMapRequest;
import com.google.android.gms.wearable.PutDataRequest;
import com.google.android.gms.wearable.Wearable;
@@ -37,27 +48,29 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TemporaryBasal;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
-import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
-import info.nightscout.androidaps.plugins.Wear.WearPlugin;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
+import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
+import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.ToastUtils;
+
+public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
-public class WatchUpdaterService extends WearableListenerService implements
- GoogleApiClient.ConnectionCallbacks,
- GoogleApiClient.OnConnectionFailedListener {
public static final String ACTION_RESEND = WatchUpdaterService.class.getName().concat(".Resend");
public static final String ACTION_OPEN_SETTINGS = WatchUpdaterService.class.getName().concat(".OpenSettings");
public static final String ACTION_SEND_STATUS = WatchUpdaterService.class.getName().concat(".SendStatus");
@@ -92,6 +105,17 @@ public class WatchUpdaterService extends WearableListenerService implements
private Handler handler;
+ // Phone
+ private static final String CAPABILITY_PHONE_APP = "phone_app_sync_bgs";
+ private static final String MESSAGE_PATH_PHONE = "/phone_message_path";
+ // Wear
+ private static final String CAPABILITY_WEAR_APP = "wear_app_sync_bgs";
+ private static final String MESSAGE_PATH_WEAR = "/wear_message_path";
+ private String mWearNodeId = null;
+ private String localnode = null;
+ private String logPrefix = ""; // "WR: "
+
+
@Override
public void onCreate() {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@@ -113,24 +137,24 @@ public class WatchUpdaterService extends WearableListenerService implements
public void setSettings() {
wear_integration = WearPlugin.getPlugin().isEnabled(PluginType.GENERAL);
+ // Log.d(TAG, "WR: wear_integration=" + wear_integration);
if (wear_integration) {
googleApiConnect();
}
}
- public void googleApiConnect() {
+
+ private void googleApiConnect() {
if (googleApiClient != null && (googleApiClient.isConnected() || googleApiClient.isConnecting())) {
googleApiClient.disconnect();
}
- googleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(Wearable.API)
- .build();
+ googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this).addApi(Wearable.API).build();
Wearable.MessageApi.addListener(googleApiClient, this);
if (googleApiClient.isConnected()) {
- Log.d("WatchUpdater", "API client is connected");
+ log.debug(logPrefix + "API client is connected");
} else {
+ // Log.d("WatchUpdater", logPrefix + "API client is not connected and is trying to connect");
googleApiClient.connect();
}
}
@@ -139,6 +163,8 @@ public class WatchUpdaterService extends WearableListenerService implements
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent != null ? intent.getAction() : null;
+ // Log.d(TAG, logPrefix + "onStartCommand: " + action);
+
if (wear_integration) {
handler.post(() -> {
if (googleApiClient.isConnected()) {
@@ -178,13 +204,63 @@ public class WatchUpdaterService extends WearableListenerService implements
}
+ private void updateWearSyncBgsCapability(CapabilityInfo capabilityInfo) {
+ Log.d("WatchUpdaterService", logPrefix + "CabilityInfo: " + capabilityInfo);
+ Set connectedNodes = capabilityInfo.getNodes();
+ mWearNodeId = pickBestNodeId(connectedNodes);
+ }
+
+
+ private String pickBestNodeId(Set nodes) {
+ String bestNodeId = null;
+ // Find a nearby node or pick one arbitrarily
+ for (Node node : nodes) {
+ if (node.isNearby()) {
+ return node.getId();
+ }
+ bestNodeId = node.getId();
+ }
+ return bestNodeId;
+ }
+
+
@Override
public void onConnected(Bundle connectionHint) {
+ CapabilityApi.CapabilityListener capabilityListener = capabilityInfo -> {
+ updateWearSyncBgsCapability(capabilityInfo);
+ // Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mWearNodeID:" + mWearNodeId);
+ // new CheckWearableConnected().execute();
+ };
+
+ Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, CAPABILITY_WEAR_APP);
sendData();
}
+
+ @Override
+ public void onPeerConnected(com.google.android.gms.wearable.Node peer) {// KS
+ super.onPeerConnected(peer);
+ String id = peer.getId();
+ String name = peer.getDisplayName();
+ // Log.d(TAG, logPrefix + "onPeerConnected peer name & ID: " + name + "|" + id);
+ }
+
+
+ @Override
+ public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) {// KS
+ super.onPeerDisconnected(peer);
+ String id = peer.getId();
+ String name = peer.getDisplayName();
+ // Log.d(TAG, logPrefix + "onPeerDisconnected peer name & ID: " + name + "|" + id);
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ }
+
+
@Override
public void onMessageReceived(MessageEvent event) {
+
+ // Log.d(TAG, logPrefix + "onMessageRecieved: " + event);
+
if (wear_integration) {
if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH)) {
resendData();
@@ -215,6 +291,7 @@ public class WatchUpdaterService extends WearableListenerService implements
private void sendData() {
BgReading lastBG = DatabaseHelper.lastBg();
+ // Log.d(TAG, logPrefix + "LastBg=" + lastBG);
if (lastBG != null) {
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
@@ -229,18 +306,19 @@ public class WatchUpdaterService extends WearableListenerService implements
return;
}
- new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap);
+ executeTask(new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient), dataMap);
}
}
}
+
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
String units = ProfileFunctions.getInstance().getProfileUnits();
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
- //convert to mg/dl
+ // convert to mg/dl
if (!units.equals(Constants.MGDL)) {
lowLine *= Constants.MMOLL_TO_MGDL;
highLine *= Constants.MMOLL_TO_MGDL;
@@ -288,7 +366,6 @@ public class WatchUpdaterService extends WearableListenerService implements
deltastring += "+";
} else {
deltastring += "-";
-
}
boolean detailed = SP.getBoolean("wear_detailed_delta", false);
@@ -353,7 +430,7 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
entries.putDataMapArrayList("entries", dataMaps);
- new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries);
+ executeTask(new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient), entries);
}
sendPreferences();
sendBasals();
@@ -502,7 +579,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dm.putDataMapArrayList("boluses", boluses);
dm.putDataMapArrayList("predictions", predictions);
- new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient).execute(dm);
+ executeTask(new SendToDataLayerThread(BASAL_DATA_PATH, googleApiClient), dm);
}
private DataMap tempDatamap(long startTime, double startBasal, long to, double toBasal, double amount) {
@@ -549,6 +626,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putString("openSettings", "openSettings");
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendNotification", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("OpenSettings", "No connection to wearable available!");
@@ -564,6 +642,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putString("progressstatus", status);
dataMapRequest.getDataMap().putInt("progresspercent", progresspercent);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendBolusProgress", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("BolusProgress", "No connection to wearable available!");
@@ -583,6 +662,7 @@ public class WatchUpdaterService extends WearableListenerService implements
log.debug("Requesting confirmation from wear: " + actionstring);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendActionConfirmationRequest", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("confirmationRequest", "No connection to wearable available!");
@@ -602,6 +682,7 @@ public class WatchUpdaterService extends WearableListenerService implements
log.debug("Requesting confirmation from wear: " + actionstring);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendChangeConfirmationRequest", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("changeConfirmRequest", "No connection to wearable available!");
@@ -619,9 +700,10 @@ public class WatchUpdaterService extends WearableListenerService implements
log.debug("Canceling notification on wear: " + actionstring);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendCancelNotificationRequest", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
- Log.e("cancelNotificationRequest", "No connection to wearable available!");
+ Log.e("cancelNotificationReq", "No connection to wearable available!");
}
}
@@ -684,6 +766,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false));
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendStatus", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("SendStatus", "No connection to wearable available!");
@@ -700,12 +783,29 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putBoolean("wearcontrol", wearcontrol);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
+ debugData("sendPreferences", putDataRequest);
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("SendStatus", "No connection to wearable available!");
}
}
+
+ private void debugData(String source, Object data) {
+ // Log.d(TAG, "WR: " + source + " " + data);
+ }
+
+
+ private void executeTask(AsyncTask task, DataMap... parameters) {
+ task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])parameters);
+ // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ // task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ // } else {
+ // task.execute();
+ // }
+ }
+
+
@NonNull
private String generateStatusString(Profile profile, String currentBasal, String iobSum, String iobDetail, String bgiString) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java
index 9c4ec1551a..fe89cc8304 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.XDripStatusline;
+package info.nightscout.androidaps.plugins.general.xdripStatusline;
import android.content.Context;
import android.content.Intent;
@@ -9,7 +9,6 @@ import android.support.annotation.NonNull;
import com.squareup.otto.Subscribe;
-import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@@ -18,7 +17,6 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
-import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange;
@@ -27,13 +25,13 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
-import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
-import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
/**
* Created by adrian on 17/11/16.
@@ -117,7 +115,7 @@ public class StatuslinePlugin extends PluginBase {
if (ConfigBuilderPlugin.getPlugin().getActivePump() == null)
return "";
-
+
LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
@@ -140,7 +138,7 @@ public class StatuslinePlugin extends PluginBase {
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
treatmentsInterface.updateTotalIOBTempBasals();
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
- status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob)+"U";
+ status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U";
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
@@ -184,7 +182,7 @@ public class StatuslinePlugin extends PluginBase {
}
@Subscribe
- public void onStatusEvent(final EventNewBG ev) {
+ public void onStatusEvent(final EventAutosensCalculationFinished ev) {
sendStatus();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java
index 8bbd1d3e7f..fd8564cf73 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/ActivityGraph.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import android.content.Context;
import android.graphics.Color;
@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.data.Iob;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java
index 79db5e1a8b..bcf445d0d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -10,8 +10,8 @@ import android.widget.TextView;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.utils.FabricPrivacy;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.utils.FabricPrivacy;
/**
* Created by mike on 17.04.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java
index a2d80efd68..7700bf4c52 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java
@@ -1,18 +1,19 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import com.squareup.otto.Bus;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
/**
* Created by adrian on 13.08.2017.
@@ -62,7 +63,8 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli
}
public double getUserDefinedDia() {
- return ProfileFunctions.getInstance().getProfile() != null ? ProfileFunctions.getInstance().getProfile().getDia() : MIN_DIA;
+ Profile profile = ProfileFunctions.getInstance().getProfile();
+ return profile != null ? profile.getDia() : MIN_DIA;
}
public Iob iobCalcForTreatment(Treatment treatment, long time) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java
index c1fc44438f..3d32d2317b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.java
@@ -1,8 +1,8 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by adrian on 14/08/17.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java
index c275aef3fd..5aceaaacaf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java
index 94e5910470..7e800cacc1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.Insulin;
+package info.nightscout.androidaps.plugins.insulin;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java
similarity index 71%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java
index 60a5851011..6a32c1084b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,15 +13,15 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
-import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
+import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 25.04.2017.
@@ -40,7 +40,7 @@ public class AutosensData implements DataPointWithLabelInterface {
double min5minCarbImpact = 0d;
double remaining = 0d;
- public CarbsInPast(Treatment t) {
+ CarbsInPast(Treatment t) {
time = t.date;
carbs = t.carbs;
remaining = t.carbs;
@@ -56,6 +56,18 @@ public class AutosensData implements DataPointWithLabelInterface {
min5minCarbImpact = SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact);
}
}
+
+ CarbsInPast (CarbsInPast other) {
+ this.time = other.time;
+ this.carbs = other.carbs;
+ this.min5minCarbImpact = other.min5minCarbImpact;
+ this.remaining = other.remaining;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("CarbsInPast: time: %s carbs: %.02f min5minCI: %.02f remaining: %.2f", new Date(time).toLocaleString(), carbs, min5minCarbImpact, remaining);
+ }
}
public long time = 0L;
@@ -89,11 +101,18 @@ public class AutosensData implements DataPointWithLabelInterface {
@Override
public String toString() {
- return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensResult.ratio + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation=" + slopeFromMinDeviation;
+ return String.format("AutosensData: %s pastSensitivity=%s delta=%.02f avgDelta=%.02f bgi=%.02f deviation=%.02f avgDeviation=%.02f absorbed=%.02f carbsFromBolus=%.02f cob=%.02f autosensRatio=%.02f slopeFromMaxDeviation=%.02f slopeFromMinDeviation=%.02f activeCarbsList=%s",
+ new Date(time).toLocaleString(), pastSensitivity, delta, avgDelta, bgi, deviation, avgDeviation, absorbed, carbsFromBolus, cob, autosensResult.ratio, slopeFromMaxDeviation, slopeFromMinDeviation, activeCarbsList.toString());
}
- public int minOld() {
- return (int) ((System.currentTimeMillis() - time) / 1000 / 60);
+ public List cloneCarbsList() {
+ List newActiveCarbsList = new ArrayList<>();
+
+ for(CarbsInPast c: activeCarbsList) {
+ newActiveCarbsList.add(new CarbsInPast(c));
+ }
+
+ return newActiveCarbsList;
}
// remove carbs older than timeframe
@@ -111,7 +130,7 @@ public class AutosensData implements DataPointWithLabelInterface {
if (c.remaining > 0)
cob -= c.remaining;
if (L.isEnabled(L.AUTOSENS))
- log.debug("Removing carbs at " + new Date(toTime).toLocaleString() + " + after " + maxAbsorptionHours + "h :" + new Date(c.time).toLocaleString());
+ log.debug("Removing carbs at " + new Date(toTime).toLocaleString() + " after " + maxAbsorptionHours + "h > " + c.toString());
}
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java
index 7bd01fa7b2..082ebc057d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java
index d8bde8acbb..a4fa66fee1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/BasalData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/BasalData.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
/**
* Created by mike on 10.06.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java
index d8b6d7674a..12d5cd5c11 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/CobInfo.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/CobInfo.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.DecimalFormatter;
public class CobInfo {
/** All COB up to now, including carbs not yet processed by IobCob calculation. */
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java
index 951fa0b895..aac0985fba 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import android.os.SystemClock;
import android.support.annotation.NonNull;
@@ -31,17 +31,17 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.T;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
/**
* Created by mike on 24.04.2017.
@@ -65,8 +65,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
private volatile List bgReadings = null; // newest at index 0
private volatile List bucketed_data = null;
- private double dia = Constants.defaultDIA;
-
final Object dataLock = new Object();
boolean stopCalculationTrigger = false;
@@ -118,11 +116,22 @@ public class IobCobCalculatorPlugin extends PluginBase {
return rounded;
}
- void loadBgData(long now) {
- long start = (long) (now - 60 * 60 * 1000L * (24 + dia));
- bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, now, false);
- if (L.isEnabled(L.AUTOSENS))
- log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(now));
+ void loadBgData(long to) {
+ Profile profile = ProfileFunctions.getInstance().getProfile(to);
+ double dia = Constants.defaultDIA;
+ if (profile != null) dia = profile.getDia();
+ long start = to - T.hours((long) (24 + dia)).msecs();
+ if (DateUtil.isCloseToNow(to)) {
+ // if close to now expect there can be some readings with time in close future (caused by wrong time setting)
+ // so read all records
+ bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false);
+ if (L.isEnabled(L.AUTOSENS))
+ log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
+ } else {
+ bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false);
+ if (L.isEnabled(L.AUTOSENS))
+ log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to));
+ }
}
public boolean isAbout5minData() {
@@ -146,8 +155,8 @@ public class IobCobCalculatorPlugin extends PluginBase {
return false;
}
}
- double averageDiff = totalDiff / (bgReadings.size() - 1) / 1000d;
- boolean is5mindata = averageDiff < 10;
+ long averageDiff = totalDiff / bgReadings.size() / 1000;
+ boolean is5mindata = averageDiff < 1;
if (L.isEnabled(L.AUTOSENS))
log.debug("Interval detection: values: " + bgReadings.size() + " averageDiff: " + averageDiff + "[s] is5minData: " + is5mindata);
return is5mindata;
@@ -231,13 +240,15 @@ public class IobCobCalculatorPlugin extends PluginBase {
bucketed_data = new ArrayList<>();
bucketed_data.add(bgReadings.get(0));
+ if (L.isEnabled(L.AUTOSENS))
+ log.debug("Adding. bgTime: " + DateUtil.toISOString(bgReadings.get(0).date) + " lastbgTime: " + "none-first-value" + " " + bgReadings.get(0).toString());
int j = 0;
for (int i = 1; i < bgReadings.size(); ++i) {
long bgTime = bgReadings.get(i).date;
long lastbgTime = bgReadings.get(i - 1).date;
//log.error("Processing " + i + ": " + new Date(bgTime).toString() + " " + bgReadings.get(i).value + " Previous: " + new Date(lastbgTime).toString() + " " + bgReadings.get(i - 1).value);
if (bgReadings.get(i).value < 39 || bgReadings.get(i - 1).value < 39) {
- continue;
+ throw new IllegalStateException("<39");
}
long elapsed_minutes = (bgTime - lastbgTime) / (60 * 1000);
@@ -294,6 +305,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
long adjusted = (msecDiff - T.mins(5).msecs()) / 1000;
if (L.isEnabled(L.AUTOSENS))
log.debug("Adjusting bucketed data time. Current: " + DateUtil.toISOString(current.date) + " to: " + DateUtil.toISOString(previous.date + T.mins(5).msecs()) + " by " + adjusted + " sec");
+ if (Math.abs(adjusted) > 90) {
+ // too big adjustment, fallback to non 5 min data
+ if (L.isEnabled(L.AUTOSENS))
+ log.debug("Fallback to non 5 min data");
+ createBucketedDataRecalculated();
+ return;
+ }
current.date = previous.date + T.mins(5).msecs();
}
@@ -599,10 +617,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
if (ConfigBuilderPlugin.getPlugin() == null)
return; // app still initializing
- Profile profile = ProfileFunctions.getInstance().getProfile();
- if (profile == null)
- return; // app still initializing
- dia = profile.getDia();
if (ev == null) { // on init no need of reset
return;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java
index 4032546f7a..e27f27c26f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import android.content.Context;
import android.os.PowerManager;
@@ -26,20 +26,24 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.MidnightTime;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
import static java.util.Calendar.MINUTE;
/**
@@ -58,7 +62,7 @@ public class IobCobOref1Thread extends Thread {
private PowerManager.WakeLock mWakeLock;
- public IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) {
+ IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) {
super();
this.iobCobCalculatorPlugin = plugin;
@@ -69,12 +73,15 @@ public class IobCobOref1Thread extends Thread {
this.end = end;
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
- mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
+ if (powerManager != null)
+ mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread");
}
@Override
public final void run() {
- mWakeLock.acquire();
+ long start = DateUtil.now();
+ if (mWakeLock != null)
+ mWakeLock.acquire(T.mins(10).msecs());
try {
if (L.isEnabled(L.AUTOSENS))
log.debug("AUTOSENSDATA thread started: " + from);
@@ -148,7 +155,7 @@ public class IobCobOref1Thread extends Thread {
AutosensData autosensData = new AutosensData();
autosensData.time = bgTime;
if (previous != null)
- autosensData.activeCarbsList = new ArrayList<>(previous.activeCarbsList);
+ autosensData.activeCarbsList = previous.cloneCarbsList();
else
autosensData.activeCarbsList = new ArrayList<>();
@@ -169,7 +176,7 @@ public class IobCobOref1Thread extends Thread {
double bgi = -iob.activity * sens * 5;
double deviation = delta - bgi;
- double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000;
+ double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d;
double slopeFromMaxDeviation = 0;
double slopeFromMinDeviation = 999;
@@ -242,6 +249,7 @@ public class IobCobOref1Thread extends Thread {
for (int ir = 0; ir < recentTreatments.size(); ir++) {
autosensData.carbsFromBolus += recentTreatments.get(ir).carbs;
autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir)));
+ autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentTreatments.get(ir).carbs) + "g]";
}
@@ -339,19 +347,19 @@ public class IobCobOref1Thread extends Thread {
// Exclude meal-related deviations (carb absorption) from autosens
if (autosensData.type.equals("non-meal")) {
if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) {
- autosensData.pastSensitivity = "=";
+ autosensData.pastSensitivity += "=";
autosensData.validDeviation = true;
} else if (deviation > 0) {
- autosensData.pastSensitivity = "+";
+ autosensData.pastSensitivity += "+";
autosensData.validDeviation = true;
} else {
- autosensData.pastSensitivity = "-";
+ autosensData.pastSensitivity += "-";
autosensData.validDeviation = true;
}
} else if (autosensData.type.equals("uam")) {
- autosensData.pastSensitivity = "u";
+ autosensData.pastSensitivity += "u";
} else {
- autosensData.pastSensitivity = "x";
+ autosensData.pastSensitivity += "x";
}
//log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation);
@@ -389,10 +397,14 @@ public class IobCobOref1Thread extends Thread {
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
}).start();
} finally {
- mWakeLock.release();
+ if (mWakeLock != null)
+ mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
- if (L.isEnabled(L.AUTOSENS))
+ if (L.isEnabled(L.AUTOSENS)) {
log.debug("AUTOSENSDATA thread ended: " + from);
+ log.debug("Midnights: " + MidnightTime.log());
+ }
+ Profiler.log(log, "IobCobOref1Thread", start);
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java
index 07df247a21..2970f07aca 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import android.content.Context;
import android.os.PowerManager;
@@ -24,22 +24,26 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress;
-import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin;
-import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.FabricPrivacy;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
+import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
+import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
+import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.MidnightTime;
+import info.nightscout.androidaps.utils.Profiler;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
-import static info.nightscout.utils.DateUtil.now;
+import static info.nightscout.androidaps.utils.DateUtil.now;
/**
* Created by mike on 23.01.2018.
@@ -57,7 +61,7 @@ public class IobCobThread extends Thread {
private PowerManager.WakeLock mWakeLock;
- public IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) {
+ IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) {
super();
this.iobCobCalculatorPlugin = plugin;
@@ -68,12 +72,15 @@ public class IobCobThread extends Thread {
this.end = end;
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
- mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
+ if (powerManager != null)
+ mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread");
}
@Override
public final void run() {
- mWakeLock.acquire();
+ long start = DateUtil.now();
+ if (mWakeLock != null)
+ mWakeLock.acquire(T.mins(10).msecs());
try {
if (L.isEnabled(L.AUTOSENS))
log.debug("AUTOSENSDATA thread started: " + from);
@@ -147,7 +154,7 @@ public class IobCobThread extends Thread {
AutosensData autosensData = new AutosensData();
autosensData.time = bgTime;
if (previous != null)
- autosensData.activeCarbsList = new ArrayList<>(previous.activeCarbsList);
+ autosensData.activeCarbsList = previous.cloneCarbsList();
else
autosensData.activeCarbsList = new ArrayList<>();
@@ -168,7 +175,7 @@ public class IobCobThread extends Thread {
double bgi = -iob.activity * sens * 5;
double deviation = delta - bgi;
- double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000;
+ double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d;
double slopeFromMaxDeviation = 0;
double slopeFromMinDeviation = 999;
@@ -241,6 +248,7 @@ public class IobCobThread extends Thread {
for (int ir = 0; ir < recentTreatments.size(); ir++) {
autosensData.carbsFromBolus += recentTreatments.get(ir).carbs;
autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir)));
+ autosensData.pastSensitivity += "[" + DecimalFormatter.to0Decimal(recentTreatments.get(ir).carbs) + "g]";
}
@@ -284,17 +292,17 @@ public class IobCobThread extends Thread {
// calculate autosens only without COB
if (autosensData.cob <= 0) {
if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) {
- autosensData.pastSensitivity = "=";
+ autosensData.pastSensitivity += "=";
autosensData.validDeviation = true;
} else if (deviation > 0) {
- autosensData.pastSensitivity = "+";
+ autosensData.pastSensitivity += "+";
autosensData.validDeviation = true;
} else {
- autosensData.pastSensitivity = "-";
+ autosensData.pastSensitivity += "-";
autosensData.validDeviation = true;
}
} else {
- autosensData.pastSensitivity = "C";
+ autosensData.pastSensitivity += "C";
}
//log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation);
@@ -316,10 +324,14 @@ public class IobCobThread extends Thread {
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
}).start();
} finally {
- mWakeLock.release();
+ if (mWakeLock != null)
+ mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
- if (L.isEnabled(L.AUTOSENS))
+ if (L.isEnabled(L.AUTOSENS)) {
log.debug("AUTOSENSDATA thread ended: " + from);
+ log.debug("Midnights: " + MidnightTime.log());
+ }
+ Profiler.log(log, "IobCobThread", start);
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java
index 2cb9b7ca4c..25622843e7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventAutosensCalculationFinished.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator.events;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventLoop;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java
similarity index 76%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java
index 08f2747e60..5a4a9a8eae 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventIobCalculationProgress.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventIobCalculationProgress.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator.events;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java
similarity index 77%
rename from app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java
index 8814741099..f84fdd1adf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/events/EventNewHistoryData.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.IobCobCalculator.events;
+package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java
index fc45928f89..ec5dc55fa8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileLocal;
+package info.nightscout.androidaps.plugins.profile.local;
import android.app.Activity;
@@ -15,9 +15,6 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
@@ -25,16 +22,15 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.interfaces.PumpDescription;
-import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.NumberPicker;
-import info.nightscout.utils.SafeParse;
-import info.nightscout.utils.TimeListEdit;
+import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SafeParse;
+import info.nightscout.androidaps.utils.TimeListEdit;
public class LocalProfileFragment extends SubscriberFragment {
NumberPicker diaView;
@@ -156,7 +152,7 @@ public class LocalProfileFragment extends SubscriberFragment {
public String getSumLabel() {
ProfileStore profile = LocalProfilePlugin.getPlugin().createProfileStore();
if (profile != null)
- return " ∑" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + "U";
+ return " ∑" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + MainApp.gs(R.string.insulin_unit_shortname);
else
return MainApp.gs(R.string.localprofile);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java
index 7a06860327..06f979876c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileLocal;
+package info.nightscout.androidaps.plugins.profile.local;
import android.support.annotation.NonNull;
@@ -18,8 +18,8 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java
index e3aeca0c45..66b895839d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileNS;
+package info.nightscout.androidaps.plugins.profile.ns;
import android.app.Activity;
import android.os.Bundle;
@@ -22,13 +22,12 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
-import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.OKDialog;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI;
+import info.nightscout.androidaps.plugins.treatments.fragments.ProfileGraph;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.OKDialog;
import static butterknife.OnItemSelected.Callback.NOTHING_SELECTED;
@@ -52,6 +51,8 @@ public class NSProfileFragment extends SubscriberFragment {
TextView isf;
@BindView(R.id.profileview_basal)
TextView basal;
+ @BindView(R.id.profileview_basaltotal)
+ TextView basaltotal;
@BindView(R.id.profileview_target)
TextView target;
@BindView(R.id.basal_graph)
@@ -116,6 +117,7 @@ public class NSProfileFragment extends SubscriberFragment {
ic.setText(profile.getIcList());
isf.setText(profile.getIsfList());
basal.setText(profile.getBasalList());
+ basaltotal.setText(String.format(MainApp.gs(R.string.profile_total), DecimalFormatter.to2Decimal(profile.baseBasalSum())));
target.setText(profile.getTargetList());
basalGraph.show(profile);
}
@@ -141,6 +143,7 @@ public class NSProfileFragment extends SubscriberFragment {
ic.setText("");
isf.setText("");
basal.setText("");
+ basaltotal.setText("");
target.setText("");
activateButton.setVisibility(View.GONE);
}
@@ -153,7 +156,7 @@ public class NSProfileFragment extends SubscriberFragment {
Profile profile = store.getSpecificProfile(name);
if (profile != null) {
OKDialog.showConfirmation(getActivity(), MainApp.gs(R.string.activate_profile) + ": " + name + " ?", () ->
- NewNSTreatmentDialog.doProfileSwitch(store, name, 0, 100, 0)
+ ProfileFunctions.doProfileSwitch(store, name, 0, 100, 0)
);
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java
index 99e4ad9115..11c38d1492 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileNS;
+package info.nightscout.androidaps.plugins.profile.ns;
import android.content.Intent;
import android.os.Bundle;
@@ -21,8 +21,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
-import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java
similarity index 72%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java
index d24c59e511..bb8b9509e8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileNS.events;
+package info.nightscout.androidaps.plugins.profile.ns.events;
import info.nightscout.androidaps.events.EventUpdateGui;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java
index b4338366bd..b8a7d16be5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfileFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileSimple;
+package info.nightscout.androidaps.plugins.profile.simple;
import android.app.Activity;
@@ -15,18 +15,15 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
-import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
-import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.utils.SafeParse;
+import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
+import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
+import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.utils.SafeParse;
public class SimpleProfileFragment extends SubscriberFragment {
EditText diaView;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java
index 09742bd3f9..d3d3952fae 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/simple/SimpleProfilePlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.ProfileSimple;
+package info.nightscout.androidaps.plugins.profile.simple;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@@ -19,7 +19,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java
index e1ae0286de..a533821d59 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboFragment.java
@@ -1,8 +1,7 @@
-package info.nightscout.androidaps.plugins.PumpCombo;
+package info.nightscout.androidaps.plugins.pump.combo;
import android.app.Activity;
-import android.app.AlertDialog;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
@@ -15,19 +14,17 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
-import org.apache.commons.lang3.StringUtils;
-
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.events.EventQueueChanged;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
public class ComboFragment extends SubscriberFragment implements View.OnClickListener {
private TextView stateView;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
index 3f30071327..a84e3db9a8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo;
+package info.nightscout.androidaps.plugins.pump.combo;
import android.content.DialogInterface;
import android.os.SystemClock;
@@ -39,32 +39,33 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
-
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyCommands;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
*/
@@ -435,6 +436,23 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
return pump.basalProfile.hourlyRates[currentHour];
}
+ @Override
+ public double getReservoirLevel() {
+ return pump.reservoirLevel;
+ }
+
+ @Override
+ public int getBatteryLevel() {
+ switch (pump.state.batteryState) {
+ case PumpState.EMPTY:
+ return 5;
+ case PumpState.LOW:
+ return 25;
+ default:
+ return 100;
+ }
+ }
+
private static BolusProgressReporter bolusProgressReporter = (state, percent, delivered) -> {
EventOverviewBolusProgress event = EventOverviewBolusProgress.getInstance();
switch (state) {
@@ -653,11 +671,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
}
}
- /**
- * Updates a DetailedBolusInfo from a pump bolus and adds it as a Treatment to the DB.
- * Handles edge cases when dates aren't unique which are extremely unlikely to occur,
- * but if they do, the user should be warned since a bolus will be missing from calculations.
- */
+ /** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
DetailedBolusInfo dbi = detailedBolusInfo.copy();
dbi.date = calculateFakeBolusDate(lastPumpBolus);
@@ -665,15 +679,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
dbi.source = Source.PUMP;
dbi.insulin = lastPumpBolus.amount;
try {
- boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false);
- if (!treatmentCreated) {
- log.error("Adding treatment record overrode an existing record: " + dbi);
- if (dbi.isSMB) {
- Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT);
- MainApp.bus().post(new EventNewNotification(notification));
- }
- return false;
- }
+ TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true);
} catch (Exception e) {
log.error("Adding treatment record failed", e);
if (dbi.isSMB) {
@@ -1149,6 +1155,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
return historyResult.success;
}
+ /** Return value indicates whether a new record was created. */
private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) {
boolean updated = false;
for (Bolus pumpBolus : history.bolusHistory) {
@@ -1158,8 +1165,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
dbi.source = Source.PUMP;
dbi.insulin = pumpBolus.amount;
dbi.eventType = CareportalEvent.CORRECTIONBOLUS;
- if (TreatmentsPlugin.getPlugin().getService().getPumpRecordById(dbi.pumpId) == null) {
- TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false);
+ if (TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true)) {
updated = true;
}
}
@@ -1374,4 +1380,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
maxIob.setIfSmaller(0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this);
return maxIob;
}
+
+ @Override
+ public List getCustomActions() {
+ return null;
+ }
+
+ @Override
+ public void executeCustomAction(CustomActionType customActionType) {
+
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java
similarity index 59%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java
index aef0f2abd5..cfe459fb58 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPump.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo;
+package info.nightscout.androidaps.plugins.pump.combo;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -6,11 +6,11 @@ import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpAlert;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd;
class ComboPump {
boolean initialized = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java
similarity index 57%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java
index e9bf3f8415..72359b7db2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/events/EventComboPumpUpdateGUI.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/events/EventComboPumpUpdateGUI.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.events;
+package info.nightscout.androidaps.plugins.pump.combo.events;
/**
* Created by mike on 24.05.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java
index fa9c2dceb0..9cdee1c9fd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BasalProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
import java.util.Arrays;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java
similarity index 77%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java
index 59d334fe6f..6fb7c54201 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/BolusProgressReporter.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
public interface BolusProgressReporter {
enum State {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java
index b595d13d28..180f10f69d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/CommandResult.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
import android.support.annotation.Nullable;
import java.util.LinkedList;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory;
public class CommandResult {
/** True if a condition indicating a broken pump setup/configuration is detected */
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java
index 63cd81e3a6..d557c067c1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpErrorCodes.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
public class PumpErrorCodes {
public static final int CARTRIDGE_EMPTY = 1;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java
index 963cdd8b4c..117ea88eb9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpState.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
/** State displayed on the main screen of the pump. */
public class PumpState {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java
index 60d1898834..b3f87e6b92 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/PumpWarningCodes.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
public class PumpWarningCodes {
public static final int CARTRIDGE_LOW = 1;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java
index 5918023d1e..0567e1cb12 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyCommands.java
@@ -1,6 +1,6 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest;
public interface RuffyCommands {
/** Issues a bolus issues updates on progress through via {@link BolusProgressReporter}. */
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java
index e69cf3b462..eb01c92c60 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/RuffyScripter.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
import android.content.ComponentName;
import android.content.Context;
@@ -26,18 +26,18 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadQuickInfoCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.Command;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CommandException;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ConfirmAlertCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadBasalProfileCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadPumpStateCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetBasalProfileCommand;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadQuickInfoCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.BolusCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.CancelTbrCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.Command;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.CommandException;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ConfirmAlertCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadBasalProfileCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadHistoryCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.ReadPumpStateCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.SetBasalProfileCommand;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands.SetTbrCommand;
/**
* Provides scripting 'runtime' and operations. consider moving operations into a separate
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java
index a4e21da289..ae4723046e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/WarningOrErrorCode.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter;
import android.support.annotation.Nullable;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java
similarity index 85%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java
index 5cc3e98b23..6cd89f2938 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BaseCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import android.support.annotation.NonNull;
@@ -12,10 +12,10 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
public abstract class BaseCommand implements Command {
// RS will inject itself here
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java
index 4188716553..da18cc5c53 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/BolusCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import android.os.SystemClock;
@@ -11,18 +11,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter;
-import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERED;
-import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERING;
-import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING;
-import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPED;
-import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPING;
+import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.DELIVERED;
+import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.DELIVERING;
+import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING;
+import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.STOPPED;
+import static info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BolusProgressReporter.State.STOPPING;
public class BolusCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(BolusCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java
index b1787005e1..4b54c87c42 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CancelTbrCommand.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes;
public class CancelTbrCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(CancelTbrCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java
similarity index 69%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java
index 152befe00d..cd6c30439a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/Command.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.RuffyScripter;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.CommandResult;
/**
* Interface for all commands to be executed by the pump.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java
similarity index 75%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java
index 77c1db5437..e92e5e32cf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/CommandException.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
public class CommandException extends RuntimeException {
public CommandException(String message) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java
index 636b6a624d..0b1fcc3821 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ConfirmAlertCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
public class ConfirmAlertCommand extends BaseCommand {
private final int warningCode;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java
index 2c23d5814b..b7145d233d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadBasalProfileCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import org.monkey.d.ruffy.ruffy.driver.display.Menu;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
@@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory;
import java.util.Arrays;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
public class ReadBasalProfileCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(ReadBasalProfileCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java
index 04298acd56..5f23b7e66d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadHistoryCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import android.support.annotation.NonNull;
@@ -12,12 +12,12 @@ import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpAlert;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistoryRequest;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tbr;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Tdd;
public class ReadHistoryCommand extends BaseCommand {
private static Logger log = LoggerFactory.getLogger(ReadHistoryCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java
index cfa8d0f329..19beb26fe6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadPumpStateCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
public class ReadPumpStateCommand extends BaseCommand {
@Override
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java
index 654861fddb..eb68f1c5e1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/ReadQuickInfoCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
@@ -9,8 +9,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory;
public class ReadQuickInfoCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(ReadQuickInfoCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java
index f403c2a89b..4d18b3d24e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetBasalProfileCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import android.os.SystemClock;
@@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.BasalProfile;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
public class SetBasalProfileCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(SetBasalProfileCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java
index f618d50156..a4459cea66 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/commands/SetTbrCommand.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.commands;
import android.os.SystemClock;
@@ -12,9 +12,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
-import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpWarningCodes;
+import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.WarningOrErrorCode;
public class SetTbrCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java
index a5d989c331..cf1450feb2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java
similarity index 67%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java
index 57e173bb49..3857a8b877 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/HistoryRecord.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
public abstract class HistoryRecord {
public final long timestamp;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java
index 413a9ca69b..0797d77151 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpAlert.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java
index ecc8a1a29f..0fffe13c50 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistory.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import android.support.annotation.NonNull;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java
index e785c1d67c..a121ea9425 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/PumpHistoryRequest.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java
index 41ec245e89..401fc026b7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tbr.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java
index 5f799f229e..35d3d31df9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ruffyscripter/history/Tdd.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history;
+package info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history;
import java.util.Date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java
index 21a893e943..f0cd1dbbf9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/DoseSettings.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/DoseSettings.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCommon.data;
+package info.nightscout.androidaps.plugins.pump.common.data;
/**
* Created by andy on 02/05/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java
index 421c441c32..7e4bd7762e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/DoseStepSize.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/DoseStepSize.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCommon.defs;
+package info.nightscout.androidaps.plugins.pump.common.defs;
/**
* Created by andy on 02/05/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
index d3e29ded0a..dc6059eed7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpCapability.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCommon.defs;
+package info.nightscout.androidaps.plugins.pump.common.defs;
/**
* Created by andy on 03/05/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java
similarity index 63%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java
index 167e886ea7..90304ca45f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpTempBasalType.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpTempBasalType.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCommon.defs;
+package info.nightscout.androidaps.plugins.pump.common.defs;
/**
* Created by andy on 02/05/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
index 1c064d0cf0..e1e7f2bf2b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/defs/PumpType.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpCommon.defs;
+package info.nightscout.androidaps.plugins.pump.common.defs;
import java.util.HashMap;
@@ -6,7 +6,7 @@ import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
+import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings;
@@ -56,7 +56,7 @@ public enum PumpType {
AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
new DoseSettings(0.05d, 30, 12*60, 0.05d), //
PumpTempBasalType.Percent, //
- new DoseSettings(10, 30, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
+ new DoseSettings(10, 30, 24*60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), //
AnimasPing("Animas Ping", AnimasVibe),
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
index c50e635eb8..d6f25f9c02 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import android.support.annotation.Nullable;
@@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
+import java.util.List;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
@@ -27,17 +28,19 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 28.01.2018.
@@ -152,6 +155,12 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
return DanaRPump.getInstance().currentBasal;
}
+ @Override
+ public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; }
+
+ @Override
+ public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; }
+
@Override
public void stopBolusDelivering() {
if (sExecutionService == null) {
@@ -467,4 +476,16 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
}
// TODO: daily total constraint
+
+ @Override
+ public List getCustomActions() {
+ return null;
+ }
+
+
+ @Override
+ public void executeCustomAction(CustomActionType customActionType) {
+
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java
index e39fdcfdaa..d02bf4690a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/BluetoothDevicePreference.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/BluetoothDevicePreference.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import android.bluetooth.*;
import android.content.Context;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java
index 33d371dca3..e044a2db27 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import android.app.Activity;
@@ -32,18 +32,18 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
-import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
-import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRUserOptionsActivity;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.dialogs.ProfileViewDialog;
+import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRHistoryActivity;
+import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRUserOptionsActivity;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.events.EventQueueChanged;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.SetWarnColor;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.SetWarnColor;
public class DanaRFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(L.PUMP);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java
index dfdca746cb..2f7484cd6f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import android.content.ComponentName;
import android.content.Context;
@@ -22,14 +22,14 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
+import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java
index 3a6b3b5786..baa636ea81 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPump.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import org.json.JSONArray;
import org.json.JSONException;
@@ -7,20 +7,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
-import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 04.07.2016.
*/
public class DanaRPump {
- private Logger log = LoggerFactory.getLogger(L.PUMP);
+ private static Logger log = LoggerFactory.getLogger(L.PUMP);
private static DanaRPump instance = null;
@@ -30,6 +29,7 @@ public class DanaRPump {
}
public static void reset() {
+ log.debug("DanaRPump reset");
instance = null;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java
index 06906aa0b4..2b09b180cf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.Dialogs;
+package info.nightscout.androidaps.plugins.pump.danaR.dialogs;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
@@ -8,14 +8,13 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
-import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.ProfileInterface;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph;
-import info.nightscout.utils.DecimalFormatter;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.treatments.fragments.ProfileGraph;
+import info.nightscout.androidaps.utils.DecimalFormatter;
/**
* Created by mike on 10.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java
index a319353d63..c8141d1265 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR;
+package info.nightscout.androidaps.plugins.pump.danaR;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
@@ -11,10 +11,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageHashTable;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread;
-import info.nightscout.utils.CRC;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTable;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread;
+import info.nightscout.androidaps.utils.CRC;
/**
* Created by mike on 17.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java
index 5a3e127b9a..95c9f25e37 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.activities;
+package info.nightscout.androidaps.plugins.pump.danaR.activities;
import android.app.Activity;
import android.os.Bundle;
@@ -32,16 +32,16 @@ import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
import info.nightscout.androidaps.queue.Callback;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.ToastUtils;
public class DanaRHistoryActivity extends Activity {
private static Logger log = LoggerFactory.getLogger(L.PUMP);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java
index eab9e8bc6e..a15c8d2883 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.activities;
+package info.nightscout.androidaps.plugins.pump.danaR.activities;
import org.json.JSONException;
import org.json.JSONObject;
@@ -14,11 +14,11 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
/**
* Created by mike on 20.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java
index d2d08a5d0b..0f2ec5f4d2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.activities;
+package info.nightscout.androidaps.plugins.pump.danaR.activities;
import android.app.Activity;
import android.os.Bundle;
@@ -20,12 +20,12 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
-import info.nightscout.utils.NumberPicker;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
+import info.nightscout.androidaps.utils.NumberPicker;
/**
* Created by Rumen Georgiev on 5/31/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java
index 0fd444412f..57244ecc20 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import android.annotation.TargetApi;
import android.os.Build;
@@ -13,7 +13,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.CRC;
+import info.nightscout.androidaps.utils.CRC;
/*
* 00 01 02 03 04 05 06
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java
index e7f1adca07..d7ec39f6b7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTable.java
@@ -1,7 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import java.util.HashMap;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java
index a285ce5120..2cba96f838 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageOriginalNames.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java
index 873824f966..6fb1993237 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgress.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusProgress.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
public class MsgBolusProgress extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java
index 06200d1f0c..4b7cd2ff41 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStart.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java
index a3160ff887..0c174807b3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStartWithSpeed.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java
index fe5d47c131..39531b8b10 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStop.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgBolusStop.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
public class MsgBolusStop extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java
index e04d9243e7..d40f8f0cd6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValue.java
@@ -1,12 +1,12 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 30.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java
index a8e67a98a0..f697894778 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgError.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
public class MsgError extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java
index 7adb335e93..8abbf55c31 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAlarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java
index 0fe64a20f5..7de2489c91 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAll.java
@@ -1,15 +1,13 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgHistoryAll extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java
index e78771f99d..7b110dd45f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDone.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryAllDone.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java
index f56e2af273..2599cc7434 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHour.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBasalHour.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java
index d675ddc488..88978be98c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryBolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java
index 6755800bba..5682c3c85f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarbo.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryCarbo.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java
index 68d46f0d20..2bed9419dd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDailyInsulin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java
index 63e51e24ba..eeaffd33a2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDone.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryDone.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java
index 8d6d0615d4..0666e8915a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryError.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryError.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java
index 10fd68e3ab..114d392f40 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucose.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryGlucose.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java
index 01f7197434..e93c440fac 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNew.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNew.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java
index fb9118e629..c58f55f2cf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDone.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryNewDone.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java
index 238a606cfb..1ccae856af 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefill.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistoryRefill.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java
index 7182722f97..1dac016f4d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspend.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgHistorySuspend.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java
index 61150079cd..9b7d7feaed 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasic.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBasic.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgInitConnStatusBasic extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java
similarity index 80%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java
index df9447cc45..27d5aa5d2d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,10 +6,10 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 28.05.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java
index f8f82e16d0..220a4d5fc0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,11 +6,11 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 28.05.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java
similarity index 82%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java
index 5404c58837..72e538355a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java
@@ -1,22 +1,20 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-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.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgInitConnStatusTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java
index 6f92c3241c..3d2084371c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStart.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStart.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java
index 255bb17532..e942f6b6e8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStop.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgPCCommStop.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java
index 2d222f9601..22f962713b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetActivateBasalProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java
index 3e87e4bf41..7ea6719e30 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
public class MsgSetBasalProfile extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java
index 59cbcdafa0..a00b5bfd72 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetCarbsEntry.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java
index 2577435e11..dad437ac72 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStart.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java
index 504db719ea..a19efe7488 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStop.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetExtendedBolusStop.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java
index eabf383b94..29c70c9379 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
public class MsgSetSingleBasalProfile extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java
index c756af3491..adc6a0b4da 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStart.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStart.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java
index 7b14e8e3e3..19427ee965 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStop.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java
index 6842344959..2840ff3faa 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTime.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.utils.DateUtil;
/**
* Created by mike on 09.12.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java
index 7484966dba..07e4ff669d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetUserOptions.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java
similarity index 84%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java
index 57ab6367b0..1776c48a20 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingActiveProfile.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java
index 899a5a08f0..dc05848b34 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasal.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java
index f231412e06..89a4228ab7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalProfileAll.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java
index ded78c6272..70964a98b2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucose.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingGlucose.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java
index 3c640e1870..1eb3defb90 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValues.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMaxValues.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java
index 558b8953c0..b8be76560b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -7,11 +7,11 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 13.12.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java
index 5b6ea9b6cf..17f18cb160 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatios.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatios.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java
index 10d424657b..becdf5a745 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAll.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAll.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java
similarity index 85%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java
index 0e57c6c2f8..d22352e69f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTime.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,8 +6,8 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgSettingPumpTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java
index b700b0baa0..7362ecfdb1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfo.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfo.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java
index e45e2050db..2dce2a6e1f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptions.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
import java.util.Arrays;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by Rumen Georgiev on 6/11/2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java
index 474c29daa1..70c0d3b944 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatus.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgStatus extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java
index 8f81220885..6a0635c378 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasic.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBasic.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgStatusBasic extends MessageBase {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java
index 30e41e2704..9b27561d5a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtended.java
@@ -1,19 +1,17 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgStatusBolusExtended extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java
index 079357c6ee..f4ee2be0a6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfile.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java
index db6080f74a..76fa0e9f43 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
import android.support.annotation.NonNull;
@@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
public class MsgStatusTempBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java
index f0de05810a..36f3402cc7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypes.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypes.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.comm;
+package info.nightscout.androidaps.plugins.pump.danaR.comm;
/**
* Created by mike on 28.05.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java
similarity index 69%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java
index 55b0ab0998..9efdee1057 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.events;
+package info.nightscout.androidaps.plugins.pump.danaR.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java
similarity index 77%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java
index f2a5dc7b2a..5fc0bd740f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRSyncStatus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.events;
+package info.nightscout.androidaps.plugins.pump.danaR.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java
similarity index 79%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java
index f45f222861..9e3c1ff3ca 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractDanaRExecutionService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.services;
+package info.nightscout.androidaps.plugins.pump.danaR.services;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
@@ -23,25 +23,25 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryAlarm;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryBasalHour;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryBolus;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryCarbo;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryDailyInsulin;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryDone;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryError;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryGlucose;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryRefill;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistorySuspend;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgPCCommStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgPCCommStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.ToastUtils;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryAlarm;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryBasalHour;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryBolus;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryCarbo;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryDailyInsulin;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryDone;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryError;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryGlucose;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistoryRefill;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgHistorySuspend;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgPCCommStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgPCCommStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.ToastUtils;
/**
* Created by mike on 28.01.2018.
@@ -55,7 +55,6 @@ public abstract class AbstractDanaRExecutionService extends Service {
protected BluetoothSocket mRfcommSocket;
protected BluetoothDevice mBTDevice;
- protected DanaRPump mDanaRPump = DanaRPump.getInstance();
protected Treatment mBolusingTreatment = null;
protected boolean mConnectionInProgress = false;
@@ -237,4 +236,15 @@ public abstract class AbstractDanaRExecutionService extends Service {
result.comment = "OK";
return result;
}
+
+ protected void waitForWholeMinute() {
+ while (true) {
+ long time = DateUtil.now();
+ long timeToWholeMinute = (60000 - time % 60000);
+ if (timeToWholeMinute > 59800 || timeToWholeMinute < 3000)
+ break;
+ MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.waitingfortimesynchronization, (int) (timeToWholeMinute / 1000))));
+ SystemClock.sleep(Math.min(timeToWholeMinute, 100));
+ }
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java
similarity index 62%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java
index 1cca0b2512..6d2cba9741 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractSerialIOThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/AbstractSerialIOThread.java
@@ -1,6 +1,6 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.services;
+package info.nightscout.androidaps.plugins.pump.danaR.services;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
/**
* Created by mike on 28.01.2018.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java
similarity index 76%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java
index 425e72ea04..4c61c92a4f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaR.services;
+package info.nightscout.androidaps.plugins.pump.danaR.services;
import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter;
@@ -22,50 +22,50 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.SerialIOThread;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgCheckValue;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetActivateBasalProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetBasalProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingActiveProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatiosAll;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatus;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgCheckValue;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetActivateBasalProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetBasalProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetUserOptions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingActiveProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatiosAll;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingUserOptions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatus;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBasic;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
public class DanaRExecutionService extends AbstractDanaRExecutionService {
@@ -133,6 +133,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public void getPumpStatus() {
+ DanaRPump danaRPump = DanaRPump.getInstance();
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus();
@@ -141,7 +142,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue checkValue = new MsgCheckValue();
- if (mDanaRPump.isNewPump) {
+ if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return;
@@ -157,11 +158,11 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
long now = System.currentTimeMillis();
- mDanaRPump.lastConnection = now;
+ danaRPump.lastConnection = now;
Profile profile = ProfileFunctions.getInstance().getProfile();
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
+ if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
@@ -169,7 +170,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
}
- if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
+ if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingActiveProfile());
@@ -184,29 +185,29 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingUserOptions());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) {
mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
}
- mDanaRPump.lastSettingsRead = now;
+ danaRPump.lastSettingsRead = now;
}
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
- if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
+ if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
- log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits);
+ log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(reportFail));
- NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U");
+ NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
lastApproachingDailyLimit = System.currentTimeMillis();
}
}
@@ -216,8 +217,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasal(int percent, int durationInHours) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
- if (mDanaRPump.isTempBasalInProgress) {
+ if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
@@ -262,6 +264,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean bolus(double amount, int carbs, long carbtime, final Treatment t) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
if (BolusProgressDialog.stopPressed) return false;
@@ -335,13 +338,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
ConfigBuilderPlugin.getPlugin().getCommandQueue().independentConnect("bolusingInterrupted", new Callback() {
@Override
public void run() {
- if (mDanaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
- t.insulin = mDanaRPump.lastBolusAmount;
+ if (danaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
+ t.insulin = danaRPump.lastBolusAmount;
if (L.isEnabled(L.PUMP))
- log.debug("Used bolus amount from history: " + mDanaRPump.lastBolusAmount);
+ log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
} else {
if (L.isEnabled(L.PUMP))
- log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(mDanaRPump.lastBolusTime));
+ log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(danaRPump.lastBolusTime));
}
synchronized (o) {
o.notify();
@@ -379,6 +382,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean updateBasalsInPump(final Profile profile) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile);
@@ -386,7 +390,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(msgSet);
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
mSerialIOThread.sendMessage(msgActivate);
- mDanaRPump.lastSettingsRead = 0; // force read full settings
+ danaRPump.lastSettingsRead = 0; // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java
index 54f0beb89b..3b4aa0ee4c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean;
+package info.nightscout.androidaps.plugins.pump.danaRKorean;
import android.content.ComponentName;
import android.content.Context;
@@ -22,16 +22,16 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java
index ea12b2b9c4..5c47d7c7d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/SerialIOThread.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean;
+package info.nightscout.androidaps.plugins.pump.danaRKorean;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
@@ -11,11 +11,11 @@ import java.io.InputStream;
import java.io.OutputStream;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MessageHashTable_k;
-import info.nightscout.utils.CRC;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTable_k;
+import info.nightscout.androidaps.utils.CRC;
/**
* Created by mike on 17.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java
index 422391c127..30ac710724 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MessageHashTable_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTable_k.java
@@ -1,12 +1,12 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.*;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.*;
/**
* Created by mike on 28.05.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java
index 7bde73d5a1..731c25d4d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgCheckValue_k.java
@@ -1,12 +1,12 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 30.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java
index 32253b0007..5c9ac9707b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,11 +6,11 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgInitConnStatusBasic_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java
similarity index 70%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java
index 4be04f538f..b77f8ee61c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBolus_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -6,11 +6,12 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
/**
* Created by mike on 28.05.2016.
@@ -51,5 +52,9 @@ public class MsgInitConnStatusBolus_k extends MessageBase {
} else {
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
}
+
+ // This is last message of initial sequence
+ if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
+ ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking();
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java
index d713bb5a6c..103c3a2234 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -8,14 +8,14 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-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.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgInitConnStatusTime_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java
index 2455f59e14..cb131634ec 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasalProfileAll_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasalProfileAll_k.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java
similarity index 80%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java
index b149ceb2ad..99ad848289 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgSettingBasal_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgSettingBasal_k.java
@@ -1,12 +1,12 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 05.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java
index d22c6e376a..e7752cfb8f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBasic_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatusBasic_k.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatusBasic_k extends MessageBase {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java
similarity index 88%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java
index 4d8b012244..4ef29247b2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatus_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgStatus_k.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatus_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java
similarity index 74%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java
index d419d7c1f1..056d336805 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRKorean.services;
+package info.nightscout.androidaps.plugins.pump.danaRKorean.services;
import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter;
@@ -22,41 +22,42 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetSingleBasalProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue_k;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal_k;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic_k;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetSingleBasalProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.SerialIOThread;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgCheckValue_k;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgSettingBasal_k;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgStatusBasic_k;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.queue.commands.Command;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.T;
public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
@@ -137,6 +138,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public void getPumpStatus() {
+ DanaRPump danaRPump = DanaRPump.getInstance();
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
//MsgStatus_k statusMsg = new MsgStatus_k();
@@ -145,7 +147,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue_k checkValue = new MsgCheckValue_k();
- if (mDanaRPump.isNewPump) {
+ if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return;
@@ -161,11 +163,11 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
long now = System.currentTimeMillis();
- mDanaRPump.lastConnection = now;
+ danaRPump.lastConnection = now;
Profile profile = ProfileFunctions.getInstance().getProfile();
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
+ if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
@@ -173,7 +175,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
}
- if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
+ if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingMeal());
@@ -184,29 +186,31 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) {
- mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
+ waitForWholeMinute(); // Dana can set only whole minute
+ // add 10sec to be sure we are over minute (will be cutted off anyway)
+ mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
}
- mDanaRPump.lastSettingsRead = now;
+ danaRPump.lastSettingsRead = now;
}
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
- if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
+ if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
- log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits);
+ log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(reportFail));
- NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U");
+ NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
lastApproachingDailyLimit = System.currentTimeMillis();
}
}
@@ -216,8 +220,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasal(int percent, int durationInHours) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
- if (mDanaRPump.isTempBasalInProgress) {
+ if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
@@ -318,12 +323,13 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public boolean updateBasalsInPump(final Profile profile) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet);
- mDanaRPump.lastSettingsRead = 0; // force read full settings
+ danaRPump.lastSettingsRead = 0; // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
index e3c8f9de94..d2eb132f61 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS;
+package info.nightscout.androidaps.plugins.pump.danaRS;
import android.content.ComponentName;
import android.content.Context;
@@ -16,6 +16,8 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
+
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@@ -36,27 +38,29 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
-import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
-import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
+import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
+import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange;
+import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 03.09.2017.
@@ -373,6 +377,12 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return DanaRPump.getInstance().currentBasal;
}
+ @Override
+ public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; }
+
+ @Override
+ public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; }
+
@Override
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
@@ -415,6 +425,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (!result.success) {
String error = "" + DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode;
switch (DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode) {
+ // 4 reported as max bolus violation. Check later
case 0x10:
error = MainApp.gs(R.string.maxbolusviolation);
break;
@@ -806,4 +817,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return loadHistory(RecordTypes.RECORD_TYPE_DAILY);
}
+ @Override
+ public List getCustomActions() {
+ return null;
+ }
+
+ @Override
+ public void executeCustomAction(CustomActionType customActionType) {
+
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java
index 7594e917c5..502c18cbc9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/BLEScanActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/BLEScanActivity.java
@@ -1,16 +1,12 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.activities;
+package info.nightscout.androidaps.plugins.pump.danaRS.activities;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
-import android.content.Context;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
-import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
@@ -18,17 +14,14 @@ import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange;
+import info.nightscout.androidaps.utils.SP;
public class BLEScanActivity extends AppCompatActivity {
private ListView listView = null;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java
index c67534ac75..a98d541963 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingHelperActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.activities;
+package info.nightscout.androidaps.plugins.pump.danaRS.activities;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java
index 08c0ce0372..1d9943a5f5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.activities;
+package info.nightscout.androidaps.plugins.pump.danaRS.activities;
import android.app.Activity;
@@ -17,7 +17,7 @@ import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess;
+import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
public class PairingProgressDialog extends DialogFragment implements View.OnClickListener {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java
index bda5d42207..a81aa3c9bc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRSMessageHashTable.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTable.java
@@ -1,9 +1,7 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import java.util.HashMap;
-import info.nightscout.androidaps.logging.L;
-
/**
* Created by mike on 28.05.2016.
*/
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java
index d913f50b94..28a081aaa8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import android.annotation.TargetApi;
import android.os.Build;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java
index c33cd7b405..c850eace0a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_Basal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java
index dd3e5398c9..f6364290c2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_Events.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -17,10 +17,10 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@@ -45,6 +45,12 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
public DanaRS_Packet_APS_History_Events(long from) {
this();
GregorianCalendar cal = new GregorianCalendar();
+
+ if (from > DateUtil.now()) {
+ log.debug("Asked to load from the future");
+ from = 0;
+ }
+
if (from != 0)
cal.setTimeInMillis(from);
else
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java
index f31bdf66e2..fda5f33959 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Set_Event_History.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_Set_Event_History.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -9,8 +9,8 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java
similarity index 83%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java
index 3cb5523dfc..5cbda121ce 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -9,10 +9,10 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java
index 60b9f6da51..04aa4cefb3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Basal_Rate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Basal_Get_Profile_Basal_Rate extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java
index 1beadfd705..6da58c7a43 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Profile_Number.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Basal_Get_Profile_Number extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java
index 748d88f242..5724c5ff80 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import android.support.annotation.NonNull;
@@ -8,8 +8,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java
index 188c1df093..cef7c8ab92 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Basal_Rate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java
index f0f2691315..0020e3ffa1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java
index a42176cc59..d6ae1c94a7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Basal_Rate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java
index 4f39fcfd2f..ab6f4174da 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Profile_Number.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java
index 65ef6ae1b1..5fbda1d902 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_Off.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java
index bde3b622db..82c282adad 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Suspend_On.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java
index 1f6106ab83..f2abcbc164 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Set_Temporary_Basal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java
index 0e5a3d79c4..73c7a8d8f0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,10 +8,10 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Bolus_Option extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java
index 9b5636eaaf..5dca32bdd3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_CIR_CF_Array.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -7,7 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_CIR_CF_Array extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java
index 194edd5d55..b024dd056c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Calculation_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Calculation_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java
index 476ae7167f..60da3683ac 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java
index 7d561bd679..5f1bbc5a39 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Dual_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Dual_Bolus extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java
index 785d8d3fbe..2b857e3fc8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Extended_Bolus extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java
index a07652218f..15d2678451 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Extended_Bolus_State extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java
index fda8778d08..9e66d9458b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java
index 15ad57d83a..37c9d9138e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Initial_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java
index a9968eb7eb..755fff3829 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java
index cc4a26f24f..2013bd74eb 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Bolus_Option.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java
index 15bde78a76..50a6871bd4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_CIR_CF_Array.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java
index 023458e5dc..da11d172fc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Dual_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java
index 504b21bbc9..4337663d6d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java
index 587e87df9d..e8d9df360c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java
index 2e7b9be1ff..206a61b6f5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Initial_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java
index e50fbd70b5..7ff91fa9ef 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.data.ConstraintChecker;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.logging.L;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java
index e12b3db7f1..5e3fe3fbcd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Stop.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -9,8 +9,8 @@ import info.nightscout.androidaps.R;
import com.cozmo.danar.util.BleCommandUtil;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java
index 8adf46f742..306787d4ee 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Keep_Connection.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java
index 1c9af359e2..7c0b652979 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Etc_Set_History_Save.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java
index c64680379f..0f5e4a8e02 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Delivery_Status.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Delivery_Status.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java
index b1553a2c05..f14197ac41 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_More_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_More_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_General_Get_More_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java
index dc5cbc59f0..0a4d15d456 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Password.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Password.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_General_Get_Password extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java
similarity index 85%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java
index 5c26e2ce74..7c0a0ec2ae 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,9 +8,9 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java
index f2cb14cf73..e1efa91296 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Shipping_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,8 +6,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java
index 2a3b136279..c154ac3476 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Today_Delivery_Total.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_General_Get_Today_Delivery_Total extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java
index 0d07ecc33d..65bf066023 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_User_Time_Change_Flag.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java
index d8e5b95c14..75b969b1bc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Initial_Screen_Information.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_General_Initial_Screen_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java
index f66c3c4afe..21a15b1dbd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_History_Upload_Mode.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java
index 9f7570d4ce..b8771c1939 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.java
index aab933e787..ceaf49908b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -10,9 +10,9 @@ import java.util.GregorianCalendar;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
+import info.nightscout.androidaps.utils.DateUtil;
public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java
index e586166783..437804b102 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Alarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Alarm.java
@@ -1,12 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
-
import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Alarm extends DanaRS_Packet_History_ {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.java
index f6411dca5f..68940dd4c5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_All_History.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_History.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.java
index 76d485695c..0a94f16a40 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Basal.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Basal.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java
index e66db9bb78..dc0e00d844 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Blood_Glucose.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_Glucose.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java
index 41a2bd0995..64fb26dd09 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Bolus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Bolus.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java
index 58d9fac3dc..9cd931718d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Carbohydrate.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Carbohydrate.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.java
index b480f76258..35a154f5e6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Daily.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Daily.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.java
index 28ea4c30f0..7ec05fc0e0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Prime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Prime.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.java
index 685c8e519e..e031ee1460 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Refill.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Refill.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java
index ef787746ce..20f4de5098 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Suspend.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Suspend.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java
index 68526b5fb2..65f86c5b7f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_History_Temporary.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Temporary.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java
index 799b3c248c..4fc28e4cc9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Alarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Alarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
public class DanaRS_Packet_Notify_Alarm extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java
similarity index 89%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java
index 836a52cb65..3c916dc399 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java
index c2eb232dac..290e9743ef 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
public class DanaRS_Packet_Notify_Delivery_Rate_Display extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java
index 8239bb34b7..0d7d9af2c5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java
index b4bcbaef98..d12ed52c79 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_Pump_Time.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Option_Get_Pump_Time extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java
index 6c6d7d7185..457b7ab2b8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Get_User_Option.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Get_User_Option.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Option_Get_User_Option extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java
index f43f82fb15..58bf00e6a6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_Pump_Time.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java
index a64e1e5142..30fc07cfd0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Option_Set_User_Option.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Option_Set_User_Option.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java
index 7a2421c310..50edd71bd6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Review_Bolus_Avg.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
+package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java
similarity index 70%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java
index dd9b86ebce..224f939ad7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSDeviceChange.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSDeviceChange.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.events;
+package info.nightscout.androidaps.plugins.pump.danaRS.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java
similarity index 65%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java
index e42b6b1440..e0c401a27f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPacket.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPacket.java
@@ -1,7 +1,7 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.events;
+package info.nightscout.androidaps.plugins.pump.danaRS.events;
import info.nightscout.androidaps.events.Event;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
/**
* Created by mike on 01.09.2017.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java
similarity index 70%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java
index 433cdec9bf..e332e9e0b2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/events/EventDanaRSPairingSuccess.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/events/EventDanaRSPairingSuccess.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.events;
+package info.nightscout.androidaps.plugins.pump.danaRS.events;
import info.nightscout.androidaps.events.Event;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java
index be241dbbfd..69ca9f1901 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.services;
+package info.nightscout.androidaps.plugins.pump.danaRS.services;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -26,17 +26,17 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
-import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPacket;
-import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPairingSuccess;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
+import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPacket;
+import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 23.09.2017.
@@ -144,9 +144,9 @@ public class BLEComm {
if (L.isEnabled(L.PUMPBTCOMM))
log.debug("Trying to create a new connection from: " + from);
+ mBluetoothDeviceName = device.getName();
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
setCharacteristicNotification(getUARTReadBTGattChar(), true);
- mBluetoothDeviceName = device.getName();
return true;
}
@@ -662,7 +662,13 @@ public class BLEComm {
private void SendPumpCheck() {
// 1st message sent to pump after connect
- byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, getConnectDeviceName());
+ String devicename = getConnectDeviceName();
+ if(devicename == null || devicename.equals("")){
+ Notification n = new Notification(Notification.DEVICENOTPAIRED, MainApp.gs(R.string.pairfirst), Notification.URGENT);
+ MainApp.bus().post(new EventNewNotification(n));
+ return;
+ }
+ byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, devicename);
if (L.isEnabled(L.PUMPBTCOMM))
log.debug(">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes));
writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java
similarity index 81%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java
index cb823a3c88..47b1fbfe2a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRS.services;
+package info.nightscout.androidaps.plugins.pump.danaRS.services;
import android.app.Service;
import android.content.Intent;
@@ -24,64 +24,64 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
-import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_History_Events;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Set_Event_History;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Pump_Check;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Shipping_Information;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Initial_Screen_Information;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Set_History_Upload_Mode;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Alarm;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Basal;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Blood_Glucose;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Bolus;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Carbohydrate;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Daily;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Prime;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Refill;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_Suspend;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Complete;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_User_Option;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
-import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_User_Option;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
+import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_History_Events;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_APS_Set_Event_History;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Shipping_Information;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Initial_Screen_Information;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Set_History_Upload_Mode;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Alarm;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Basal;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Blood_Glucose;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Bolus;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Carbohydrate;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Daily;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Prime;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Refill;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_History_Suspend;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Notify_Delivery_Complete;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Get_User_Option;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
+import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Option_Set_User_Option;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
public class DanaRSService extends Service {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java
index 86c07b89ff..9e3ca499d0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2;
+package info.nightscout.androidaps.plugins.pump.danaRv2;
import android.content.ComponentName;
import android.content.Context;
@@ -19,19 +19,21 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
-import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
-import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
-import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.utils.Round;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
+import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+
+import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
+import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2ExecutionService;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 05.08.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java
index 61047a8d5a..ba1fdc5cb2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/SerialIOThread.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2;
+package info.nightscout.androidaps.plugins.pump.danaRv2;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
@@ -11,11 +11,11 @@ import java.io.InputStream;
import java.io.OutputStream;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractSerialIOThread;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2;
-import info.nightscout.utils.CRC;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MessageHashTable_v2;
+import info.nightscout.androidaps.utils.CRC;
/**
* Created by mike on 17.07.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java
index c95a800128..66376290af 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_v2.java
@@ -1,9 +1,9 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import java.util.HashMap;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.*;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.*;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java
index 034c7648a0..5af7705106 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -8,14 +8,14 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
-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.plugins.PumpDanaR.DanaRPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
+import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
/**
* Created by mike on 30.06.2016.
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java
similarity index 91%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java
index b12116e1a0..b3c7d00612 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEvents_v2.java
@@ -1,9 +1,8 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.MainApp;
@@ -14,11 +13,11 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgHistoryEvents_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@@ -26,23 +25,30 @@ public class MsgHistoryEvents_v2 extends MessageBase {
public static long lastEventTimeLoaded = 0;
- public MsgHistoryEvents_v2(long from) {
- SetCommand(0xE003);
- GregorianCalendar gfrom = new GregorianCalendar();
- gfrom.setTimeInMillis(from);
- AddParamDate(gfrom);
- done = false;
- if (L.isEnabled(L.PUMPCOMM))
- log.debug("New message");
+ public MsgHistoryEvents_v2() {
+ this(0);
}
- public MsgHistoryEvents_v2() {
+ public MsgHistoryEvents_v2(long from) {
SetCommand(0xE003);
- AddParamByte((byte) 0);
- AddParamByte((byte) 1);
- AddParamByte((byte) 1);
- AddParamByte((byte) 0);
- AddParamByte((byte) 0);
+
+ if (from > DateUtil.now()) {
+ log.debug("Asked to load from the future");
+ from = 0;
+ }
+
+ if (from == 0) {
+ AddParamByte((byte) 0);
+ AddParamByte((byte) 1);
+ AddParamByte((byte) 1);
+ AddParamByte((byte) 0);
+ AddParamByte((byte) 0);
+ } else {
+ GregorianCalendar gfrom = new GregorianCalendar();
+ gfrom.setTimeInMillis(from);
+ AddParamDate(gfrom);
+ }
+
done = false;
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java
index 42964a64c6..875cd4ac64 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetAPSTempBasalStart_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetAPSTempBasalStart_v2.java
@@ -1,10 +1,10 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgSetAPSTempBasalStart_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java
index 0c55b29a3f..b817495ba3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgSetHistoryEntry_v2.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -7,7 +7,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgSetHistoryEntry_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java
similarity index 79%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java
index 5d0238f2f7..601a5d4933 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusAPS_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusAPS_v2.java
@@ -1,11 +1,11 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatusAPS_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java
similarity index 93%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java
index 5a442e39c1..578be6d4b6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusBolusExtended_v2.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import android.support.annotation.NonNull;
@@ -6,8 +6,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatusBolusExtended_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java
index fb26d2c0de..a92c534d92 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgStatusTempBasal_v2.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
+package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import android.support.annotation.NonNull;
@@ -6,9 +6,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.utils.DateUtil;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.utils.DateUtil;
public class MsgStatusTempBasal_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java
similarity index 76%
rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java
index 073cbbde1e..8cabb8959d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.PumpDanaRv2.services;
+package info.nightscout.androidaps.plugins.pump.danaRv2.services;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
@@ -23,57 +23,57 @@ import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
-import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
-import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
-import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
-import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
-import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
-import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetActivateBasalProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetBasalProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetCarbsEntry;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetExtendedBolusStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingActiveProfile;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingBasal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatiosAll;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatus;
-import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic;
-import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
-import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
-import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
-import info.nightscout.androidaps.plugins.Treatments.Treatment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.BolusProgressDialog;
+import info.nightscout.androidaps.plugins.general.overview.Dialogs.ErrorHelperActivity;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetActivateBasalProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetBasalProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetCarbsEntry;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetExtendedBolusStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStart;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTempBasalStop;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSetUserOptions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingActiveProfile;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingBasal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingGlucose;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMaxValues;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingMeal;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatios;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingProfileRatiosAll;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingPumpTime;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingShippingInfo;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgSettingUserOptions;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatus;
+import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBasic;
+import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
+import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService;
+import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
+import info.nightscout.androidaps.plugins.pump.danaRv2.SerialIOThread;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgCheckValue_v2;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgHistoryEvents_v2;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetAPSTempBasalStart_v2;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetHistoryEntry_v2;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusBolusExtended_v2;
+import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusTempBasal_v2;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
-import info.nightscout.utils.DateUtil;
-import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
-import info.nightscout.utils.SP;
-import info.nightscout.utils.T;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.T;
public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
@@ -156,6 +156,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
public void getPumpStatus() {
+ DanaRPump danaRPump = DanaRPump.getInstance();
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus();
@@ -164,7 +165,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MsgStatusBolusExtended_v2 exStatusMsg = new MsgStatusBolusExtended_v2();
MsgCheckValue_v2 checkValue = new MsgCheckValue_v2();
- if (mDanaRPump.isNewPump) {
+ if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return;
@@ -179,11 +180,11 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus)));
mSerialIOThread.sendMessage(exStatusMsg);
- mDanaRPump.lastConnection = System.currentTimeMillis();
+ danaRPump.lastConnection = System.currentTimeMillis();
Profile profile = ProfileFunctions.getInstance().getProfile();
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
+ if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
@@ -193,7 +194,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 3) {
@@ -209,7 +210,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.instance().startActivity(i);
//deinitialize pump
- mDanaRPump.lastConnection = 0;
+ danaRPump.lastConnection = 0;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
return;
@@ -218,14 +219,14 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
// add 10sec to be sure we are over minute (will be cutted off anyway)
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
- timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
+ timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
}
}
long now = System.currentTimeMillis();
- if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
+ if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingActiveProfile());
@@ -238,7 +239,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
mSerialIOThread.sendMessage(new MsgSettingUserOptions());
mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll());
- mDanaRPump.lastSettingsRead = now;
+ danaRPump.lastSettingsRead = now;
}
loadEvents();
@@ -246,13 +247,13 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
- if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
+ if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
- log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits);
+ log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(reportFail));
- NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U");
+ NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
lastApproachingDailyLimit = System.currentTimeMillis();
}
}
@@ -262,8 +263,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasal(int percent, int durationInHours) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
- if (mDanaRPump.isTempBasalInProgress) {
+ if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
@@ -277,8 +279,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
public boolean highTempBasal(int percent) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
- if (mDanaRPump.isTempBasalInProgress) {
+ if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
@@ -292,13 +295,14 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasalShortDuration(int percent, int durationInMinutes) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (durationInMinutes != 15 && durationInMinutes != 30) {
log.error("Wrong duration param");
return false;
}
if (!isConnected()) return false;
- if (mDanaRPump.isTempBasalInProgress) {
+ if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
@@ -449,6 +453,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
public PumpEnactResult loadEvents() {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
PumpEnactResult result = new PumpEnactResult().success(false);
@@ -460,16 +465,10 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected())
return new PumpEnactResult().success(false);
SystemClock.sleep(300);
- MsgHistoryEvents_v2 msg;
- if (lastHistoryFetched == 0) {
- msg = new MsgHistoryEvents_v2();
- if (L.isEnabled(L.PUMP))
- log.debug("Loading complete event history");
- } else {
- msg = new MsgHistoryEvents_v2(lastHistoryFetched);
- if (L.isEnabled(L.PUMP))
- log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched));
- }
+ MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched);
+ if (L.isEnabled(L.PUMP))
+ log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched));
+
mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) {
SystemClock.sleep(100);
@@ -479,11 +478,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - T.mins(1).msecs();
else
lastHistoryFetched = 0;
- mDanaRPump.lastConnection = System.currentTimeMillis();
+ danaRPump.lastConnection = System.currentTimeMillis();
return new PumpEnactResult().success(true);
}
public boolean updateBasalsInPump(final Profile profile) {
+ DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile);
@@ -491,23 +491,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(msgSet);
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
mSerialIOThread.sendMessage(msgActivate);
- mDanaRPump.lastSettingsRead = 0; // force read full settings
+ danaRPump.lastSettingsRead = 0; // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
- void waitForWholeMinute() {
- while (true) {
- long time = DateUtil.now();
- long timeToWholeMinute = (60000 - time % 60000);
- if (timeToWholeMinute > 59800 || timeToWholeMinute < 3000)
- break;
- MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.waitingfortimesynchronization, (int) (timeToWholeMinute / 1000))));
- SystemClock.sleep(Math.min(timeToWholeMinute, 100));
- }
- }
-
public PumpEnactResult setUserOptions() {
if (!isConnected())
return new PumpEnactResult().success(false);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java
new file mode 100644
index 0000000000..89b001891c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/EventLocalInsightUpdateGUI.java
@@ -0,0 +1,6 @@
+package info.nightscout.androidaps.plugins.pump.insight;
+
+import info.nightscout.androidaps.events.EventUpdateGui;
+
+public class EventLocalInsightUpdateGUI extends EventUpdateGui {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java
new file mode 100644
index 0000000000..d851389aaf
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/InsightAlertService.java
@@ -0,0 +1,260 @@
+package info.nightscout.androidaps.plugins.pump.insight;
+
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Vibrator;
+import android.support.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SnoozeAlertMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveAlertMessage;
+import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
+
+public class InsightAlertService extends Service implements InsightConnectionService.StateCallback {
+
+ private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
+
+ private LocalBinder localBinder = new LocalBinder();
+ private boolean connectionRequested;
+ private final Object $alertLock = new Object[0];
+ private Alert alert;
+ private Thread thread;
+ private InsightAlertActivity alertActivity;
+ private Ringtone ringtone;
+ private Vibrator vibrator;
+ private boolean vibrating;
+ private InsightConnectionService connectionService;
+ private long ignoreTimestamp;
+ private AlertType ignoreType;
+
+ private ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder binder) {
+ connectionService = ((InsightConnectionService.LocalBinder) binder).getService();
+ connectionService.registerStateCallback(InsightAlertService.this);
+ onStateChanged(connectionService.getState());
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ connectionService = null;
+ }
+ };
+
+ private void retrieveRingtone() {
+ Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
+ ringtone = RingtoneManager.getRingtone(this, uri);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ ringtone.setAudioAttributes(new AudioAttributes.Builder()
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
+ .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
+ .setLegacyStreamType(AudioManager.STREAM_RING).build());
+ } else ringtone.setStreamType(AudioManager.STREAM_RING);
+ }
+
+ public Alert getAlert() {
+ synchronized ($alertLock) {
+ return alert;
+ }
+ }
+
+ public void setAlertActivity(InsightAlertActivity alertActivity) {
+ this.alertActivity = alertActivity;
+ }
+
+ public void ignore(AlertType alertType) {
+ synchronized ($alertLock) {
+ if (alertType == null) {
+ ignoreTimestamp = 0;
+ ignoreType = null;
+ } else {
+ ignoreTimestamp = System.currentTimeMillis();
+ ignoreType = alertType;
+ }
+ }
+ }
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return localBinder;
+ }
+
+ @Override
+ public void onCreate() {
+ vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+ bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE);
+ }
+
+ @Override
+ public void onDestroy() {
+ if (thread != null) thread.interrupt();
+ unbindService(serviceConnection);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ return START_STICKY;
+ }
+
+ @Override
+ public void onStateChanged(InsightState state) {
+ if (state == InsightState.CONNECTED) {
+ thread = new Thread(this::queryActiveAlert);
+ thread.start();
+
+ } else if (thread != null) thread.interrupt();
+ }
+
+ private void queryActiveAlert() {
+ while (!Thread.currentThread().isInterrupted()) {
+ try {
+ Alert alert = connectionService.requestMessage(new GetActiveAlertMessage()).await().getAlert();
+ if (Thread.currentThread().isInterrupted()) {
+ connectionService.withdrawConnectionRequest(thread);
+ break;
+ }
+ synchronized ($alertLock) {
+ if ((this.alert == null && alert != null)
+ || (this.alert != null && alert == null)
+ || (this.alert != null && alert != null && !this.alert.equals(alert))) {
+ if (this.alert != null && (alert == null || this.alert.getAlertId() != alert.getAlertId())) stopAlerting();
+ this.alert = alert;
+ if (alertActivity != null && alert != null)
+ new Handler(Looper.getMainLooper()).post(() -> alertActivity.update(alert));
+ }
+ if (alert == null) {
+ stopAlerting();
+ if (connectionRequested) {
+ connectionService.withdrawConnectionRequest(this);
+ connectionRequested = false;
+ }
+ if (alertActivity != null)
+ new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish());
+ } else if (!(alert.getAlertType() == ignoreType && System.currentTimeMillis() - ignoreTimestamp < 10000)) {
+ if (alert.getAlertStatus() == AlertStatus.ACTIVE) alert();
+ else stopAlerting();
+ if (!connectionRequested) {
+ connectionService.requestConnection(this);
+ connectionRequested = true;
+ }
+ if (alertActivity == null) {
+ Intent intent = new Intent(InsightAlertService.this, InsightAlertActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+ new Handler(Looper.getMainLooper()).post(() -> startActivity(intent));
+ }
+ }
+ }
+ } catch (InterruptedException ignored) {
+ connectionService.withdrawConnectionRequest(thread);
+ break;
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while fetching alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while fetching alert: " + e.getClass().getSimpleName());
+ } catch (Exception e) {
+ log.error("Exception while fetching alert", e);
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ if (connectionRequested) {
+ connectionService.withdrawConnectionRequest(thread);
+ connectionRequested = false;
+ }
+ if (alertActivity != null)
+ new Handler(Looper.getMainLooper()).post(() -> alertActivity.finish());
+ stopAlerting();
+ thread = null;
+ }
+
+ private void alert() {
+ if (!vibrating) {
+ vibrator.vibrate(new long[] {0, 1000, 1000}, 0);
+ vibrating = true;
+ }
+ if (ringtone == null || !ringtone.isPlaying()) {
+ retrieveRingtone();
+ ringtone.play();
+ }
+ }
+
+ private void stopAlerting() {
+ if (vibrating) {
+ vibrator.cancel();
+ vibrating = false;
+ }
+ if (ringtone != null && ringtone.isPlaying()) ringtone.stop();
+ }
+
+ public void mute() {
+ new Thread(() -> {
+ try {
+ SnoozeAlertMessage snoozeAlertMessage = new SnoozeAlertMessage();
+ snoozeAlertMessage.setAlertID(alert.getAlertId());
+ connectionService.requestMessage(snoozeAlertMessage).await();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while muting alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ } catch (InsightException e) {
+ log.info("Exception while muting alert: " + e.getClass().getSimpleName());
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ } catch (Exception e) {
+ log.error("Exception while muting alert", e);
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ }
+ }).start();
+ }
+
+ public void confirm() {
+ new Thread(() -> {
+ try {
+ ConfirmAlertMessage confirmAlertMessage = new ConfirmAlertMessage();
+ confirmAlertMessage.setAlertID(alert.getAlertId());
+ connectionService.requestMessage(confirmAlertMessage).await();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ } catch (InsightException e) {
+ log.info("Exception while confirming alert: " + e.getClass().getSimpleName());
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ } catch (Exception e) {
+ log.error("Exception while confirming alert", e);
+ ExceptionTranslator.makeToast(InsightAlertService.this, e);
+ }
+ }).start();
+ }
+
+ public class LocalBinder extends Binder {
+ public InsightAlertService getService() {
+ return InsightAlertService.this;
+ }
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java
new file mode 100644
index 0000000000..26f5180f47
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java
@@ -0,0 +1,301 @@
+package info.nightscout.androidaps.plugins.pump.insight;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.squareup.otto.Subscribe;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.common.SubscriberFragment;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.TBROverNotificationBlock;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeStatus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.TotalDailyDose;
+import info.nightscout.androidaps.queue.Callback;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.DecimalFormatter;
+
+public class LocalInsightFragment extends SubscriberFragment implements View.OnClickListener {
+
+ private static final boolean ENABLE_OPERATING_MODE_BUTTON = false;
+
+ private boolean viewsCreated;
+ private Button operatingMode;
+ private Button tbrOverNotification;
+ private Button refresh;
+ private LinearLayout statusItemContainer = null;
+
+ private Callback operatingModeCallback;
+ private Callback tbrOverNotificationCallback;
+ private Callback refreshCallback;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.local_insight_fragment, container, false);
+ statusItemContainer = view.findViewById(R.id.status_item_container);
+ tbrOverNotification = view.findViewById(R.id.tbr_over_notification);
+ tbrOverNotification.setOnClickListener(this);
+ operatingMode = view.findViewById(R.id.operating_mode);
+ operatingMode.setOnClickListener(this);
+ refresh = view.findViewById(R.id.refresh);
+ refresh.setOnClickListener(this);
+ viewsCreated = true;
+ return view;
+ }
+
+ @Override
+ public synchronized void onDestroyView() {
+ super.onDestroyView();
+ viewsCreated = false;
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == operatingMode) {
+ if (LocalInsightPlugin.getPlugin().getOperatingMode() != null) {
+ operatingMode.setEnabled(false);
+ operatingModeCallback = new Callback() {
+ @Override
+ public void run() {
+ new Handler(Looper.getMainLooper()).post(() -> {
+ operatingModeCallback = null;
+ updateGUI();
+ });
+ }
+ };
+ switch (LocalInsightPlugin.getPlugin().getOperatingMode()) {
+ case PAUSED:
+ case STOPPED:
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().startPump(operatingModeCallback);
+ break;
+ case STARTED:
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().stopPump(operatingModeCallback);
+ }
+ }
+ } else if (v == tbrOverNotification) {
+ TBROverNotificationBlock notificationBlock = LocalInsightPlugin.getPlugin().getTBROverNotificationBlock();
+ if (notificationBlock != null) {
+ tbrOverNotification.setEnabled(false);
+ tbrOverNotificationCallback = new Callback() {
+ @Override
+ public void run() {
+ new Handler(Looper.getMainLooper()).post(() -> {
+ tbrOverNotificationCallback = null;
+ updateGUI();
+ });
+ }
+ };
+ ConfigBuilderPlugin.getPlugin().getCommandQueue()
+ .setTBROverNotification(tbrOverNotificationCallback, !notificationBlock.isEnabled());
+ }
+ } else if (v == refresh) {
+ refresh.setEnabled(false);
+ refreshCallback = new Callback() {
+ @Override
+ public void run() {
+ new Handler(Looper.getMainLooper()).post(() -> {
+ refreshCallback = null;
+ updateGUI();
+ });
+ }
+ };
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("InsightRefreshButton", refreshCallback);
+ }
+ }
+
+ @Subscribe
+ public void onUpdateGUIEvent(EventLocalInsightUpdateGUI event) {
+ updateGUI();
+ }
+
+ @Override
+ protected void updateGUI() {
+ if (!viewsCreated) return;
+ statusItemContainer.removeAllViews();
+ if (!LocalInsightPlugin.getPlugin().isInitialized()) {
+ operatingMode.setVisibility(View.GONE);
+ tbrOverNotification.setVisibility(View.GONE);
+ refresh.setVisibility(View.GONE);
+ return;
+ }
+ refresh.setVisibility(View.VISIBLE);
+ refresh.setEnabled(refreshCallback == null);
+ TBROverNotificationBlock notificationBlock = LocalInsightPlugin.getPlugin().getTBROverNotificationBlock();
+ tbrOverNotification.setVisibility(notificationBlock == null ? View.GONE : View.VISIBLE);
+ if (notificationBlock != null)
+ tbrOverNotification.setText(notificationBlock.isEnabled() ? R.string.disable_tbr_over_notification : R.string.enable_tbr_over_notification);
+ tbrOverNotification.setEnabled(tbrOverNotificationCallback == null);
+ List statusItems = new ArrayList<>();
+ getConnectionStatusItem(statusItems);
+ getLastConnectedItem(statusItems);
+ getOperatingModeItem(statusItems);
+ getBatteryStatusItem(statusItems);
+ getCartridgeStatusItem(statusItems);
+ getTDDItems(statusItems);
+ getBaseBasalRateItem(statusItems);
+ getTBRItem(statusItems);
+ getBolusItems(statusItems);
+ for (int i = 0; i < statusItems.size(); i++) {
+ statusItemContainer.addView(statusItems.get(i));
+ if (i != statusItems.size() - 1)
+ getLayoutInflater().inflate(R.layout.local_insight_status_delimitter, statusItemContainer);
+ }
+ }
+
+ private View getStatusItem(String label, String value) {
+ View statusItem = getLayoutInflater().inflate(R.layout.local_insight_status_item, null);
+ ((TextView) statusItem.findViewById(R.id.label)).setText(label);
+ ((TextView) statusItem.findViewById(R.id.value)).setText(value);
+ return statusItem;
+ }
+
+ private void getConnectionStatusItem(List statusItems) {
+ int string = 0;
+ InsightState state = LocalInsightPlugin.getPlugin().getConnectionService().getState();
+ switch (state) {
+ case NOT_PAIRED:
+ string = R.string.not_paired;
+ break;
+ case DISCONNECTED:
+ string = R.string.disconnected;
+ break;
+ case CONNECTING:
+ case SATL_CONNECTION_REQUEST:
+ case SATL_KEY_REQUEST:
+ case SATL_SYN_REQUEST:
+ case SATL_VERIFY_CONFIRM_REQUEST:
+ case SATL_VERIFY_DISPLAY_REQUEST:
+ case APP_ACTIVATE_PARAMETER_SERVICE:
+ case APP_ACTIVATE_STATUS_SERVICE:
+ case APP_BIND_MESSAGE:
+ case APP_CONNECT_MESSAGE:
+ case APP_FIRMWARE_VERSIONS:
+ case APP_SYSTEM_IDENTIFICATION:
+ case AWAITING_CODE_CONFIRMATION:
+ string = R.string.connecting;
+ break;
+ case CONNECTED:
+ string = R.string.connected;
+ break;
+ case RECOVERING:
+ string = R.string.recovering;
+ break;
+ }
+ statusItems.add(getStatusItem(MainApp.gs(R.string.insight_status), MainApp.gs(string)));
+ if (state == InsightState.RECOVERING) {
+ statusItems.add(getStatusItem(MainApp.gs(R.string.recovery_duration), LocalInsightPlugin.getPlugin().getConnectionService().getRecoveryDuration() / 1000 + "s"));
+ }
+ }
+
+ private void getLastConnectedItem(List statusItems) {
+ switch (LocalInsightPlugin.getPlugin().getConnectionService().getState()) {
+ case CONNECTED:
+ case NOT_PAIRED:
+ return;
+ default:
+ long lastConnection = LocalInsightPlugin.getPlugin().getConnectionService().getLastConnected();
+ if (lastConnection == 0) return;
+ int min = (int) ((System.currentTimeMillis() - lastConnection) / 60000);
+ statusItems.add(getStatusItem(MainApp.gs(R.string.last_connected), DateUtil.timeString(lastConnection)));
+ }
+ }
+
+ private void getOperatingModeItem(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getOperatingMode() == null) {
+ operatingMode.setVisibility(View.GONE);
+ return;
+ }
+ int string = 0;
+ if (ENABLE_OPERATING_MODE_BUTTON) operatingMode.setVisibility(View.VISIBLE);
+ operatingMode.setEnabled(operatingModeCallback == null);
+ switch (LocalInsightPlugin.getPlugin().getOperatingMode()) {
+ case STARTED:
+ operatingMode.setText(R.string.stop_pump);
+ string = R.string.started;
+ break;
+ case STOPPED:
+ operatingMode.setText(R.string.start_pump);
+ string = R.string.stopped;
+ break;
+ case PAUSED:
+ operatingMode.setText(R.string.start_pump);
+ string = R.string.paused;
+ break;
+ }
+ statusItems.add(getStatusItem(MainApp.gs(R.string.operating_mode), MainApp.gs(string)));
+ }
+
+ private void getBatteryStatusItem(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getBatteryStatus() == null) return;
+ statusItems.add(getStatusItem(MainApp.gs(R.string.pump_battery_label),
+ LocalInsightPlugin.getPlugin().getBatteryStatus().getBatteryAmount() + "%"));
+ }
+
+ private void getCartridgeStatusItem(List statusItems) {
+ CartridgeStatus cartridgeStatus = LocalInsightPlugin.getPlugin().getCartridgeStatus();
+ if (cartridgeStatus == null) return;
+ String status;
+ if (cartridgeStatus.isInserted())
+ status = DecimalFormatter.to2Decimal(LocalInsightPlugin.getPlugin().getCartridgeStatus().getRemainingAmount()) + "U";
+ else status = MainApp.gs(R.string.not_inserted);
+ statusItems.add(getStatusItem(MainApp.gs(R.string.pump_reservoir_label), status));
+ }
+
+ private void getTDDItems(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getTotalDailyDose() == null) return;
+ TotalDailyDose tdd = LocalInsightPlugin.getPlugin().getTotalDailyDose();
+ statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_bolus), DecimalFormatter.to2Decimal(tdd.getBolus())));
+ statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_basal), DecimalFormatter.to2Decimal(tdd.getBasal())));
+ statusItems.add(getStatusItem(MainApp.gs(R.string.tdd_total), DecimalFormatter.to2Decimal(tdd.getBolusAndBasal())));
+ }
+
+ private void getBaseBasalRateItem(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getActiveBasalRate() == null) return;
+ ActiveBasalRate activeBasalRate = LocalInsightPlugin.getPlugin().getActiveBasalRate();
+ statusItems.add(getStatusItem(MainApp.gs(R.string.pump_basebasalrate_label),
+ DecimalFormatter.to2Decimal(activeBasalRate.getActiveBasalRate()) + " U/h (" + activeBasalRate.getActiveBasalProfileName() + ")"));
+ }
+
+ private void getTBRItem(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getActiveTBR() == null) return;
+ ActiveTBR activeTBR = LocalInsightPlugin.getPlugin().getActiveTBR();
+ statusItems.add(getStatusItem(MainApp.gs(R.string.pump_tempbasal_label),
+ MainApp.gs(R.string.tbr_formatter, activeTBR.getPercentage(), activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration())));
+ }
+
+ private void getBolusItems(List statusItems) {
+ if (LocalInsightPlugin.getPlugin().getActiveBoluses() == null) return;
+ for (ActiveBolus activeBolus : LocalInsightPlugin.getPlugin().getActiveBoluses()) {
+ String label;
+ switch (activeBolus.getBolusType()) {
+ case MULTIWAVE:
+ label = MainApp.gs(R.string.multiwave_bolus);
+ break;
+ case EXTENDED:
+ label = MainApp.gs(R.string.extended_bolus);
+ break;
+ default:
+ continue;
+ }
+ statusItems.add(getStatusItem(label, MainApp.gs(R.string.eb_formatter, activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration())));
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java
new file mode 100644
index 0000000000..22b329edbb
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java
@@ -0,0 +1,1572 @@
+package info.nightscout.androidaps.plugins.pump.insight;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
+import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.*;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.*;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import info.nightscout.androidaps.BuildConfig;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.data.DetailedBolusInfo;
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.db.CareportalEvent;
+import info.nightscout.androidaps.db.ExtendedBolus;
+import info.nightscout.androidaps.db.Source;
+import info.nightscout.androidaps.db.TDD;
+import info.nightscout.androidaps.db.TemporaryBasal;
+import info.nightscout.androidaps.events.EventInitializationChanged;
+import info.nightscout.androidaps.events.EventRefreshOverview;
+import info.nightscout.androidaps.interfaces.Constraint;
+import info.nightscout.androidaps.interfaces.ConstraintsInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PluginDescription;
+import info.nightscout.androidaps.interfaces.PluginType;
+import info.nightscout.androidaps.interfaces.PumpDescription;
+import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
+import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
+import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.HistoryReadingDirection;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.ReadHistoryEventsMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StartReadingHistoryMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.StopReadingHistoryMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusDeliveredEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.BolusProgrammedEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.CannulaFilledEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DateTimeChangedEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.DefaultDateTimeSetEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.EndOfTBREvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.HistoryEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OccurrenceOfAlertEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.OperatingModeChangedEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.PowerUpEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.SniffingDoneEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.StartOfTBREvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TotalDailyDoseEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TubeFilledEvent;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelBolusMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelTBRMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ChangeTBRMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ConfirmAlertMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.DeliverBolusMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetDateTimeMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetOperatingModeMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.SetTBRMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveAlertMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBasalRateMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveBolusesMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetActiveTBRMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetBatteryStatusMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetCartridgeStatusMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetDateTimeMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetOperatingModeMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetPumpStatusRegisterMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetTotalDailyDoseMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.ResetPumpStatusRegisterMessage;
+import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
+import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID;
+import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset;
+import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
+import info.nightscout.androidaps.plugins.treatments.Treatment;
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.SP;
+
+public class LocalInsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface, InsightConnectionService.StateCallback {
+
+ private static LocalInsightPlugin instance = null;
+
+ private Logger log = LoggerFactory.getLogger(L.PUMP);
+
+ private PumpDescription pumpDescription;
+ private InsightAlertService alertService;
+ private InsightConnectionService connectionService;
+ private long timeOffset;
+ private ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder binder) {
+ if (binder instanceof InsightConnectionService.LocalBinder) {
+ connectionService = ((InsightConnectionService.LocalBinder) binder).getService();
+ connectionService.registerStateCallback(LocalInsightPlugin.this);
+ } else if (binder instanceof InsightAlertService.LocalBinder) {
+ alertService = ((InsightAlertService.LocalBinder) binder).getService();
+ }
+ if (connectionService != null && alertService != null)
+ MainApp.bus().post(new EventInitializationChanged());
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ connectionService = null;
+ }
+ };
+
+ private final Object $bolusLock = new Object[0];
+ private int bolusID;
+ private boolean bolusCancelled;
+ private BasalProfile activeBasalProfile;
+ private List profileBlocks;
+ private boolean limitsFetched;
+ private double maximumBolusAmount;
+ private double maximumBasalAmount;
+ private double minimumBolusAmount;
+ private double minimumBasalAmount;
+ private long lastUpdated = -1;
+ private OperatingMode operatingMode;
+ private BatteryStatus batteryStatus;
+ private CartridgeStatus cartridgeStatus;
+ private TotalDailyDose totalDailyDose;
+ private ActiveBasalRate activeBasalRate;
+ private ActiveTBR activeTBR;
+ private List activeBoluses;
+ private boolean statusLoaded;
+ private TBROverNotificationBlock tbrOverNotificationBlock;
+
+ public static LocalInsightPlugin getPlugin() {
+ if (instance == null) instance = new LocalInsightPlugin();
+ return instance;
+ }
+
+ public LocalInsightPlugin() {
+ super(new PluginDescription()
+ .pluginName(R.string.insight_local)
+ .shortName(R.string.insightpump_shortname)
+ .mainType(PluginType.PUMP)
+ .description(R.string.description_pump_insight_local)
+ .fragmentClass(LocalInsightFragment.class.getName())
+ .preferencesId(R.xml.pref_insight_local));
+
+ pumpDescription = new PumpDescription();
+ pumpDescription.setPumpDescription(PumpType.AccuChekInsight);
+ }
+
+ public TBROverNotificationBlock getTBROverNotificationBlock() {
+ return tbrOverNotificationBlock;
+ }
+
+ public long getLastUpdated() {
+ return lastUpdated;
+ }
+
+ public InsightConnectionService getConnectionService() {
+ return connectionService;
+ }
+
+ public OperatingMode getOperatingMode() {
+ return operatingMode;
+ }
+
+ public BatteryStatus getBatteryStatus() {
+ return batteryStatus;
+ }
+
+ public CartridgeStatus getCartridgeStatus() {
+ return cartridgeStatus;
+ }
+
+ public TotalDailyDose getTotalDailyDose() {
+ return totalDailyDose;
+ }
+
+ public ActiveBasalRate getActiveBasalRate() {
+ return activeBasalRate;
+ }
+
+ public ActiveTBR getActiveTBR() {
+ return activeTBR;
+ }
+
+ public List getActiveBoluses() {
+ return activeBoluses;
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ MainApp.instance().bindService(new Intent(MainApp.instance(), InsightConnectionService.class), serviceConnection, Context.BIND_AUTO_CREATE);
+ MainApp.instance().bindService(new Intent(MainApp.instance(), InsightAlertService.class), serviceConnection, Context.BIND_AUTO_CREATE);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ MainApp.instance().unbindService(serviceConnection);
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return connectionService != null && alertService != null && connectionService.isPaired();
+ }
+
+ @Override
+ public boolean isSuspended() {
+ return operatingMode != null && operatingMode != OperatingMode.STARTED;
+ }
+
+ @Override
+ public boolean isBusy() {
+ return false;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return connectionService != null
+ && alertService != null
+ && connectionService.hasRequestedConnection(this)
+ && connectionService.getState() == InsightState.CONNECTED;
+ }
+
+ @Override
+ public boolean isConnecting() {
+ if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this))
+ return false;
+ InsightState state = connectionService.getState();
+ return state == InsightState.CONNECTING
+ || state == InsightState.APP_CONNECT_MESSAGE
+ || state == InsightState.RECOVERING;
+ }
+
+ @Override
+ public boolean isHandshakeInProgress() {
+ return false;
+ }
+
+ @Override
+ public void finishHandshaking() {
+
+ }
+
+ @Override
+ public void connect(String reason) {
+ if (connectionService != null && alertService != null)
+ connectionService.requestConnection(this);
+ }
+
+ @Override
+ public void disconnect(String reason) {
+ if (connectionService != null && alertService != null)
+ connectionService.withdrawConnectionRequest(this);
+ }
+
+ @Override
+ public void stopConnecting() {
+ if (connectionService != null && alertService != null)
+ connectionService.withdrawConnectionRequest(this);
+ }
+
+ @Override
+ public void getPumpStatus() {
+ try {
+ tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class);
+ readHistory();
+ fetchBasalProfile();
+ fetchLimitations();
+ updatePumpTimeIfNeeded();
+ fetchStatus();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while fetching status: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception while fetching status", e);
+ }
+ }
+
+ private void updatePumpTimeIfNeeded() throws Exception {
+ PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime();
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(Calendar.YEAR, pumpTime.getYear());
+ calendar.set(Calendar.MONTH, pumpTime.getMonth() - 1);
+ calendar.set(Calendar.DAY_OF_MONTH, pumpTime.getDay());
+ calendar.set(Calendar.HOUR_OF_DAY, pumpTime.getHour());
+ calendar.set(Calendar.MINUTE, pumpTime.getMinute());
+ calendar.set(Calendar.SECOND, pumpTime.getSecond());
+ if (Math.abs(calendar.getTimeInMillis() - System.currentTimeMillis()) > 10000) {
+ calendar.setTime(new Date());
+ pumpTime.setYear(calendar.get(Calendar.YEAR));
+ pumpTime.setMonth(calendar.get(Calendar.MONTH) + 1);
+ pumpTime.setDay(calendar.get(Calendar.DAY_OF_MONTH));
+ pumpTime.setHour(calendar.get(Calendar.HOUR_OF_DAY));
+ pumpTime.setMinute(calendar.get(Calendar.MINUTE));
+ pumpTime.setSecond(calendar.get(Calendar.SECOND));
+ SetDateTimeMessage setDateTimeMessage = new SetDateTimeMessage();
+ setDateTimeMessage.setPumpTime(pumpTime);
+ connectionService.requestMessage(setDateTimeMessage).await();
+ Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60);
+ MainApp.bus().post(new EventNewNotification(notification));
+ }
+ }
+
+ private void fetchBasalProfile() throws Exception {
+ activeBasalProfile = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, ActiveBRProfileBlock.class).getActiveBasalProfile();
+ profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, BRProfile1Block.class).getProfileBlocks();
+ }
+
+ private void fetchStatus() throws Exception {
+ if (statusLoaded) {
+ GetPumpStatusRegisterMessage registerMessage = connectionService.requestMessage(new GetPumpStatusRegisterMessage()).await();
+ ResetPumpStatusRegisterMessage resetMessage = new ResetPumpStatusRegisterMessage();
+ resetMessage.setOperatingModeChanged(registerMessage.isOperatingModeChanged());
+ resetMessage.setBatteryStatusChanged(registerMessage.isBatteryStatusChanged());
+ resetMessage.setCartridgeStatusChanged(registerMessage.isCartridgeStatusChanged());
+ resetMessage.setTotalDailyDoseChanged(registerMessage.isTotalDailyDoseChanged());
+ resetMessage.setActiveTBRChanged(registerMessage.isActiveTBRChanged());
+ resetMessage.setActiveBolusesChanged(registerMessage.isActiveBolusesChanged());
+ connectionService.requestMessage(resetMessage).await();
+ if (registerMessage.isOperatingModeChanged())
+ operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
+ if (registerMessage.isBatteryStatusChanged())
+ batteryStatus = connectionService.requestMessage(new GetBatteryStatusMessage()).await().getBatteryStatus();
+ if (registerMessage.isCartridgeStatusChanged())
+ cartridgeStatus = connectionService.requestMessage(new GetCartridgeStatusMessage()).await().getCartridgeStatus();
+ if (registerMessage.isTotalDailyDoseChanged())
+ totalDailyDose = connectionService.requestMessage(new GetTotalDailyDoseMessage()).await().getTDD();
+ if (operatingMode == OperatingMode.STARTED) {
+ if (registerMessage.isActiveBasalRateChanged())
+ activeBasalRate = connectionService.requestMessage(new GetActiveBasalRateMessage()).await().getActiveBasalRate();
+ if (registerMessage.isActiveTBRChanged())
+ activeTBR = connectionService.requestMessage(new GetActiveTBRMessage()).await().getActiveTBR();
+ if (registerMessage.isActiveBolusesChanged())
+ activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses();
+ } else {
+ activeBasalRate = null;
+ activeTBR = null;
+ activeBoluses = null;
+ }
+
+ } else {
+ ResetPumpStatusRegisterMessage resetMessage = new ResetPumpStatusRegisterMessage();
+ resetMessage.setOperatingModeChanged(true);
+ resetMessage.setBatteryStatusChanged(true);
+ resetMessage.setCartridgeStatusChanged(true);
+ resetMessage.setTotalDailyDoseChanged(true);
+ resetMessage.setActiveBasalRateChanged(true);
+ resetMessage.setActiveTBRChanged(true);
+ resetMessage.setActiveBolusesChanged(true);
+ connectionService.requestMessage(resetMessage).await();
+ operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
+ batteryStatus = connectionService.requestMessage(new GetBatteryStatusMessage()).await().getBatteryStatus();
+ cartridgeStatus = connectionService.requestMessage(new GetCartridgeStatusMessage()).await().getCartridgeStatus();
+ totalDailyDose = connectionService.requestMessage(new GetTotalDailyDoseMessage()).await().getTDD();
+ if (operatingMode == OperatingMode.STARTED) {
+ activeBasalRate = connectionService.requestMessage(new GetActiveBasalRateMessage()).await().getActiveBasalRate();
+ activeTBR = connectionService.requestMessage(new GetActiveTBRMessage()).await().getActiveTBR();
+ activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses();
+ } else {
+ activeBasalRate = null;
+ activeTBR = null;
+ activeBoluses = null;
+ }
+ statusLoaded = true;
+ }
+ lastUpdated = System.currentTimeMillis();
+ new Handler(Looper.getMainLooper()).post(() -> {
+ MainApp.bus().post(new EventLocalInsightUpdateGUI());
+ MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::fetchStatus"));
+ });
+ }
+
+ private void fetchLimitations() throws Exception {
+ maximumBolusAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, MaxBolusAmountBlock.class).getAmountLimitation();
+ maximumBasalAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, MaxBasalAmountBlock.class).getAmountLimitation();
+ minimumBolusAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, FactoryMinBolusAmountBlock.class).getAmountLimitation();
+ minimumBasalAmount = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, FactoryMinBolusAmountBlock.class).getAmountLimitation();
+ this.pumpDescription.basalMaximumRate = maximumBasalAmount;
+ this.pumpDescription.basalMinimumRate = minimumBasalAmount;
+ limitsFetched = true;
+ }
+
+ @Override
+ public PumpEnactResult setNewBasalProfile(Profile profile) {
+ PumpEnactResult result = new PumpEnactResult();
+ MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
+ List profileBlocks = new ArrayList<>();
+ for (int i = 0; i < profile.getBasalValues().length; i++) {
+ Profile.BasalValue basalValue = profile.getBasalValues()[i];
+ Profile.BasalValue nextValue = null;
+ if (profile.getBasalValues().length > i + 1)
+ nextValue = profile.getBasalValues()[i + 1];
+ BasalProfileBlock profileBlock = new BasalProfileBlock();
+ profileBlock.setBasalAmount(basalValue.value);
+ profileBlock.setDuration((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
+ profileBlocks.add(profileBlock);
+ }
+ try {
+ ActiveBRProfileBlock activeBRProfileBlock = new ActiveBRProfileBlock();
+ activeBRProfileBlock.setActiveBasalProfile(BasalProfile.PROFILE_1);
+ ParameterBlockUtil.writeConfigurationBlock(connectionService, activeBRProfileBlock);
+ activeBasalProfile = BasalProfile.PROFILE_1;
+ BRProfileBlock profileBlock = new BRProfile1Block();
+ profileBlock.setProfileBlocks(profileBlocks);
+ ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock);
+ MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
+ Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
+ MainApp.bus().post(new EventNewNotification(notification));
+ result.success = true;
+ result.enacted = true;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ this.profileBlocks = profileBlocks;
+ try {
+ fetchStatus();
+ } catch (Exception ignored) {
+ }
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while setting profile: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
+ MainApp.bus().post(new EventNewNotification(notification));
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while setting profile: " + e.getClass().getCanonicalName());
+ Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
+ MainApp.bus().post(new EventNewNotification(notification));
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while setting profile", e);
+ Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
+ MainApp.bus().post(new EventNewNotification(notification));
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isThisProfileSet(Profile profile) {
+ if (!isInitialized() || profileBlocks == null) return true;
+ if (profile.getBasalValues().length != profileBlocks.size()) return false;
+ if (activeBasalProfile != BasalProfile.PROFILE_1) return false;
+ for (int i = 0; i < profileBlocks.size(); i++) {
+ BasalProfileBlock profileBlock = profileBlocks.get(i);
+ Profile.BasalValue basalValue = profile.getBasalValues()[i];
+ Profile.BasalValue nextValue = null;
+ if (profile.getBasalValues().length > i + 1)
+ nextValue = profile.getBasalValues()[i + 1];
+ if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds)
+ return false;
+ if (Math.abs(profileBlock.getBasalAmount() - basalValue.value) > 0.01D)
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public long lastDataTime() {
+ if (connectionService == null || alertService == null) return System.currentTimeMillis();
+ return connectionService.getLastDataTime();
+ }
+
+ @Override
+ public double getBaseBasalRate() {
+ if (connectionService == null || alertService == null) return 0;
+ if (activeBasalRate != null) return activeBasalRate.getActiveBasalRate();
+ else return 0;
+ }
+
+ @Override
+ public double getReservoirLevel() {
+ if (cartridgeStatus == null) return 0;
+ return cartridgeStatus.getRemainingAmount();
+ }
+
+ @Override
+ public int getBatteryLevel() {
+ if (batteryStatus == null) return 0;
+ return batteryStatus.getBatteryAmount();
+ }
+
+ @Override
+ public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
+ PumpEnactResult result = new PumpEnactResult();
+ if (detailedBolusInfo.insulin > 0) {
+ try {
+ synchronized ($bolusLock) {
+ DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
+ bolusMessage.setBolusType(BolusType.STANDARD);
+ bolusMessage.setDuration(0);
+ bolusMessage.setExtendedAmount(0);
+ bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
+ bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
+ bolusCancelled = false;
+ }
+ result.success = true;
+ result.enacted = true;
+ Treatment t = new Treatment();
+ t.isSMB = detailedBolusInfo.isSMB;
+ final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
+ bolusingEvent.t = t;
+ bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, detailedBolusInfo.insulin);
+ bolusingEvent.percent = 0;
+ MainApp.bus().post(bolusingEvent);
+ int trials = 0;
+ InsightBolusID insightBolusID = new InsightBolusID();
+ insightBolusID.bolusID = bolusID;
+ insightBolusID.timestamp = System.currentTimeMillis();
+ insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
+ MainApp.getDbHelper().createOrUpdate(insightBolusID);
+ detailedBolusInfo.date = insightBolusID.timestamp;
+ detailedBolusInfo.source = Source.PUMP;
+ detailedBolusInfo.pumpId = insightBolusID.id;
+ TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
+ while (true) {
+ synchronized ($bolusLock) {
+ if (bolusCancelled) break;
+ }
+ OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
+ if (operatingMode != OperatingMode.STARTED) break;
+ List activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses();
+ ActiveBolus activeBolus = null;
+ for (ActiveBolus bolus : activeBoluses) {
+ if (bolus.getBolusID() == bolusID) {
+ activeBolus = bolus;
+ break;
+ }
+ }
+ if (activeBolus != null) {
+ trials = -1;
+ int percentBefore = bolusingEvent.percent;
+ bolusingEvent.percent = (int) (100D / activeBolus.getInitialAmount() * (activeBolus.getInitialAmount() - activeBolus.getRemainingAmount()));
+ bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
+ if (percentBefore != bolusingEvent.percent)
+ MainApp.bus().post(bolusingEvent);
+ } else {
+ synchronized ($bolusLock) {
+ if (bolusCancelled || trials == -1 || trials++ >= 5) {
+ if (!bolusCancelled) {
+ bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
+ bolusingEvent.percent = 100;
+ MainApp.bus().post(bolusingEvent);
+ }
+ break;
+ }
+ }
+ }
+ Thread.sleep(200);
+ }
+ readHistory();
+ fetchStatus();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while delivering bolus", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ } else if (detailedBolusInfo.carbs > 0) {
+ result.success = true;
+ result.enacted = true;
+ }
+ result.carbsDelivered = detailedBolusInfo.carbs;
+ return result;
+ }
+
+ @Override
+ public void stopBolusDelivering() {
+ new Thread(() -> {
+ try {
+ synchronized ($bolusLock) {
+ alertService.ignore(AlertType.WARNING_38);
+ CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
+ cancelBolusMessage.setBolusID(bolusID);
+ connectionService.requestMessage(cancelBolusMessage).await();
+ bolusCancelled = true;
+ }
+ confirmAlert(AlertType.WARNING_38);
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception while canceling bolus", e);
+ }
+ }).start();
+ }
+
+ @Override
+ public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
+ PumpEnactResult result = new PumpEnactResult();
+ if (activeBasalRate == null) return result;
+ if (activeBasalRate.getActiveBasalRate() == 0) return result;
+ double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
+ if (isFakingTempsByExtendedBoluses()) {
+ PumpEnactResult cancelEBResult = cancelExtendedBolusOnly();
+ if (cancelEBResult.success) {
+ if (percent > 250) {
+ PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
+ if (cancelTBRResult.success) {
+ PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
+ * ((double) durationInMinutes), durationInMinutes);
+ if (ebResult.success) {
+ result.success = true;
+ result.enacted = true;
+ result.isPercent = false;
+ result.absolute = absoluteRate;
+ result.duration = durationInMinutes;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ } else {
+ result.comment = ebResult.comment;
+ }
+ } else {
+ result.comment = cancelTBRResult.comment;
+ }
+ } else {
+ return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
+ }
+ } else {
+ result.comment = cancelEBResult.comment;
+ }
+ } else {
+ return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
+ }
+ try {
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception after setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception after setting TBR: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception after setting TBR", e);
+ }
+ return result;
+ }
+
+ @Override
+ public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
+ PumpEnactResult result = new PumpEnactResult();
+ percent = (int) Math.round(((double) percent) / 10d) * 10;
+ if (percent == 100) return cancelTempBasal(true);
+ else if (percent > 250) percent = 250;
+ try {
+ if (activeTBR != null) {
+ ChangeTBRMessage message = new ChangeTBRMessage();
+ message.setDuration(durationInMinutes);
+ message.setPercentage(percent);
+ connectionService.requestMessage(message);
+ } else {
+ SetTBRMessage message = new SetTBRMessage();
+ message.setDuration(durationInMinutes);
+ message.setPercentage(percent);
+ connectionService.requestMessage(message);
+ }
+ result.isPercent = true;
+ result.percent = percent;
+ result.duration = durationInMinutes;
+ result.success = true;
+ result.enacted = true;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ readHistory();
+ fetchStatus();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while setting TBR: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while setting TBR", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ @Override
+ public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
+ PumpEnactResult result = cancelExtendedBolusOnly();
+ if (result.success) result = setExtendedBolusOnly(insulin, durationInMinutes);
+ try {
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception after delivering extended bolus", e);
+ }
+ return result;
+ }
+
+ public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes) {
+ PumpEnactResult result = new PumpEnactResult();
+ try {
+ DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
+ bolusMessage.setBolusType(BolusType.EXTENDED);
+ bolusMessage.setDuration(durationInMinutes);
+ bolusMessage.setExtendedAmount(insulin);
+ bolusMessage.setImmediateAmount(0);
+ int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
+ InsightBolusID insightBolusID = new InsightBolusID();
+ insightBolusID.bolusID = bolusID;
+ insightBolusID.timestamp = System.currentTimeMillis();
+ insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
+ MainApp.getDbHelper().createOrUpdate(insightBolusID);
+ ExtendedBolus extendedBolus = new ExtendedBolus();
+ extendedBolus.date = insightBolusID.timestamp;
+ extendedBolus.source = Source.PUMP;
+ extendedBolus.durationInMinutes = durationInMinutes;
+ extendedBolus.insulin = insulin;
+ extendedBolus.pumpId = insightBolusID.id;
+ TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
+ result.success = true;
+ result.enacted = true;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while delivering extended bolus", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ @Override
+ public PumpEnactResult cancelTempBasal(boolean enforceNew) {
+ PumpEnactResult result = new PumpEnactResult();
+ PumpEnactResult cancelEBResult = null;
+ if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
+ PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
+ result.success = (cancelEBResult != null && cancelEBResult.success) && cancelTBRResult.success;
+ result.enacted = (cancelEBResult != null && cancelEBResult.enacted) || cancelTBRResult.enacted;
+ result.comment = cancelEBResult != null ? cancelEBResult.comment : cancelTBRResult.comment;
+ try {
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception after canceling TBR", e);
+ }
+ return result;
+ }
+
+ private PumpEnactResult cancelTempBasalOnly() {
+ PumpEnactResult result = new PumpEnactResult();
+ try {
+ alertService.ignore(AlertType.WARNING_36);
+ connectionService.requestMessage(new CancelTBRMessage()).await();
+ result.success = true;
+ result.enacted = true;
+ result.isTempCancel = true;
+ confirmAlert(AlertType.WARNING_36);
+ alertService.ignore(null);
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ } catch (NoActiveTBRToCanceLException e) {
+ result.success = true;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while canceling TBR", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ @Override
+ public PumpEnactResult cancelExtendedBolus() {
+ PumpEnactResult result = cancelExtendedBolusOnly();
+ try {
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception after canceling extended bolus", e);
+ }
+ return result;
+ }
+
+ private PumpEnactResult cancelExtendedBolusOnly() {
+ PumpEnactResult result = new PumpEnactResult();
+ try {
+ for (ActiveBolus activeBolus : activeBoluses) {
+ if (activeBolus.getBolusType() == BolusType.EXTENDED || activeBolus.getBolusType() == BolusType.MULTIWAVE) {
+ alertService.ignore(AlertType.WARNING_38);
+ CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
+ cancelBolusMessage.setBolusID(activeBolus.getBolusID());
+ connectionService.requestMessage(cancelBolusMessage).await();
+ confirmAlert(AlertType.WARNING_38);
+ alertService.ignore(null);
+ InsightBolusID insightBolusID = MainApp.getDbHelper().getInsightBolusID(connectionService.getPumpSystemIdentification().getSerialNumber(),
+ activeBolus.getBolusID(), System.currentTimeMillis());
+ if (insightBolusID != null) {
+ ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(insightBolusID.id);
+ if (extendedBolus != null) {
+ extendedBolus.durationInMinutes = (int) ((System.currentTimeMillis() - extendedBolus.date) / 60000);
+ if (extendedBolus.durationInMinutes <= 0) {
+ ;
+ final String _id = extendedBolus._id;
+ if (NSUpload.isIdValid(_id))
+ NSUpload.removeCareportalEntryFromNS(_id);
+ else UploadQueue.removeID("dbAdd", _id);
+ MainApp.getDbHelper().delete(extendedBolus);
+ } else
+ TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
+ }
+ result.enacted = true;
+ result.success = true;
+ }
+ }
+ }
+ result.success = true;
+ result.comment = MainApp.gs(R.string.virtualpump_resultok);
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while canceling extended bolus", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ private void confirmAlert(AlertType alertType) {
+ try {
+ long started = System.currentTimeMillis();
+ while (System.currentTimeMillis() - started < 10000) {
+ GetActiveAlertMessage activeAlertMessage = connectionService.requestMessage(new GetActiveAlertMessage()).await();
+ if (activeAlertMessage.getAlert() != null) {
+ if (activeAlertMessage.getAlert().getAlertType() == alertType) {
+ ConfirmAlertMessage confirmMessage = new ConfirmAlertMessage();
+ confirmMessage.setAlertID(activeAlertMessage.getAlert().getAlertId());
+ connectionService.requestMessage(confirmMessage).await();
+ } else break;
+ }
+ }
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while confirming alert: " + e.getClass().getCanonicalName());
+ } catch (Exception e) {
+ log.error("Exception while confirming alert", e);
+ }
+ }
+
+ @Override
+ public JSONObject getJSONStatus(Profile profile, String profileName) {
+ long now = System.currentTimeMillis();
+ if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) {
+ return null;
+ }
+
+ final JSONObject pump = new JSONObject();
+ final JSONObject battery = new JSONObject();
+ final JSONObject status = new JSONObject();
+ final JSONObject extended = new JSONObject();
+ try {
+ status.put("timestamp", DateUtil.toISOString(connectionService.getLastConnected()));
+ extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
+ try {
+ extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName());
+ } catch (Exception e) {
+ }
+ TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now);
+ if (tb != null) {
+ extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
+ extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
+ extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
+ }
+ ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now);
+ if (eb != null) {
+ extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
+ extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
+ extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
+ }
+ extended.put("BaseBasalRate", getBaseBasalRate());
+ status.put("timestamp", DateUtil.toISOString(now));
+
+ pump.put("extended", extended);
+ if (statusLoaded) {
+ status.put("status", operatingMode != OperatingMode.STARTED ? "suspended" : "normal");
+ pump.put("status", status);
+ battery.put("percent", batteryStatus.getBatteryAmount());
+ pump.put("battery", battery);
+ pump.put("reservoir", cartridgeStatus.getRemainingAmount());
+ }
+ pump.put("clock", DateUtil.toISOString(now));
+ } catch (JSONException e) {
+ log.error("Unhandled exception", e);
+ }
+ return pump;
+ }
+
+ @Override
+ public String deviceID() {
+ if (connectionService == null || alertService == null) return null;
+ return connectionService.getPumpSystemIdentification().getSerialNumber();
+ }
+
+ public PumpEnactResult stopPump() {
+ PumpEnactResult result = new PumpEnactResult();
+ try {
+ SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
+ operatingModeMessage.setOperatingMode(OperatingMode.STOPPED);
+ connectionService.requestMessage(operatingModeMessage).await();
+ result.success = true;
+ result.enacted = true;
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while stopping pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while stopping pump: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while stopping pump", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ public PumpEnactResult startPump() {
+ PumpEnactResult result = new PumpEnactResult();
+ try {
+ SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
+ operatingModeMessage.setOperatingMode(OperatingMode.STARTED);
+ connectionService.requestMessage(operatingModeMessage).await();
+ result.success = true;
+ result.enacted = true;
+ fetchStatus();
+ readHistory();
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while starting pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ log.info("Exception while starting pump: " + e.getClass().getCanonicalName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ log.error("Exception while starting pump", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ public PumpEnactResult setTBROverNotification(boolean enabled) {
+ PumpEnactResult result = new PumpEnactResult();
+ boolean valueBefore = tbrOverNotificationBlock.isEnabled();
+ tbrOverNotificationBlock.setEnabled(enabled);
+ try {
+ ParameterBlockUtil.writeConfigurationBlock(connectionService, tbrOverNotificationBlock);
+ result.success = true;
+ result.enacted = true;
+ } catch (AppLayerErrorException e) {
+ tbrOverNotificationBlock.setEnabled(valueBefore);
+ log.info("Exception while updating TBR notification block: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (InsightException e) {
+ tbrOverNotificationBlock.setEnabled(valueBefore);
+ log.info("Exception while updating TBR notification block: " + e.getClass().getSimpleName());
+ result.comment = ExceptionTranslator.getString(e);
+ } catch (Exception e) {
+ tbrOverNotificationBlock.setEnabled(valueBefore);
+ log.error("Exception while updating TBR notification block", e);
+ result.comment = ExceptionTranslator.getString(e);
+ }
+ return result;
+ }
+
+ @Override
+ public PumpDescription getPumpDescription() {
+ return pumpDescription;
+ }
+
+ @Override
+ public String shortStatus(boolean veryShort) {
+ StringBuilder ret = new StringBuilder();
+ if (connectionService.getLastConnected() != 0) {
+ Long agoMsec = System.currentTimeMillis() - connectionService.getLastConnected();
+ int agoMin = (int) (agoMsec / 60d / 1000d);
+ ret.append(MainApp.gs(R.string.short_status_last_connected, agoMin) + "\n");
+ }
+ if (activeTBR != null) {
+ ret.append(MainApp.gs(R.string.short_status_tbr, activeTBR.getPercentage(),
+ activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()) + "\n");
+ }
+ if (activeBoluses != null) for (ActiveBolus activeBolus : activeBoluses) {
+ if (activeBolus.getBolusType() == BolusType.STANDARD) continue;
+ ret.append(MainApp.gs(activeBolus.getBolusType() == BolusType.MULTIWAVE ? R.string.short_status_multiwave : R.string.short_status_extended,
+ activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration()) + "\n");
+ }
+ if (!veryShort && totalDailyDose != null) {
+ ret.append(MainApp.gs(R.string.short_status_tdd, totalDailyDose.getBolusAndBasal()) + "\n");
+ }
+ if (cartridgeStatus != null) {
+ ret.append(MainApp.gs(R.string.short_status_reservoir, cartridgeStatus.getRemainingAmount()) + "\n");
+ }
+ if (batteryStatus != null) {
+ ret.append(MainApp.gs(R.string.short_status_battery, batteryStatus.getBatteryAmount()) + "\n");
+ }
+ return ret.toString();
+ }
+
+ @Override
+ public boolean isFakingTempsByExtendedBoluses() {
+ return SP.getBoolean("insight_enable_tbr_emulation", false);
+ }
+
+ @Override
+ public PumpEnactResult loadTDDs() {
+ return new PumpEnactResult().success(true);
+ }
+
+ @Override
+ public List getCustomActions() {
+ return null;
+ }
+
+ @Override
+ public void executeCustomAction(CustomActionType customActionType) {
+
+ }
+
+ private void readHistory() {
+ try {
+ PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime();
+ String pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
+ timeOffset = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() - parseDate(pumpTime.getYear(),
+ pumpTime.getMonth(), pumpTime.getDay(), pumpTime.getHour(), pumpTime.getMinute(), pumpTime.getSecond());
+ InsightHistoryOffset historyOffset = MainApp.getDbHelper().getInsightHistoryOffset(pumpSerial);
+ try {
+ List historyEvents = new ArrayList<>();
+ if (historyOffset == null) {
+ StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
+ startMessage.setDirection(HistoryReadingDirection.BACKWARD);
+ startMessage.setOffset(0xFFFFFFFF);
+ connectionService.requestMessage(startMessage).await();
+ historyEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
+ } else {
+ StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
+ startMessage.setDirection(HistoryReadingDirection.FORWARD);
+ startMessage.setOffset(historyOffset.offset + 1);
+ connectionService.requestMessage(startMessage).await();
+ while (true) {
+ List newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
+ if (newEvents.size() == 0) break;
+ historyEvents.addAll(newEvents);
+ }
+ }
+ Collections.sort(historyEvents);
+ Collections.reverse(historyEvents);
+ if (historyOffset != null) processHistoryEvents(pumpSerial, historyEvents);
+ if (historyEvents.size() > 0) {
+ historyOffset = new InsightHistoryOffset();
+ historyOffset.pumpSerial = pumpSerial;
+ historyOffset.offset = historyEvents.get(0).getEventPosition();
+ MainApp.getDbHelper().createOrUpdate(historyOffset);
+ }
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while reading history: " + e.getClass().getSimpleName());
+ } catch (Exception e) {
+ log.error("Exception while reading history", e);
+ } finally {
+ try {
+ connectionService.requestMessage(new StopReadingHistoryMessage()).await();
+ } catch (Exception ignored) {
+ }
+ }
+ } catch (AppLayerErrorException e) {
+ log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
+ } catch (InsightException e) {
+ log.info("Exception while reading history: " + e.getClass().getSimpleName());
+ } catch (Exception e) {
+ log.error("Exception while reading history", e);
+ }
+ new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::readHistory")));
+ }
+
+ private void processHistoryEvents(String serial, List historyEvents) {
+ List temporaryBasals = new ArrayList<>();
+ List pumpStartedEvents = new ArrayList<>();
+ for (HistoryEvent historyEvent : historyEvents)
+ if (!processHistoryEvent(serial, temporaryBasals, pumpStartedEvents, historyEvent))
+ break;
+ Collections.reverse(temporaryBasals);
+ for (InsightPumpID pumpID : pumpStartedEvents) {
+ InsightPumpID stoppedEvent = MainApp.getDbHelper().getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
+ if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue;
+ long tbrStart = stoppedEvent.timestamp + 10000;
+ TemporaryBasal temporaryBasal = new TemporaryBasal();
+ temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000);
+ temporaryBasal.date = tbrStart;
+ temporaryBasal.source = Source.PUMP;
+ temporaryBasal.pumpId = pumpID.id;
+ temporaryBasal.percentRate = 0;
+ temporaryBasal.isAbsolute = false;
+ temporaryBasals.add(temporaryBasal);
+ }
+ Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date));
+ for (TemporaryBasal temporaryBasal : temporaryBasals)
+ TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
+ }
+
+ private boolean processHistoryEvent(String serial, List temporaryBasals, List pumpStartedEvents, HistoryEvent event) {
+ if (event instanceof DefaultDateTimeSetEvent) return false;
+ else if (event instanceof DateTimeChangedEvent)
+ processDateTimeChangedEvent((DateTimeChangedEvent) event);
+ else if (event instanceof CannulaFilledEvent)
+ processCannulaFilledEvent((CannulaFilledEvent) event);
+ else if (event instanceof TotalDailyDoseEvent)
+ processTotalDailyDoseEvent((TotalDailyDoseEvent) event);
+ else if (event instanceof TubeFilledEvent) processTubeFilledEvent((TubeFilledEvent) event);
+ else if (event instanceof SniffingDoneEvent)
+ processSniffingDoneEvent((SniffingDoneEvent) event);
+ else if (event instanceof PowerUpEvent) processPowerUpEvent((PowerUpEvent) event);
+ else if (event instanceof OperatingModeChangedEvent)
+ processOperatingModeChangedEvent(serial, pumpStartedEvents, (OperatingModeChangedEvent) event);
+ else if (event instanceof StartOfTBREvent)
+ processStartOfTBREvent(serial, temporaryBasals, (StartOfTBREvent) event);
+ else if (event instanceof EndOfTBREvent)
+ processEndOfTBREvent(serial, temporaryBasals, (EndOfTBREvent) event);
+ else if (event instanceof BolusProgrammedEvent)
+ processBolusProgrammedEvent(serial, (BolusProgrammedEvent) event);
+ else if (event instanceof BolusDeliveredEvent)
+ processBolusDeliveredEvent(serial, (BolusDeliveredEvent) event);
+ else if (event instanceof OccurrenceOfAlertEvent)
+ processOccurrenceOfAlertEvent((OccurrenceOfAlertEvent) event);
+ return true;
+ }
+
+ private void processDateTimeChangedEvent(DateTimeChangedEvent event) {
+ long timeAfter = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(), event.getEventMinute(), event.getEventSecond());
+ long timeBefore = parseDate(event.getBeforeYear(), event.getBeforeMonth(), event.getBeforeDay(), event.getBeforeHour(), event.getBeforeMinute(), event.getBeforeSecond());
+ timeOffset -= timeAfter - timeBefore;
+ }
+
+ private void processCannulaFilledEvent(CannulaFilledEvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ uploadCareportalEvent(timestamp, CareportalEvent.SITECHANGE);
+ }
+
+ private void processTotalDailyDoseEvent(TotalDailyDoseEvent event) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(new Date(0));
+ calendar.set(Calendar.YEAR, event.getTotalYear());
+ calendar.set(Calendar.MONTH, event.getTotalMonth() - 1);
+ calendar.set(Calendar.DAY_OF_MONTH, event.getTotalDay());
+ TDD tdd = new TDD();
+ tdd.basal = event.getBasalTotal();
+ tdd.bolus = event.getBolusTotal();
+ tdd.total = tdd.basal + tdd.bolus;
+ tdd.date = calendar.getTimeInMillis();
+ MainApp.getDbHelper().createOrUpdateTDD(tdd);
+ }
+
+ private void processTubeFilledEvent(TubeFilledEvent event) {
+ if (!SP.getBoolean("insight_log_tube_changes", false)) return;
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ logNote(timestamp, MainApp.gs(R.string.tube_changed));
+ }
+
+ private void processSniffingDoneEvent(SniffingDoneEvent event) {
+ if (!SP.getBoolean("insight_log_site_changes", false)) return;
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ uploadCareportalEvent(timestamp, CareportalEvent.INSULINCHANGE);
+ }
+
+ private void processPowerUpEvent(PowerUpEvent event) {
+ if (!SP.getBoolean("insight_log_battery_changes", false)) return;
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ uploadCareportalEvent(timestamp, CareportalEvent.PUMPBATTERYCHANGE);
+ }
+
+ private void processOperatingModeChangedEvent(String serial, List pumpStartedEvents, OperatingModeChangedEvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ InsightPumpID pumpID = new InsightPumpID();
+ pumpID.eventID = event.getEventPosition();
+ pumpID.pumpSerial = serial;
+ pumpID.timestamp = timestamp;
+ switch (event.getNewValue()) {
+ case STARTED:
+ pumpID.eventType = "PumpStarted";
+ pumpStartedEvents.add(pumpID);
+ if (SP.getBoolean("insight_log_operating_mode_changes", false))
+ logNote(timestamp, MainApp.gs(R.string.pump_started));
+ break;
+ case STOPPED:
+ pumpID.eventType = "PumpStopped";
+ if (SP.getBoolean("insight_log_operating_mode_changes", false))
+ logNote(timestamp, MainApp.gs(R.string.pump_stopped));
+ break;
+ case PAUSED:
+ pumpID.eventType = "PumpPaused";
+ if (SP.getBoolean("insight_log_operating_mode_changes", false))
+ logNote(timestamp, MainApp.gs(R.string.pump_paused));
+ break;
+ }
+ MainApp.getDbHelper().createOrUpdate(pumpID);
+ }
+
+ private void processStartOfTBREvent(String serial, List temporaryBasals, StartOfTBREvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ InsightPumpID pumpID = new InsightPumpID();
+ pumpID.eventID = event.getEventPosition();
+ pumpID.pumpSerial = serial;
+ pumpID.timestamp = timestamp;
+ pumpID.eventType = "StartOfTBR";
+ MainApp.getDbHelper().createOrUpdate(pumpID);
+ TemporaryBasal temporaryBasal = new TemporaryBasal();
+ temporaryBasal.durationInMinutes = event.getDuration();
+ temporaryBasal.source = Source.PUMP;
+ temporaryBasal.pumpId = pumpID.id;
+ temporaryBasal.percentRate = event.getAmount();
+ temporaryBasal.isAbsolute = false;
+ temporaryBasal.date = timestamp;
+ temporaryBasals.add(temporaryBasal);
+ }
+
+ private void processEndOfTBREvent(String serial, List temporaryBasals, EndOfTBREvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ InsightPumpID pumpID = new InsightPumpID();
+ pumpID.eventID = event.getEventPosition();
+ pumpID.pumpSerial = serial;
+ pumpID.eventType = "EndOfTBR";
+ pumpID.timestamp = timestamp;
+ MainApp.getDbHelper().createOrUpdate(pumpID);
+ TemporaryBasal temporaryBasal = new TemporaryBasal();
+ temporaryBasal.durationInMinutes = 0;
+ temporaryBasal.source = Source.PUMP;
+ temporaryBasal.pumpId = pumpID.id;
+ temporaryBasal.date = timestamp;
+ temporaryBasals.add(temporaryBasal);
+ }
+
+ private void processBolusProgrammedEvent(String serial, BolusProgrammedEvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ InsightBolusID bolusID = MainApp.getDbHelper().getInsightBolusID(serial, event.getBolusID(), timestamp);
+ if (bolusID != null && bolusID.endID != null) {
+ bolusID.startID = event.getEventPosition();
+ MainApp.getDbHelper().createOrUpdate(bolusID);
+ return;
+ }
+ if (bolusID == null || bolusID.startID != null) {
+ bolusID = new InsightBolusID();
+ bolusID.timestamp = timestamp;
+ bolusID.bolusID = event.getBolusID();
+ bolusID.pumpSerial = serial;
+ }
+ bolusID.startID = event.getEventPosition();
+ MainApp.getDbHelper().createOrUpdate(bolusID);
+ if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
+ DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
+ detailedBolusInfo.date = bolusID.timestamp;
+ detailedBolusInfo.source = Source.PUMP;
+ detailedBolusInfo.pumpId = bolusID.id;
+ detailedBolusInfo.insulin = event.getImmediateAmount();
+ TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
+ }
+ if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) {
+ ExtendedBolus extendedBolus = new ExtendedBolus();
+ extendedBolus.date = bolusID.timestamp;
+ extendedBolus.source = Source.PUMP;
+ extendedBolus.durationInMinutes = event.getDuration();
+ extendedBolus.insulin = event.getExtendedAmount();
+ extendedBolus.pumpId = bolusID.id;
+ if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null)
+ TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
+ }
+ }
+
+ private void processBolusDeliveredEvent(String serial, BolusDeliveredEvent event) {
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ long startTimestamp = parseRelativeDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(),
+ event.getEventMinute(), event.getEventSecond(), event.getStartHour(), event.getStartMinute(), event.getStartSecond()) + timeOffset;
+ InsightBolusID bolusID = MainApp.getDbHelper().getInsightBolusID(serial, event.getBolusID(), timestamp);
+ if (bolusID == null || bolusID.endID != null) {
+ bolusID = new InsightBolusID();
+ bolusID.timestamp = startTimestamp;
+ bolusID.bolusID = event.getBolusID();
+ bolusID.pumpSerial = serial;
+ }
+ bolusID.endID = event.getEventPosition();
+ MainApp.getDbHelper().createOrUpdate(bolusID);
+ if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
+ DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
+ detailedBolusInfo.date = bolusID.timestamp;
+ detailedBolusInfo.source = Source.PUMP;
+ detailedBolusInfo.pumpId = bolusID.id;
+ detailedBolusInfo.insulin = event.getImmediateAmount();
+ TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
+ }
+ if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) {
+ if (event.getDuration() == 0) {
+ ExtendedBolus extendedBolus = MainApp.getDbHelper().getExtendedBolusByPumpId(bolusID.id);
+ if (extendedBolus != null) {
+ final String _id = extendedBolus._id;
+ if (NSUpload.isIdValid(_id)) NSUpload.removeCareportalEntryFromNS(_id);
+ else UploadQueue.removeID("dbAdd", _id);
+ MainApp.getDbHelper().delete(extendedBolus);
+ }
+ } else {
+ ExtendedBolus extendedBolus = new ExtendedBolus();
+ extendedBolus.date = bolusID.timestamp;
+ extendedBolus.source = Source.PUMP;
+ extendedBolus.durationInMinutes = event.getDuration();
+ extendedBolus.insulin = event.getExtendedAmount();
+ extendedBolus.pumpId = bolusID.id;
+ if (ProfileFunctions.getInstance().getProfile(extendedBolus.date) != null)
+ TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
+ }
+ }
+ }
+
+ private void processOccurrenceOfAlertEvent(OccurrenceOfAlertEvent event) {
+ if (!SP.getBoolean("insight_log_alerts", false)) return;
+ long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
+ event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
+ Integer code = null;
+ Integer title = null;
+ switch (event.getAlertType()) {
+ case ERROR_6:
+ code = R.string.alert_e6_code;
+ title = R.string.alert_e6_title;
+ break;
+ case ERROR_10:
+ code = R.string.alert_e10_code;
+ title = R.string.alert_e10_title;
+ break;
+ case ERROR_13:
+ code = R.string.alert_e13_code;
+ title = R.string.alert_e13_title;
+ break;
+ case MAINTENANCE_20:
+ code = R.string.alert_m20_code;
+ title = R.string.alert_m20_title;
+ break;
+ case MAINTENANCE_21:
+ code = R.string.alert_m21_code;
+ title = R.string.alert_m21_title;
+ break;
+ case MAINTENANCE_22:
+ code = R.string.alert_m22_code;
+ title = R.string.alert_m22_title;
+ break;
+ case MAINTENANCE_23:
+ code = R.string.alert_m23_code;
+ title = R.string.alert_m23_title;
+ break;
+ case MAINTENANCE_24:
+ code = R.string.alert_m24_code;
+ title = R.string.alert_m24_title;
+ break;
+ case MAINTENANCE_25:
+ code = R.string.alert_m25_code;
+ title = R.string.alert_m25_title;
+ break;
+ case MAINTENANCE_26:
+ code = R.string.alert_m26_code;
+ title = R.string.alert_m26_title;
+ break;
+ case MAINTENANCE_27:
+ code = R.string.alert_m27_code;
+ title = R.string.alert_m27_title;
+ break;
+ case MAINTENANCE_28:
+ code = R.string.alert_m28_code;
+ title = R.string.alert_m28_title;
+ break;
+ case MAINTENANCE_29:
+ code = R.string.alert_m29_code;
+ title = R.string.alert_m29_title;
+ break;
+ case MAINTENANCE_30:
+ code = R.string.alert_m30_code;
+ title = R.string.alert_m30_title;
+ break;
+ case WARNING_31:
+ code = R.string.alert_w31_code;
+ title = R.string.alert_w31_title;
+ break;
+ case WARNING_32:
+ code = R.string.alert_w32_code;
+ title = R.string.alert_w32_title;
+ break;
+ case WARNING_33:
+ code = R.string.alert_w33_code;
+ title = R.string.alert_w33_title;
+ break;
+ case WARNING_34:
+ code = R.string.alert_w34_code;
+ title = R.string.alert_w34_title;
+ break;
+ case WARNING_39:
+ code = R.string.alert_w39_code;
+ title = R.string.alert_w39_title;
+ break;
+ }
+ if (code != null)
+ logNote(timestamp, MainApp.gs(R.string.insight_alert_formatter, MainApp.gs(code), MainApp.gs(title)));
+ }
+
+ private long parseDate(int year, int month, int day, int hour, int minute, int second) {
+ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month - 1);
+ calendar.set(Calendar.DAY_OF_MONTH, day);
+ calendar.set(Calendar.HOUR_OF_DAY, hour);
+ calendar.set(Calendar.MINUTE, minute);
+ calendar.set(Calendar.SECOND, second);
+ return calendar.getTimeInMillis();
+ }
+
+ private void logNote(long date, String note) {
+ try {
+ if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
+ return;
+ JSONObject data = new JSONObject();
+ String enteredBy = SP.getString("careportal_enteredby", "");
+ if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
+ data.put("created_at", DateUtil.toISOString(date));
+ data.put("eventType", CareportalEvent.NOTE);
+ data.put("notes", note);
+ NSUpload.uploadCareportalEntryToNS(data);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private long parseRelativeDate(int year, int month, int day, int hour, int minute, int second, int relativeHour, int relativeMinute, int relativeSecond) {
+ if (relativeHour * 60 * 60 + relativeMinute * 60 + relativeSecond >= hour * 60 * 60 * minute * 60 + second)
+ day--;
+ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month - 1);
+ calendar.set(Calendar.DAY_OF_MONTH, day);
+ calendar.set(Calendar.HOUR_OF_DAY, relativeHour);
+ calendar.set(Calendar.MINUTE, relativeMinute);
+ calendar.set(Calendar.SECOND, relativeSecond);
+ return calendar.getTimeInMillis();
+ }
+
+ private void uploadCareportalEvent(long date, String event) {
+ if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
+ return;
+ try {
+ JSONObject data = new JSONObject();
+ String enteredBy = SP.getString("careportal_enteredby", "");
+ if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
+ data.put("created_at", DateUtil.toISOString(date));
+ data.put("eventType", event);
+ NSUpload.uploadCareportalEntryToNS(data);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public Constraint applyBasalPercentConstraints(Constraint percentRate, Profile profile) {
+ percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this);
+ percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this);
+ return percentRate;
+ }
+
+ @Override
+ public Constraint applyBolusConstraints(Constraint insulin) {
+ if (!limitsFetched) return insulin;
+ insulin.setIfSmaller(maximumBolusAmount, String.format(MainApp.gs(R.string.limitingbolus), maximumBolusAmount, MainApp.gs(R.string.pumplimit)), this);
+ if (insulin.value() < minimumBolusAmount) {
+
+ //TODO: Add function to Constraints or use different approach
+ // This only works if the interface of the InsightPlugin is called last.
+ // If not, another constraint could theoretically set the value between 0 and minimumBolusAmount
+
+ insulin.set(0d, String.format(MainApp.gs(R.string.limitingbolus), minimumBolusAmount, MainApp.gs(R.string.pumplimit)), this);
+ }
+ return insulin;
+ }
+
+ @Override
+ public void onStateChanged(InsightState state) {
+ if (state == InsightState.CONNECTED) {
+ statusLoaded = false;
+ new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE)));
+ } else if (state == InsightState.NOT_PAIRED) {
+ connectionService.withdrawConnectionRequest(this);
+ statusLoaded = false;
+ profileBlocks = null;
+ operatingMode = null;
+ batteryStatus = null;
+ cartridgeStatus = null;
+ totalDailyDose = null;
+ activeBasalRate = null;
+ activeTBR = null;
+ activeBoluses = null;
+ tbrOverNotificationBlock = null;
+ new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::onStateChanged")));
+ }
+ new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventLocalInsightUpdateGUI()));
+ }
+
+ @Override
+ public void onPumpPaired() {
+ ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Pump paired", null);
+ }
+
+ @Override
+ public void onTimeoutDuringHandshake() {
+ Notification notification = new Notification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE, MainApp.gs(R.string.timeout_during_handshake), Notification.URGENT);
+ new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventNewNotification(notification)));
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java
new file mode 100644
index 0000000000..c40cb99ed6
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightAlertActivity.java
@@ -0,0 +1,257 @@
+package info.nightscout.androidaps.plugins.pump.insight.activities;
+
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AppCompatActivity;
+import android.text.Html;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.text.DecimalFormat;
+
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertStatus;
+
+public class InsightAlertActivity extends AppCompatActivity {
+
+ private Alert alert;
+ private InsightAlertService alertService;
+
+ private ImageView icon;
+ private TextView errorCode;
+ private TextView errorTitle;
+ private TextView errorDescription;
+ private Button mute;
+ private Button confirm;
+
+ private ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder binder) {
+ alertService = ((InsightAlertService.LocalBinder) binder).getService();
+ alertService.setAlertActivity(InsightAlertActivity.this);
+ alert = alertService.getAlert();
+ if (alert == null) finish();
+ update(alert);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ alertService = null;
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_insight_alert);
+
+ bindService(new Intent(this, InsightAlertService.class), serviceConnection, BIND_AUTO_CREATE);
+
+ icon = findViewById(R.id.icon);
+ errorCode = findViewById(R.id.error_code);
+ errorTitle = findViewById(R.id.error_title);
+ errorDescription = findViewById(R.id.error_description);
+ mute = findViewById(R.id.mute);
+ confirm = findViewById(R.id.confirm);
+
+ setFinishOnTouchOutside(false);
+
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
+ | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+ WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
+ layoutParams.screenBrightness = 1.0F;
+ getWindow().setAttributes(layoutParams);
+ }
+
+ @Override
+ protected void onDestroy() {
+ alertService.setAlertActivity(null);
+ unbindService(serviceConnection);
+ super.onDestroy();
+ }
+
+ public void update(Alert alert) {
+ this.alert = alert;
+ mute.setEnabled(true);
+ mute.setVisibility(alert.getAlertStatus() == AlertStatus.SNOOZED ? View.GONE : View.VISIBLE);
+ confirm.setEnabled(true);
+ int icon = 0;
+ int code = 0;
+ int title = 0;
+ String description = null;
+ switch (alert.getAlertCategory()) {
+ case ERROR:
+ icon = R.drawable.ic_error;
+ break;
+ case MAINTENANCE:
+ icon = R.drawable.ic_maintenance;
+ break;
+ case WARNING:
+ icon = R.drawable.ic_warning;
+ break;
+ case REMINDER:
+ icon = R.drawable.ic_reminder;
+ break;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat("##0.00");
+ int hours = alert.getTBRDuration() / 60;
+ int minutes = alert.getTBRDuration() - hours * 60;
+ switch (alert.getAlertType()) {
+ case REMINDER_01:
+ code = R.string.alert_r1_code;
+ title = R.string.alert_r1_title;
+ break;
+ case REMINDER_02:
+ code = R.string.alert_r2_code;
+ title = R.string.alert_r2_title;
+ break;
+ case REMINDER_03:
+ code = R.string.alert_r3_code;
+ title = R.string.alert_r3_title;
+ break;
+ case REMINDER_04:
+ code = R.string.alert_r4_code;
+ title = R.string.alert_r4_title;
+ break;
+ case REMINDER_07:
+ code = R.string.alert_r7_code;
+ title = R.string.alert_r7_title;
+ description = getString(R.string.alert_r7_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes));
+ break;
+ case WARNING_31:
+ code = R.string.alert_w31_code;
+ title = R.string.alert_w31_title;
+ description = getString(R.string.alert_w31_description, decimalFormat.format(alert.getCartridgeAmount()));
+ break;
+ case WARNING_32:
+ code = R.string.alert_w32_code;
+ title = R.string.alert_w32_title;
+ description = getString(R.string.alert_w32_description);
+ break;
+ case WARNING_33:
+ code = R.string.alert_w33_code;
+ title = R.string.alert_w33_title;
+ description = getString(R.string.alert_w33_description);
+ break;
+ case WARNING_34:
+ code = R.string.alert_w34_code;
+ title = R.string.alert_w34_title;
+ description = getString(R.string.alert_w34_description);
+ break;
+ case WARNING_36:
+ code = R.string.alert_w36_code;
+ title = R.string.alert_w36_title;
+ description = getString(R.string.alert_w36_description, alert.getTBRAmount(), new DecimalFormat("#0").format(hours) + ":" + new DecimalFormat("00").format(minutes));
+ break;
+ case WARNING_38:
+ code = R.string.alert_w38_code;
+ title = R.string.alert_w38_title;
+ description = getString(R.string.alert_w38_description, decimalFormat.format(alert.getProgrammedBolusAmount()), decimalFormat.format(alert.getDeliveredBolusAmount()));
+ break;
+ case WARNING_39:
+ code = R.string.alert_w39_code;
+ title = R.string.alert_w39_title;
+ break;
+ case MAINTENANCE_20:
+ code = R.string.alert_m20_code;
+ title = R.string.alert_m20_title;
+ description = getString(R.string.alert_m20_description);
+ break;
+ case MAINTENANCE_21:
+ code = R.string.alert_m21_code;
+ title = R.string.alert_m21_title;
+ description = getString(R.string.alert_m21_description);
+ break;
+ case MAINTENANCE_22:
+ code = R.string.alert_m22_code;
+ title = R.string.alert_m22_title;
+ description = getString(R.string.alert_m22_description);
+ break;
+ case MAINTENANCE_23:
+ code = R.string.alert_m23_code;
+ title = R.string.alert_m23_title;
+ description = getString(R.string.alert_m23_description);
+ break;
+ case MAINTENANCE_24:
+ code = R.string.alert_m24_code;
+ title = R.string.alert_m24_title;
+ description = getString(R.string.alert_m24_description);
+ break;
+ case MAINTENANCE_25:
+ code = R.string.alert_m25_code;
+ title = R.string.alert_m25_title;
+ description = getString(R.string.alert_m25_description);
+ break;
+ case MAINTENANCE_26:
+ code = R.string.alert_m26_code;
+ title = R.string.alert_m26_title;
+ description = getString(R.string.alert_m26_description);
+ break;
+ case MAINTENANCE_27:
+ code = R.string.alert_m27_code;
+ title = R.string.alert_m27_title;
+ description = getString(R.string.alert_m27_description);
+ break;
+ case MAINTENANCE_28:
+ code = R.string.alert_m28_code;
+ title = R.string.alert_m28_title;
+ description = getString(R.string.alert_m28_description);
+ break;
+ case MAINTENANCE_29:
+ code = R.string.alert_m29_code;
+ title = R.string.alert_m29_title;
+ description = getString(R.string.alert_m29_description);
+ break;
+ case MAINTENANCE_30:
+ code = R.string.alert_m30_code;
+ title = R.string.alert_m30_title;
+ description = getString(R.string.alert_m30_description);
+ break;
+ case ERROR_6:
+ code = R.string.alert_e6_code;
+ title = R.string.alert_e6_title;
+ description = getString(R.string.alert_e6_description);
+ break;
+ case ERROR_10:
+ code = R.string.alert_e10_code;
+ title = R.string.alert_e10_title;
+ description = getString(R.string.alert_e10_description);
+ break;
+ case ERROR_13:
+ code = R.string.alert_e13_code;
+ title = R.string.alert_e13_title;
+ description = getString(R.string.alert_e13_description);
+ break;
+ }
+ this.icon.setImageDrawable(ContextCompat.getDrawable(this, icon));
+ this.errorCode.setText(code);
+ this.errorTitle.setText(title);
+ if (description == null) this.errorDescription.setVisibility(View.GONE);
+ else {
+ this.errorDescription.setVisibility(View.VISIBLE);
+ this.errorDescription.setText(Html.fromHtml(description));
+ }
+ }
+
+ public void muteClicked(View view) {
+ mute.setEnabled(false);
+ alertService.mute();
+ }
+
+ public void confirmClicked(View view) {
+ mute.setEnabled(false);
+ confirm.setEnabled(false);
+ alertService.confirm();
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java
new file mode 100644
index 0000000000..7ea52ed271
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingActivity.java
@@ -0,0 +1,254 @@
+package info.nightscout.androidaps.plugins.pump.insight.activities;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
+
+public class InsightPairingActivity extends AppCompatActivity implements InsightConnectionService.StateCallback, View.OnClickListener, InsightConnectionService.ExceptionCallback {
+
+ private boolean scanning;
+ private LinearLayout deviceSearchSection;
+ private TextView pleaseWaitSection;
+ private LinearLayout codeCompareSection;
+ private LinearLayout pairingCompletedSection;
+ private Button yes;
+ private Button no;
+ private TextView code;
+ private Button exit;
+ private RecyclerView deviceList;
+ private DeviceAdapter deviceAdapter = new DeviceAdapter();
+
+ private InsightConnectionService service;
+
+ private ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder binder) {
+ service = ((InsightConnectionService.LocalBinder) binder).getService();
+ if (service.isPaired()) return;
+ else {
+ service.requestConnection(InsightPairingActivity.this);
+ service.registerStateCallback(InsightPairingActivity.this);
+ service.registerExceptionCallback(InsightPairingActivity.this);
+ onStateChanged(service.getState());
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+
+ }
+ };
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_insight_pairing);
+
+ deviceSearchSection = findViewById(R.id.device_search_section);
+ pleaseWaitSection = findViewById(R.id.please_wait_section);
+ codeCompareSection = findViewById(R.id.code_compare_section);
+ pairingCompletedSection = findViewById(R.id.pairing_completed_section);
+ yes = findViewById(R.id.yes);
+ no = findViewById(R.id.no);
+ code = findViewById(R.id.code);
+ exit = findViewById(R.id.exit);
+ deviceList = findViewById(R.id.device_list);
+
+ yes.setOnClickListener(this);
+ no.setOnClickListener(this);
+ exit.setOnClickListener(this);
+
+ deviceList.setLayoutManager(new LinearLayoutManager(this));
+ deviceList.setAdapter(deviceAdapter);
+
+
+ bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE);
+}
+
+ @Override
+ protected void onDestroy() {
+ if (service != null) {
+ service.withdrawConnectionRequest(InsightPairingActivity.this);
+ service.unregisterStateCallback(InsightPairingActivity.this);
+ service.unregisterExceptionCallback(InsightPairingActivity.this);
+ }
+ unbindService(serviceConnection);
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (service != null && service.getState() == InsightState.NOT_PAIRED) startBLScan();
+ }
+
+ @Override
+ protected void onStop() {
+ stopBLScan();
+ super.onStop();
+ }
+
+ @Override
+ public void onStateChanged(InsightState state) {
+ runOnUiThread(() -> {
+ switch (state) {
+ case NOT_PAIRED:
+ startBLScan();
+ deviceSearchSection.setVisibility(View.VISIBLE);
+ pleaseWaitSection.setVisibility(View.GONE);
+ codeCompareSection.setVisibility(View.GONE);
+ pairingCompletedSection.setVisibility(View.GONE);
+ break;
+ case CONNECTING:
+ case SATL_CONNECTION_REQUEST:
+ case SATL_KEY_REQUEST:
+ case SATL_VERIFY_DISPLAY_REQUEST:
+ case SATL_VERIFY_CONFIRM_REQUEST:
+ case APP_BIND_MESSAGE:
+ stopBLScan();
+ deviceSearchSection.setVisibility(View.GONE);
+ pleaseWaitSection.setVisibility(View.VISIBLE);
+ codeCompareSection.setVisibility(View.GONE);
+ pairingCompletedSection.setVisibility(View.GONE);
+ break;
+ case AWAITING_CODE_CONFIRMATION:
+ stopBLScan();
+ deviceSearchSection.setVisibility(View.GONE);
+ pleaseWaitSection.setVisibility(View.GONE);
+ codeCompareSection.setVisibility(View.VISIBLE);
+ pairingCompletedSection.setVisibility(View.GONE);
+ code.setText(service.getVerificationString());
+ break;
+ case DISCONNECTED:
+ case CONNECTED:
+ stopBLScan();
+ deviceSearchSection.setVisibility(View.GONE);
+ pleaseWaitSection.setVisibility(View.GONE);
+ codeCompareSection.setVisibility(View.GONE);
+ pairingCompletedSection.setVisibility(View.VISIBLE);
+ break;
+ }
+ });
+ }
+
+ private void startBLScan() {
+ if (!scanning) {
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable();
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
+ intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
+ registerReceiver(broadcastReceiver, intentFilter);
+ bluetoothAdapter.startDiscovery();
+ scanning = true;
+ }
+ }
+
+ private void stopBLScan() {
+ if (scanning) {
+ unregisterReceiver(broadcastReceiver);
+ BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
+ scanning = false;
+ }
+ }
+ @Override
+ public void onClick(View v) {
+ if (v == exit) finish();
+ else if (v == yes) service.confirmVerificationString();
+ else if (v == no) service.rejectVerificationString();
+ }
+
+ @Override
+ public void onExceptionOccur(Exception e) {
+ ExceptionTranslator.makeToast(this, e);
+ }
+
+ private void deviceSelected(BluetoothDevice device) {
+ service.pair(device.getAddress());
+ }
+
+ private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
+ BluetoothAdapter.getDefaultAdapter().startDiscovery();
+ else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
+ BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ deviceAdapter.addDevice(bluetoothDevice);
+ }
+ }
+ };
+
+ private class DeviceAdapter extends RecyclerView.Adapter {
+
+ private List bluetoothDevices = new ArrayList<>();
+
+ public void addDevice(BluetoothDevice bluetoothDevice) {
+ if (!bluetoothDevices.contains(bluetoothDevice)) {
+ bluetoothDevices.add(bluetoothDevice);
+ notifyDataSetChanged();
+ }
+ }
+
+ public void clear() {
+ bluetoothDevices.clear();
+ notifyDataSetChanged();
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.bluetooth_device, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
+ BluetoothDevice bluetoothDevice = bluetoothDevices.get(position);
+ holder.deviceName.setText(bluetoothDevice.getName() == null ? bluetoothDevice.getAddress() : bluetoothDevice.getName());
+ holder.deviceName.setOnClickListener((v) -> deviceSelected(bluetoothDevice));
+ }
+
+ @Override
+ public int getItemCount() {
+ return bluetoothDevices.size();
+ }
+
+ public class ViewHolder extends RecyclerView.ViewHolder {
+
+ private TextView deviceName;
+
+ public ViewHolder(View itemView) {
+ super(itemView);
+ deviceName = (TextView) itemView;
+ }
+ }
+
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java
new file mode 100644
index 0000000000..8580b30dca
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/activities/InsightPairingInformationActivity.java
@@ -0,0 +1,88 @@
+package info.nightscout.androidaps.plugins.pump.insight.activities;
+
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.TextView;
+
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
+
+public class InsightPairingInformationActivity extends AppCompatActivity {
+
+ private InsightConnectionService connectionService;
+
+ private TextView serialNumber;
+ private TextView releaseSWVersion;
+ private TextView uiProcSWVersion;
+ private TextView pcProcSWVersion;
+ private TextView mdTelSWVersion;
+ private TextView safetyProcSWVersion;
+ private TextView btInfoPageVersion;
+ private TextView bluetoothAddress;
+ private TextView systemIdAppendix;
+ private TextView manufacturingDate;
+
+ private ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder binder) {
+ connectionService = ((InsightConnectionService.LocalBinder) binder).getService();
+ if (!connectionService.isPaired()) {
+ overridePendingTransition(0, 0);
+ finish();
+ startActivity(new Intent(InsightPairingInformationActivity.this, InsightPairingActivity.class));
+ } else {
+ serialNumber.setText(connectionService.getPumpSystemIdentification().getSerialNumber());
+ manufacturingDate.setText(connectionService.getPumpSystemIdentification().getManufacturingDate());
+ systemIdAppendix.setText(connectionService.getPumpSystemIdentification().getSystemIdAppendix() + "");
+ releaseSWVersion.setText(connectionService.getPumpFirmwareVersions().getReleaseSWVersion());
+ uiProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getUiProcSWVersion());
+ pcProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getPcProcSWVersion());
+ mdTelSWVersion.setText(connectionService.getPumpFirmwareVersions().getMdTelProcSWVersion());
+ safetyProcSWVersion.setText(connectionService.getPumpFirmwareVersions().getSafetyProcSWVersion());
+ btInfoPageVersion.setText(connectionService.getPumpFirmwareVersions().getBtInfoPageVersion());
+ bluetoothAddress.setText(connectionService.getBluetoothAddress());
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ connectionService = null;
+ }
+ };
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_insight_pairing_information);
+ serialNumber = findViewById(R.id.serial_number);
+ releaseSWVersion = findViewById(R.id.release_sw_version);
+ uiProcSWVersion = findViewById(R.id.ui_proc_sw_version);
+ pcProcSWVersion = findViewById(R.id.pc_proc_sw_version);
+ mdTelSWVersion = findViewById(R.id.md_tel_sw_version);
+ safetyProcSWVersion = findViewById(R.id.safety_proc_sw_version);
+ btInfoPageVersion = findViewById(R.id.bt_info_page_version);
+ bluetoothAddress = findViewById(R.id.bluetooth_address);
+ systemIdAppendix = findViewById(R.id.system_id_appendix);
+ manufacturingDate = findViewById(R.id.manufacturing_date);
+ bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE);
+ }
+
+ @Override
+ protected void onDestroy() {
+ unbindService(serviceConnection);
+ super.onDestroy();
+ }
+
+ public void deletePairing(View view) {
+ if (connectionService != null) {
+ connectionService.reset();
+ finish();
+ }
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java
new file mode 100644
index 0000000000..7783abe063
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/AppLayerMessage.java
@@ -0,0 +1,91 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.IncompatibleAppVersionException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidAppCRCException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.UnknownAppCommandException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.UnknownServiceException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.UnknownAppLayerErrorCodeException;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AppCommandIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AppErrorIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ServiceIDs;
+import info.nightscout.androidaps.plugins.pump.insight.satl.DataMessage;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.Cryptograph;
+
+public class AppLayerMessage implements Comparable {
+
+ private static final byte VERSION = 0x20;
+
+ private final MessagePriority messagePriority;
+ private final boolean inCRC;
+ private final boolean outCRC;
+ private final Service service;
+
+ public AppLayerMessage(MessagePriority messagePriority, boolean inCRC, boolean outCRC, Service service) {
+ this.messagePriority = messagePriority;
+ this.inCRC = inCRC;
+ this.outCRC = outCRC;
+ this.service = service;
+ }
+
+ protected ByteBuf getData() {
+ return new ByteBuf(0);
+ }
+
+ protected void parse(ByteBuf byteBuf) throws Exception {
+
+ }
+
+ public ByteBuf serialize(Class extends AppLayerMessage> clazz) {
+ byte[] data = getData().getBytes();
+ ByteBuf byteBuf = new ByteBuf(4 + data.length + (outCRC ? 2 : 0));
+ byteBuf.putByte(VERSION);
+ byteBuf.putByte(ServiceIDs.IDS.getID(getService()));
+ byteBuf.putUInt16LE(AppCommandIDs.IDS.getID(clazz));
+ byteBuf.putBytes(data);
+ if (outCRC) byteBuf.putUInt16LE(Cryptograph.calculateCRC(data));
+ return byteBuf;
+ }
+
+ public static AppLayerMessage deserialize(ByteBuf byteBuf) throws Exception {
+ byte version = byteBuf.readByte();
+ byte service = byteBuf.readByte();
+ int command = byteBuf.readUInt16LE();
+ int error = byteBuf.readUInt16LE();
+ Class extends AppLayerMessage> clazz = AppCommandIDs.IDS.getType(command);
+ if (clazz == null) throw new UnknownAppCommandException();
+ if (version != VERSION) throw new IncompatibleAppVersionException();
+ AppLayerMessage message = clazz.newInstance();
+ if (ServiceIDs.IDS.getType(service) == null) throw new UnknownServiceException();
+ if (error != 0) {
+ Class extends AppLayerErrorException> exceptionClass = AppErrorIDs.IDS.getType(error);
+ if (exceptionClass == null) throw new UnknownAppLayerErrorCodeException(error);
+ else throw exceptionClass.getConstructor(int.class).newInstance(error);
+ }
+ byte[] data = byteBuf.readBytes(byteBuf.getSize() - (message.inCRC ? 2 : 0));
+ if (message.inCRC && Cryptograph.calculateCRC(data) != byteBuf.readUInt16LE()) throw new InvalidAppCRCException();
+ message.parse(ByteBuf.from(data));
+ return message;
+ }
+
+ public static DataMessage wrap(AppLayerMessage message) {
+ DataMessage dataMessage = new DataMessage();
+ dataMessage.setData(message.serialize(message.getClass()));
+ return dataMessage;
+ }
+
+ public static AppLayerMessage unwrap(DataMessage dataMessage) throws Exception {
+ return deserialize(dataMessage.getData());
+ }
+
+ @Override
+ public int compareTo(AppLayerMessage o) {
+ return messagePriority.compareTo(o.messagePriority);
+ }
+
+ public Service getService() {
+ return this.service;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java
new file mode 100644
index 0000000000..221cf80462
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/ReadParameterBlockMessage.java
@@ -0,0 +1,48 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ParameterBlockIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ReadParameterBlockMessage extends AppLayerMessage {
+
+ private Class extends ParameterBlock> parameterBlockId;
+ private ParameterBlock parameterBlock;
+ private Service service;
+
+ public ReadParameterBlockMessage() {
+ super(MessagePriority.NORMAL, true, false, null);
+ }
+
+ @Override
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(ParameterBlockIDs.IDS.getID(parameterBlockId));
+ return byteBuf;
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) throws Exception {
+ parameterBlock = ParameterBlockIDs.IDS.getType(byteBuf.readUInt16LE()).newInstance();
+ byteBuf.shift(2); //Restriction level
+ parameterBlock.parse(byteBuf);
+ }
+
+ public ParameterBlock getParameterBlock() {
+ return this.parameterBlock;
+ }
+
+ public void setParameterBlockId(Class extends ParameterBlock> configurationBlockId) {
+ this.parameterBlockId = configurationBlockId;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java
new file mode 100644
index 0000000000..aeec3150d3
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/Service.java
@@ -0,0 +1,31 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer;
+
+public enum Service {
+
+ CONNECTION((short) 0x0000, null),
+ STATUS((short) 0x0100, null),
+ HISTORY((short) 0x0200, null),
+ CONFIGURATION((short) 0x0200, "u+5Fhz6Gw4j1Kkas"),
+ PARAMETER((short) 0x0200, null),
+ REMOTE_CONTROL((short) 0x0100, "MAbcV2X6PVjxuz+R");
+
+ private short version;
+ private String servicePassword;
+
+ Service(short version, String servicePassword) {
+ this.version = version;
+ this.servicePassword = servicePassword;
+ }
+
+ public short getVersion() {
+ return this.version;
+ }
+
+ public String getServicePassword() {
+ return this.servicePassword;
+ }
+
+ public void setServicePassword(String servicePassword) {
+ this.servicePassword = servicePassword;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java
new file mode 100644
index 0000000000..2e6133b79e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/CloseConfigurationWriteSessionMessage.java
@@ -0,0 +1,12 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+
+public class CloseConfigurationWriteSessionMessage extends AppLayerMessage {
+
+ public CloseConfigurationWriteSessionMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java
new file mode 100644
index 0000000000..0706742559
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/OpenConfigurationWriteSessionMessage.java
@@ -0,0 +1,12 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+
+public class OpenConfigurationWriteSessionMessage extends AppLayerMessage {
+
+ public OpenConfigurationWriteSessionMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONFIGURATION);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java
new file mode 100644
index 0000000000..a33530d48e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/configuration/WriteConfigurationBlockMessage.java
@@ -0,0 +1,41 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.ParameterBlock;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ParameterBlockIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class WriteConfigurationBlockMessage extends AppLayerMessage {
+
+ private ParameterBlock parameterBlock;
+ private Class extends ParameterBlock> configurationBlockId;
+
+ public WriteConfigurationBlockMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.CONFIGURATION);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf configBlockData = parameterBlock.getData();
+ ByteBuf data = new ByteBuf(4 + configBlockData.getSize());
+ data.putUInt16LE(ParameterBlockIDs.IDS.getID(parameterBlock.getClass()));
+ data.putUInt16LE(31);
+ data.putByteBuf(configBlockData);
+ return data;
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) throws Exception {
+ configurationBlockId = ParameterBlockIDs.IDS.getType(byteBuf.readUInt16LE());
+ }
+
+ public Class extends ParameterBlock> getConfigurationBlockId() {
+ return this.configurationBlockId;
+ }
+
+ public void setParameterBlock(ParameterBlock parameterBlock) {
+ this.parameterBlock = parameterBlock;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java
new file mode 100644
index 0000000000..322864bffe
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ActivateServiceMessage.java
@@ -0,0 +1,51 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ActivateServiceMessage extends AppLayerMessage {
+
+ private byte serviceID;
+ private short version;
+ private byte[] servicePassword;
+
+ public ActivateServiceMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONNECTION);
+ }
+
+ protected void parse(ByteBuf byteBuf) {
+ serviceID = byteBuf.readByte();
+ version = byteBuf.readShort();
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(19);
+ byteBuf.putByte(serviceID);
+ byteBuf.putShort(version);
+ byteBuf.putBytes(servicePassword);
+ return byteBuf;
+ }
+
+ public byte getServiceID() {
+ return this.serviceID;
+ }
+
+ public short getVersion() {
+ return this.version;
+ }
+
+ public void setServiceID(byte serviceID) {
+ this.serviceID = serviceID;
+ }
+
+ public void setVersion(short version) {
+ this.version = version;
+ }
+
+ public void setServicePassword(byte[] servicePassword) {
+ this.servicePassword = servicePassword;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java
new file mode 100644
index 0000000000..b636797464
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/BindMessage.java
@@ -0,0 +1,20 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection;
+
+import org.spongycastle.util.encoders.Hex;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class BindMessage extends AppLayerMessage {
+
+ public BindMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONNECTION);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ return ByteBuf.from(Hex.decode("3438310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java
new file mode 100644
index 0000000000..c56864209c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ConnectMessage.java
@@ -0,0 +1,20 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection;
+
+import org.spongycastle.util.encoders.Hex;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ConnectMessage extends AppLayerMessage {
+
+ public ConnectMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONNECTION);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ return ByteBuf.from(Hex.decode("0000080100196000"));
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java
new file mode 100644
index 0000000000..22ddbc7608
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/DisconnectMessage.java
@@ -0,0 +1,20 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection;
+
+import org.spongycastle.util.encoders.Hex;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class DisconnectMessage extends AppLayerMessage {
+
+ public DisconnectMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONNECTION);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ return ByteBuf.from(Hex.decode("0360"));
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java
new file mode 100644
index 0000000000..07be4dd469
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/connection/ServiceChallengeMessage.java
@@ -0,0 +1,42 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.connection;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ServiceChallengeMessage extends AppLayerMessage {
+
+ private byte serviceID;
+ private byte[] randomData;
+ private short version;
+
+ public ServiceChallengeMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.CONNECTION);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ randomData = byteBuf.getBytes(16);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(3);
+ byteBuf.putByte(serviceID);
+ byteBuf.putShort(version);
+ return byteBuf;
+ }
+
+ public byte[] getRandomData() {
+ return this.randomData;
+ }
+
+ public void setServiceID(byte serviceID) {
+ this.serviceID = serviceID;
+ }
+
+ public void setVersion(short version) {
+ this.version = version;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java
new file mode 100644
index 0000000000..327304eb21
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/HistoryReadingDirection.java
@@ -0,0 +1,8 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history;
+
+public enum HistoryReadingDirection {
+
+ FORWARD,
+ BACKWARD;
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java
new file mode 100644
index 0000000000..f4c8cb4557
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/ReadHistoryEventsMessage.java
@@ -0,0 +1,34 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.HistoryEvent;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ReadHistoryEventsMessage extends AppLayerMessage {
+
+ private List historyEvents;
+
+ public ReadHistoryEventsMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.HISTORY);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) throws Exception {
+ historyEvents = new ArrayList<>();
+ byteBuf.shift(2);
+ int frameCount = byteBuf.readUInt16LE();
+ for (int i = 0; i < frameCount; i++) {
+ int length = byteBuf.readUInt16LE();
+ historyEvents.add(HistoryEvent.deserialize(ByteBuf.from(byteBuf.readBytes(length))));
+ }
+ }
+
+ public List getHistoryEvents() {
+ return historyEvents;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java
new file mode 100644
index 0000000000..9b8c2c6b16
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StartReadingHistoryMessage.java
@@ -0,0 +1,34 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryReadingDirectionIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class StartReadingHistoryMessage extends AppLayerMessage {
+
+ private long offset;
+ private HistoryReadingDirection direction;
+
+ public StartReadingHistoryMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.HISTORY);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(8);
+ byteBuf.putUInt16LE(31);
+ byteBuf.putUInt16LE(HistoryReadingDirectionIDs.IDS.getID(direction));
+ byteBuf.putUInt32LE(offset);
+ return byteBuf;
+ }
+
+ public void setOffset(long offset) {
+ this.offset = offset;
+ }
+
+ public void setDirection(HistoryReadingDirection direction) {
+ this.direction = direction;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java
new file mode 100644
index 0000000000..56749fcffe
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/StopReadingHistoryMessage.java
@@ -0,0 +1,12 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+
+public class StopReadingHistoryMessage extends AppLayerMessage {
+
+ public StopReadingHistoryMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.HISTORY);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java
new file mode 100644
index 0000000000..1eb62c6c42
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BasalDeliveryChangedEvent.java
@@ -0,0 +1,23 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class BasalDeliveryChangedEvent extends HistoryEvent {
+
+ private double oldBasalRate;
+ private double newBasalRate;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ oldBasalRate = byteBuf.readUInt32Decimal1000();
+ newBasalRate = byteBuf.readUInt32Decimal1000();
+ }
+
+ public double getOldBasalRate() {
+ return oldBasalRate;
+ }
+
+ public double getNewBasalRate() {
+ return newBasalRate;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java
new file mode 100644
index 0000000000..05ba09ccf3
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusDeliveredEvent.java
@@ -0,0 +1,64 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType;
+import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class BolusDeliveredEvent extends HistoryEvent {
+
+ private BolusType bolusType;
+ private int startHour;
+ private int startMinute;
+ private int startSecond;
+ private double immediateAmount;
+ private double extendedAmount;
+ private int duration;
+ private int bolusID;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ bolusType = BolusTypeIDs.IDS.getType(byteBuf.readUInt16LE());
+ byteBuf.shift(1);
+ startHour = BOCUtil.parseBOC(byteBuf.readByte());
+ startMinute = BOCUtil.parseBOC(byteBuf.readByte());
+ startSecond = BOCUtil.parseBOC(byteBuf.readByte());
+ immediateAmount = byteBuf.readUInt16Decimal();
+ extendedAmount = byteBuf.readUInt16Decimal();
+ duration = byteBuf.readUInt16LE();
+ byteBuf.shift(2);
+ bolusID = byteBuf.readUInt16LE();
+ }
+
+ public BolusType getBolusType() {
+ return bolusType;
+ }
+
+ public int getStartHour() {
+ return startHour;
+ }
+
+ public int getStartMinute() {
+ return startMinute;
+ }
+
+ public int getStartSecond() {
+ return startSecond;
+ }
+
+ public double getImmediateAmount() {
+ return immediateAmount;
+ }
+
+ public double getExtendedAmount() {
+ return extendedAmount;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+
+ public int getBolusID() {
+ return bolusID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java
new file mode 100644
index 0000000000..0a456406d0
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/BolusProgrammedEvent.java
@@ -0,0 +1,45 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType;
+import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class BolusProgrammedEvent extends HistoryEvent {
+
+ private BolusType bolusType;
+ private double immediateAmount;
+ private double extendedAmount;
+ private int duration;
+ private int bolusID;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ bolusType = BolusTypeIDs.IDS.getType(byteBuf.readUInt16LE());
+ immediateAmount = byteBuf.readUInt16Decimal();
+ extendedAmount = byteBuf.readUInt16Decimal();
+ duration = byteBuf.readUInt16LE();
+ byteBuf.shift(4);
+ bolusID = byteBuf.readUInt16LE();
+ }
+
+
+ public BolusType getBolusType() {
+ return bolusType;
+ }
+
+ public double getImmediateAmount() {
+ return immediateAmount;
+ }
+
+ public double getExtendedAmount() {
+ return extendedAmount;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+
+ public int getBolusID() {
+ return bolusID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java
new file mode 100644
index 0000000000..4ee16e35e1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CannulaFilledEvent.java
@@ -0,0 +1,17 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class CannulaFilledEvent extends HistoryEvent {
+
+ private double amount;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ amount = byteBuf.readUInt16Decimal();
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java
new file mode 100644
index 0000000000..94ebcc442e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeInsertedEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class CartridgeInsertedEvent extends HistoryEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java
new file mode 100644
index 0000000000..f65d85b06e
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/CartridgeRemovedEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class CartridgeRemovedEvent extends HistoryEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java
new file mode 100644
index 0000000000..1397bb2529
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DateTimeChangedEvent.java
@@ -0,0 +1,49 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class DateTimeChangedEvent extends HistoryEvent {
+
+ private int beforeYear;
+ private int beforeMonth;
+ private int beforeDay;
+ private int beforeHour;
+ private int beforeMinute;
+ private int beforeSecond;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ beforeYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte());
+ beforeMonth = BOCUtil.parseBOC(byteBuf.readByte());
+ beforeDay = BOCUtil.parseBOC(byteBuf.readByte());
+ byteBuf.shift(1);
+ beforeHour = BOCUtil.parseBOC(byteBuf.readByte());
+ beforeMinute = BOCUtil.parseBOC(byteBuf.readByte());
+ beforeSecond = BOCUtil.parseBOC(byteBuf.readByte());
+ }
+
+ public int getBeforeYear() {
+ return beforeYear;
+ }
+
+ public int getBeforeMonth() {
+ return beforeMonth;
+ }
+
+ public int getBeforeDay() {
+ return beforeDay;
+ }
+
+ public int getBeforeHour() {
+ return beforeHour;
+ }
+
+ public int getBeforeMinute() {
+ return beforeMinute;
+ }
+
+ public int getBeforeSecond() {
+ return beforeSecond;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java
new file mode 100644
index 0000000000..b3b468f09a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/DefaultDateTimeSetEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class DefaultDateTimeSetEvent extends HistoryEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java
new file mode 100644
index 0000000000..2edbec2dd4
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/EndOfTBREvent.java
@@ -0,0 +1,43 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class EndOfTBREvent extends HistoryEvent {
+
+ private int startHour;
+ private int startMinute;
+ private int startSecond;
+ private int amount;
+ private int duration;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ byteBuf.shift(1);
+ startHour = BOCUtil.parseBOC(byteBuf.readByte());
+ startMinute = BOCUtil.parseBOC(byteBuf.readByte());
+ startSecond = BOCUtil.parseBOC(byteBuf.readByte());
+ amount = byteBuf.readUInt16LE();
+ duration = byteBuf.readUInt16LE();
+ }
+
+ public int getStartHour() {
+ return startHour;
+ }
+
+ public int getStartMinute() {
+ return startMinute;
+ }
+
+ public int getStartSecond() {
+ return startSecond;
+ }
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java
new file mode 100644
index 0000000000..874c908ca5
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/HistoryEvent.java
@@ -0,0 +1,83 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryEventIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class HistoryEvent implements Comparable {
+
+ private int eventYear;
+ private int eventMonth;
+ private int eventDay;
+ private int eventHour;
+ private int eventMinute;
+ private int eventSecond;
+ private long eventPosition;
+
+ public static HistoryEvent deserialize(ByteBuf byteBuf) {
+ int eventID = byteBuf.readUInt16LE();
+ Class extends HistoryEvent> eventClass = HistoryEventIDs.IDS.getType(eventID);
+ HistoryEvent event = null;
+ if (eventClass == null) event = new HistoryEvent();
+ else {
+ try {
+ event = eventClass.newInstance();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ }
+ }
+ event.parseHeader(byteBuf);
+ event.parse(byteBuf);
+ return event;
+ }
+
+ public final void parseHeader(ByteBuf byteBuf) {
+ eventYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte());
+ eventMonth = BOCUtil.parseBOC(byteBuf.readByte());
+ eventDay = BOCUtil.parseBOC(byteBuf.readByte());
+ byteBuf.shift(1);
+ eventHour = BOCUtil.parseBOC(byteBuf.readByte());
+ eventMinute = BOCUtil.parseBOC(byteBuf.readByte());
+ eventSecond = BOCUtil.parseBOC(byteBuf.readByte());
+ eventPosition = byteBuf.readUInt32LE();
+ }
+
+ public void parse(ByteBuf byteBuf) {
+
+ }
+
+ public int getEventYear() {
+ return eventYear;
+ }
+
+ public int getEventMonth() {
+ return eventMonth;
+ }
+
+ public int getEventDay() {
+ return eventDay;
+ }
+
+ public int getEventHour() {
+ return eventHour;
+ }
+
+ public int getEventMinute() {
+ return eventMinute;
+ }
+
+ public int getEventSecond() {
+ return eventSecond;
+ }
+
+ public long getEventPosition() {
+ return eventPosition;
+ }
+
+ @Override
+ public int compareTo(HistoryEvent historyEvent) {
+ return (int) (eventPosition - historyEvent.eventPosition);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java
new file mode 100644
index 0000000000..e6edc8c95c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfAlertEvent.java
@@ -0,0 +1,25 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AlertTypeIncrementalIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public abstract class OccurrenceOfAlertEvent extends HistoryEvent {
+
+ private AlertType alertType;
+ private int alertID;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ alertType = AlertTypeIncrementalIDs.IDS.getType(byteBuf.readUInt16LE());
+ alertID = byteBuf.readUInt16LE();
+ }
+
+ public AlertType getAlertType() {
+ return alertType;
+ }
+
+ public int getAlertID() {
+ return alertID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java
new file mode 100644
index 0000000000..7d6c61e9c2
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfErrorEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class OccurrenceOfErrorEvent extends OccurrenceOfAlertEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java
new file mode 100644
index 0000000000..6884797250
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfMaintenanceEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class OccurrenceOfMaintenanceEvent extends OccurrenceOfAlertEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java
new file mode 100644
index 0000000000..b504e4e09a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OccurrenceOfWarningEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class OccurrenceOfWarningEvent extends OccurrenceOfAlertEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java
new file mode 100644
index 0000000000..067b46e51f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/OperatingModeChangedEvent.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode;
+import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class OperatingModeChangedEvent extends HistoryEvent {
+
+ private OperatingMode oldValue;
+ private OperatingMode newValue;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ oldValue = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE());
+ newValue = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE());
+ }
+
+
+ public OperatingMode getOldValue() {
+ return oldValue;
+ }
+
+ public OperatingMode getNewValue() {
+ return newValue;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java
new file mode 100644
index 0000000000..ff73ce0383
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerDownEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class PowerDownEvent extends HistoryEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java
new file mode 100644
index 0000000000..d31690e9e9
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/PowerUpEvent.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+public class PowerUpEvent extends HistoryEvent {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java
new file mode 100644
index 0000000000..4afe3c72ba
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/SniffingDoneEvent.java
@@ -0,0 +1,18 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SniffingDoneEvent extends HistoryEvent {
+
+ private double amount;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ amount = byteBuf.readUInt16Decimal();
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java
new file mode 100644
index 0000000000..99795ed12c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/StartOfTBREvent.java
@@ -0,0 +1,23 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class StartOfTBREvent extends HistoryEvent {
+
+ private int amount;
+ private int duration;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ amount = byteBuf.readUInt16LE();
+ duration = byteBuf.readUInt16LE();
+ }
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java
new file mode 100644
index 0000000000..c7f52ce1ef
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TotalDailyDoseEvent.java
@@ -0,0 +1,42 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class TotalDailyDoseEvent extends HistoryEvent {
+
+ private double basalTotal;
+ private double bolusTotal;
+ private int totalYear;
+ private int totalMonth;
+ private int totalDay;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ basalTotal = byteBuf.readUInt32Decimal100();
+ bolusTotal = byteBuf.readUInt32Decimal100();
+ totalYear = BOCUtil.parseBOC(byteBuf.readByte()) * 100 + BOCUtil.parseBOC(byteBuf.readByte());
+ totalMonth = BOCUtil.parseBOC(byteBuf.readByte());
+ totalDay = BOCUtil.parseBOC(byteBuf.readByte());
+ }
+
+ public double getBasalTotal() {
+ return basalTotal;
+ }
+
+ public double getBolusTotal() {
+ return bolusTotal;
+ }
+
+ public int getTotalYear() {
+ return totalYear;
+ }
+
+ public int getTotalMonth() {
+ return totalMonth;
+ }
+
+ public int getTotalDay() {
+ return totalDay;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java
new file mode 100644
index 0000000000..58a1851936
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/history/history_events/TubeFilledEvent.java
@@ -0,0 +1,17 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class TubeFilledEvent extends HistoryEvent {
+
+ private double amount;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ amount = byteBuf.readUInt16Decimal();
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java
new file mode 100644
index 0000000000..1d5630ea94
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ActiveBRProfileBlock.java
@@ -0,0 +1,30 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfile;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBasalProfileIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ActiveBRProfileBlock extends ParameterBlock {
+
+ private BasalProfile activeBasalProfile;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ activeBasalProfile = ActiveBasalProfileIDs.IDS.getType(byteBuf.readUInt16LE());
+ }
+
+ @Override
+ public ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(ActiveBasalProfileIDs.IDS.getID(activeBasalProfile));
+ return byteBuf;
+ }
+
+ public BasalProfile getActiveBasalProfile() {
+ return activeBasalProfile;
+ }
+
+ public void setActiveBasalProfile(BasalProfile activeBasalProfile) {
+ this.activeBasalProfile = activeBasalProfile;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java
new file mode 100644
index 0000000000..5f6be32181
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1Block.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile1Block extends BRProfileBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java
new file mode 100644
index 0000000000..1135eac5ac
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile1NameBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile1NameBlock extends NameBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java
new file mode 100644
index 0000000000..0b961458f2
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2Block.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile2Block extends BRProfileBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java
new file mode 100644
index 0000000000..591dd4d08c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile2NameBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile2NameBlock extends NameBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java
new file mode 100644
index 0000000000..31e0ac0409
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3Block.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile3Block extends BRProfileBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java
new file mode 100644
index 0000000000..390e3be0dc
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile3NameBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile3NameBlock extends NameBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java
new file mode 100644
index 0000000000..06eaeb943c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4Block.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile4Block extends BRProfileBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java
new file mode 100644
index 0000000000..5e2a5eb811
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile4NameBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile4NameBlock extends NameBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java
new file mode 100644
index 0000000000..738ea270f1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5Block.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile5Block extends BRProfileBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java
new file mode 100644
index 0000000000..1ff159aeb2
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfile5NameBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class BRProfile5NameBlock extends NameBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java
new file mode 100644
index 0000000000..c6b4a515a1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/BRProfileBlock.java
@@ -0,0 +1,50 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfileBlock;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public abstract class BRProfileBlock extends ParameterBlock {
+
+ private List profileBlocks;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ profileBlocks = new ArrayList<>();
+ for (int i = 0; i < 24; i++) {
+ BasalProfileBlock basalProfileBlock = new BasalProfileBlock();
+ basalProfileBlock.setDuration(byteBuf.readUInt16LE());
+ profileBlocks.add(basalProfileBlock);
+ }
+ for (int i = 0; i < 24; i++) profileBlocks.get(i).setBasalAmount(byteBuf.readUInt16Decimal());
+ Iterator iterator = profileBlocks.iterator();
+ while (iterator.hasNext())
+ if (iterator.next().getDuration() == 0)
+ iterator.remove();
+ }
+
+ @Override
+ public ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(96);
+ for (int i = 0; i < 24; i++) {
+ if (profileBlocks.size() > i) byteBuf.putUInt16LE(profileBlocks.get(i).getDuration());
+ else byteBuf.putUInt16LE(0);
+ }
+ for (int i = 0; i < 24; i++) {
+ if (profileBlocks.size() > i) byteBuf.putUInt16Decimal(profileBlocks.get(i).getBasalAmount());
+ else byteBuf.putUInt16Decimal(0);
+ }
+ return byteBuf;
+ }
+
+ public List getProfileBlocks() {
+ return profileBlocks;
+ }
+
+ public void setProfileBlocks(List profileBlocks) {
+ this.profileBlocks = profileBlocks;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java
new file mode 100644
index 0000000000..9db116edaf
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBasalAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class FactoryMaxBasalAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java
new file mode 100644
index 0000000000..9df9cf4dff
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMaxBolusAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class FactoryMaxBolusAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java
new file mode 100644
index 0000000000..70cd39c07b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBasalAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class FactoryMinBasalAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java
new file mode 100644
index 0000000000..46ae394834
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/FactoryMinBolusAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class FactoryMinBolusAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java
new file mode 100644
index 0000000000..a753a62567
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/InsulinAmountLimitationBlock.java
@@ -0,0 +1,28 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public abstract class InsulinAmountLimitationBlock extends ParameterBlock {
+
+ private double amountLimitation;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ amountLimitation = byteBuf.readUInt16Decimal();
+ }
+
+ @Override
+ public ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16Decimal(amountLimitation);
+ return byteBuf;
+ }
+
+ public double getAmountLimitation() {
+ return this.amountLimitation;
+ }
+
+ public void setAmountLimitation(double amountLimitation) {
+ this.amountLimitation = amountLimitation;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java
new file mode 100644
index 0000000000..d09b4681c0
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBasalAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class MaxBasalAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java
new file mode 100644
index 0000000000..d53fe5e742
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/MaxBolusAmountBlock.java
@@ -0,0 +1,4 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+public class MaxBolusAmountBlock extends InsulinAmountLimitationBlock {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java
new file mode 100644
index 0000000000..d4cf2060cb
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/NameBlock.java
@@ -0,0 +1,28 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public abstract class NameBlock extends ParameterBlock {
+
+ private String name;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ name = byteBuf.readUTF16(40);
+ }
+
+ @Override
+ public ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(42);
+ byteBuf.putUTF16(name, 40);
+ return byteBuf;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java
new file mode 100644
index 0000000000..6ed2ca15c1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/ParameterBlock.java
@@ -0,0 +1,10 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public abstract class ParameterBlock {
+
+ public abstract void parse(ByteBuf byteBuf);
+ public abstract ByteBuf getData();
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java
new file mode 100644
index 0000000000..e4e5d10c70
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/SystemIdentificationBlock.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.SystemIdentification;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SystemIdentificationBlock extends ParameterBlock {
+
+ private SystemIdentification systemIdentification;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ systemIdentification = new SystemIdentification();
+ systemIdentification.setSerialNumber(byteBuf.readUTF16(18));
+ systemIdentification.setSystemIdAppendix(byteBuf.readUInt32LE());
+ systemIdentification.setManufacturingDate(byteBuf.readUTF16(22));
+ }
+
+ @Override
+ public ByteBuf getData() {
+ return null;
+ }
+
+ public SystemIdentification getSystemIdentification() {
+ return systemIdentification;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java
new file mode 100644
index 0000000000..aec41ded44
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/parameter_blocks/TBROverNotificationBlock.java
@@ -0,0 +1,31 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks;
+
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class TBROverNotificationBlock extends ParameterBlock {
+
+ private boolean enabled;
+ private int melody;
+
+ @Override
+ public void parse(ByteBuf byteBuf) {
+ enabled = byteBuf.readBoolean();
+ melody = byteBuf.readUInt16LE();
+ }
+
+ @Override
+ public ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(4);
+ byteBuf.putBoolean(enabled);
+ byteBuf.putUInt16LE(melody);
+ return byteBuf;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java
new file mode 100644
index 0000000000..559d5dfcbd
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelBolusMessage.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class CancelBolusMessage extends AppLayerMessage {
+
+ private int bolusID;
+
+ public CancelBolusMessage() {
+ super(MessagePriority.HIGHEST, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(bolusID);
+ return byteBuf;
+ }
+
+ public void setBolusID(int bolusID) {
+ this.bolusID = bolusID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java
new file mode 100644
index 0000000000..09b1762d2f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/CancelTBRMessage.java
@@ -0,0 +1,11 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+
+public class CancelTBRMessage extends AppLayerMessage {
+ public CancelTBRMessage() {
+ super(MessagePriority.HIGHER, false, false, Service.REMOTE_CONTROL);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java
new file mode 100644
index 0000000000..f9ea0b9d2f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ChangeTBRMessage.java
@@ -0,0 +1,33 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ChangeTBRMessage extends AppLayerMessage {
+
+ private int percentage;
+ private int duration;
+
+ public ChangeTBRMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(6);
+ byteBuf.putUInt16LE(percentage);
+ byteBuf.putUInt16LE(duration);
+ byteBuf.putUInt16LE(31);
+ return byteBuf;
+ }
+
+ public void setPercentage(int percentage) {
+ this.percentage = percentage;
+ }
+
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java
new file mode 100644
index 0000000000..1d8e905c1c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/ConfirmAlertMessage.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ConfirmAlertMessage extends AppLayerMessage {
+
+ private int alertID;
+
+ public ConfirmAlertMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(alertID);
+ return byteBuf;
+ }
+
+ public void setAlertID(int alertID) {
+ this.alertID = alertID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java
new file mode 100644
index 0000000000..f1b4c3f6de
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java
@@ -0,0 +1,63 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.BolusTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class DeliverBolusMessage extends AppLayerMessage {
+
+ private BolusType bolusType;
+ private double immediateAmount;
+ private double extendedAmount;
+ private int duration;
+ private int bolusId;
+
+ public DeliverBolusMessage() {
+ super(MessagePriority.NORMAL, true, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(22);
+ byteBuf.putUInt16LE(805);
+ byteBuf.putUInt16LE(BolusTypeIDs.IDS.getID(bolusType));
+ byteBuf.putUInt16LE(31);
+ byteBuf.putUInt16LE(0);
+ byteBuf.putUInt16Decimal(immediateAmount);
+ byteBuf.putUInt16Decimal(extendedAmount);
+ byteBuf.putUInt16LE(duration);
+ byteBuf.putUInt16LE(0);
+ byteBuf.putUInt16Decimal(immediateAmount);
+ byteBuf.putUInt16Decimal(extendedAmount);
+ byteBuf.putUInt16LE(duration);
+ return byteBuf;
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) throws Exception {
+ bolusId = byteBuf.readUInt16LE();
+ }
+
+ public void setBolusType(BolusType bolusType) {
+ this.bolusType = bolusType;
+ }
+
+ public void setImmediateAmount(double immediateAmount) {
+ this.immediateAmount = immediateAmount;
+ }
+
+ public void setExtendedAmount(double extendedAmount) {
+ this.extendedAmount = extendedAmount;
+ }
+
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
+
+ public int getBolusId() {
+ return bolusId;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java
new file mode 100644
index 0000000000..965d0bd3fd
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/GetAvailableBolusTypesMessage.java
@@ -0,0 +1,28 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.AvailableBolusTypes;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetAvailableBolusTypesMessage extends AppLayerMessage {
+
+ private AvailableBolusTypes availableBolusTypes;
+
+ public GetAvailableBolusTypesMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) throws Exception {
+ availableBolusTypes = new AvailableBolusTypes();
+ availableBolusTypes.setStandardAvailable(byteBuf.readBoolean());
+ availableBolusTypes.setExtendedAvailable(byteBuf.readBoolean());
+ availableBolusTypes.setMultiwaveAvailable(byteBuf.readBoolean());
+ }
+
+ public AvailableBolusTypes getAvailableBolusTypes() {
+ return this.availableBolusTypes;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java
new file mode 100644
index 0000000000..5fe99f2bdf
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetDateTimeMessage.java
@@ -0,0 +1,32 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.PumpTime;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SetDateTimeMessage extends AppLayerMessage {
+
+ private PumpTime pumpTime;
+
+ public SetDateTimeMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.CONFIGURATION);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(7);
+ byteBuf.putUInt16LE(pumpTime.getYear());
+ byteBuf.putUInt8((short) pumpTime.getMonth());
+ byteBuf.putUInt8((short) pumpTime.getDay());
+ byteBuf.putUInt8((short) pumpTime.getHour());
+ byteBuf.putUInt8((short) pumpTime.getMinute());
+ byteBuf.putUInt8((short) pumpTime.getSecond());
+ return byteBuf;
+ }
+
+ public void setPumpTime(PumpTime pumpTime) {
+ this.pumpTime = pumpTime;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java
new file mode 100644
index 0000000000..41dff43ed4
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetOperatingModeMessage.java
@@ -0,0 +1,28 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode;
+import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SetOperatingModeMessage extends AppLayerMessage {
+
+ private OperatingMode operatingMode;
+
+ public SetOperatingModeMessage() {
+ super(MessagePriority.HIGHEST, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(OperatingModeIDs.IDS.getID(operatingMode));
+ return byteBuf;
+ }
+
+ public void setOperatingMode(OperatingMode operatingMode) {
+ this.operatingMode = operatingMode;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java
new file mode 100644
index 0000000000..0bdff3295d
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SetTBRMessage.java
@@ -0,0 +1,33 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SetTBRMessage extends AppLayerMessage {
+
+ private int percentage;
+ private int duration;
+
+ public SetTBRMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(6);
+ byteBuf.putUInt16LE(percentage);
+ byteBuf.putUInt16LE(duration);
+ byteBuf.putUInt16LE(31);
+ return byteBuf;
+ }
+
+ public void setPercentage(int percentage) {
+ this.percentage = percentage;
+ }
+
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java
new file mode 100644
index 0000000000..139ea7e82b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/SnoozeAlertMessage.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class SnoozeAlertMessage extends AppLayerMessage {
+
+ private int alertID;
+
+ public SnoozeAlertMessage() {
+ super(MessagePriority.NORMAL, false, true, Service.REMOTE_CONTROL);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(2);
+ byteBuf.putUInt16LE(alertID);
+ return byteBuf;
+ }
+
+ public void setAlertID(int alertID) {
+ this.alertID = alertID;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java
new file mode 100644
index 0000000000..899ba182e8
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveAlertMessage.java
@@ -0,0 +1,54 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.Alert;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AlertCategoryIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AlertStatusIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.AlertTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetActiveAlertMessage extends AppLayerMessage {
+
+ private Alert alert;
+
+ public GetActiveAlertMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ Alert alert = new Alert();
+ alert.setAlertId(byteBuf.readUInt16LE());
+ alert.setAlertCategory(AlertCategoryIDs.IDS.getType(byteBuf.readUInt16LE()));
+ alert.setAlertType(AlertTypeIDs.IDS.getType(byteBuf.readUInt16LE()));
+ alert.setAlertStatus(AlertStatusIDs.IDS.getType(byteBuf.readUInt16LE()));
+ if (alert.getAlertType() != null) {
+ switch (alert.getAlertType()) {
+ case WARNING_38:
+ byteBuf.shift(4);
+ alert.setProgrammedBolusAmount(byteBuf.readUInt16Decimal());
+ alert.setDeliveredBolusAmount(byteBuf.readUInt16Decimal());
+ break;
+ case REMINDER_07:
+ case WARNING_36:
+ byteBuf.shift(2);
+ alert.setTBRAmount(byteBuf.readUInt16LE());
+ alert.setTBRDuration(byteBuf.readUInt16LE());
+ break;
+ case WARNING_31:
+ alert.setCartridgeAmount(byteBuf.readUInt16Decimal());
+ break;
+ }
+ }
+ if (alert.getAlertCategory() != null
+ && alert.getAlertType() != null
+ && alert.getAlertStatus() != null)
+ this.alert = alert;
+ }
+
+ public Alert getAlert() {
+ return this.alert;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java
new file mode 100644
index 0000000000..4b68739583
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBasalRateMessage.java
@@ -0,0 +1,30 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBasalProfileIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetActiveBasalRateMessage extends AppLayerMessage {
+
+ private ActiveBasalRate activeBasalRate;
+
+ public GetActiveBasalRateMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ ActiveBasalRate activeBasalRate = new ActiveBasalRate();
+ activeBasalRate.setActiveBasalProfile(ActiveBasalProfileIDs.IDS.getType(byteBuf.readUInt16LE()));
+ activeBasalRate.setActiveBasalProfileName(byteBuf.readUTF16(30));
+ activeBasalRate.setActiveBasalRate(byteBuf.readUInt16Decimal());
+ if (activeBasalRate.getActiveBasalProfile() != null) this.activeBasalRate = activeBasalRate;
+ }
+
+ public ActiveBasalRate getActiveBasalRate() {
+ return this.activeBasalRate;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java
new file mode 100644
index 0000000000..4bcb988afd
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveBolusesMessage.java
@@ -0,0 +1,40 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ActiveBolusTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetActiveBolusesMessage extends AppLayerMessage {
+
+ private List activeBoluses;
+
+ public GetActiveBolusesMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ activeBoluses = new ArrayList<>();
+ for (int i = 0; i < 3; i++) {
+ ActiveBolus activeBolus = new ActiveBolus();
+ activeBolus.setBolusID(byteBuf.readUInt16LE());
+ activeBolus.setBolusType(ActiveBolusTypeIDs.IDS.getType(byteBuf.readUInt16LE()));
+ byteBuf.shift(2);
+ byteBuf.shift(2);
+ activeBolus.setInitialAmount(byteBuf.readUInt16Decimal());
+ activeBolus.setRemainingAmount(byteBuf.readUInt16Decimal());
+ activeBolus.setRemainingDuration(byteBuf.readUInt16LE());
+ if (activeBolus.getBolusType() != null) activeBoluses.add(activeBolus);
+ }
+ }
+
+ public List getActiveBoluses() {
+ return this.activeBoluses;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java
new file mode 100644
index 0000000000..b685c65304
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetActiveTBRMessage.java
@@ -0,0 +1,29 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetActiveTBRMessage extends AppLayerMessage {
+
+ private ActiveTBR activeTBR;
+
+ public GetActiveTBRMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ ActiveTBR activeTBR = new ActiveTBR();
+ activeTBR.setPercentage(byteBuf.readUInt16LE());
+ activeTBR.setRemainingDuration(byteBuf.readUInt16LE());
+ activeTBR.setInitialDuration(byteBuf.readUInt16LE());
+ if (activeTBR.getPercentage() != 100) this.activeTBR = activeTBR;
+ }
+
+ public ActiveTBR getActiveTBR() {
+ return this.activeTBR;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java
new file mode 100644
index 0000000000..af4b7dc17a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetBatteryStatusMessage.java
@@ -0,0 +1,30 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.BatteryStatus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.BatteryTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.SymbolStatusIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetBatteryStatusMessage extends AppLayerMessage {
+
+ private BatteryStatus batteryStatus;
+
+ public GetBatteryStatusMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ batteryStatus = new BatteryStatus();
+ batteryStatus.setBatteryType(BatteryTypeIDs.IDS.getType(byteBuf.readUInt16LE()));
+ batteryStatus.setBatteryAmount(byteBuf.readUInt16LE());
+ batteryStatus.setSymbolStatus(SymbolStatusIDs.IDS.getType(byteBuf.readUInt16LE()));
+ }
+
+ public BatteryStatus getBatteryStatus() {
+ return this.batteryStatus;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java
new file mode 100644
index 0000000000..33740c5ce1
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetCartridgeStatusMessage.java
@@ -0,0 +1,31 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeStatus;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.ids.CartridgeTypeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.ids.SymbolStatusIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetCartridgeStatusMessage extends AppLayerMessage {
+
+ private CartridgeStatus cartridgeStatus;
+
+ public GetCartridgeStatusMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ cartridgeStatus = new CartridgeStatus();
+ cartridgeStatus.setInserted(byteBuf.readBoolean());
+ cartridgeStatus.setCartridgeType(CartridgeTypeIDs.IDS.getType(byteBuf.readUInt16LE()));
+ cartridgeStatus.setSymbolStatus(SymbolStatusIDs.IDS.getType(byteBuf.readUInt16LE()));
+ cartridgeStatus.setRemainingAmount(byteBuf.readUInt16Decimal());
+ }
+
+ public CartridgeStatus getCartridgeStatus() {
+ return this.cartridgeStatus;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java
new file mode 100644
index 0000000000..e29bc5eaa2
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetDateTimeMessage.java
@@ -0,0 +1,31 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.PumpTime;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetDateTimeMessage extends AppLayerMessage {
+
+ private PumpTime pumpTime;
+
+ public GetDateTimeMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ pumpTime = new PumpTime();
+ pumpTime.setYear(byteBuf.readUInt16LE());
+ pumpTime.setMonth(byteBuf.readUInt8());
+ pumpTime.setDay(byteBuf.readUInt8());
+ pumpTime.setHour(byteBuf.readUInt8());
+ pumpTime.setMinute(byteBuf.readUInt8());
+ pumpTime.setSecond(byteBuf.readUInt8());
+ }
+
+ public PumpTime getPumpTime() {
+ return this.pumpTime;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java
new file mode 100644
index 0000000000..705a5e228c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetFirmwareVersionsMessage.java
@@ -0,0 +1,35 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.FirmwareVersions;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetFirmwareVersionsMessage extends AppLayerMessage {
+
+ private FirmwareVersions firmwareVersions;
+
+ public GetFirmwareVersionsMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ firmwareVersions = new FirmwareVersions();
+ firmwareVersions.setReleaseSWVersion(byteBuf.readASCII(13));
+ firmwareVersions.setUiProcSWVersion(byteBuf.readASCII(11));
+ firmwareVersions.setPcProcSWVersion(byteBuf.readASCII(11));
+ firmwareVersions.setMdTelProcSWVersion(byteBuf.readASCII(11));
+ firmwareVersions.setBtInfoPageVersion(byteBuf.readASCII(11));
+ firmwareVersions.setSafetyProcSWVersion(byteBuf.readASCII(11));
+ firmwareVersions.setConfigIndex(byteBuf.readUInt16LE());
+ firmwareVersions.setHistoryIndex(byteBuf.readUInt16LE());
+ firmwareVersions.setStateIndex(byteBuf.readUInt16LE());
+ firmwareVersions.setVocabularyIndex(byteBuf.readUInt16LE());
+ }
+
+ public FirmwareVersions getFirmwareVersions() {
+ return this.firmwareVersions;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java
new file mode 100644
index 0000000000..27053a2a6a
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetOperatingModeMessage.java
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode;
+import info.nightscout.androidaps.plugins.pump.insight.ids.OperatingModeIDs;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetOperatingModeMessage extends AppLayerMessage {
+
+ private OperatingMode operatingMode;
+
+ public GetOperatingModeMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ this.operatingMode = OperatingModeIDs.IDS.getType(byteBuf.readUInt16LE());
+ }
+
+ public OperatingMode getOperatingMode() {
+ return this.operatingMode;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java
new file mode 100644
index 0000000000..11d777c197
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetPumpStatusRegisterMessage.java
@@ -0,0 +1,60 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetPumpStatusRegisterMessage extends AppLayerMessage {
+
+ private boolean operatingModeChanged;
+ private boolean batteryStatusChanged;
+ private boolean cartridgeStatusChanged;
+ private boolean totalDailyDoseChanged;
+ private boolean activeBasalRateChanged;
+ private boolean activeTBRChanged;
+ private boolean activeBolusesChanged;
+
+ public GetPumpStatusRegisterMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ operatingModeChanged = byteBuf.readBoolean();
+ batteryStatusChanged = byteBuf.readBoolean();
+ cartridgeStatusChanged = byteBuf.readBoolean();
+ totalDailyDoseChanged = byteBuf.readBoolean();
+ activeBasalRateChanged = byteBuf.readBoolean();
+ activeTBRChanged = byteBuf.readBoolean();
+ activeBolusesChanged = byteBuf.readBoolean();
+ }
+
+ public boolean isOperatingModeChanged() {
+ return this.operatingModeChanged;
+ }
+
+ public boolean isBatteryStatusChanged() {
+ return this.batteryStatusChanged;
+ }
+
+ public boolean isCartridgeStatusChanged() {
+ return this.cartridgeStatusChanged;
+ }
+
+ public boolean isTotalDailyDoseChanged() {
+ return this.totalDailyDoseChanged;
+ }
+
+ public boolean isActiveBasalRateChanged() {
+ return this.activeBasalRateChanged;
+ }
+
+ public boolean isActiveTBRChanged() {
+ return this.activeTBRChanged;
+ }
+
+ public boolean isActiveBolusesChanged() {
+ return this.activeBolusesChanged;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java
new file mode 100644
index 0000000000..e622614eea
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/GetTotalDailyDoseMessage.java
@@ -0,0 +1,28 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.TotalDailyDose;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class GetTotalDailyDoseMessage extends AppLayerMessage {
+
+ private TotalDailyDose tdd;
+
+ public GetTotalDailyDoseMessage() {
+ super(MessagePriority.NORMAL, true, false, Service.STATUS);
+ }
+
+ @Override
+ protected void parse(ByteBuf byteBuf) {
+ tdd = new TotalDailyDose();
+ tdd.setBolus(byteBuf.readUInt32Decimal100());
+ tdd.setBasal(byteBuf.readUInt32Decimal100());
+ tdd.setBolusAndBasal(byteBuf.readUInt32Decimal100());
+ }
+
+ public TotalDailyDose getTDD() {
+ return this.tdd;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java
new file mode 100644
index 0000000000..eacdf14769
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/status/ResetPumpStatusRegisterMessage.java
@@ -0,0 +1,63 @@
+package info.nightscout.androidaps.plugins.pump.insight.app_layer.status;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.Service;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.MessagePriority;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+
+public class ResetPumpStatusRegisterMessage extends AppLayerMessage {
+
+ private boolean operatingModeChanged;
+ private boolean batteryStatusChanged;
+ private boolean cartridgeStatusChanged;
+ private boolean totalDailyDoseChanged;
+ private boolean activeBasalRateChanged;
+ private boolean activeTBRChanged;
+ private boolean activeBolusesChanged;
+
+ public ResetPumpStatusRegisterMessage() {
+ super(MessagePriority.NORMAL, false, false, Service.STATUS);
+ }
+
+ @Override
+ protected ByteBuf getData() {
+ ByteBuf byteBuf = new ByteBuf(28);
+ byteBuf.putBoolean(operatingModeChanged);
+ byteBuf.putBoolean(batteryStatusChanged);
+ byteBuf.putBoolean(cartridgeStatusChanged);
+ byteBuf.putBoolean(totalDailyDoseChanged);
+ byteBuf.putBoolean(activeBasalRateChanged);
+ byteBuf.putBoolean(activeTBRChanged);
+ byteBuf.putBoolean(activeBolusesChanged);
+ for (int i = 0; i < 7; i++) byteBuf.putBoolean(false);
+ return byteBuf;
+ }
+
+ public void setOperatingModeChanged(boolean operatingModeChanged) {
+ this.operatingModeChanged = operatingModeChanged;
+ }
+
+ public void setBatteryStatusChanged(boolean batteryStatusChanged) {
+ this.batteryStatusChanged = batteryStatusChanged;
+ }
+
+ public void setCartridgeStatusChanged(boolean cartridgeStatusChanged) {
+ this.cartridgeStatusChanged = cartridgeStatusChanged;
+ }
+
+ public void setTotalDailyDoseChanged(boolean totalDailyDoseChanged) {
+ this.totalDailyDoseChanged = totalDailyDoseChanged;
+ }
+
+ public void setActiveBasalRateChanged(boolean activeBasalRateChanged) {
+ this.activeBasalRateChanged = activeBasalRateChanged;
+ }
+
+ public void setActiveTBRChanged(boolean activeTBRChanged) {
+ this.activeTBRChanged = activeTBRChanged;
+ }
+
+ public void setActiveBolusesChanged(boolean activeBolusesChanged) {
+ this.activeBolusesChanged = activeBolusesChanged;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java
new file mode 100644
index 0000000000..44812eb48b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/ConfigurationMessageRequest.java
@@ -0,0 +1,33 @@
+package info.nightscout.androidaps.plugins.pump.insight.connection_service;
+
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.CloseConfigurationWriteSessionMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.OpenConfigurationWriteSessionMessage;
+
+public class ConfigurationMessageRequest extends MessageRequest {
+
+ private MessageRequest openRequest;
+ private MessageRequest closeRequest;
+
+ public ConfigurationMessageRequest(T request, MessageRequest openRequest, MessageRequest closeRequest) {
+ super(request);
+ this.openRequest = openRequest;
+ this.closeRequest = closeRequest;
+ }
+
+ @Override
+ public T await() throws Exception {
+ openRequest.await();
+ T response = super.await();
+ closeRequest.await();
+ return response;
+ }
+
+ @Override
+ public T await(long timeout) throws Exception {
+ openRequest.await(timeout);
+ T response = super.await(timeout);
+ closeRequest.await(timeout);
+ return response;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java
new file mode 100644
index 0000000000..e964c9fa20
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/connection_service/InsightConnectionService.java
@@ -0,0 +1,827 @@
+package info.nightscout.androidaps.plugins.pump.insight.connection_service;
+
+import android.app.Service;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothSocket;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.support.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.spongycastle.crypto.InvalidCipherTextException;
+
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.List;
+
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.ReadParameterBlockMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.CloseConfigurationWriteSessionMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.OpenConfigurationWriteSessionMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.configuration.WriteConfigurationBlockMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ActivateServiceMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.BindMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ConnectMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.DisconnectMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.connection.ServiceChallengeMessage;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.SystemIdentificationBlock;
+import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetFirmwareVersionsMessage;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.FirmwareVersions;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
+import info.nightscout.androidaps.plugins.pump.insight.descriptors.SystemIdentification;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionFailedException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.ConnectionLostException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.DisconnectedException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidNonceException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.InvalidSatlCommandException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.ReceivedPacketInInvalidStateException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.TimeoutException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.TooChattyPumpException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlCompatibleStateErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlDecryptVerifyFailedErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlIncompatibleVersionErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidCRCErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidCommIdErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidMacErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidMessageTypeErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidNonceErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidPacketErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlInvalidPayloadLengthErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlNoneErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlPairingRejectedException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlUndefinedErrorException;
+import info.nightscout.androidaps.plugins.pump.insight.exceptions.satl_errors.SatlWrongStateException;
+import info.nightscout.androidaps.plugins.pump.insight.ids.ServiceIDs;
+import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionRequest;
+import info.nightscout.androidaps.plugins.pump.insight.satl.ConnectionResponse;
+import info.nightscout.androidaps.plugins.pump.insight.satl.DataMessage;
+import info.nightscout.androidaps.plugins.pump.insight.satl.ErrorMessage;
+import info.nightscout.androidaps.plugins.pump.insight.satl.KeyRequest;
+import info.nightscout.androidaps.plugins.pump.insight.satl.KeyResponse;
+import info.nightscout.androidaps.plugins.pump.insight.satl.SatlMessage;
+import info.nightscout.androidaps.plugins.pump.insight.satl.SynAckResponse;
+import info.nightscout.androidaps.plugins.pump.insight.satl.SynRequest;
+import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmRequest;
+import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyConfirmResponse;
+import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayRequest;
+import info.nightscout.androidaps.plugins.pump.insight.satl.VerifyDisplayResponse;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
+import info.nightscout.androidaps.plugins.pump.insight.utils.ConnectionEstablisher;
+import info.nightscout.androidaps.plugins.pump.insight.utils.DelayedActionThread;
+import info.nightscout.androidaps.plugins.pump.insight.utils.InputStreamReader;
+import info.nightscout.androidaps.plugins.pump.insight.utils.Nonce;
+import info.nightscout.androidaps.plugins.pump.insight.utils.OutputStreamWriter;
+import info.nightscout.androidaps.plugins.pump.insight.utils.PairingDataStorage;
+import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.Cryptograph;
+import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.DerivedKeys;
+import info.nightscout.androidaps.plugins.pump.insight.utils.crypto.KeyPair;
+import info.nightscout.androidaps.utils.SP;
+
+public class InsightConnectionService extends Service implements ConnectionEstablisher.Callback, InputStreamReader.Callback, OutputStreamWriter.Callback {
+
+ private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
+
+ private static final int BUFFER_SIZE = 1024;
+ private static final int TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD = 3;
+ private static final long RESPONSE_TIMEOUT = 6000;
+
+ private List stateCallbacks = new ArrayList<>();
+ private final List