DanaRFragment -> kotlin
This commit is contained in:
parent
a0eef61745
commit
8f3c4e25c5
18 changed files with 280 additions and 435 deletions
|
@ -464,7 +464,7 @@ public class Profile {
|
||||||
public String getBasalList() {
|
public String getBasalList() {
|
||||||
if (basal_v == null)
|
if (basal_v == null)
|
||||||
basal_v = convertToSparseArray(basal);
|
basal_v = convertToSparseArray(basal);
|
||||||
return getValuesList(basal_v, null, new DecimalFormat("0.00"), MainApp.gs(R.string.profile_ins_units_per_hout));
|
return getValuesList(basal_v, null, new DecimalFormat("0.00"), MainApp.gs(R.string.profile_ins_units_per_hour));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProfileValue {
|
public class ProfileValue {
|
||||||
|
|
|
@ -635,6 +635,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.gs(R.string.danar_viewprofile))) {
|
} else if (item.getTitle().equals(MainApp.gs(R.string.danar_viewprofile))) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("time", DateUtil.now());
|
args.putLong("time", DateUtil.now());
|
||||||
|
args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal());
|
||||||
ProfileViewerDialog pvd = new ProfileViewerDialog();
|
ProfileViewerDialog pvd = new ProfileViewerDialog();
|
||||||
pvd.setArguments(args);
|
pvd.setArguments(args);
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
|
|
|
@ -1,304 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaR;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import android.text.Spanned;
|
|
||||||
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 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.activities.TDDStatsActivity;
|
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
|
||||||
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.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.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);
|
|
||||||
|
|
||||||
private Handler loopHandler = new Handler();
|
|
||||||
private Runnable refreshLoop = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@BindView(R.id.danar_lastconnection)
|
|
||||||
TextView lastConnectionView;
|
|
||||||
@BindView(R.id.danar_btconnection)
|
|
||||||
TextView btConnectionView;
|
|
||||||
@BindView(R.id.danar_lastbolus)
|
|
||||||
TextView lastBolusView;
|
|
||||||
@BindView(R.id.danar_dailyunits)
|
|
||||||
TextView dailyUnitsView;
|
|
||||||
@BindView(R.id.danar_basabasalrate)
|
|
||||||
TextView basaBasalRateView;
|
|
||||||
@BindView(R.id.danar_tempbasal)
|
|
||||||
TextView tempBasalView;
|
|
||||||
@BindView(R.id.danar_extendedbolus)
|
|
||||||
TextView extendedBolusView;
|
|
||||||
@BindView(R.id.danar_battery)
|
|
||||||
TextView batteryView;
|
|
||||||
@BindView(R.id.danar_reservoir)
|
|
||||||
TextView reservoirView;
|
|
||||||
@BindView(R.id.danar_iob)
|
|
||||||
TextView iobView;
|
|
||||||
@BindView(R.id.danar_firmware)
|
|
||||||
TextView firmwareView;
|
|
||||||
@BindView(R.id.danar_basalstep)
|
|
||||||
TextView basalStepView;
|
|
||||||
@BindView(R.id.danar_bolusstep)
|
|
||||||
TextView bolusStepView;
|
|
||||||
@BindView(R.id.danar_serialnumber)
|
|
||||||
TextView serialNumberView;
|
|
||||||
@BindView(R.id.danar_queue)
|
|
||||||
TextView queueView;
|
|
||||||
|
|
||||||
@BindView(R.id.overview_pumpstatuslayout)
|
|
||||||
LinearLayout pumpStatusLayout;
|
|
||||||
@BindView(R.id.overview_pumpstatus)
|
|
||||||
TextView pumpStatusView;
|
|
||||||
@BindView(R.id.danar_user_options)
|
|
||||||
Button danar_user_options;
|
|
||||||
|
|
||||||
public DanaRFragment() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
loopHandler.removeCallbacks(refreshLoop);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.danar_fragment, container, false);
|
|
||||||
unbinder = ButterKnife.bind(this, view);
|
|
||||||
|
|
||||||
pumpStatusView.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder));
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.danar_history)
|
|
||||||
void onHistoryClick() {
|
|
||||||
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.danar_viewprofile)
|
|
||||||
void onViewProfileClick() {
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
ProfileViewDialog profileViewDialog = new ProfileViewDialog();
|
|
||||||
profileViewDialog.show(manager, "ProfileViewDialog");
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.danar_stats)
|
|
||||||
void onStatsClick() {
|
|
||||||
startActivity(new Intent(getContext(), TDDStatsActivity.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.danar_user_options)
|
|
||||||
void onUserOptionsClick() {
|
|
||||||
startActivity(new Intent(getContext(), DanaRUserOptionsActivity.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.danar_btconnection)
|
|
||||||
void onBtConnectionClick() {
|
|
||||||
if (L.isEnabled(L.PUMP))
|
|
||||||
log.debug("Clicked connect to pump");
|
|
||||||
DanaRPump.getInstance().lastConnection = 0;
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Clicked connect to pump", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventPumpStatusChanged c) {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
final String status = c.textStatus();
|
|
||||||
if (activity != null) {
|
|
||||||
activity.runOnUiThread(
|
|
||||||
() -> {
|
|
||||||
synchronized (DanaRFragment.this) {
|
|
||||||
|
|
||||||
if (btConnectionView == null || pumpStatusView == null || pumpStatusLayout == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
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}");
|
|
||||||
|
|
||||||
if (!status.equals("")) {
|
|
||||||
pumpStatusView.setText(status);
|
|
||||||
pumpStatusLayout.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
pumpStatusLayout.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRNewStatus s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempBasalChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventQueueChanged s) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GUI functions
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null && basaBasalRateView != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
synchronized (DanaRFragment.this) {
|
|
||||||
if (!isBound()) return;
|
|
||||||
|
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
|
||||||
if (pump.lastConnection != 0) {
|
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
|
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
|
||||||
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
|
|
||||||
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
|
|
||||||
}
|
|
||||||
if (pump.lastBolusTime != 0) {
|
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime;
|
|
||||||
double agoHours = agoMsec / 60d / 60d / 1000d;
|
|
||||||
if (agoHours < 6) // max 6h back
|
|
||||||
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime) + " " + 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(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h");
|
|
||||||
// DanaRPlugin, DanaRKoreanPlugin
|
|
||||||
if (ConfigBuilderPlugin.getPlugin().getActivePump().isFakingTempsByExtendedBoluses()) {
|
|
||||||
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
|
|
||||||
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
|
||||||
} else {
|
|
||||||
tempBasalView.setText("");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// v2 plugin
|
|
||||||
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
|
||||||
if (tb != null) {
|
|
||||||
tempBasalView.setText(tb.toStringFull());
|
|
||||||
} else {
|
|
||||||
tempBasalView.setText("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
|
||||||
if (activeExtendedBolus != null) {
|
|
||||||
extendedBolusView.setText(activeExtendedBolus.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.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
|
|
||||||
firmwareView.setText(String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
|
|
||||||
} else {
|
|
||||||
firmwareView.setText("OLD");
|
|
||||||
}
|
|
||||||
basalStepView.setText("" + pump.basalStep);
|
|
||||||
bolusStepView.setText("" + pump.bolusStep);
|
|
||||||
serialNumberView.setText("" + pump.serialNumber);
|
|
||||||
if (queueView != null) {
|
|
||||||
Spanned status = ConfigBuilderPlugin.getPlugin().getCommandQueue().spannedStatus();
|
|
||||||
if (status.toString().equals("")) {
|
|
||||||
queueView.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
queueView.setVisibility(View.VISIBLE);
|
|
||||||
queueView.setText(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//hide user options button if not an RS pump or old firmware
|
|
||||||
// also excludes pump with model 03 because of untested error
|
|
||||||
boolean isKorean = DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP);
|
|
||||||
if (isKorean || firmwareView.getText() == "OLD" || pump.model == 3) {
|
|
||||||
danar_user_options.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBound() {
|
|
||||||
return lastConnectionView != null
|
|
||||||
&& lastBolusView != null
|
|
||||||
&& dailyUnitsView != null
|
|
||||||
&& basaBasalRateView != null
|
|
||||||
&& tempBasalView != null
|
|
||||||
&& extendedBolusView != null
|
|
||||||
&& reservoirView != null
|
|
||||||
&& batteryView != null
|
|
||||||
&& iobView != null
|
|
||||||
&& firmwareView != null
|
|
||||||
&& basalStepView != null
|
|
||||||
&& bolusStepView != null
|
|
||||||
&& serialNumberView != null
|
|
||||||
&& danar_user_options != null
|
|
||||||
&& queueView != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,212 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaR
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.squareup.otto.Subscribe
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||||
|
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
||||||
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||||
|
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface
|
||||||
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
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.plugins.treatments.fragments.ProfileViewerDialog
|
||||||
|
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
import info.nightscout.androidaps.utils.SetWarnColor
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import kotlinx.android.synthetic.main.danar_fragment.*
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
class DanaRFragment : Fragment() {
|
||||||
|
private val log = LoggerFactory.getLogger(L.PUMP)
|
||||||
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
|
||||||
|
add(disposable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val loopHandler = Handler()
|
||||||
|
private lateinit var refreshLoop: Runnable
|
||||||
|
|
||||||
|
init {
|
||||||
|
refreshLoop = Runnable {
|
||||||
|
activity?.runOnUiThread { updateGUI() }
|
||||||
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
loopHandler.removeCallbacks(refreshLoop)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.danar_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
dana_pumpstatus.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder))
|
||||||
|
|
||||||
|
danar_history.setOnClickListener { startActivity(Intent(context, DanaRHistoryActivity::class.java)) }
|
||||||
|
danar_viewprofile.setOnClickListener {
|
||||||
|
fragmentManager?.let { fragmentManager ->
|
||||||
|
val args = Bundle()
|
||||||
|
args.putLong("time", DateUtil.now())
|
||||||
|
args.putInt("mode", ProfileViewerDialog.Mode.PUMP_PROFILE.ordinal)
|
||||||
|
val pvd = ProfileViewerDialog()
|
||||||
|
pvd.arguments = args
|
||||||
|
pvd.show(fragmentManager, "ProfileViewDialog")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
danar_stats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) }
|
||||||
|
danar_user_options.setOnClickListener { startActivity(Intent(context, DanaRUserOptionsActivity::class.java)) }
|
||||||
|
danar_btconnection.setOnClickListener {
|
||||||
|
if (L.isEnabled(L.PUMP))
|
||||||
|
log.debug("Clicked connect to pump")
|
||||||
|
DanaRPump.getInstance().lastConnection = 0
|
||||||
|
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked connect to pump", null)
|
||||||
|
}
|
||||||
|
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventDanaRNewStatus::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
MainApp.bus().unregister(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
MainApp.bus().register(this)
|
||||||
|
activity?.runOnUiThread { updateGUI() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public fun onStatusEvent(c: EventPumpStatusChanged) {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
when {
|
||||||
|
c.sStatus == EventPumpStatusChanged.CONNECTING -> danar_btconnection.text = "{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"
|
||||||
|
c.sStatus == EventPumpStatusChanged.CONNECTED -> danar_btconnection.text = "{fa-bluetooth}"
|
||||||
|
c.sStatus == EventPumpStatusChanged.DISCONNECTED -> danar_btconnection.text = "{fa-bluetooth-b}"
|
||||||
|
}
|
||||||
|
if (c.textStatus() != "") {
|
||||||
|
dana_pumpstatus.text = c.textStatus()
|
||||||
|
dana_pumpstatuslayout.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
dana_pumpstatuslayout.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public fun onStatusEvent(s: EventTempBasalChange) =
|
||||||
|
activity?.runOnUiThread { updateGUI() }
|
||||||
|
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public fun onStatusEvent(s: EventExtendedBolusChange) =
|
||||||
|
activity?.runOnUiThread { updateGUI() }
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public fun onStatusEvent(s: EventQueueChanged) =
|
||||||
|
activity?.runOnUiThread { updateGUI() }
|
||||||
|
|
||||||
|
// GUI functions
|
||||||
|
internal fun updateGUI() {
|
||||||
|
val pump = DanaRPump.getInstance()
|
||||||
|
val plugin: PumpInterface = ConfigBuilderPlugin.getPlugin().activePump ?: return
|
||||||
|
if (pump.lastConnection != 0L) {
|
||||||
|
val agoMsec = System.currentTimeMillis() - pump.lastConnection
|
||||||
|
val agoMin = (agoMsec.toDouble() / 60.0 / 1000.0).toInt()
|
||||||
|
danar_lastconnection.text = DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")"
|
||||||
|
SetWarnColor.setColor(danar_lastconnection, agoMin.toDouble(), 16.0, 31.0)
|
||||||
|
}
|
||||||
|
if (pump.lastBolusTime != 0L) {
|
||||||
|
val agoMsec = System.currentTimeMillis() - pump.lastBolusTime
|
||||||
|
val agoHours = agoMsec.toDouble() / 60.0 / 60.0 / 1000.0
|
||||||
|
if (agoHours < 6)
|
||||||
|
// max 6h back
|
||||||
|
danar_lastbolus.text = DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime) + " " + MainApp.gs(R.string.formatinsulinunits, pump.lastBolusAmount)
|
||||||
|
else
|
||||||
|
danar_lastbolus.text = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
danar_dailyunits.text = MainApp.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits)
|
||||||
|
SetWarnColor.setColor(danar_dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9)
|
||||||
|
danar_basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + MainApp.gs(R.string.pump_basebasalrate, plugin.baseBasalRate)
|
||||||
|
// DanaRPlugin, DanaRKoreanPlugin
|
||||||
|
if (ConfigBuilderPlugin.getPlugin().activePump!!.isFakingTempsByExtendedBoluses) {
|
||||||
|
danar_tempbasal.text = TreatmentsPlugin.getPlugin()
|
||||||
|
.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: ""
|
||||||
|
} else {
|
||||||
|
// v2 plugin
|
||||||
|
danar_tempbasal.text = TreatmentsPlugin.getPlugin()
|
||||||
|
.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: ""
|
||||||
|
}
|
||||||
|
danar_extendedbolus.text = TreatmentsPlugin.getPlugin()
|
||||||
|
.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() ?: ""
|
||||||
|
danar_reservoir.text = MainApp.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300)
|
||||||
|
SetWarnColor.setColorInverse(danar_reservoir, pump.reservoirRemainingUnits, 50.0, 20.0)
|
||||||
|
danar_battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}"
|
||||||
|
SetWarnColor.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0)
|
||||||
|
danar_iob.text = MainApp.gs(R.string.formatinsulinunits, pump.iob)
|
||||||
|
if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
|
||||||
|
danar_firmware.text = String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode)
|
||||||
|
} else {
|
||||||
|
danar_firmware.text = "OLD"
|
||||||
|
}
|
||||||
|
danar_basalstep.text = pump.basalStep.toString()
|
||||||
|
danar_bolusstep.text = pump.bolusStep.toString()
|
||||||
|
danar_serialnumber.text = pump.serialNumber
|
||||||
|
val status = ConfigBuilderPlugin.getPlugin().commandQueue.spannedStatus()
|
||||||
|
if (status.toString() == "") {
|
||||||
|
danar_queue.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
danar_queue.visibility = View.VISIBLE
|
||||||
|
danar_queue.text = status
|
||||||
|
}
|
||||||
|
//hide user options button if not an RS pump or old firmware
|
||||||
|
// also excludes pump with model 03 because of untested error
|
||||||
|
val isKorean = DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP)
|
||||||
|
if (isKorean || danar_firmware.text === "OLD" || pump.model == 3) {
|
||||||
|
danar_user_options.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,91 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaR.dialogs;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
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.androidaps.utils.DecimalFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 10.07.2016.
|
|
||||||
*/
|
|
||||||
public class ProfileViewDialog extends DialogFragment {
|
|
||||||
private TextView noProfile;
|
|
||||||
private TextView units;
|
|
||||||
private TextView dia;
|
|
||||||
private TextView activeProfile;
|
|
||||||
private TextView ic;
|
|
||||||
private TextView isf;
|
|
||||||
private TextView basal;
|
|
||||||
private TextView target;
|
|
||||||
private ProfileGraph basalGraph;
|
|
||||||
|
|
||||||
|
|
||||||
private Button refreshButton;
|
|
||||||
|
|
||||||
public ProfileViewDialog() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View layout = inflater.inflate(R.layout.profileviewer_fragment, container, false);
|
|
||||||
|
|
||||||
noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile);
|
|
||||||
units = (TextView) layout.findViewById(R.id.profileview_units);
|
|
||||||
dia = (TextView) layout.findViewById(R.id.profileview_dia);
|
|
||||||
activeProfile = (TextView) layout.findViewById(R.id.profileview_activeprofile);
|
|
||||||
ic = (TextView) layout.findViewById(R.id.profileview_ic);
|
|
||||||
isf = (TextView) layout.findViewById(R.id.profileview_isf);
|
|
||||||
basal = (TextView) layout.findViewById(R.id.profileview_basal);
|
|
||||||
target = (TextView) layout.findViewById(R.id.profileview_target);
|
|
||||||
refreshButton = (Button) layout.findViewById(R.id.profileview_reload);
|
|
||||||
refreshButton.setVisibility(View.VISIBLE);
|
|
||||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("ProfileViewDialog", null);
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
basalGraph = (ProfileGraph) layout.findViewById(R.id.basal_graph);
|
|
||||||
setContent();
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setContent() {
|
|
||||||
ProfileStore store = ((ProfileInterface)ConfigBuilderPlugin.getPlugin().getActivePump()).getProfile();
|
|
||||||
if (store != null) {
|
|
||||||
noProfile.setVisibility(View.GONE);
|
|
||||||
Profile profile = store.getDefaultProfile();
|
|
||||||
units.setText(profile.getUnits());
|
|
||||||
dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h");
|
|
||||||
activeProfile.setText(((ProfileInterface) ConfigBuilderPlugin.getPlugin().getActivePump()).getProfileName());
|
|
||||||
ic.setText(profile.getIcList());
|
|
||||||
isf.setText(profile.getIsfList());
|
|
||||||
basal.setText(profile.getBasalList());
|
|
||||||
target.setText(profile.getTargetList());
|
|
||||||
basalGraph.show(store.getDefaultProfile());
|
|
||||||
} else {
|
|
||||||
noProfile.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.Constants;
|
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.activities.NoSplashActivity;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
|
@ -43,7 +44,7 @@ import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
|
|
||||||
public class DanaRHistoryActivity extends Activity {
|
public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
@ -96,7 +97,7 @@ public class DanaRHistoryActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.danar_historyactivity);
|
setContentView(R.layout.danar_historyactivity);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.Constants;
|
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.activities.NoSplashActivity;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
@ -31,7 +32,7 @@ import info.nightscout.androidaps.utils.NumberPicker;
|
||||||
* Created by Rumen Georgiev on 5/31/2018.
|
* Created by Rumen Georgiev on 5/31/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DanaRUserOptionsActivity extends Activity {
|
public class DanaRUserOptionsActivity extends NoSplashActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||||
|
|
||||||
Switch timeFormat;
|
Switch timeFormat;
|
||||||
|
@ -65,7 +66,7 @@ public class DanaRUserOptionsActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.danar_user_options);
|
setContentView(R.layout.danar_user_options);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaR.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 08.07.2016.
|
|
||||||
*/
|
|
||||||
public class EventDanaRNewStatus extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaR.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventDanaRNewStatus : Event()
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
@ -198,7 +199,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
danaRPump.lastSettingsRead = now;
|
danaRPump.lastSettingsRead = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
@ -201,7 +202,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
danaRPump.lastSettingsRead = now;
|
danaRPump.lastSettingsRead = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog;
|
||||||
|
@ -173,7 +174,7 @@ public class DanaRSService extends Service {
|
||||||
|
|
||||||
//deinitialize pump
|
//deinitialize pump
|
||||||
danaRPump.lastConnection = 0;
|
danaRPump.lastConnection = 0;
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
@ -211,7 +212,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
|
|
||||||
//deinitialize pump
|
//deinitialize pump
|
||||||
danaRPump.lastConnection = 0;
|
danaRPump.lastConnection = 0;
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -244,7 +245,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
|
|
||||||
loadEvents();
|
loadEvents();
|
||||||
|
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||||
|
|
|
@ -7,23 +7,30 @@ import android.view.ViewGroup
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
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.Profile
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileInterface
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import kotlinx.android.synthetic.main.close.*
|
import kotlinx.android.synthetic.main.close.*
|
||||||
import kotlinx.android.synthetic.main.profileviewer_fragment.*
|
import kotlinx.android.synthetic.main.profileviewer_fragment.*
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 17/08/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ProfileViewerDialog : DialogFragment() {
|
class ProfileViewerDialog : DialogFragment() {
|
||||||
private var time: Long = 0
|
private var time: Long = 0
|
||||||
|
|
||||||
|
enum class Mode(val i: Int) {
|
||||||
|
RUNNING_PROFILE(1),
|
||||||
|
PUMP_PROFILE(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var mode: Mode = Mode.RUNNING_PROFILE;
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?): View? {
|
savedInstanceState: Bundle?): View? {
|
||||||
// load data from bundle
|
// load data from bundle
|
||||||
(savedInstanceState ?: arguments)?.let { bundle ->
|
(savedInstanceState ?: arguments)?.let { bundle ->
|
||||||
time = bundle.getLong("time", 0)
|
time = bundle.getLong("time", 0)
|
||||||
|
mode = Mode.values()[bundle.getInt("mode", Mode.RUNNING_PROFILE.ordinal)]
|
||||||
}
|
}
|
||||||
|
|
||||||
return inflater.inflate(R.layout.profileviewer_fragment, container, false)
|
return inflater.inflate(R.layout.profileviewer_fragment, container, false)
|
||||||
|
@ -33,18 +40,38 @@ class ProfileViewerDialog : DialogFragment() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
close.setOnClickListener { dismiss() }
|
close.setOnClickListener { dismiss() }
|
||||||
|
profileview_reload.setOnClickListener {
|
||||||
|
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("ProfileViewDialog", null)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
profileview_reload.visibility = View.GONE
|
val profile: Profile?
|
||||||
profileview_datedelimiter.visibility = View.VISIBLE
|
val profileName: String?
|
||||||
profileview_datelayout.visibility = View.VISIBLE
|
val date: String?
|
||||||
|
when (mode) {
|
||||||
|
Mode.RUNNING_PROFILE -> {
|
||||||
|
profile = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.profileObject
|
||||||
|
profileName = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.customizedName
|
||||||
|
date = DateUtil.dateAndTimeString(TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.date
|
||||||
|
?: 0)
|
||||||
|
profileview_reload.visibility = View.GONE
|
||||||
|
profileview_datelayout.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
Mode.PUMP_PROFILE -> {
|
||||||
|
profile = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profile?.defaultProfile
|
||||||
|
profileName = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profileName
|
||||||
|
date = ""
|
||||||
|
profileview_reload.visibility = View.VISIBLE
|
||||||
|
profileview_datelayout.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
profileview_noprofile.visibility = View.VISIBLE
|
profileview_noprofile.visibility = View.VISIBLE
|
||||||
|
|
||||||
val profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)
|
profile?.let {
|
||||||
profileSwitch?.profileObject?.let {
|
|
||||||
profileview_units.text = it.units
|
profileview_units.text = it.units
|
||||||
profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia)
|
profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia)
|
||||||
profileview_activeprofile.text = profileSwitch.customizedName
|
profileview_activeprofile.text = profileName
|
||||||
profileview_date.text = DateUtil.dateAndTimeString(profileSwitch.date)
|
profileview_date.text = date
|
||||||
profileview_ic.text = it.icList
|
profileview_ic.text = it.icList
|
||||||
profileview_isf.text = it.isfList
|
profileview_isf.text = it.isfList
|
||||||
profileview_basal.text = it.basalList
|
profileview_basal.text = it.basalList
|
||||||
|
@ -57,18 +84,14 @@ class ProfileViewerDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
dialog.window?.let {
|
dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||||
val params = it.attributes
|
|
||||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT
|
|
||||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT
|
|
||||||
it.attributes = params
|
|
||||||
}
|
|
||||||
super.onResume()
|
super.onResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(bundle: Bundle) {
|
override fun onSaveInstanceState(bundle: Bundle) {
|
||||||
super.onSaveInstanceState(bundle)
|
super.onSaveInstanceState(bundle)
|
||||||
bundle.putLong("time", time)
|
bundle.putLong("time", time)
|
||||||
|
bundle.putInt("mode", mode.ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
|
||||||
case R.id.profileswitch_name:
|
case R.id.profileswitch_name:
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("time", ((ProfileSwitch) v.getTag()).date);
|
args.putLong("time", ((ProfileSwitch) v.getTag()).date);
|
||||||
|
args.putLong("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal());
|
||||||
ProfileViewerDialog pvd = new ProfileViewerDialog();
|
ProfileViewerDialog pvd = new ProfileViewerDialog();
|
||||||
pvd.setArguments(args);
|
pvd.setArguments(args);
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/overview_pumpstatuslayout"
|
android:id="@+id/dana_pumpstatuslayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/overview_pumpstatus"
|
android:id="@+id/dana_pumpstatus"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
|
|
|
@ -1359,7 +1359,7 @@
|
||||||
<string name="automation">Automation</string>
|
<string name="automation">Automation</string>
|
||||||
|
|
||||||
<string name="profile_total">== ∑ %1$s U</string>
|
<string name="profile_total">== ∑ %1$s U</string>
|
||||||
<string name="profile_ins_units_per_hout">U/h</string>
|
<string name="profile_ins_units_per_hour">U/h</string>
|
||||||
<string name="profile_carbs_per_unit">g/U</string>
|
<string name="profile_carbs_per_unit">g/U</string>
|
||||||
<string name="profile_per_unit">/U</string>
|
<string name="profile_per_unit">/U</string>
|
||||||
<string name="key_dexcom_lognssensorchange" translatable="false">dexcom_lognssensorchange</string>
|
<string name="key_dexcom_lognssensorchange" translatable="false">dexcom_lognssensorchange</string>
|
||||||
|
@ -1660,6 +1660,7 @@
|
||||||
<string name="insulinFromCob"><![CDATA[COB insulin: <font color=\'%1$s\'>%2$.1fg %3$.2fU</font>]]></string>
|
<string name="insulinFromCob"><![CDATA[COB insulin: <font color=\'%1$s\'>%2$.1fg %3$.2fU</font>]]></string>
|
||||||
<string name="bolusconstraintappliedwarning"><![CDATA[<font color=\'%1$s\'>Bolus constraint applied: %2$.2fU to %3$.2fU</font>]]></string>
|
<string name="bolusconstraintappliedwarning"><![CDATA[<font color=\'%1$s\'>Bolus constraint applied: %2$.2fU to %3$.2fU</font>]]></string>
|
||||||
<string name="slowabsorptiondetected"><![CDATA[<font color=\'%1$s\'>!!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be really off !!!!!</font>]]></string>
|
<string name="slowabsorptiondetected"><![CDATA[<font color=\'%1$s\'>!!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be really off !!!!!</font>]]></string>
|
||||||
|
<string name="reservoirvalue">%1$.0f / %2$d U</string>
|
||||||
|
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class AAPSMocker {
|
||||||
when(MainApp.gs(R.string.bolusdelivering)).thenReturn("Delivering 0.0U");
|
when(MainApp.gs(R.string.bolusdelivering)).thenReturn("Delivering 0.0U");
|
||||||
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
when(MainApp.gs(R.string.profile_per_unit)).thenReturn("/U");
|
||||||
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
when(MainApp.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U");
|
||||||
when(MainApp.gs(R.string.profile_ins_units_per_hout)).thenReturn("U/h");
|
when(MainApp.gs(R.string.profile_ins_units_per_hour)).thenReturn("U/h");
|
||||||
when(MainApp.gs(R.string.sms_wrongcode)).thenReturn("Wrong code. Command cancelled.");
|
when(MainApp.gs(R.string.sms_wrongcode)).thenReturn("Wrong code. Command cancelled.");
|
||||||
when(MainApp.gs(R.string.sms_iob)).thenReturn("IOB:");
|
when(MainApp.gs(R.string.sms_iob)).thenReturn("IOB:");
|
||||||
when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:");
|
when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:");
|
||||||
|
|
Loading…
Reference in a new issue