diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboErrorHistoryDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboErrorHistoryDialog.java new file mode 100644 index 0000000000..b206d248ae --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboErrorHistoryDialog.java @@ -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 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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 6af24294cd..c5f609e4f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCombo; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; +import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; 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 public class ComboFragment extends SubscriberFragment implements View.OnClickListener, View.OnLongClickListener { - private static Logger log = LoggerFactory.getLogger(ComboFragment.class); - private TextView stateView; private TextView activityView; private TextView batteryView; @@ -34,8 +33,6 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis private TextView lastBolusView; private TextView tempBasalText; - private Button refresh; - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -49,10 +46,13 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus); 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.setOnLongClickListener(this); + Button errorHistory = (Button) view.findViewById(R.id.combo_error_history); + errorHistory.setOnClickListener(this); + updateGUI(); return view; } @@ -64,7 +64,9 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start(); break; 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; } } @@ -73,7 +75,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis public boolean onLongClick(View view) { switch (view.getId()) { case R.id.combo_refresh: - new Thread(() -> ComboPlugin.getPlugin().forceSyncFullHistory()).start(); + new Thread(() -> ComboPlugin.getPlugin().forceFullHistoryRead()).start(); return true; } return false; diff --git a/app/src/main/res/layout/combo_error_history_fragment.xml b/app/src/main/res/layout/combo_error_history_fragment.xml new file mode 100644 index 0000000000..ae9429b58e --- /dev/null +++ b/app/src/main/res/layout/combo_error_history_fragment.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + +