consolidate DanaR fragments
This commit is contained in:
parent
7da8b2de5c
commit
c312b51fcf
7 changed files with 53 additions and 526 deletions
|
@ -47,11 +47,11 @@ import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPe
|
||||||
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment;
|
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanFragment;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Fragment;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
@ -120,9 +120,9 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(SensitivityOref0Plugin.getPlugin());
|
pluginsList.add(SensitivityOref0Plugin.getPlugin());
|
||||||
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
||||||
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRPlugin.getPlugin());
|
||||||
if (Config.DANAR) pluginsList.add(DanaRKoreanFragment.getPlugin());
|
if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
||||||
if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin());
|
if (Config.DANARv2) pluginsList.add(DanaRv2Plugin.getPlugin());
|
||||||
pluginsList.add(CareportalFragment.getPlugin());
|
pluginsList.add(CareportalFragment.getPlugin());
|
||||||
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
||||||
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance());
|
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance());
|
||||||
|
|
|
@ -39,15 +39,6 @@ import info.nightscout.utils.SetWarnColor;
|
||||||
public class DanaRFragment extends SubscriberFragment {
|
public class DanaRFragment extends SubscriberFragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
||||||
|
|
||||||
private static DanaRPlugin danaRPlugin;
|
|
||||||
|
|
||||||
public static DanaRPlugin getPlugin() {
|
|
||||||
if (danaRPlugin == null) {
|
|
||||||
danaRPlugin = new DanaRPlugin();
|
|
||||||
}
|
|
||||||
return danaRPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Handler sHandler;
|
private static Handler sHandler;
|
||||||
private static HandlerThread sHandlerThread;
|
private static HandlerThread sHandlerThread;
|
||||||
|
|
||||||
|
@ -146,7 +137,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
sHandler.post(new Runnable() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DanaRPlugin.sExecutionService.connect("Connect request from GUI");
|
MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -218,11 +209,21 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
|
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
|
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getBaseBasalRate()) + " U/h");
|
||||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
// DanaRPlugin, DanaRKoreanPlugin
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
||||||
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
|
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||||
|
} else {
|
||||||
|
tempBasalView.setText("");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tempBasalView.setText("");
|
// v2 plugin
|
||||||
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
|
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||||
|
} else {
|
||||||
|
tempBasalView.setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||||
extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString());
|
extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString());
|
||||||
|
|
|
@ -69,6 +69,14 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
private static DanaRPump pump = DanaRPump.getInstance();
|
private static DanaRPump pump = DanaRPump.getInstance();
|
||||||
private static boolean useExtendedBoluses = false;
|
private static boolean useExtendedBoluses = false;
|
||||||
|
|
||||||
|
private static DanaRPlugin plugin = null;
|
||||||
|
|
||||||
|
public static DanaRPlugin getPlugin() {
|
||||||
|
if (plugin == null)
|
||||||
|
plugin = new DanaRPlugin();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public static PumpDescription pumpDescription = new PumpDescription();
|
public static PumpDescription pumpDescription = new PumpDescription();
|
||||||
|
|
||||||
public DanaRPlugin() {
|
public DanaRPlugin() {
|
||||||
|
|
|
@ -1,248 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaRKorean;
|
|
||||||
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
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.EventExtendedBolusChange;
|
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
|
||||||
import info.nightscout.utils.DateUtil;
|
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.utils.SetWarnColor;
|
|
||||||
|
|
||||||
public class DanaRKoreanFragment extends SubscriberFragment {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRKoreanFragment.class);
|
|
||||||
|
|
||||||
private static DanaRKoreanPlugin danaRKoreanPlugin = new DanaRKoreanPlugin();
|
|
||||||
|
|
||||||
public static DanaRKoreanPlugin getPlugin() {
|
|
||||||
return danaRKoreanPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private Handler loopHandler = new Handler();
|
|
||||||
private Runnable refreshLoop = null;
|
|
||||||
|
|
||||||
TextView lastConnectionView;
|
|
||||||
TextView btConnectionView;
|
|
||||||
TextView lastBolusView;
|
|
||||||
TextView dailyUnitsView;
|
|
||||||
TextView basaBasalRateView;
|
|
||||||
TextView tempBasalView;
|
|
||||||
TextView extendedBolusView;
|
|
||||||
TextView batteryView;
|
|
||||||
TextView reservoirView;
|
|
||||||
TextView iobView;
|
|
||||||
TextView firmwareView;
|
|
||||||
TextView basalStepView;
|
|
||||||
TextView bolusStepView;
|
|
||||||
Button viewProfileButton;
|
|
||||||
Button historyButton;
|
|
||||||
Button statsButton;
|
|
||||||
|
|
||||||
|
|
||||||
public DanaRKoreanFragment() {
|
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(DanaRKoreanFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (refreshLoop == null) {
|
|
||||||
refreshLoop = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.danar_fragment, container, false);
|
|
||||||
btConnectionView = (TextView) view.findViewById(R.id.danar_btconnection);
|
|
||||||
lastConnectionView = (TextView) view.findViewById(R.id.danar_lastconnection);
|
|
||||||
lastBolusView = (TextView) view.findViewById(R.id.danar_lastbolus);
|
|
||||||
dailyUnitsView = (TextView) view.findViewById(R.id.danar_dailyunits);
|
|
||||||
basaBasalRateView = (TextView) view.findViewById(R.id.danar_basabasalrate);
|
|
||||||
tempBasalView = (TextView) view.findViewById(R.id.danar_tempbasal);
|
|
||||||
extendedBolusView = (TextView) view.findViewById(R.id.danar_extendedbolus);
|
|
||||||
batteryView = (TextView) view.findViewById(R.id.danar_battery);
|
|
||||||
reservoirView = (TextView) view.findViewById(R.id.danar_reservoir);
|
|
||||||
iobView = (TextView) view.findViewById(R.id.danar_iob);
|
|
||||||
firmwareView = (TextView) view.findViewById(R.id.danar_firmware);
|
|
||||||
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
|
|
||||||
historyButton = (Button) view.findViewById(R.id.danar_history);
|
|
||||||
statsButton = (Button) view.findViewById(R.id.danar_stats);
|
|
||||||
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
|
||||||
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
|
||||||
|
|
||||||
|
|
||||||
viewProfileButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
ProfileViewDialog profileViewDialog = new ProfileViewDialog();
|
|
||||||
profileViewDialog.show(manager, "ProfileViewDialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
historyButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
statsButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
startActivity(new Intent(getContext(), DanaRStatsActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btConnectionView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRKoreanPlugin.sExecutionService.connect("Connect request from GUI");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventPumpStatusChanged c) {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
activity.runOnUiThread(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (c.sStatus == EventPumpStatusChanged.CONNECTING)
|
|
||||||
btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s");
|
|
||||||
else if (c.sStatus == EventPumpStatusChanged.CONNECTED)
|
|
||||||
btConnectionView.setText("{fa-bluetooth}");
|
|
||||||
else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED)
|
|
||||||
btConnectionView.setText("{fa-bluetooth-b}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRNewStatus s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempBasalChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GUI functions
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null && basaBasalRateView != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
|
||||||
if (pump.lastConnection.getTime() != 0) {
|
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime();
|
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
|
||||||
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")");
|
|
||||||
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
|
|
||||||
}
|
|
||||||
// if (pump.lastBolusTime.getTime() != 0) {
|
|
||||||
// Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
|
|
||||||
// double agoHours = agoMsec / 60d / 60d / 1000d;
|
|
||||||
// if (agoHours < 6) // max 6h back
|
|
||||||
// lastBolusView.setText(formatTime.format(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + " U");
|
|
||||||
// else lastBolusView.setText("");
|
|
||||||
// }
|
|
||||||
|
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h");
|
|
||||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
|
||||||
} else {
|
|
||||||
tempBasalView.setText("");
|
|
||||||
}
|
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
|
||||||
extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString());
|
|
||||||
} else {
|
|
||||||
extendedBolusView.setText("");
|
|
||||||
}
|
|
||||||
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
|
|
||||||
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
|
|
||||||
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
|
|
||||||
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
|
|
||||||
iobView.setText(pump.iob + " U");
|
|
||||||
if (pump.isNewPump) {
|
|
||||||
firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
|
|
||||||
} else {
|
|
||||||
firmwareView.setText("OLD");
|
|
||||||
}
|
|
||||||
basalStepView.setText("" + pump.basalStep);
|
|
||||||
bolusStepView.setText("" + pump.bolusStep);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,6 +23,8 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -36,12 +38,11 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -57,7 +58,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentClass() {
|
public String getFragmentClass() {
|
||||||
return DanaRKoreanFragment.class.getName();
|
return DanaRFragment.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean fragmentPumpEnabled = false;
|
static boolean fragmentPumpEnabled = false;
|
||||||
|
@ -70,6 +71,14 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
private static DanaRPump pump = DanaRPump.getInstance();
|
private static DanaRPump pump = DanaRPump.getInstance();
|
||||||
private static boolean useExtendedBoluses = false;
|
private static boolean useExtendedBoluses = false;
|
||||||
|
|
||||||
|
private static DanaRKoreanPlugin plugin = null;
|
||||||
|
|
||||||
|
public static DanaRKoreanPlugin getPlugin() {
|
||||||
|
if (plugin == null)
|
||||||
|
plugin = new DanaRKoreanPlugin();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public static PumpDescription pumpDescription = new PumpDescription();
|
public static PumpDescription pumpDescription = new PumpDescription();
|
||||||
|
|
||||||
public DanaRKoreanPlugin() {
|
public DanaRKoreanPlugin() {
|
||||||
|
|
|
@ -1,250 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaRv2;
|
|
||||||
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
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.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
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.EventExtendedBolusChange;
|
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
|
||||||
import info.nightscout.utils.DateUtil;
|
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.utils.SetWarnColor;
|
|
||||||
|
|
||||||
public class DanaRv2Fragment extends SubscriberFragment {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRv2Fragment.class);
|
|
||||||
|
|
||||||
private static DanaRv2Plugin danaRPlugin;
|
|
||||||
|
|
||||||
public static DanaRv2Plugin getPlugin() {
|
|
||||||
if (danaRPlugin == null) {
|
|
||||||
danaRPlugin = new DanaRv2Plugin();
|
|
||||||
}
|
|
||||||
return danaRPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private Handler loopHandler = new Handler();
|
|
||||||
private Runnable refreshLoop = null;
|
|
||||||
|
|
||||||
TextView lastConnectionView;
|
|
||||||
TextView btConnectionView;
|
|
||||||
TextView lastBolusView;
|
|
||||||
TextView dailyUnitsView;
|
|
||||||
TextView basaBasalRateView;
|
|
||||||
TextView tempBasalView;
|
|
||||||
TextView extendedBolusView;
|
|
||||||
TextView batteryView;
|
|
||||||
TextView reservoirView;
|
|
||||||
TextView iobView;
|
|
||||||
TextView firmwareView;
|
|
||||||
TextView basalStepView;
|
|
||||||
TextView bolusStepView;
|
|
||||||
Button viewProfileButton;
|
|
||||||
Button historyButton;
|
|
||||||
Button statsButton;
|
|
||||||
|
|
||||||
|
|
||||||
public DanaRv2Fragment() {
|
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(DanaRv2Fragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (refreshLoop == null) {
|
|
||||||
refreshLoop = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.danar_fragment, container, false);
|
|
||||||
btConnectionView = (TextView) view.findViewById(R.id.danar_btconnection);
|
|
||||||
lastConnectionView = (TextView) view.findViewById(R.id.danar_lastconnection);
|
|
||||||
lastBolusView = (TextView) view.findViewById(R.id.danar_lastbolus);
|
|
||||||
dailyUnitsView = (TextView) view.findViewById(R.id.danar_dailyunits);
|
|
||||||
basaBasalRateView = (TextView) view.findViewById(R.id.danar_basabasalrate);
|
|
||||||
tempBasalView = (TextView) view.findViewById(R.id.danar_tempbasal);
|
|
||||||
extendedBolusView = (TextView) view.findViewById(R.id.danar_extendedbolus);
|
|
||||||
batteryView = (TextView) view.findViewById(R.id.danar_battery);
|
|
||||||
reservoirView = (TextView) view.findViewById(R.id.danar_reservoir);
|
|
||||||
iobView = (TextView) view.findViewById(R.id.danar_iob);
|
|
||||||
firmwareView = (TextView) view.findViewById(R.id.danar_firmware);
|
|
||||||
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
|
|
||||||
historyButton = (Button) view.findViewById(R.id.danar_history);
|
|
||||||
statsButton = (Button) view.findViewById(R.id.danar_stats);
|
|
||||||
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
|
||||||
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
|
||||||
|
|
||||||
|
|
||||||
viewProfileButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
ProfileViewDialog profileViewDialog = new ProfileViewDialog();
|
|
||||||
profileViewDialog.show(manager, "ProfileViewDialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
historyButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
statsButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
startActivity(new Intent(getContext(), DanaRStatsActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btConnectionView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
sHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRv2Plugin.sExecutionService.connect("Connect request from GUI");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventPumpStatusChanged c) {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
activity.runOnUiThread(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (c.sStatus == EventPumpStatusChanged.CONNECTING)
|
|
||||||
btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s");
|
|
||||||
else if (c.sStatus == EventPumpStatusChanged.CONNECTED)
|
|
||||||
btConnectionView.setText("{fa-bluetooth}");
|
|
||||||
else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED)
|
|
||||||
btConnectionView.setText("{fa-bluetooth-b}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRNewStatus s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempBasalChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GUI functions
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null && basaBasalRateView != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
|
||||||
if (pump.lastConnection.getTime() != 0) {
|
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime();
|
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
|
||||||
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")");
|
|
||||||
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
|
|
||||||
}
|
|
||||||
if (pump.lastBolusTime.getTime() != 0) {
|
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
|
|
||||||
double agoHours = agoMsec / 60d / 60d / 1000d;
|
|
||||||
if (agoHours < 6) // max 6h back
|
|
||||||
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
|
|
||||||
else lastBolusView.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
|
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
|
||||||
} else {
|
|
||||||
tempBasalView.setText("");
|
|
||||||
}
|
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
|
||||||
extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString());
|
|
||||||
} else {
|
|
||||||
extendedBolusView.setText("");
|
|
||||||
}
|
|
||||||
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
|
|
||||||
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
|
|
||||||
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
|
|
||||||
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
|
|
||||||
iobView.setText(pump.iob + " U");
|
|
||||||
if (pump.isNewPump) {
|
|
||||||
firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
|
|
||||||
} else {
|
|
||||||
firmwareView.setText("OLD");
|
|
||||||
}
|
|
||||||
basalStepView.setText("" + pump.basalStep);
|
|
||||||
bolusStepView.setText("" + pump.bolusStep);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -4,9 +4,7 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -25,6 +23,8 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -37,13 +37,12 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -58,7 +57,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentClass() {
|
public String getFragmentClass() {
|
||||||
return DanaRv2Fragment.class.getName();
|
return DanaRFragment.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean fragmentPumpEnabled = false;
|
static boolean fragmentPumpEnabled = false;
|
||||||
|
@ -68,6 +67,14 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
public static DanaRv2ExecutionService sExecutionService;
|
public static DanaRv2ExecutionService sExecutionService;
|
||||||
|
|
||||||
|
|
||||||
|
private static DanaRv2Plugin plugin = null;
|
||||||
|
|
||||||
|
public static DanaRv2Plugin getPlugin() {
|
||||||
|
if (plugin == null)
|
||||||
|
plugin = new DanaRv2Plugin();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
private static DanaRPump pump = DanaRPump.getInstance();
|
private static DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
|
||||||
public static PumpDescription pumpDescription = new PumpDescription();
|
public static PumpDescription pumpDescription = new PumpDescription();
|
||||||
|
|
Loading…
Reference in a new issue