Draft for Dash History

This commit is contained in:
Philoul 2021-10-23 02:07:14 +02:00 committed by Andrei Vereha
parent 04a104a9b0
commit e161ef6bb9
10 changed files with 471 additions and 1 deletions

View file

@ -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"

View file

@ -11,5 +11,6 @@
<activity android:name=".ui.wizard.activation.DashPodActivationWizardActivity" />
<activity android:name=".ui.wizard.deactivation.DashPodDeactivationWizardActivity" />
<activity android:name=".ui.DashPodManagementActivity" />
<activity android:name=".ui.DashPodHistoryActivity" />
</application>
</manifest>

View file

@ -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

View file

@ -83,7 +83,7 @@ class DashHistory @Inject constructor(
fun getRecords(): Single<List<HistoryRecord>> =
dao.all().map { list -> list.map(historyMapper::entityToDomain) }
fun getRecordsAfter(time: Long): Single<List<HistoryRecordEntity>> = dao.allSince(time)
fun getRecordsAfter(time: Long): List<HistoryRecordEntity> = dao.allSince(time).blockingGet()
fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer {
val historyId = podState.activeCommand?.historyId

View file

@ -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<HistoryRecordEntity> fullHistoryList = new ArrayList<>();
private final List<HistoryRecordEntity> filteredHistoryList = new ArrayList<>();
private RecyclerViewAdapter recyclerViewAdapter;
private boolean manualChange = false;
private List<TypeList> 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<TypeList> 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<TypeList> getTypeList(List<PumpHistoryEntryGroup> list) {
ArrayList<TypeList> 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<RecyclerViewAdapter.HistoryViewHolder> {
List<HistoryRecordEntity> historyList;
RecyclerViewAdapter(List<HistoryRecordEntity> historyList) {
this.historyList = historyList;
}
void setHistoryList(List<HistoryRecordEntity> 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);
}
}
}
}

View file

@ -96,6 +96,10 @@ class DashPodManagementActivity : NoSplashAppCompatActivity() {
}
)
}
binding.buttonPodHistory.setOnClickListener {
startActivity(Intent(this, DashPodHistoryActivity::class.java))
}
}
override fun onResume() {

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<LinearLayout
android:id="@+id/omnipod_historytop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="20dp"
android:text="@string/omnipod_dash_history_type"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="@+id/omnipod_historytype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:background="@drawable/pillborder"
android:gravity="center_horizontal"
android:text="@string/omnipod_dash_history_title" />
</LinearLayout>
<TextView
android:id="@+id/omnipod_historystatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/omnipod_historytop"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/omnipod_history_recyclerview"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/omnipod_historystatus" />
</RelativeLayout>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingTop="10dp"
android:paddingEnd="20dp">
<TextView
android:id="@+id/omnipod_history_time"
android:layout_width="88dp"
android:layout_height="match_parent"
android:text="@string/omnipod_dash_history_item_date"
android:textSize="12sp" />
<TextView
android:id="@+id/omnipod_history_source"
android:layout_width="132dp"
android:layout_height="match_parent"
android:text="@string/omnipod_dash_history_item_source"
android:textSize="12sp" />
<TextView
android:id="@+id/omnipod_history_description"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="@string/omnipod_dash_history_item_description"
android:textSize="12sp" />
</LinearLayout>

View file

@ -111,6 +111,20 @@
app:layout_constraintRight_toLeftOf="@+id/Actions_Col_1_Row_2_vertical_guideline"
app:layout_constraintTop_toTopOf="parent" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/button_pod_history"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_pod_management_pod_history"
android:text="@string/omnipod_common_pod_management_button_pod_history"
android:textAllCaps="false"
android:visibility="visible"
app:layout_constrainedHeight="@+id/Actions_Row_2_horizontal_guideline"
app:layout_constraintLeft_toRightOf="@+id/Actions_Col_1_Row_2_vertical_guideline"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/Actions_Col_1_Row_2_vertical_guideline"
android:layout_width="wrap_content"

View file

@ -8,6 +8,16 @@
<!-- Omnipod Dash - Keys -->
<string name="key_omnipod_dash_pod_state" translatable="false">AAPS.OmnipodDash.pod_state</string>
<!-- Omnipod Dash - History -->
<string name="omnipod_dash_history_title">Pod History</string>
<string name="omnipod_dash_history_item_description">Description</string>
<string name="omnipod_dash_history_item_source">Source</string>
<string name="omnipod_dash_history_item_date">Date</string>
<string name="omnipod_dash_history_type">Type:</string>
<string name="omnipod_dash_history_bolus_value">%1$.2f U</string>
<string name="omnipod_dash_history_bolus_value_with_carbs">%1$.2f U, CH=%2$.1f g</string>
<string name="omnipod_dash_history_tbr_value">Rate: %1$.2f U, duration: %2$d minutes</string>
<!-- Omnipod Dash - Overview -->
<string name="omnipod_dash_overview_bluetooth_status">Bluetooth Status</string>
<string name="omnipod_dash_overview_bluetooth_address">Bluetooth Address</string>