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;
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<StatusItem> l = insightPumpPlugin.getStatusItems();
holder.removeAllViews();
for (StatusItem row : l) {
viewAdapter.inflateStatus(row);
}
statusView.setText(connector.getLastStatusMessage());
}
});
}