diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 8524246d02..2bcd3794be 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -464,7 +464,7 @@ public class Profile { public String getBasalList() { if (basal_v == null) 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 { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 25d9d483f2..63e06253a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -635,6 +635,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (item.getTitle().equals(MainApp.gs(R.string.danar_viewprofile))) { Bundle args = new Bundle(); args.putLong("time", DateUtil.now()); + args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal()); ProfileViewerDialog pvd = new ProfileViewerDialog(); pvd.setArguments(args); FragmentManager manager = getFragmentManager(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java deleted file mode 100644 index 30e99ebbe2..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.java +++ /dev/null @@ -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; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt new file mode 100644 index 0000000000..ae25a07cff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -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 + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java deleted file mode 100644 index 06cfc289ad..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/Dialogs/ProfileViewDialog.java +++ /dev/null @@ -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); - } - } - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java index 617f99071d..dd28c632a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java @@ -27,6 +27,7 @@ import java.util.List; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.activities.NoSplashActivity; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.DanaRHistoryRecord; 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.ToastUtils; -public class DanaRHistoryActivity extends Activity { +public class DanaRHistoryActivity extends NoSplashActivity { private static Logger log = LoggerFactory.getLogger(L.PUMP); private Handler mHandler; @@ -96,7 +97,7 @@ public class DanaRHistoryActivity extends Activity { } @Override - protected void onCreate(Bundle savedInstanceState) { + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.danar_historyactivity); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java index 6b99b2d553..d5b4fd3158 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.java @@ -17,6 +17,7 @@ import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.activities.NoSplashActivity; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; @@ -31,7 +32,7 @@ import info.nightscout.androidaps.utils.NumberPicker; * 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); Switch timeFormat; @@ -65,7 +66,7 @@ public class DanaRUserOptionsActivity extends Activity { } @Override - protected void onCreate(Bundle savedInstanceState) { + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.danar_user_options); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java deleted file mode 100644 index 9efdee1057..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.java +++ /dev/null @@ -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 { -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt new file mode 100644 index 0000000000..67b12d954c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/events/EventDanaRNewStatus.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.danaR.events + +import info.nightscout.androidaps.events.Event + +class EventDanaRNewStatus : Event() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 22d98368a6..0f46448aee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -198,7 +199,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { danaRPump.lastSettingsRead = now; } - MainApp.bus().post(new EventDanaRNewStatus()); + RxBus.INSTANCE.send(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index 749b977c2c..c61a2ab6a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -201,7 +202,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { danaRPump.lastSettingsRead = now; } - MainApp.bus().post(new EventDanaRNewStatus()); + RxBus.INSTANCE.send(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index 06a3a651ca..1fbcf70dfd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog; @@ -173,7 +174,7 @@ public class DanaRSService extends Service { //deinitialize pump danaRPump.lastConnection = 0; - MainApp.bus().post(new EventDanaRNewStatus()); + RxBus.INSTANCE.send(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); return; } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index 2d2d2526dd..235e7d3bd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate; import info.nightscout.androidaps.events.EventPumpStatusChanged; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -211,7 +212,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { //deinitialize pump danaRPump.lastConnection = 0; - MainApp.bus().post(new EventDanaRNewStatus()); + RxBus.INSTANCE.send(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); return; } else { @@ -244,7 +245,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { loadEvents(); - MainApp.bus().post(new EventDanaRNewStatus()); + RxBus.INSTANCE.send(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); NSUpload.uploadDeviceStatus(); if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt index e0c9ef1dda..0d09f60755 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/ProfileViewerDialog.kt @@ -7,23 +7,30 @@ import android.view.ViewGroup import androidx.fragment.app.DialogFragment import info.nightscout.androidaps.MainApp 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.utils.DateUtil import kotlinx.android.synthetic.main.close.* import kotlinx.android.synthetic.main.profileviewer_fragment.* -/** - * Created by adrian on 17/08/17. - */ - class ProfileViewerDialog : DialogFragment() { 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?, savedInstanceState: Bundle?): View? { // load data from bundle (savedInstanceState ?: arguments)?.let { bundle -> time = bundle.getLong("time", 0) + mode = Mode.values()[bundle.getInt("mode", Mode.RUNNING_PROFILE.ordinal)] } return inflater.inflate(R.layout.profileviewer_fragment, container, false) @@ -33,18 +40,38 @@ class ProfileViewerDialog : DialogFragment() { super.onViewCreated(view, savedInstanceState) close.setOnClickListener { dismiss() } + profileview_reload.setOnClickListener { + ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("ProfileViewDialog", null) + dismiss() + } - profileview_reload.visibility = View.GONE - profileview_datedelimiter.visibility = View.VISIBLE - profileview_datelayout.visibility = View.VISIBLE + val profile: Profile? + val profileName: String? + 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 - val profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time) - profileSwitch?.profileObject?.let { + profile?.let { profileview_units.text = it.units profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia) - profileview_activeprofile.text = profileSwitch.customizedName - profileview_date.text = DateUtil.dateAndTimeString(profileSwitch.date) + profileview_activeprofile.text = profileName + profileview_date.text = date profileview_ic.text = it.icList profileview_isf.text = it.isfList profileview_basal.text = it.basalList @@ -57,18 +84,14 @@ class ProfileViewerDialog : DialogFragment() { } override fun onResume() { - dialog.window?.let { - val params = it.attributes - params.width = ViewGroup.LayoutParams.MATCH_PARENT - params.height = ViewGroup.LayoutParams.MATCH_PARENT - it.attributes = params - } + dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) super.onResume() } override fun onSaveInstanceState(bundle: Bundle) { super.onSaveInstanceState(bundle) bundle.putLong("time", time) + bundle.putInt("mode", mode.ordinal) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java index 1113dabbee..46ee065ed7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -161,6 +161,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen case R.id.profileswitch_name: Bundle args = new Bundle(); args.putLong("time", ((ProfileSwitch) v.getTag()).date); + args.putLong("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal()); ProfileViewerDialog pvd = new ProfileViewerDialog(); pvd.setArguments(args); FragmentManager manager = getFragmentManager(); diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index f1ea8f7cd4..0636472821 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -22,7 +22,7 @@ android:orientation="vertical"> Automation == ∑ %1$s U - U/h + U/h g/U /U dexcom_lognssensorchange @@ -1660,6 +1660,7 @@ %2$.1fg %3$.2fU]]> Bolus constraint applied: %2$.2fU to %3$.2fU]]> !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be really off !!!!!]]> + %1$.0f / %2$d U %1$d day diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 1ca2566eb8..f95ecf581b 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -111,7 +111,7 @@ public class AAPSMocker { 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_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_iob)).thenReturn("IOB:"); when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:");