Initial dialog to display pump alerts.

This commit is contained in:
Johannes Mockenhaupt 2017-11-11 21:41:51 +01:00
parent a1b0240088
commit 3072a42cd7
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 94 additions and 7 deletions

View file

@ -0,0 +1,58 @@
package info.nightscout.androidaps.plugins.PumpCombo;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.List;
import de.jotomo.ruffy.spi.history.PumpError;
import info.nightscout.androidaps.R;
/**
* Created by adrian on 17/08/17.
*/
public class ComboErrorHistoryDialog extends DialogFragment {
private static Logger log = LoggerFactory.getLogger(ComboErrorHistoryDialog.class);
private TextView text;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.combo_error_history_fragment, container, false);
text = (TextView) layout.findViewById(R.id.combo_error_history_text);
List<PumpError> errors = ComboPlugin.getPlugin().getPump().history.pumpErrorHistory;
StringBuilder sb = new StringBuilder();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM HH:mm");
if (errors.isEmpty()) {
text.setText("No errors. To retrieve the error history from the pump, long press the Refresh button.");
} else {
for (PumpError error : errors) {
sb.append(simpleDateFormat.format(error.timestamp));
sb.append(" ");
sb.append(error.message);
if (error.warningCode != null) {
sb.append(" (W");
sb.append(error.warningCode);
sb.append(")");
}
if (error.errorCode != null) {
sb.append(" (E");
sb.append(error.errorCode);
sb.append(")");
}
sb.append("\n");
}
text.setText(sb.toString());
}
return layout;
}
}

View file

@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCombo;
import android.app.Activity; import android.app.Activity;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,8 +25,6 @@ import info.nightscout.utils.DateUtil;
// TODO clean up time/date formatting once this stabilizes a bit more // TODO clean up time/date formatting once this stabilizes a bit more
public class ComboFragment extends SubscriberFragment implements View.OnClickListener, View.OnLongClickListener { public class ComboFragment extends SubscriberFragment implements View.OnClickListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(ComboFragment.class);
private TextView stateView; private TextView stateView;
private TextView activityView; private TextView activityView;
private TextView batteryView; private TextView batteryView;
@ -34,8 +33,6 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
private TextView lastBolusView; private TextView lastBolusView;
private TextView tempBasalText; private TextView tempBasalText;
private Button refresh;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -49,10 +46,13 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus); lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal); tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
refresh = (Button) view.findViewById(R.id.combo_refresh); Button refresh = (Button) view.findViewById(R.id.combo_refresh);
refresh.setOnClickListener(this); refresh.setOnClickListener(this);
refresh.setOnLongClickListener(this); refresh.setOnLongClickListener(this);
Button errorHistory = (Button) view.findViewById(R.id.combo_error_history);
errorHistory.setOnClickListener(this);
updateGUI(); updateGUI();
return view; return view;
} }
@ -64,7 +64,9 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start(); new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start();
break; break;
case R.id.combo_error_history: case R.id.combo_error_history:
// TODO v2 show popup with pump errors and comm problems steal code from profile view, called on overview ComboErrorHistoryDialog ehd = new ComboErrorHistoryDialog();
FragmentManager manager = getFragmentManager();
ehd.show(manager, ComboErrorHistoryDialog.class.getSimpleName());
break; break;
} }
} }
@ -73,7 +75,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
public boolean onLongClick(View view) { public boolean onLongClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.combo_refresh: case R.id.combo_refresh:
new Thread(() -> ComboPlugin.getPlugin().forceSyncFullHistory()).start(); new Thread(() -> ComboPlugin.getPlugin().forceFullHistoryRead()).start();
return true; return true;
} }
return false; return false;

View file

@ -0,0 +1,27 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.ProfileNS.NSProfileFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/combo_error_history_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textStart"
android:padding="10dp"
android:gravity="start"/>
</LinearLayout>
</ScrollView>
</FrameLayout>