Use getBatteryLevel() for BAT status. Refactor code and layout.
This commit is contained in:
parent
a7aa4c2b5a
commit
217583d601
2 changed files with 48 additions and 43 deletions
|
@ -1331,51 +1331,30 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
if (cageView != null) {
|
if (cageView != null) {
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||||
if (careportalEvent != null) {
|
double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||||
cageView.setTextColor(determineTextColor(careportalEvent, cageWarn, cageUrgent));
|
applyRibbonView(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE);
|
||||||
cageView.setText("CAN"); //: " + careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
cageView.setText("n/a");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iageView != null) {
|
if (iageView != null) {
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||||
if (careportalEvent != null) {
|
double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||||
iageView.setTextColor(determineTextColor(careportalEvent, iageWarn, iageUrgent));
|
applyRibbonView(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE);
|
||||||
iageView.setText("INS"); //: + careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
iageView.setText("n/a");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reservoirView != null) {
|
if (reservoirView != null) {
|
||||||
if (pump.isInitialized() && pump.getReservoirLevel() < 50) {
|
double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
|
||||||
reservoirView.setTextColor(MainApp.gc(R.color.low));
|
applyRibbonView(reservoirView, "RES", reservoirLevel, 80, 10, -1);
|
||||||
} else {
|
|
||||||
reservoirView.setTextColor(MainApp.gc(R.color.colorLightGray));
|
|
||||||
}
|
|
||||||
reservoirView.setText("RES");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sageView != null) {
|
if (sageView != null) {
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
||||||
if (careportalEvent != null) {
|
double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||||
sageView.setTextColor(determineTextColor(careportalEvent, sageWarn, sageUrgent));
|
applyRibbonView(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE);
|
||||||
sageView.setText("SEN"); // + careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
sageView.setText("n/a");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbageView != null) {
|
if (pbageView != null) {
|
||||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
|
double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
|
||||||
if (careportalEvent != null) {
|
applyRibbonView(pbageView, "BAT", batteryLevel, 25, 5, -1);
|
||||||
pbageView.setTextColor(determineTextColor(careportalEvent, pbageWarn, pbageUrgent));
|
|
||||||
pbageView.setText("BAT"); //careportalEvent.age());
|
|
||||||
} else {
|
|
||||||
pbageView.setText("n/a");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
|
||||||
|
@ -1540,14 +1519,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold) {
|
public static void applyRibbonView(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid) {
|
||||||
if (careportalEvent.isOlderThan(urgentThreshold)) {
|
if (value != invalid) {
|
||||||
return MainApp.gc(R.color.low);
|
view.setText(text);
|
||||||
} else if (careportalEvent.isOlderThan(warnThreshold)) {
|
if (value <= urgentThreshold) {
|
||||||
return MainApp.gc(R.color.high);
|
view.setTextColor(MainApp.gc(R.color.ribbonTextCritical));
|
||||||
|
view.setBackgroundColor(MainApp.gc(R.color.ribbonBgCritical));
|
||||||
|
} else if (value <= warnThreshold) {
|
||||||
|
view.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
|
||||||
|
view.setBackgroundColor(MainApp.gc(R.color.ribbonBgWarning));
|
||||||
} else {
|
} else {
|
||||||
return MainApp.gc(R.color.colorLightGray);
|
view.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
|
||||||
|
view.setBackgroundColor(MainApp.gc(R.color.ribbonBgDefault));
|
||||||
}
|
}
|
||||||
|
view.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
view.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,13 +187,18 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/overview_canulaage"
|
android:id="@+id/overview_canulaage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="0dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:layout_marginHorizontal="3dp"
|
||||||
|
android:gravity="center"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
@ -201,7 +206,10 @@
|
||||||
android:id="@+id/overview_insulinage"
|
android:id="@+id/overview_insulinage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:layout_marginHorizontal="3dp"
|
||||||
|
android:gravity="center"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
@ -209,7 +217,10 @@
|
||||||
android:id="@+id/overview_reservoirlevel"
|
android:id="@+id/overview_reservoirlevel"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:layout_marginHorizontal="3dp"
|
||||||
|
android:gravity="center"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
@ -217,7 +228,10 @@
|
||||||
android:id="@+id/overview_sensorage"
|
android:id="@+id/overview_sensorage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:layout_marginHorizontal="3dp"
|
||||||
|
android:gravity="center"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
@ -225,7 +239,10 @@
|
||||||
android:id="@+id/overview_pbage"
|
android:id="@+id/overview_pbage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:layout_marginHorizontal="3dp"
|
||||||
|
android:gravity="center"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue