From f30efd02243b9a5b5383c0edb21967991169c1da Mon Sep 17 00:00:00 2001 From: Jamorham Date: Fri, 26 Jan 2018 16:59:14 +0000 Subject: [PATCH] Insight fragment use status list --- .../PumpInsight/InsightPumpFragment.java | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpFragment.java index 557bba6fd1..b5036b93f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpFragment.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.PumpInsight; - import android.app.Activity; import android.os.Bundle; import android.os.Handler; @@ -8,38 +7,35 @@ import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import android.widget.LinearLayout; +import com.crashlytics.android.Crashlytics; import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.MainApp; +import java.util.List; + import info.nightscout.androidaps.R; 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.utils.StatusItem; +import info.nightscout.androidaps.plugins.PumpInsight.utils.ui.StatusItemViewAdapter; -import com.crashlytics.android.Crashlytics; public class InsightPumpFragment extends SubscriberFragment { 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 Runnable sRefreshLoop = null; + StatusItemViewAdapter viewAdapter; + LinearLayout holder; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (sRefreshLoop == null) { sRefreshLoop = new Runnable() { @Override @@ -57,12 +53,8 @@ public class InsightPumpFragment extends SubscriberFragment { Bundle savedInstanceState) { try { View view = inflater.inflate(R.layout.insightpump_fragment, container, false); - basaBasalRateView = (TextView) view.findViewById(R.id.insightpump_basabasalrate); - tempBasalView = (TextView) view.findViewById(R.id.insightpump_tempbasal); - 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); + holder = view.findViewById(R.id.insightholder); + viewAdapter = new StatusItemViewAdapter(getActivity(), holder); return view; } catch (Exception e) { @@ -79,27 +71,20 @@ public class InsightPumpFragment extends SubscriberFragment { @Override protected void updateGUI() { - Activity activity = getActivity(); - if (activity != null && basaBasalRateView != null) + final Activity activity = getActivity(); + if (activity != null && holder != null) activity.runOnUiThread(new Runnable() { @Override public void run() { - InsightPumpPlugin insightPumpPlugin = InsightPumpPlugin.getPlugin(); - basaBasalRateView.setText(insightPumpPlugin.getBaseBasalRateString() + "U"); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); - } else { - tempBasalView.setText(""); - } - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { - extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString()); - } else { - extendedBolusView.setText(""); - } - batteryView.setText(insightPumpPlugin.batteryPercent + "%"); - reservoirView.setText(insightPumpPlugin.reservoirInUnits + "U"); + final InsightPumpPlugin insightPumpPlugin = InsightPumpPlugin.getPlugin(); + final List l = insightPumpPlugin.getStatusItems(); + + holder.removeAllViews(); + + for (StatusItem row : l) { + viewAdapter.inflateStatus(row); + } - statusView.setText(connector.getLastStatusMessage()); } }); }