Insight fragment use status list

This commit is contained in:
Jamorham 2018-01-26 16:59:14 +00:00
parent 076685992c
commit f30efd0224
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpInsight; package info.nightscout.androidaps.plugins.PumpInsight;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -8,38 +7,35 @@ import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.LinearLayout;
import com.crashlytics.android.Crashlytics;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import java.util.List;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpUpdateGui; import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpUpdateGui;
import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
import info.nightscout.androidaps.plugins.PumpInsight.utils.ui.StatusItemViewAdapter;
import com.crashlytics.android.Crashlytics;
public class InsightPumpFragment extends SubscriberFragment { public class InsightPumpFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(InsightPumpFragment.class); private static Logger log = LoggerFactory.getLogger(InsightPumpFragment.class);
TextView basaBasalRateView;
TextView tempBasalView;
TextView extendedBolusView;
TextView batteryView;
TextView reservoirView;
TextView statusView;
Connector connector = Connector.get();
private static Handler sLoopHandler = new Handler(); private static Handler sLoopHandler = new Handler();
private static Runnable sRefreshLoop = null; private static Runnable sRefreshLoop = null;
StatusItemViewAdapter viewAdapter;
LinearLayout holder;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (sRefreshLoop == null) { if (sRefreshLoop == null) {
sRefreshLoop = new Runnable() { sRefreshLoop = new Runnable() {
@Override @Override
@ -57,12 +53,8 @@ public class InsightPumpFragment extends SubscriberFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
try { try {
View view = inflater.inflate(R.layout.insightpump_fragment, container, false); View view = inflater.inflate(R.layout.insightpump_fragment, container, false);
basaBasalRateView = (TextView) view.findViewById(R.id.insightpump_basabasalrate); holder = view.findViewById(R.id.insightholder);
tempBasalView = (TextView) view.findViewById(R.id.insightpump_tempbasal); viewAdapter = new StatusItemViewAdapter(getActivity(), holder);
extendedBolusView = (TextView) view.findViewById(R.id.insightpump_extendedbolus);
batteryView = (TextView) view.findViewById(R.id.insightpump_battery);
reservoirView = (TextView) view.findViewById(R.id.insightpump_reservoir);
statusView = (TextView) view.findViewById(R.id.insightpump_status);
return view; return view;
} catch (Exception e) { } catch (Exception e) {
@ -79,27 +71,20 @@ public class InsightPumpFragment extends SubscriberFragment {
@Override @Override
protected void updateGUI() { protected void updateGUI() {
Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null && basaBasalRateView != null) if (activity != null && holder != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
InsightPumpPlugin insightPumpPlugin = InsightPumpPlugin.getPlugin(); final InsightPumpPlugin insightPumpPlugin = InsightPumpPlugin.getPlugin();
basaBasalRateView.setText(insightPumpPlugin.getBaseBasalRateString() + "U"); final List<StatusItem> l = insightPumpPlugin.getStatusItems();
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); holder.removeAllViews();
} else {
tempBasalView.setText(""); for (StatusItem row : l) {
} viewAdapter.inflateStatus(row);
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { }
extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString());
} else {
extendedBolusView.setText("");
}
batteryView.setText(insightPumpPlugin.batteryPercent + "%");
reservoirView.setText(insightPumpPlugin.reservoirInUnits + "U");
statusView.setText(connector.getLastStatusMessage());
} }
}); });
} }