From e161ef6bb91167eaa92897835b89b4f0458d7b62 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 23 Oct 2021 02:07:14 +0200 Subject: [PATCH 01/15] Draft for Dash History --- omnipod-dash/build.gradle | 1 + omnipod-dash/src/main/AndroidManifest.xml | 1 + .../omnipod/dash/dagger/OmnipodDashModule.kt | 4 + .../pump/omnipod/dash/history/DashHistory.kt | 2 +- .../dash/ui/DashPodHistoryActivity.java | 350 ++++++++++++++++++ .../dash/ui/DashPodManagementActivity.kt | 4 + .../omnipod_dash_pod_history_activity.xml | 55 +++ .../layout/omnipod_dash_pod_history_item.xml | 31 ++ .../layout/omnipod_dash_pod_management.xml | 14 + omnipod-dash/src/main/res/values/strings.xml | 10 + 10 files changed, 471 insertions(+), 1 deletion(-) create mode 100644 omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java create mode 100644 omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml create mode 100644 omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml diff --git a/omnipod-dash/build.gradle b/omnipod-dash/build.gradle index b9dd868a07..b71b1a419f 100644 --- a/omnipod-dash/build.gradle +++ b/omnipod-dash/build.gradle @@ -22,6 +22,7 @@ detekt { // TODO move to `subprojects` section in global build.gradle dependencies { implementation project(':core') + implementation project(':pump-common') implementation project(':omnipod-common') implementation "androidx.room:room-runtime:$room_version" diff --git a/omnipod-dash/src/main/AndroidManifest.xml b/omnipod-dash/src/main/AndroidManifest.xml index 180d3b98ce..4f6d8178c6 100644 --- a/omnipod-dash/src/main/AndroidManifest.xml +++ b/omnipod-dash/src/main/AndroidManifest.xml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt index cbd7e42804..c565d67abc 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/dagger/OmnipodDashModule.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodD import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManagerImpl import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManagerImpl +import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.DashPodHistoryActivity import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.DashPodManagementActivity import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.activation.DashPodActivationWizardActivity @@ -21,6 +22,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.deactivati abstract class OmnipodDashModule { // ACTIVITIES + @ContributesAndroidInjector + abstract fun contributesDashPodHistoryActivity(): DashPodHistoryActivity + @ContributesAndroidInjector abstract fun contributesDashPodManagementActivity(): DashPodManagementActivity diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index f1e91651f7..6f9a9b471c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -83,7 +83,7 @@ class DashHistory @Inject constructor( fun getRecords(): Single> = dao.all().map { list -> list.map(historyMapper::entityToDomain) } - fun getRecordsAfter(time: Long): Single> = dao.allSince(time) + fun getRecordsAfter(time: Long): List = dao.allSince(time).blockingGet() fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer { val historyId = podState.activeCommand?.historyId diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java new file mode 100644 index 0000000000..ff3d300804 --- /dev/null +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java @@ -0,0 +1,350 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui; + +import android.os.Bundle; +import android.os.SystemClock; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.GregorianCalendar; +import java.util.List; + +import javax.inject.Inject; + +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; +import info.nightscout.androidaps.interfaces.Profile; +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.logging.LTag; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair; +import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; +import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil; +import info.nightscout.androidaps.plugins.pump.omnipod.dash.R; +//import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType; +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory; +//import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil; +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity; +import info.nightscout.androidaps.utils.resources.ResourceHelper; + +public class DashPodHistoryActivity extends NoSplashAppCompatActivity { + + @Inject AAPSLogger aapsLogger; + //@Inject AapsOmnipodUtil aapsOmnipodUtil; + @Inject ResourceHelper resourceHelper; + @Inject DashHistory dashHistory; + + private Spinner historyTypeSpinner; + private TextView statusView; + private RecyclerView recyclerView; + private LinearLayoutManager linearLayoutManager; + + private static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All; + private final List fullHistoryList = new ArrayList<>(); + private final List filteredHistoryList = new ArrayList<>(); + + private RecyclerViewAdapter recyclerViewAdapter; + private boolean manualChange = false; + + private List typeListFull; + + + public DashPodHistoryActivity() { + super(); + } + + + private void prepareData() { + GregorianCalendar gc = new GregorianCalendar(); + gc.add(Calendar.HOUR_OF_DAY, -24); + // + //fullHistoryList.addAll(dashHistory.getRecordsAfter(gc.getTimeInMillis())); + } + + + private void filterHistory(PumpHistoryEntryGroup group) { + + this.filteredHistoryList.clear(); + + aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size()); + + if (group == PumpHistoryEntryGroup.All) { + this.filteredHistoryList.addAll(fullHistoryList); + } /* Here you can add dedicated dao according to type of event selection in history Block + disabled because PodHistoryEntryType doesn't exist in Dash module + else { + for (HistoryRecordEntity pumpHistoryEntry : fullHistoryList) { + if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) { + this.filteredHistoryList.add(pumpHistoryEntry); + } + } + }*/ + + if (this.recyclerViewAdapter != null) { + this.recyclerViewAdapter.setHistoryList(this.filteredHistoryList); + this.recyclerViewAdapter.notifyDataSetChanged(); + } + + aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size()); + } + + + @Override + protected void onResume() { + super.onResume(); + filterHistory(selectedGroup); + setHistoryTypeSpinner(); + } + + + private void setHistoryTypeSpinner() { + this.manualChange = true; + + for (int i = 0; i < typeListFull.size(); i++) { + if (typeListFull.get(i).entryGroup == selectedGroup) { + historyTypeSpinner.setSelection(i); + break; + } + } + + SystemClock.sleep(200); + this.manualChange = false; + } + + + @Override + protected void onPause() { + super.onPause(); + } + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.omnipod_dash_pod_history_activity); + + historyTypeSpinner = findViewById(R.id.omnipod_historytype); + statusView = findViewById(R.id.omnipod_historystatus); + recyclerView = findViewById(R.id.omnipod_history_recyclerview); + recyclerView.setHasFixedSize(true); + + linearLayoutManager = new LinearLayoutManager(this); + recyclerView.setLayoutManager(linearLayoutManager); + + prepareData(); + + recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList); + recyclerView.setAdapter(recyclerViewAdapter); + + statusView.setVisibility(View.GONE); + + typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper)); + + ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, R.layout.spinner_centered, typeListFull); + historyTypeSpinner.setAdapter(spinnerAdapter); + + historyTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (manualChange) + return; + TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem(); + selectedGroup = selected.entryGroup; + filterHistory(selectedGroup); + } + + + @Override + public void onNothingSelected(AdapterView parent) { + if (manualChange) + return; + filterHistory(PumpHistoryEntryGroup.All); + } + }); + + } + + + private List getTypeList(List list) { + + ArrayList typeList = new ArrayList<>(); + + for (PumpHistoryEntryGroup pumpHistoryEntryGroup : list) { + typeList.add(new TypeList(pumpHistoryEntryGroup)); + } + + return typeList; + } + + static class TypeList { + + final PumpHistoryEntryGroup entryGroup; + final String name; + + TypeList(PumpHistoryEntryGroup entryGroup) { + this.entryGroup = entryGroup; + this.name = entryGroup.getTranslated(); + } + + @NonNull + @Override + public String toString() { + return name; + } + } + + public class RecyclerViewAdapter extends RecyclerView.Adapter { + + List historyList; + + RecyclerViewAdapter(List historyList) { + this.historyList = historyList; + } + + + void setHistoryList(List historyList) { + this.historyList = historyList; + //Collections.sort(this.historyList); + } + + + @NonNull + @Override + public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + View v = + LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.omnipod_dash_pod_history_item, // + viewGroup, false); + return new HistoryViewHolder(v); + } + + + @Override + public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) { + HistoryRecordEntity record = historyList.get(position); + + if (record != null) { + holder.timeView.setText(DateTimeUtil.toStringFromTimeInMillis(record.getDate())); + //holder.typeView.setText(PodHistoryEntryType.getByCode(record.getPodEntryTypeCode()).getResourceId()); + setValue(record, holder.valueView); + } + } + + + private void setValue(HistoryRecordEntity historyEntry, TextView valueView) { + valueView.setText(historyEntry.toString()); + /* Here you define which information to show in history according to historyEntry Type + if (historyEntry.isSuccess()) { + PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); + switch (entryType) { + + case SET_TEMPORARY_BASAL: + case SPLIT_TEMPORARY_BASAL: { + TempBasalPair tempBasalPair = aapsOmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); + } + break; + + case INSERT_CANNULA: + case SET_BASAL_SCHEDULE: { + if (historyEntry.getData() != null) { + setProfileValue(historyEntry.getData(), valueView); + } + } + break; + + case SET_BOLUS: { + if (historyEntry.getData().contains(";")) { + String[] splitVal = historyEntry.getData().split(";"); + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); + } else { + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value, Double.valueOf(historyEntry.getData()))); + } + } + break; + + case PLAY_TEST_BEEP: { + if (historyEntry.getData() != null) { + valueView.setText(historyEntry.getData()); + } + } + break; + case GET_POD_STATUS: + case GET_POD_INFO: + case SET_TIME: + case INITIALIZE_POD: + case CANCEL_TEMPORARY_BASAL_BY_DRIVER: + case CANCEL_TEMPORARY_BASAL: + case CONFIGURE_ALERTS: + case CANCEL_BOLUS: + case DEACTIVATE_POD: + case DISCARD_POD: + case ACKNOWLEDGE_ALERTS: + case SUSPEND_DELIVERY: + case RESUME_DELIVERY: + case UNKNOWN_ENTRY_TYPE: + default: + valueView.setText(""); + break; + + } + } else { + valueView.setText(historyEntry.toString()); + } + */ + } + + private void setProfileValue(String data, TextView valueView) { + aapsLogger.debug(LTag.PUMP, "Profile json:\n" + data); + valueView.setText("Profile informations from history"); + /* + try { + Profile.ProfileValue[] profileValuesArray = aapsOmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); + valueView.setText(ProfileUtil.INSTANCE.getBasalProfilesDisplayable(profileValuesArray, PumpType.OMNIPOD_EROS)); + } catch (Exception e) { + aapsLogger.error(LTag.PUMP, "Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); + valueView.setText(""); + } + */ + } + + + @Override + public int getItemCount() { + return historyList.size(); + } + + + @Override + public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + } + + + class HistoryViewHolder extends RecyclerView.ViewHolder { + + final TextView timeView; + final TextView typeView; + final TextView valueView; + + HistoryViewHolder(View itemView) { + super(itemView); + timeView = itemView.findViewById(R.id.omnipod_history_time); + typeView = itemView.findViewById(R.id.omnipod_history_source); + valueView = itemView.findViewById(R.id.omnipod_history_description); + } + } + } + +} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt index 9ac1a1ec3f..c2bb6240ea 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt @@ -96,6 +96,10 @@ class DashPodManagementActivity : NoSplashAppCompatActivity() { } ) } + + binding.buttonPodHistory.setOnClickListener { + startActivity(Intent(this, DashPodHistoryActivity::class.java)) + } } override fun onResume() { diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml new file mode 100644 index 0000000000..be8a49d07a --- /dev/null +++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_activity.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml new file mode 100644 index 0000000000..93b4bee75a --- /dev/null +++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_history_item.xml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml index 4ea9533d45..c9d97e870c 100644 --- a/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml +++ b/omnipod-dash/src/main/res/layout/omnipod_dash_pod_management.xml @@ -111,6 +111,20 @@ app:layout_constraintRight_toLeftOf="@+id/Actions_Col_1_Row_2_vertical_guideline" app:layout_constraintTop_toTopOf="parent" /> + + AAPS.OmnipodDash.pod_state + + Pod History + Description + Source + Date + Type: + %1$.2f U + %1$.2f U, CH=%2$.1f g + Rate: %1$.2f U, duration: %2$d minutes + Bluetooth Status Bluetooth Address From fdcf75c1d9ad8b56d3a960d917eb18bbfb3a4286 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 10:02:02 +0200 Subject: [PATCH 02/15] move to Kotlin --- omnipod-dash/build.gradle | 1 + .../pump/omnipod/dash/history/DashHistory.kt | 3 +- .../dash/ui/DashPodHistoryActivity.java | 350 ------------------ .../omnipod/dash/ui/DashPodHistoryActivity.kt | 280 ++++++++++++++ 4 files changed, 283 insertions(+), 351 deletions(-) delete mode 100644 omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java create mode 100644 omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt diff --git a/omnipod-dash/build.gradle b/omnipod-dash/build.gradle index b71b1a419f..7ed945c1aa 100644 --- a/omnipod-dash/build.gradle +++ b/omnipod-dash/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation "androidx.room:room-runtime:$room_version" implementation "androidx.room:room-rxjava2:$room_version" + implementation project(path: ':pump-common') kapt "androidx.room:room-compiler:$room_version" implementation 'com.github.guepardoapps:kulid:2.0.0.0' } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index 6f9a9b471c..ab29bedbb9 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -83,7 +83,8 @@ class DashHistory @Inject constructor( fun getRecords(): Single> = dao.all().map { list -> list.map(historyMapper::entityToDomain) } - fun getRecordsAfter(time: Long): List = dao.allSince(time).blockingGet() + fun getRecordsAfter(time: Long): Single> = + dao.allSince(time) fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer { val historyId = podState.activeCommand?.historyId diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java deleted file mode 100644 index ff3d300804..0000000000 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.java +++ /dev/null @@ -1,350 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui; - -import android.os.Bundle; -import android.os.SystemClock; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.GregorianCalendar; -import java.util.List; - -import javax.inject.Inject; - -import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; -import info.nightscout.androidaps.interfaces.Profile; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair; -import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; -import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.dash.R; -//import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType; -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory; -//import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity; -import info.nightscout.androidaps.utils.resources.ResourceHelper; - -public class DashPodHistoryActivity extends NoSplashAppCompatActivity { - - @Inject AAPSLogger aapsLogger; - //@Inject AapsOmnipodUtil aapsOmnipodUtil; - @Inject ResourceHelper resourceHelper; - @Inject DashHistory dashHistory; - - private Spinner historyTypeSpinner; - private TextView statusView; - private RecyclerView recyclerView; - private LinearLayoutManager linearLayoutManager; - - private static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All; - private final List fullHistoryList = new ArrayList<>(); - private final List filteredHistoryList = new ArrayList<>(); - - private RecyclerViewAdapter recyclerViewAdapter; - private boolean manualChange = false; - - private List typeListFull; - - - public DashPodHistoryActivity() { - super(); - } - - - private void prepareData() { - GregorianCalendar gc = new GregorianCalendar(); - gc.add(Calendar.HOUR_OF_DAY, -24); - // - //fullHistoryList.addAll(dashHistory.getRecordsAfter(gc.getTimeInMillis())); - } - - - private void filterHistory(PumpHistoryEntryGroup group) { - - this.filteredHistoryList.clear(); - - aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size()); - - if (group == PumpHistoryEntryGroup.All) { - this.filteredHistoryList.addAll(fullHistoryList); - } /* Here you can add dedicated dao according to type of event selection in history Block - disabled because PodHistoryEntryType doesn't exist in Dash module - else { - for (HistoryRecordEntity pumpHistoryEntry : fullHistoryList) { - if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) { - this.filteredHistoryList.add(pumpHistoryEntry); - } - } - }*/ - - if (this.recyclerViewAdapter != null) { - this.recyclerViewAdapter.setHistoryList(this.filteredHistoryList); - this.recyclerViewAdapter.notifyDataSetChanged(); - } - - aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size()); - } - - - @Override - protected void onResume() { - super.onResume(); - filterHistory(selectedGroup); - setHistoryTypeSpinner(); - } - - - private void setHistoryTypeSpinner() { - this.manualChange = true; - - for (int i = 0; i < typeListFull.size(); i++) { - if (typeListFull.get(i).entryGroup == selectedGroup) { - historyTypeSpinner.setSelection(i); - break; - } - } - - SystemClock.sleep(200); - this.manualChange = false; - } - - - @Override - protected void onPause() { - super.onPause(); - } - - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.omnipod_dash_pod_history_activity); - - historyTypeSpinner = findViewById(R.id.omnipod_historytype); - statusView = findViewById(R.id.omnipod_historystatus); - recyclerView = findViewById(R.id.omnipod_history_recyclerview); - recyclerView.setHasFixedSize(true); - - linearLayoutManager = new LinearLayoutManager(this); - recyclerView.setLayoutManager(linearLayoutManager); - - prepareData(); - - recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList); - recyclerView.setAdapter(recyclerViewAdapter); - - statusView.setVisibility(View.GONE); - - typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper)); - - ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, R.layout.spinner_centered, typeListFull); - historyTypeSpinner.setAdapter(spinnerAdapter); - - historyTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - if (manualChange) - return; - TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem(); - selectedGroup = selected.entryGroup; - filterHistory(selectedGroup); - } - - - @Override - public void onNothingSelected(AdapterView parent) { - if (manualChange) - return; - filterHistory(PumpHistoryEntryGroup.All); - } - }); - - } - - - private List getTypeList(List list) { - - ArrayList typeList = new ArrayList<>(); - - for (PumpHistoryEntryGroup pumpHistoryEntryGroup : list) { - typeList.add(new TypeList(pumpHistoryEntryGroup)); - } - - return typeList; - } - - static class TypeList { - - final PumpHistoryEntryGroup entryGroup; - final String name; - - TypeList(PumpHistoryEntryGroup entryGroup) { - this.entryGroup = entryGroup; - this.name = entryGroup.getTranslated(); - } - - @NonNull - @Override - public String toString() { - return name; - } - } - - public class RecyclerViewAdapter extends RecyclerView.Adapter { - - List historyList; - - RecyclerViewAdapter(List historyList) { - this.historyList = historyList; - } - - - void setHistoryList(List historyList) { - this.historyList = historyList; - //Collections.sort(this.historyList); - } - - - @NonNull - @Override - public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - View v = - LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.omnipod_dash_pod_history_item, // - viewGroup, false); - return new HistoryViewHolder(v); - } - - - @Override - public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) { - HistoryRecordEntity record = historyList.get(position); - - if (record != null) { - holder.timeView.setText(DateTimeUtil.toStringFromTimeInMillis(record.getDate())); - //holder.typeView.setText(PodHistoryEntryType.getByCode(record.getPodEntryTypeCode()).getResourceId()); - setValue(record, holder.valueView); - } - } - - - private void setValue(HistoryRecordEntity historyEntry, TextView valueView) { - valueView.setText(historyEntry.toString()); - /* Here you define which information to show in history according to historyEntry Type - if (historyEntry.isSuccess()) { - PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); - switch (entryType) { - - case SET_TEMPORARY_BASAL: - case SPLIT_TEMPORARY_BASAL: { - TempBasalPair tempBasalPair = aapsOmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); - } - break; - - case INSERT_CANNULA: - case SET_BASAL_SCHEDULE: { - if (historyEntry.getData() != null) { - setProfileValue(historyEntry.getData(), valueView); - } - } - break; - - case SET_BOLUS: { - if (historyEntry.getData().contains(";")) { - String[] splitVal = historyEntry.getData().split(";"); - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); - } else { - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value, Double.valueOf(historyEntry.getData()))); - } - } - break; - - case PLAY_TEST_BEEP: { - if (historyEntry.getData() != null) { - valueView.setText(historyEntry.getData()); - } - } - break; - case GET_POD_STATUS: - case GET_POD_INFO: - case SET_TIME: - case INITIALIZE_POD: - case CANCEL_TEMPORARY_BASAL_BY_DRIVER: - case CANCEL_TEMPORARY_BASAL: - case CONFIGURE_ALERTS: - case CANCEL_BOLUS: - case DEACTIVATE_POD: - case DISCARD_POD: - case ACKNOWLEDGE_ALERTS: - case SUSPEND_DELIVERY: - case RESUME_DELIVERY: - case UNKNOWN_ENTRY_TYPE: - default: - valueView.setText(""); - break; - - } - } else { - valueView.setText(historyEntry.toString()); - } - */ - } - - private void setProfileValue(String data, TextView valueView) { - aapsLogger.debug(LTag.PUMP, "Profile json:\n" + data); - valueView.setText("Profile informations from history"); - /* - try { - Profile.ProfileValue[] profileValuesArray = aapsOmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); - valueView.setText(ProfileUtil.INSTANCE.getBasalProfilesDisplayable(profileValuesArray, PumpType.OMNIPOD_EROS)); - } catch (Exception e) { - aapsLogger.error(LTag.PUMP, "Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); - valueView.setText(""); - } - */ - } - - - @Override - public int getItemCount() { - return historyList.size(); - } - - - @Override - public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { - super.onAttachedToRecyclerView(recyclerView); - } - - - class HistoryViewHolder extends RecyclerView.ViewHolder { - - final TextView timeView; - final TextView typeView; - final TextView valueView; - - HistoryViewHolder(View itemView) { - super(itemView); - timeView = itemView.findViewById(R.id.omnipod_history_time); - typeView = itemView.findViewById(R.id.omnipod_history_source); - valueView = itemView.findViewById(R.id.omnipod_history_description); - } - } - } - -} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt new file mode 100644 index 0000000000..ee5d1c60be --- /dev/null +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -0,0 +1,280 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui +//import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType; +//import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil; +import android.os.Bundle +import android.os.SystemClock +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import android.widget.Spinner +import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup +import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil +import info.nightscout.androidaps.plugins.pump.omnipod.dash.R +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.rx.AapsSchedulers +import java.util.* +import javax.inject.Inject + +class DashPodHistoryActivity : NoSplashAppCompatActivity() { + + @Inject lateinit var aapsLogger: AAPSLogger + + //@Inject AapsOmnipodUtil aapsOmnipodUtil; + //@Inject lateinit var resourceHelper: ResourceHelper + + @Inject lateinit var dashHistory: DashHistory + @Inject lateinit var aapsSchedulers: AapsSchedulers + + private var historyTypeSpinner: Spinner? = null + private var statusView: TextView? = null + private var recyclerView: RecyclerView? = null + private var linearLayoutManager: LinearLayoutManager? = null + private val fullHistoryList: List = ArrayList() + private val filteredHistoryList: MutableList = ArrayList() + private var recyclerViewAdapter: RecyclerViewAdapter? = null + private var manualChange = false + private var typeListFull: List? = null + + private fun prepareData() { + val gc = GregorianCalendar() + gc.add(Calendar.HOUR_OF_DAY, -24) + + // + //fullHistoryList.addAll(dashHistory.getRecordsAfter(gc.getTimeInMillis())); + } + + private fun filterHistory(group: PumpHistoryEntryGroup) { + filteredHistoryList.clear() + aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size) + if (group === PumpHistoryEntryGroup.All) { + filteredHistoryList.addAll(fullHistoryList) + } /* Here you can add dedicated dao according to type of event selection in history Block + disabled because PodHistoryEntryType doesn't exist in Dash module + else { + for (HistoryRecordEntity pumpHistoryEntry : fullHistoryList) { + if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) { + this.filteredHistoryList.add(pumpHistoryEntry); + } + } + }*/ + if (recyclerViewAdapter != null) { + recyclerViewAdapter!!.historyList = filteredHistoryList + recyclerViewAdapter!!.notifyDataSetChanged() + } + aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size) + } + + override fun onResume() { + super.onResume() + filterHistory(selectedGroup) + setHistoryTypeSpinner() + } + + private fun setHistoryTypeSpinner() { + manualChange = true + for (i in typeListFull!!.indices) { + if (typeListFull!![i].entryGroup === selectedGroup) { + historyTypeSpinner!!.setSelection(i) + break + } + } + SystemClock.sleep(200) + manualChange = false + } + + override fun onPause() { + super.onPause() + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.omnipod_dash_pod_history_activity) + historyTypeSpinner = findViewById(R.id.omnipod_historytype) + statusView = findViewById(R.id.omnipod_historystatus) + recyclerView = findViewById(R.id.omnipod_history_recyclerview) + recyclerView!!.setHasFixedSize(true) + linearLayoutManager = LinearLayoutManager(this) + recyclerView!!.layoutManager = linearLayoutManager + prepareData() + recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) + recyclerView!!.adapter = recyclerViewAdapter + statusView!!.setVisibility(View.GONE) + typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper))!! + val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!) + historyTypeSpinner!!.setAdapter(spinnerAdapter) + historyTypeSpinner!!.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) { + if (manualChange) return + val selected = historyTypeSpinner!!.getSelectedItem() as TypeList + selectedGroup = selected.entryGroup + filterHistory(selectedGroup) + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + if (manualChange) return + filterHistory(PumpHistoryEntryGroup.All) + } + }) + } + + private fun getTypeList(list: List): List { + val typeList = ArrayList() + for (pumpHistoryEntryGroup in list) { + typeList.add(TypeList(pumpHistoryEntryGroup)) + } + return typeList + } + + internal class TypeList(entryGroup: PumpHistoryEntryGroup) { + + val entryGroup: PumpHistoryEntryGroup + val name: String + override fun toString(): String { + return name + } + + init { + this.entryGroup = entryGroup + name = entryGroup.translated ?: "XXX TODO" + } + } + + inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() { + + var historyList: List + + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder { + val v: View = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.omnipod_dash_pod_history_item, // + viewGroup, false + ) + return HistoryViewHolder(v) + } + + override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { + val record: HistoryRecordEntity = historyList[position] + if (record != null) { + holder.timeView.setText(DateTimeUtil.toStringFromTimeInMillis(record.date)) + //holder.typeView.setText(PodHistoryEntryType.getByCode(record.getPodEntryTypeCode()).getResourceId()); + setValue(record, holder.valueView) + } + } + + private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { + valueView.setText(historyEntry.toString()) + /* Here you define which information to show in history according to historyEntry Type + if (historyEntry.isSuccess()) { + PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); + switch (entryType) { + + case SET_TEMPORARY_BASAL: + case SPLIT_TEMPORARY_BASAL: { + TempBasalPair tempBasalPair = aapsOmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); + } + break; + + case INSERT_CANNULA: + case SET_BASAL_SCHEDULE: { + if (historyEntry.getData() != null) { + setProfileValue(historyEntry.getData(), valueView); + } + } + break; + + case SET_BOLUS: { + if (historyEntry.getData().contains(";")) { + String[] splitVal = historyEntry.getData().split(";"); + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); + } else { + valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value, Double.valueOf(historyEntry.getData()))); + } + } + break; + + case PLAY_TEST_BEEP: { + if (historyEntry.getData() != null) { + valueView.setText(historyEntry.getData()); + } + } + break; + case GET_POD_STATUS: + case GET_POD_INFO: + case SET_TIME: + case INITIALIZE_POD: + case CANCEL_TEMPORARY_BASAL_BY_DRIVER: + case CANCEL_TEMPORARY_BASAL: + case CONFIGURE_ALERTS: + case CANCEL_BOLUS: + case DEACTIVATE_POD: + case DISCARD_POD: + case ACKNOWLEDGE_ALERTS: + case SUSPEND_DELIVERY: + case RESUME_DELIVERY: + case UNKNOWN_ENTRY_TYPE: + default: + valueView.setText(""); + break; + + } + } else { + valueView.setText(historyEntry.toString()); + } + */ + } + + private fun setProfileValue(data: String, valueView: TextView) { + aapsLogger.debug(LTag.PUMP, "Profile json:\n$data") + valueView.setText("Profile informations from history") + /* + try { + Profile.ProfileValue[] profileValuesArray = aapsOmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); + valueView.setText(ProfileUtil.INSTANCE.getBasalProfilesDisplayable(profileValuesArray, PumpType.OMNIPOD_EROS)); + } catch (Exception e) { + aapsLogger.error(LTag.PUMP, "Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); + valueView.setText(""); + } + */ + } + + override fun getItemCount(): Int { + return historyList.size + } + + override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { + super.onAttachedToRecyclerView(recyclerView) + } + + inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + + val timeView: TextView + val typeView: TextView + val valueView: TextView + + init { + timeView = itemView.findViewById(R.id.omnipod_history_time) + typeView = itemView.findViewById(R.id.omnipod_history_source) + valueView = itemView.findViewById(R.id.omnipod_history_description) + } + } + + init { + this.historyList = historyList + } + } + + companion object { + + private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All + } +} \ No newline at end of file From 269e94a8b5f1f9c18521dbbf82bae46c1a828530 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:01:43 +0200 Subject: [PATCH 03/15] get history --- .../pump/omnipod/dash/ui/DashPodHistoryActivity.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index ee5d1c60be..390b183f90 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -39,7 +39,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private var statusView: TextView? = null private var recyclerView: RecyclerView? = null private var linearLayoutManager: LinearLayoutManager? = null - private val fullHistoryList: List = ArrayList() + private val fullHistoryList: MutableList = ArrayList() private val filteredHistoryList: MutableList = ArrayList() private var recyclerViewAdapter: RecyclerViewAdapter? = null private var manualChange = false @@ -47,10 +47,14 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private fun prepareData() { val gc = GregorianCalendar() - gc.add(Calendar.HOUR_OF_DAY, -24) + // TODO: limit to the last 3 days. Using 30days here for testing + gc.add(Calendar.DAY_OF_MONTH, -30) - // - //fullHistoryList.addAll(dashHistory.getRecordsAfter(gc.getTimeInMillis())); + val since = gc.timeInMillis + val records = dashHistory.getRecordsAfter(since) + .subscribeOn(aapsSchedulers.io) + .blockingGet() + fullHistoryList.addAll(records) } private fun filterHistory(group: PumpHistoryEntryGroup) { From d1b2fa207cf42bbe557b139fa275cbac681be335 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:06:39 +0200 Subject: [PATCH 04/15] kotlin fixes --- .../omnipod/dash/ui/DashPodHistoryActivity.kt | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 390b183f90..4c9eb3bc1f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -71,9 +71,9 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } } }*/ - if (recyclerViewAdapter != null) { - recyclerViewAdapter!!.historyList = filteredHistoryList - recyclerViewAdapter!!.notifyDataSetChanged() + recyclerViewAdapter?.let { + it.historyList = filteredHistoryList + it.notifyDataSetChanged() } aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size) } @@ -112,7 +112,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { prepareData() recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) recyclerView!!.adapter = recyclerViewAdapter - statusView!!.setVisibility(View.GONE) + statusView!!.visibility = View.GONE typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper))!! val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!) historyTypeSpinner!!.setAdapter(spinnerAdapter) @@ -141,21 +141,18 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { internal class TypeList(entryGroup: PumpHistoryEntryGroup) { - val entryGroup: PumpHistoryEntryGroup - val name: String + val entryGroup: PumpHistoryEntryGroup = entryGroup + val name: String = entryGroup.translated ?: "XXX TODO" + override fun toString(): String { return name } - init { - this.entryGroup = entryGroup - name = entryGroup.translated ?: "XXX TODO" - } } inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() { - var historyList: List + var historyList: List = historyList override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder { val v: View = LayoutInflater.from(viewGroup.getContext()).inflate( @@ -175,7 +172,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { - valueView.setText(historyEntry.toString()) + valueView.text = historyEntry.toString() /* Here you define which information to show in history according to historyEntry Type if (historyEntry.isSuccess()) { PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); @@ -272,9 +269,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } } - init { - this.historyList = historyList - } } companion object { From 80de823bfafaaa4268605fceaca9388ef1e42019 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:12:25 +0200 Subject: [PATCH 05/15] kotlin --- .../pump/omnipod/dash/ui/DashPodHistoryActivity.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 4c9eb3bc1f..cf48b8605f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -257,16 +257,9 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - - val timeView: TextView - val typeView: TextView - val valueView: TextView - - init { - timeView = itemView.findViewById(R.id.omnipod_history_time) - typeView = itemView.findViewById(R.id.omnipod_history_source) - valueView = itemView.findViewById(R.id.omnipod_history_description) - } + val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time) + val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) + val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description) } } From 89a6a2d2abe02bdef8681ce730f36e2ccae941d6 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:30:24 +0200 Subject: [PATCH 06/15] kotlin --- .../omnipod/dash/ui/DashPodHistoryActivity.kt | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index cf48b8605f..0b7cdaeecc 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -102,33 +102,41 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.omnipod_dash_pod_history_activity) - historyTypeSpinner = findViewById(R.id.omnipod_historytype) - statusView = findViewById(R.id.omnipod_historystatus) - recyclerView = findViewById(R.id.omnipod_history_recyclerview) - recyclerView!!.setHasFixedSize(true) - linearLayoutManager = LinearLayoutManager(this) - recyclerView!!.layoutManager = linearLayoutManager - prepareData() - recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) - recyclerView!!.adapter = recyclerViewAdapter - statusView!!.visibility = View.GONE - typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper))!! - val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!) - historyTypeSpinner!!.setAdapter(spinnerAdapter) - historyTypeSpinner!!.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener { - override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) { - if (manualChange) return - val selected = historyTypeSpinner!!.getSelectedItem() as TypeList - selectedGroup = selected.entryGroup - filterHistory(selectedGroup) - } - override fun onNothingSelected(parent: AdapterView<*>?) { - if (manualChange) return - filterHistory(PumpHistoryEntryGroup.All) + setContentView(R.layout.omnipod_dash_pod_history_activity) + prepareData() + + recyclerView = findViewById(R.id.omnipod_history_recyclerview) + recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) + linearLayoutManager = LinearLayoutManager(this) + recyclerView?.run { + setHasFixedSize(true) + layoutManager = linearLayoutManager + adapter = recyclerViewAdapter + } + + statusView = findViewById(R.id.omnipod_historystatus) + statusView?.run { visibility = View.GONE } + + historyTypeSpinner = findViewById(R.id.omnipod_historytype) + typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper)) + val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!) + historyTypeSpinner?.run { + adapter = spinnerAdapter + onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) { + if (manualChange) return + val selected = selectedItem as TypeList + selectedGroup = selected.entryGroup + filterHistory(selectedGroup) + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + if (manualChange) return + filterHistory(PumpHistoryEntryGroup.All) + } } - }) + } } private fun getTypeList(list: List): List { @@ -155,8 +163,8 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { var historyList: List = historyList override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder { - val v: View = LayoutInflater.from(viewGroup.getContext()).inflate( - R.layout.omnipod_dash_pod_history_item, // + val v: View = LayoutInflater.from(viewGroup.context).inflate( + R.layout.omnipod_dash_pod_history_item, viewGroup, false ) return HistoryViewHolder(v) @@ -173,6 +181,8 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { valueView.text = historyEntry.toString() + //val entryType = historyEntry.commandType + /* Here you define which information to show in history according to historyEntry Type if (historyEntry.isSuccess()) { PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); @@ -236,7 +246,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private fun setProfileValue(data: String, valueView: TextView) { aapsLogger.debug(LTag.PUMP, "Profile json:\n$data") - valueView.setText("Profile informations from history") + valueView.text = "Profile informations from history" /* try { Profile.ProfileValue[] profileValuesArray = aapsOmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); From abfd71a4b8e86d728db8c1cb413c07a001a937d7 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:33:49 +0200 Subject: [PATCH 07/15] ktlintFormat --- .../omnipod/dash/ui/DashPodHistoryActivity.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 0b7cdaeecc..e6c8c7da7f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui -//import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType; -//import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil; +// import info.nightscout.androidaps.plugins.pump.omnipod.dash.definition.PodHistoryEntryType; +// import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.AapsOmnipodUtil; import android.os.Bundle import android.os.SystemClock import android.view.LayoutInflater @@ -20,7 +20,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity -import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import java.util.* import javax.inject.Inject @@ -29,8 +28,8 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { @Inject lateinit var aapsLogger: AAPSLogger - //@Inject AapsOmnipodUtil aapsOmnipodUtil; - //@Inject lateinit var resourceHelper: ResourceHelper + // @Inject AapsOmnipodUtil aapsOmnipodUtil; + // @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var dashHistory: DashHistory @Inject lateinit var aapsSchedulers: AapsSchedulers @@ -155,7 +154,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { override fun toString(): String { return name } - } inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() { @@ -172,16 +170,19 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { val record: HistoryRecordEntity = historyList[position] - if (record != null) { - holder.timeView.setText(DateTimeUtil.toStringFromTimeInMillis(record.date)) - //holder.typeView.setText(PodHistoryEntryType.getByCode(record.getPodEntryTypeCode()).getResourceId()); + record?.let { + holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(record.date) setValue(record, holder.valueView) + setType(record, holder.typeView) } } + private fun setType(record: HistoryRecordEntity, typeView: TextView) { + } + private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { valueView.text = historyEntry.toString() - //val entryType = historyEntry.commandType + // val entryType = historyEntry.commandType /* Here you define which information to show in history according to historyEntry Type if (historyEntry.isSuccess()) { @@ -271,11 +272,10 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description) } - } companion object { private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All } -} \ No newline at end of file +} From 6cd06edd29369e9681e36bdf065d9d13c7dfdb27 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 11:51:36 +0200 Subject: [PATCH 08/15] display the correct time. display type --- .../pump/omnipod/dash/history/DashHistory.kt | 2 +- .../pump/omnipod/dash/history/data/ResultStates.kt | 2 +- .../dash/history/database/HistoryRecordEntity.kt | 13 ++++++++++++- .../pump/omnipod/dash/ui/DashPodHistoryActivity.kt | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index ab29bedbb9..9a79f5028d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -49,7 +49,7 @@ class DashHistory @Inject constructor( @Suppress("ReturnCount") fun createRecord( commandType: OmnipodCommandType, - date: Long = System.currentTimeMillis(), + date: Long = currentTimeMillis(), initialResult: InitialResult = InitialResult.NOT_SENT, tempBasalRecord: TempBasalRecord? = null, bolusRecord: BolusRecord? = null, diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt index ee92d9ed78..676ba33168 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/ResultStates.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data enum class InitialResult { - NOT_SENT, FAILURE_SENDING, UNCONFIRMED, SENT + NOT_SENT, FAILURE_SENDING, SENT } enum class ResolvedResult { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt index 18ff9c14d2..d4a613a75b 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt @@ -20,4 +20,15 @@ data class HistoryRecordEntity( @Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?, val resolvedResult: ResolvedResult?, val resolvedAt: Long? -) +) { + fun displayTimestamp(): Long { + resolvedAt?.let { + return it + } + return date + } + + fun isSuccess(): Boolean { + return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS + } +} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index e6c8c7da7f..72622ae4a7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -171,13 +171,14 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { val record: HistoryRecordEntity = historyList[position] record?.let { - holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(record.date) + holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(record.displayTimestamp()) setValue(record, holder.valueView) setType(record, holder.typeView) } } private fun setType(record: HistoryRecordEntity, typeView: TextView) { + typeView.text = resourceHelper.gs(record.commandType.resourceId) } private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { From 7a608c8146e548a8601c507588f3aadf17c92db4 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 22:49:52 +0200 Subject: [PATCH 09/15] display history --- .../common/definition/OmnipodCommandType.java | 36 ---- .../common/definition/OmnipodCommandType.kt | 26 +++ .../history/database/HistoryRecordEntity.kt | 1 + .../omnipod/dash/ui/DashPodHistoryActivity.kt | 166 ++++++++++-------- omnipod-dash/src/main/res/values/strings.xml | 6 + 5 files changed, 123 insertions(+), 112 deletions(-) delete mode 100644 omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java create mode 100644 omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java deleted file mode 100644 index f76e6a0471..0000000000 --- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.java +++ /dev/null @@ -1,36 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.common.definition; - -import info.nightscout.androidaps.plugins.pump.omnipod.common.R; - -/** - * Created by andy on 4.8.2019 - */ -public enum OmnipodCommandType { - INITIALIZE_POD(R.string.omnipod_common_cmd_initialize_pod), // First step of Pod activation - INSERT_CANNULA(R.string.omnipod_common_cmd_insert_cannula), // Second step of Pod activation - DEACTIVATE_POD(R.string.omnipod_common_cmd_deactivate_pod), // - SET_BASAL_PROFILE(R.string.omnipod_common_cmd_set_basal_schedule), // - SET_BOLUS(R.string.omnipod_common_cmd_set_bolus), // - CANCEL_BOLUS(R.string.omnipod_common_cmd_cancel_bolus), // - SET_TEMPORARY_BASAL(R.string.omnipod_common_cmd_set_tbr), // - CANCEL_TEMPORARY_BASAL(R.string.omnipod_common_cmd_cancel_tbr_by_driver), // - DISCARD_POD(R.string.omnipod_common_cmd_discard_pod), // - GET_POD_STATUS(R.string.omnipod_common_cmd_get_pod_status), // - SET_TIME(R.string.omnipod_common_cmd_set_time), // - CONFIGURE_ALERTS(R.string.omnipod_common_cmd_configure_alerts), // - ACKNOWLEDGE_ALERTS(R.string.omnipod_common_cmd_silence_alerts), // - READ_POD_PULSE_LOG(R.string.omnipod_common_cmd_read_pulse_log), // - SUSPEND_DELIVERY(R.string.omnipod_common_cmd_suspend_delivery), - RESUME_DELIVERY(R.string.omnipod_common_cmd_resume_delivery), - PLAY_TEST_BEEP(R.string.omnipod_common_cmd_play_test_beep); - - private final int resourceId; - - OmnipodCommandType(int resourceId) { - this.resourceId = resourceId; - } - - public int getResourceId() { - return resourceId; - } -} diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt new file mode 100644 index 0000000000..333faef1e9 --- /dev/null +++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/definition/OmnipodCommandType.kt @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.common.definition + +import info.nightscout.androidaps.plugins.pump.omnipod.common.R + +/** + * Created by andy on 4.8.2019 + */ +enum class OmnipodCommandType(val resourceId: Int) { + + INITIALIZE_POD(R.string.omnipod_common_cmd_initialize_pod), // First step of Pod activation + INSERT_CANNULA(R.string.omnipod_common_cmd_insert_cannula), // Second step of Pod activation + DEACTIVATE_POD(R.string.omnipod_common_cmd_deactivate_pod), // + SET_BASAL_PROFILE(R.string.omnipod_common_cmd_set_basal_schedule), // + SET_BOLUS(R.string.omnipod_common_cmd_set_bolus), // + CANCEL_BOLUS(R.string.omnipod_common_cmd_cancel_bolus), // + SET_TEMPORARY_BASAL(R.string.omnipod_common_cmd_set_tbr), // + CANCEL_TEMPORARY_BASAL(R.string.omnipod_common_cmd_cancel_tbr_by_driver), // + DISCARD_POD(R.string.omnipod_common_cmd_discard_pod), // + GET_POD_STATUS(R.string.omnipod_common_cmd_get_pod_status), // + SET_TIME(R.string.omnipod_common_cmd_set_time), // + CONFIGURE_ALERTS(R.string.omnipod_common_cmd_configure_alerts), // + ACKNOWLEDGE_ALERTS(R.string.omnipod_common_cmd_silence_alerts), // + READ_POD_PULSE_LOG(R.string.omnipod_common_cmd_read_pulse_log), // + SUSPEND_DELIVERY(R.string.omnipod_common_cmd_suspend_delivery), RESUME_DELIVERY(R.string.omnipod_common_cmd_resume_delivery), PLAY_TEST_BEEP(R.string.omnipod_common_cmd_play_test_beep); + +} \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt index d4a613a75b..dddef6ae46 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt @@ -31,4 +31,5 @@ data class HistoryRecordEntity( fun isSuccess(): Boolean { return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS } + } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 72622ae4a7..b47c7045f6 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -17,8 +17,11 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil +import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity import info.nightscout.androidaps.utils.rx.AapsSchedulers import java.util.* @@ -27,10 +30,6 @@ import javax.inject.Inject class DashPodHistoryActivity : NoSplashAppCompatActivity() { @Inject lateinit var aapsLogger: AAPSLogger - - // @Inject AapsOmnipodUtil aapsOmnipodUtil; - // @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var dashHistory: DashHistory @Inject lateinit var aapsSchedulers: AapsSchedulers @@ -56,20 +55,57 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { fullHistoryList.addAll(records) } + private fun groupForCommandType(type: OmnipodCommandType): PumpHistoryEntryGroup { + return when(type) { + OmnipodCommandType.INITIALIZE_POD -> + PumpHistoryEntryGroup.Prime + OmnipodCommandType.INSERT_CANNULA -> + PumpHistoryEntryGroup.Prime + OmnipodCommandType.DEACTIVATE_POD -> + PumpHistoryEntryGroup.Prime + OmnipodCommandType.DISCARD_POD -> + PumpHistoryEntryGroup.Prime + + OmnipodCommandType.CANCEL_TEMPORARY_BASAL -> + PumpHistoryEntryGroup.Basal + OmnipodCommandType.SET_BASAL_PROFILE -> + PumpHistoryEntryGroup.Basal + OmnipodCommandType.SET_TEMPORARY_BASAL -> + PumpHistoryEntryGroup.Basal + OmnipodCommandType.RESUME_DELIVERY -> + PumpHistoryEntryGroup.Basal + OmnipodCommandType.SUSPEND_DELIVERY -> + PumpHistoryEntryGroup.Basal + + OmnipodCommandType.SET_BOLUS -> + PumpHistoryEntryGroup.Bolus + OmnipodCommandType.CANCEL_BOLUS -> + PumpHistoryEntryGroup.Bolus + + OmnipodCommandType.ACKNOWLEDGE_ALERTS -> + PumpHistoryEntryGroup.Alarm + OmnipodCommandType.CONFIGURE_ALERTS -> + PumpHistoryEntryGroup.Alarm + OmnipodCommandType.PLAY_TEST_BEEP -> + PumpHistoryEntryGroup.Alarm + + OmnipodCommandType.GET_POD_STATUS -> + PumpHistoryEntryGroup.Configuration + OmnipodCommandType.SET_TIME -> + PumpHistoryEntryGroup.Configuration + + OmnipodCommandType.READ_POD_PULSE_LOG -> + PumpHistoryEntryGroup.Unknown + } + } private fun filterHistory(group: PumpHistoryEntryGroup) { filteredHistoryList.clear() aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size) if (group === PumpHistoryEntryGroup.All) { filteredHistoryList.addAll(fullHistoryList) - } /* Here you can add dedicated dao according to type of event selection in history Block - disabled because PodHistoryEntryType doesn't exist in Dash module - else { - for (HistoryRecordEntity pumpHistoryEntry : fullHistoryList) { - if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) { - this.filteredHistoryList.add(pumpHistoryEntry); - } - } - }*/ + } else { + filteredHistoryList.addAll(fullHistoryList.filter { groupForCommandType(it.commandType) == group }) + } recyclerViewAdapter?.let { it.historyList = filteredHistoryList it.notifyDataSetChanged() @@ -85,10 +121,13 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private fun setHistoryTypeSpinner() { manualChange = true - for (i in typeListFull!!.indices) { - if (typeListFull!![i].entryGroup === selectedGroup) { - historyTypeSpinner!!.setSelection(i) - break + val typeList = typeListFull + typeList?.let { + for (i in it.indices) { + if (it[i].entryGroup === selectedGroup) { + historyTypeSpinner!!.setSelection(i) + break + } } } SystemClock.sleep(200) @@ -184,66 +223,27 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { valueView.text = historyEntry.toString() // val entryType = historyEntry.commandType - - /* Here you define which information to show in history according to historyEntry Type - if (historyEntry.isSuccess()) { - PodHistoryEntryType entryType = PodHistoryEntryType.getByCode(historyEntry.getPodEntryTypeCode()); - switch (entryType) { - - case SET_TEMPORARY_BASAL: - case SPLIT_TEMPORARY_BASAL: { - TempBasalPair tempBasalPair = aapsOmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); - } - break; - - case INSERT_CANNULA: - case SET_BASAL_SCHEDULE: { - if (historyEntry.getData() != null) { - setProfileValue(historyEntry.getData(), valueView); - } - } - break; - - case SET_BOLUS: { - if (historyEntry.getData().contains(";")) { - String[] splitVal = historyEntry.getData().split(";"); - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); - } else { - valueView.setText(resourceHelper.gs(R.string.omnipod_eros_history_bolus_value, Double.valueOf(historyEntry.getData()))); - } - } - break; - - case PLAY_TEST_BEEP: { - if (historyEntry.getData() != null) { - valueView.setText(historyEntry.getData()); - } - } - break; - case GET_POD_STATUS: - case GET_POD_INFO: - case SET_TIME: - case INITIALIZE_POD: - case CANCEL_TEMPORARY_BASAL_BY_DRIVER: - case CANCEL_TEMPORARY_BASAL: - case CONFIGURE_ALERTS: - case CANCEL_BOLUS: - case DEACTIVATE_POD: - case DISCARD_POD: - case ACKNOWLEDGE_ALERTS: - case SUSPEND_DELIVERY: - case RESUME_DELIVERY: - case UNKNOWN_ENTRY_TYPE: - default: - valueView.setText(""); - break; - - } - } else { - valueView.setText(historyEntry.toString()); + if (!historyEntry.isSuccess()) { + valueView.text = resourceHelper.gs(translatedFailure(historyEntry)) + return + } + valueView.text = when (historyEntry.commandType) { + OmnipodCommandType.SET_TEMPORARY_BASAL -> { + val tbr = historyEntry.tempBasalRecord + tbr?.let { + resourceHelper.gs(R.string.omnipod_common_history_tbr_value, it.rate, it.duration) + } ?: "n/a" + } + OmnipodCommandType.SET_BOLUS -> { + val bolus = historyEntry.bolusRecord + bolus?.let { + resourceHelper.gs(R.string.omnipod_common_history_bolus_value, it.amout) + } ?: "n/a" + } + else -> + "" + } - */ } private fun setProfileValue(data: String, valueView: TextView) { @@ -275,6 +275,20 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } } + private fun translatedFailure(historyEntry: HistoryRecordEntity): Int { + return when { + historyEntry.initialResult == InitialResult.FAILURE_SENDING -> + R.string.omnipod_dash_failed_to_send + historyEntry.initialResult == InitialResult.NOT_SENT -> + R.string.omnipod_dash_command_not_sent + historyEntry.initialResult == InitialResult.SENT && + historyEntry.resolvedResult == ResolvedResult.FAILURE -> + R.string.omnipod_dash_command_not_received_by_the_pod + else -> + R.string.omnipod_dash_unknown + } + } + companion object { private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All diff --git a/omnipod-dash/src/main/res/values/strings.xml b/omnipod-dash/src/main/res/values/strings.xml index 5a7bddb482..1b6f4dbb45 100644 --- a/omnipod-dash/src/main/res/values/strings.xml +++ b/omnipod-dash/src/main/res/values/strings.xml @@ -40,4 +40,10 @@ Found too many pods for activation Could not find an available pod for activation Generic error: %1$s + Failed to send the command + Command not sent + Command not received by the pod + Unknown state for the command + Rate: %1$.2f U, duration: %2$d minutes + %1$.2f U From 64682d01fcc3859a4ebc4082ac7d507b9a9602b6 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 23:47:50 +0200 Subject: [PATCH 10/15] kotlin --- .../pump/omnipod/dash/ui/DashPodHistoryActivity.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index b47c7045f6..28cf076259 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -144,7 +144,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { setContentView(R.layout.omnipod_dash_pod_history_activity) prepareData() - recyclerView = findViewById(R.id.omnipod_history_recyclerview) + recyclerView = findViewById(R.id.omnipod_history_recyclerview) recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) linearLayoutManager = LinearLayoutManager(this) recyclerView?.run { @@ -153,10 +153,10 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { adapter = recyclerViewAdapter } - statusView = findViewById(R.id.omnipod_historystatus) + statusView = findViewById(R.id.omnipod_historystatus) statusView?.run { visibility = View.GONE } - historyTypeSpinner = findViewById(R.id.omnipod_historytype) + historyTypeSpinner = findViewById(R.id.omnipod_historytype) typeListFull = getTypeList(PumpHistoryEntryGroup.Companion.getTranslatedList(resourceHelper)) val spinnerAdapter: ArrayAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull!!) historyTypeSpinner?.run { @@ -269,9 +269,9 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time) - val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) - val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description) + val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time) + val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) + val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description) } } From 75f51b1408516c01ddadca2982ed20ca7cc016c3 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 24 Oct 2021 23:50:21 +0200 Subject: [PATCH 11/15] ktlintFormat --- .../pump/omnipod/dash/history/database/HistoryRecordEntity.kt | 1 - .../plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt index dddef6ae46..d4a613a75b 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt @@ -31,5 +31,4 @@ data class HistoryRecordEntity( fun isSuccess(): Boolean { return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS } - } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 28cf076259..92d01d41da 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -56,7 +56,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } private fun groupForCommandType(type: OmnipodCommandType): PumpHistoryEntryGroup { - return when(type) { + return when (type) { OmnipodCommandType.INITIALIZE_POD -> PumpHistoryEntryGroup.Prime OmnipodCommandType.INSERT_CANNULA -> @@ -242,7 +242,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } else -> "" - } } @@ -290,7 +289,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } companion object { - private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All } } From a51c49f81cea2926f74c7c6b27529b01376469bf Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Mon, 25 Oct 2021 23:25:38 +0200 Subject: [PATCH 12/15] create history records on pod activation. save basal profiles to history --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 8 +++- .../pump/omnipod/dash/history/DashHistory.kt | 8 ++-- .../pump/omnipod/dash/history/data/Record.kt | 3 ++ .../dash/history/database/Converters.kt | 15 +++++++ .../history/database/DashHistoryDatabase.kt | 4 +- .../history/database/HistoryRecordEntity.kt | 2 + .../dash/history/mapper/HistoryMapper.kt | 6 ++- .../action/DashInitializePodViewModel.kt | 45 ++++++++++--------- .../action/DashInsertCannulaViewModel.kt | 5 ++- 9 files changed, 62 insertions(+), 34 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 15b53ed2e5..521dc2527a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response. import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmed import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord @@ -372,7 +373,10 @@ class OmnipodDashPumpPlugin @Inject constructor( deliverySuspended = true } }, - historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE), + historyEntry = history.createRecord( + commandType = OmnipodCommandType.SET_BASAL_PROFILE, + basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList()) + ), activeCommandEntry = { historyId -> podStateManager.createActiveCommand(historyId, basalProgram = basalProgram) }, @@ -1139,7 +1143,7 @@ class OmnipodDashPumpPlugin @Inject constructor( return profileFunction.getProfile()?.let { executeProgrammingCommand( pre = observeDeliverySuspended(), - historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY), + historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY, basalProfileRecord = BasalValuesRecord(it.getBasalValues().toList())), command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(it), hasBasalBeepEnabled()) .ignoreElements() ).doFinally { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index 9a79f5028d..8f3cf1018e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -7,11 +7,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.Omnipod import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_BOLUS import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_TEMPORARY_BASAL import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.* -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.* import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordDao import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper.HistoryMapper @@ -53,6 +49,7 @@ class DashHistory @Inject constructor( initialResult: InitialResult = InitialResult.NOT_SENT, tempBasalRecord: TempBasalRecord? = null, bolusRecord: BolusRecord? = null, + basalProfileRecord: BasalValuesRecord? = null, resolveResult: ResolvedResult? = null, resolvedAt: Long? = null ): Single = Single.defer { @@ -72,6 +69,7 @@ class DashHistory @Inject constructor( commandType = commandType, tempBasalRecord = tempBasalRecord, bolusRecord = bolusRecord, + basalProfileRecord = basalProfileRecord, initialResult = initialResult, resolvedResult = resolveResult, resolvedAt = resolvedAt diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt index c5ea0ab4b3..f129ab292d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.interfaces.Profile sealed class Record @@ -8,6 +9,8 @@ data class BolusRecord(val amout: Double, val bolusType: BolusType) : Record() data class TempBasalRecord(val duration: Int, val rate: Double) : Record() +data class BasalValuesRecord(val segments: List) : Record() + enum class BolusType { DEFAULT, SMB; diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt index 8d21ea751a..5f90d9b7c8 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/Converters.kt @@ -1,6 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database import androidx.room.TypeConverter +import com.google.gson.GsonBuilder +import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult @@ -31,4 +33,17 @@ class Converters { @TypeConverter fun fromOmnipodCommandType(omnipodCommandType: OmnipodCommandType) = omnipodCommandType.name + + @TypeConverter + fun toSegments(s: String?): List { + s ?: return emptyList() + val gson = GsonBuilder().create() + return gson.fromJson(s, Array::class.java).toList() + } + + @TypeConverter + fun fromBasalValues(segments: List): String { + val gson = GsonBuilder().create() + return gson.toJson(segments) + } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt index 3014f3eba0..993d49d564 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/DashHistoryDatabase.kt @@ -18,13 +18,13 @@ abstract class DashHistoryDatabase : RoomDatabase() { companion object { - const val VERSION = 1 + const val VERSION = 2 fun build(context: Context) = Room.databaseBuilder( context.applicationContext, DashHistoryDatabase::class.java, - "omnipod_dash_history_database.db" + "omnipod_dash_history_database.db", ) .fallbackToDestructiveMigration() .build() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt index d4a613a75b..41493d8fde 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt @@ -4,6 +4,7 @@ import androidx.room.Embedded import androidx.room.Entity import androidx.room.PrimaryKey import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult @@ -18,6 +19,7 @@ data class HistoryRecordEntity( val initialResult: InitialResult, @Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?, @Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?, + @Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?, val resolvedResult: ResolvedResult?, val resolvedAt: Long? ) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt index 5266924514..765c538ee6 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/mapper/HistoryMapper.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord @@ -17,7 +18,8 @@ class HistoryMapper { tempBasalRecord = historyRecord.record as? TempBasalRecord, bolusRecord = historyRecord.record as? BolusRecord, resolvedResult = historyRecord.resolvedResult, - resolvedAt = historyRecord.resolvedAt + resolvedAt = historyRecord.resolvedAt, + basalProfileRecord = historyRecord.record as? BasalValuesRecord ) fun entityToDomain(entity: HistoryRecordEntity): HistoryRecord = @@ -27,7 +29,7 @@ class HistoryMapper { date = entity.date, initialResult = entity.initialResult, commandType = entity.commandType, - record = entity.bolusRecord ?: entity.tempBasalRecord, + record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord, resolvedResult = entity.resolvedResult, resolvedAt = entity.resolvedAt ) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index 715387abeb..3c055b5d31 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -5,11 +5,13 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -24,7 +26,9 @@ class DashInitializePodViewModel @Inject constructor( logger: AAPSLogger, private val sp: SP, private val podStateManager: OmnipodDashPodStateManager, - private val resourceHelper: ResourceHelper + private val resourceHelper: ResourceHelper, + private val history: DashHistory, + ) : InitializePodViewModel(injector, logger) { override fun isPodInAlarm(): Boolean = false // TODO @@ -41,27 +45,24 @@ class DashInitializePodViewModel @Inject constructor( } else null - super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( - onNext = { podEvent -> - logger.debug( - LTag.PUMP, - "Received PodEvent in Pod activation part 1: $podEvent" - ) - }, - onError = { throwable -> - logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable) - source.onSuccess( - PumpEnactResult(injector) - .success(false) - .comment(I8n.textFromException(throwable, resourceHelper)) - ) - }, - onComplete = { - logger.debug("Pod activation part 1 completed") - podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits) - source.onSuccess(PumpEnactResult(injector).success(true)) - } - ) + super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger) + .ignoreElements() + .andThen(podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits)) + .andThen(history.createRecord(OmnipodCommandType.INITIALIZE_POD).ignoreElement()) + .subscribeBy( + onError = { throwable -> + logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable) + source.onSuccess( + PumpEnactResult(injector) + .success(false) + .comment(I8n.textFromException(throwable, resourceHelper)) + ) + }, + onComplete = { + logger.debug("Pod activation part 1 completed") + source.onSuccess(PumpEnactResult(injector).success(true)) + } + ) } @StringRes diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index f22cddd96a..b67ee1897d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -12,10 +12,12 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.pump.common.defs.PumpType +import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram @@ -34,6 +36,7 @@ class DashInsertCannulaViewModel @Inject constructor( private val rxBus: RxBus, private val sp: SP, private val resourceHelper: ResourceHelper, + private val history: DashHistory, injector: HasAndroidInjector, logger: AAPSLogger @@ -67,6 +70,7 @@ class DashInsertCannulaViewModel @Inject constructor( super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown) .ignoreElements() .andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours)) + .andThen(history.createRecord(OmnipodCommandType.INSERT_CANNULA).ignoreElement()) .subscribeBy( onError = { throwable -> logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable) @@ -98,7 +102,6 @@ class DashInsertCannulaViewModel @Inject constructor( pumpType = PumpType.OMNIPOD_DASH, pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a" ) - rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED)) source.onSuccess(PumpEnactResult(injector).success(true)) } From 45fb0a5a21452d8e00971cdd948469a3a66cab7a Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 26 Oct 2021 22:19:22 +0200 Subject: [PATCH 13/15] history updates: auto resolve history entried for activation. update history on deactivation. use the right history name for set_time --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 18 +++-- .../dash/driver/OmnipodDashManagerImpl.kt | 1 - .../pump/omnipod/dash/history/DashHistory.kt | 8 +-- .../dash/history/data/HistoryRecord.kt | 11 ++++ .../dash/history/database/HistoryRecordDao.kt | 2 +- .../history/database/HistoryRecordEntity.kt | 13 +--- .../omnipod/dash/ui/DashPodHistoryActivity.kt | 65 +++++++------------ .../action/DashInitializePodViewModel.kt | 11 +++- .../action/DashInsertCannulaViewModel.kt | 13 +++- 9 files changed, 76 insertions(+), 66 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 521dc2527a..b16ff9e837 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -364,8 +364,12 @@ class OmnipodDashPumpPlugin @Inject constructor( return PumpEnactResult(injector).success(true).enacted(true) } aapsLogger.debug(LTag.PUMP, "setNewBasalProfile profile=$profile") - val basalProgram = mapProfileToBasalProgram(profile) + return setNewBasalProfile(profile, OmnipodCommandType.SET_BASAL_PROFILE) + } + + private fun setNewBasalProfile(profile: Profile, historyType: OmnipodCommandType): PumpEnactResult { var deliverySuspended = false + val basalProgram = mapProfileToBasalProgram(profile) return executeProgrammingCommand( pre = suspendDeliveryIfActive().doOnComplete { if (podStateManager.activeCommand == null) { @@ -374,7 +378,7 @@ class OmnipodDashPumpPlugin @Inject constructor( } }, historyEntry = history.createRecord( - commandType = OmnipodCommandType.SET_BASAL_PROFILE, + commandType = historyType, basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList()) ), activeCommandEntry = { historyId -> @@ -1157,16 +1161,20 @@ class OmnipodDashPumpPlugin @Inject constructor( } private fun deactivatePod(): PumpEnactResult { + var success = true val ret = executeProgrammingCommand( historyEntry = history.createRecord(OmnipodCommandType.DEACTIVATE_POD), command = omnipodManager.deactivatePod().ignoreElements(), checkNoActiveCommand = false, post = createFakeTBRWhenNoActivePod(), ).doOnComplete { + if (podStateManager.activeCommand != null) { + success = false + } + podStateManager.reset() rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_FAULT)) }.toPumpEnactResult() - - if (podStateManager.activeCommand != null) { + if (!success) { ret.success(false) } return ret @@ -1174,7 +1182,7 @@ class OmnipodDashPumpPlugin @Inject constructor( private fun handleTimeChange(): PumpEnactResult { return profileFunction.getProfile()?.let { - setNewBasalProfile(it) + setNewBasalProfile(it, OmnipodCommandType.SET_TIME) } ?: PumpEnactResult(injector).success(true).enacted(false).comment("No profile active") } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index 923109c5c1..2a88cc2d0d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -641,7 +641,6 @@ class OmnipodDashManagerImpl @Inject constructor( observeConnectToPod, observeSendDeactivateCommand ).interceptPodEvents() - .doOnComplete(podStateManager::reset) } inner class PodEventInterceptor : Consumer { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index 8f3cf1018e..637d3c383f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -36,9 +36,7 @@ class DashHistory @Inject constructor( fun getById(id: String): HistoryRecord { val entry = dao.byIdBlocking(id) - if (entry == null) { - throw java.lang.IllegalArgumentException("history entry [$id] not found") - } + ?: throw java.lang.IllegalArgumentException("history entry [$id] not found") return historyMapper.entityToDomain(entry) } @@ -81,8 +79,8 @@ class DashHistory @Inject constructor( fun getRecords(): Single> = dao.all().map { list -> list.map(historyMapper::entityToDomain) } - fun getRecordsAfter(time: Long): Single> = - dao.allSince(time) + fun getRecordsAfter(time: Long): Single> = + dao.allSince(time).map { list -> list.map(historyMapper::entityToDomain) } fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer { val historyId = podState.activeCommand?.historyId diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt index f7510c40b1..ad2b2f73a3 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt @@ -18,4 +18,15 @@ data class HistoryRecord( val entropy = ULID.getEntropy(id) return ByteBuffer.wrap(entropy).long } + + fun displayTimestamp(): Long { + resolvedAt?.let { + return it + } + return date + } + + fun isSuccess(): Boolean { + return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS + } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt index a91a838d1d..1beaab6bca 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt @@ -19,7 +19,7 @@ abstract class HistoryRecordDao { @Query("SELECT * from historyrecords") abstract fun allBlocking(): List - @Query("SELECT * from historyrecords WHERE createdAt >= :since") + @Query("SELECT * from historyrecords WHERE createdAt >= :since ORDER BY createdAt DESC") abstract fun allSince(since: Long): Single> @Query("SELECT * FROM historyrecords WHERE id = :id LIMIT 1") diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt index 41493d8fde..c135e24cd5 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordEntity.kt @@ -22,15 +22,4 @@ data class HistoryRecordEntity( @Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?, val resolvedResult: ResolvedResult?, val resolvedAt: Long? -) { - fun displayTimestamp(): Long { - resolvedAt?.let { - return it - } - return date - } - - fun isSuccess(): Boolean { - return initialResult == InitialResult.SENT && resolvedResult == ResolvedResult.SUCCESS - } -} +) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index 92d01d41da..fba505ffaa 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -16,13 +16,13 @@ import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil +import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult -import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.* import info.nightscout.androidaps.utils.rx.AapsSchedulers import java.util.* import javax.inject.Inject @@ -37,16 +37,15 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { private var statusView: TextView? = null private var recyclerView: RecyclerView? = null private var linearLayoutManager: LinearLayoutManager? = null - private val fullHistoryList: MutableList = ArrayList() - private val filteredHistoryList: MutableList = ArrayList() + private val fullHistoryList: MutableList = ArrayList() + private val filteredHistoryList: MutableList = ArrayList() private var recyclerViewAdapter: RecyclerViewAdapter? = null private var manualChange = false private var typeListFull: List? = null private fun prepareData() { val gc = GregorianCalendar() - // TODO: limit to the last 3 days. Using 30days here for testing - gc.add(Calendar.DAY_OF_MONTH, -30) + gc.add(Calendar.DAY_OF_MONTH, -DAYS_TO_DISPLAY) val since = gc.timeInMillis val records = dashHistory.getRecordsAfter(since) @@ -134,10 +133,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { manualChange = false } - override fun onPause() { - super.onPause() - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -195,9 +190,9 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } } - inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() { + inner class RecyclerViewAdapter internal constructor(historyList: List) : RecyclerView.Adapter() { - var historyList: List = historyList + var historyList: List = historyList override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder { val v: View = LayoutInflater.from(viewGroup.context).inflate( @@ -208,19 +203,19 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { - val record: HistoryRecordEntity = historyList[position] + val record: HistoryRecord = historyList[position] record?.let { - holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(record.displayTimestamp()) - setValue(record, holder.valueView) - setType(record, holder.typeView) + holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(it.displayTimestamp()) + setValue(it, holder.valueView) + setType(it, holder.typeView) } } - private fun setType(record: HistoryRecordEntity, typeView: TextView) { + private fun setType(record: HistoryRecord, typeView: TextView) { typeView.text = resourceHelper.gs(record.commandType.resourceId) } - private fun setValue(historyEntry: HistoryRecordEntity, valueView: TextView) { + private fun setValue(historyEntry: HistoryRecord, valueView: TextView) { valueView.text = historyEntry.toString() // val entryType = historyEntry.commandType if (!historyEntry.isSuccess()) { @@ -229,44 +224,33 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } valueView.text = when (historyEntry.commandType) { OmnipodCommandType.SET_TEMPORARY_BASAL -> { - val tbr = historyEntry.tempBasalRecord + val tbr = historyEntry.record as TempBasalRecord tbr?.let { resourceHelper.gs(R.string.omnipod_common_history_tbr_value, it.rate, it.duration) } ?: "n/a" } OmnipodCommandType.SET_BOLUS -> { - val bolus = historyEntry.bolusRecord + val bolus = historyEntry.record as BolusRecord bolus?.let { resourceHelper.gs(R.string.omnipod_common_history_bolus_value, it.amout) } ?: "n/a" } + OmnipodCommandType.SET_BASAL_PROFILE, + OmnipodCommandType.SET_TIME, + OmnipodCommandType.INSERT_CANNULA, + OmnipodCommandType.RESUME_DELIVERY -> { + val basal = historyEntry.record as BasalValuesRecord + ProfileUtil.getBasalProfilesDisplayable(basal.segments.toTypedArray(), PumpType.OMNIPOD_DASH) + } else -> "" } } - private fun setProfileValue(data: String, valueView: TextView) { - aapsLogger.debug(LTag.PUMP, "Profile json:\n$data") - valueView.text = "Profile informations from history" - /* - try { - Profile.ProfileValue[] profileValuesArray = aapsOmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); - valueView.setText(ProfileUtil.INSTANCE.getBasalProfilesDisplayable(profileValuesArray, PumpType.OMNIPOD_EROS)); - } catch (Exception e) { - aapsLogger.error(LTag.PUMP, "Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); - valueView.setText(""); - } - */ - } - override fun getItemCount(): Int { return historyList.size } - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - super.onAttachedToRecyclerView(recyclerView) - } - inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time) val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) @@ -274,7 +258,7 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { } } - private fun translatedFailure(historyEntry: HistoryRecordEntity): Int { + private fun translatedFailure(historyEntry: HistoryRecord): Int { return when { historyEntry.initialResult == InitialResult.FAILURE_SENDING -> R.string.omnipod_dash_failed_to_send @@ -290,5 +274,6 @@ class DashPodHistoryActivity : NoSplashAppCompatActivity() { companion object { private var selectedGroup: PumpHistoryEntryGroup = PumpHistoryEntryGroup.All + const val DAYS_TO_DISPLAY = 5 } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index 3c055b5d31..dc0a36d920 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -12,6 +12,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashMa import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -48,7 +50,14 @@ class DashInitializePodViewModel @Inject constructor( super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger) .ignoreElements() .andThen(podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits)) - .andThen(history.createRecord(OmnipodCommandType.INITIALIZE_POD).ignoreElement()) + .andThen( + history.createRecord( + OmnipodCommandType.INITIALIZE_POD, + initialResult = InitialResult.SENT, + resolveResult = ResolvedResult.SUCCESS, + resolvedAt = System.currentTimeMillis(), + ).ignoreElement() + ) .subscribeBy( onError = { throwable -> logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index b67ee1897d..d9a2660076 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -18,6 +18,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult +import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram @@ -70,7 +73,15 @@ class DashInsertCannulaViewModel @Inject constructor( super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown) .ignoreElements() .andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours)) - .andThen(history.createRecord(OmnipodCommandType.INSERT_CANNULA).ignoreElement()) + .andThen( + history.createRecord( + OmnipodCommandType.INSERT_CANNULA, + basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList()), + initialResult = InitialResult.SENT, + resolveResult = ResolvedResult.SUCCESS, + resolvedAt = System.currentTimeMillis(), + ).ignoreElement() + ) .subscribeBy( onError = { throwable -> logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable) From abc051d64ebc80b1befd4da855306613b0ad2f4e Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 26 Oct 2021 22:50:03 +0200 Subject: [PATCH 14/15] fix alerts. fix display for basal rates --- .../plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 2 +- .../dash/driver/pod/state/OmnipodDashPodStateManager.kt | 2 +- .../dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt | 2 +- .../androidaps/plugins/pump/common/utils/ProfileUtil.kt | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index b16ff9e837..4db2aa2bc1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -1193,7 +1193,7 @@ class OmnipodDashPumpPlugin @Inject constructor( val lowReservoirAlertEnabled = sp.getBoolean(R.string.key_omnipod_common_low_reservoir_alert_enabled, true) val lowReservoirAlertUnits = sp.getInt(R.string.key_omnipod_common_low_reservoir_alert_units, 10) - if (!podStateManager.differentAlertSettings( + if (podStateManager.sameAlertSettings( expirationReminderEnabled, expirationHours, lowReservoirAlertEnabled, diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index d27a3b28c4..6f5ab0ee62 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -105,7 +105,7 @@ interface OmnipodDashPodStateManager { - after getPodStatus was successful(we have an up-to-date podStatus) */ fun recoverActivationFromPodStatus(): String? - fun differentAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean + fun sameAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int): Completable fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Completable diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 899f94d386..07404b8607 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -435,7 +435,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( } } - override fun differentAlertSettings( + override fun sameAlertSettings( expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt index 8997e02482..f5100096dc 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.kt @@ -25,8 +25,9 @@ object ProfileUtil { val basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value) val hour = basalValue.timeAsSeconds / (60 * 60) stringBuilder.append((if (hour < 10) "0" else "") + hour + ":00") + stringBuilder.append(" ") stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValueValue)) - stringBuilder.append(", ") + stringBuilder.append(",\n") } return if (stringBuilder.length > 3) stringBuilder.substring(0, stringBuilder.length - 2) else stringBuilder.toString() } From 784f76ca30c930ead2429b4f2882dd2202d4ac26 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Wed, 27 Oct 2021 09:11:04 +0200 Subject: [PATCH 15/15] use the original date for history, not the resolved date --- .../plugins/pump/omnipod/dash/history/data/HistoryRecord.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt index ad2b2f73a3..baef277087 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt @@ -20,9 +20,6 @@ data class HistoryRecord( } fun displayTimestamp(): Long { - resolvedAt?.let { - return it - } return date }