added determineTextColor() to shorten source

This commit is contained in:
Roumen Georgiev 2018-04-05 10:01:16 +03:00 committed by GitHub
parent 6ace7080b2
commit 934fedaa73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.Careportal;
import android.app.Activity; import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -221,14 +222,15 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
CareportalEvent careportalEvent; CareportalEvent careportalEvent;
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
JSONObject extendedSettings = nsSettings.getExtendedValues(); JSONObject extendedSettings = nsSettings.getExtendedValues();
double iageUrgent = 7 * 24;
double iageWarn = 5 * 24; double iageUrgent = 0;
double cageUrgent = 3 * 24; double iageWarn = 0;
double cageWarn = 2 * 24; double cageUrgent = 0;
double sageUrgent = 7 * 24; double cageWarn = 0;
double sageWarn = 6 * 24; double sageUrgent = 0;
double pbageUrgent = 10 * 24; double sageWarn = 0;
double pbageWarn = 15 * 24; double pbageUrgent = 0;
double pbageWarn = 0;
log.debug("Values from NSSettings "+extendedSettings.toString()); log.debug("Values from NSSettings "+extendedSettings.toString());
// Thresholds in NS are in hours // Thresholds in NS are in hours
try { try {
@ -251,16 +253,8 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
if (sage != null) { if (sage != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
if(careportalEvent != null) { if(careportalEvent != null) {
if(careportalEvent.isOlderThan( sageUrgent/24)){ sage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, sageUrgent, sageWarn));
sage.setTextColor(MainApp.sResources.getColor(R.color.low)); sage.setText(careportalEvent.age());
sage.setText(careportalEvent.age());
} else if(careportalEvent.isOlderThan( sageWarn/24)){
sage.setTextColor(MainApp.sResources.getColor(R.color.high));
sage.setText(careportalEvent.age());
} else {
sage.setText(careportalEvent.age());
}
} else { } else {
sage.setText(notavailable); sage.setText(notavailable);
} }
@ -268,16 +262,8 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
if (iage != null) { if (iage != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
if(careportalEvent != null) { if(careportalEvent != null) {
if(careportalEvent.isOlderThan(iageUrgent/24)){ iage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, iageUrgent, iageWarn));
iage.setTextColor(MainApp.sResources.getColor(R.color.low)); iage.setText(careportalEvent.age());
iage.setText(careportalEvent.age());
} else if(careportalEvent.isOlderThan( iageWarn/24)) {
iage.setTextColor(MainApp.sResources.getColor(R.color.high));
iage.setText(careportalEvent.age());
} else {
iage.setText(careportalEvent.age());
}
} else { } else {
iage.setText(notavailable); iage.setText(notavailable);
} }
@ -285,33 +271,17 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
if (cage != null) { if (cage != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
if (careportalEvent != null) { if (careportalEvent != null) {
if(careportalEvent.isOlderThan(cageUrgent/24)){ cage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, cageUrgent, cageWarn));
cage.setTextColor(MainApp.sResources.getColor(R.color.low)); cage.setText(careportalEvent.age());
cage.setText(careportalEvent.age());
} else if(careportalEvent.isOlderThan( cageWarn/24)) {
cage.setTextColor(MainApp.sResources.getColor(R.color.high));
cage.setText(careportalEvent.age());
} else {
cage.setText(careportalEvent.age());
}
} else { } else {
cage.setText(notavailable); cage.setText(notavailable);
} }
} }
if (pbage != null) { if (pbage != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE); careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE);
if(careportalEvent != null) { if (careportalEvent != null) {
if(careportalEvent.isOlderThan(pbageUrgent/24)){ pbage.setTextColor(CareportalFragment.determineTextColor(careportalEvent, pbageUrgent, pbageWarn));
pbage.setTextColor(MainApp.sResources.getColor(R.color.low));
pbage.setText(careportalEvent.age()); pbage.setText(careportalEvent.age());
} else if(careportalEvent.isOlderThan( pbageWarn/24)) {
pbage.setTextColor(MainApp.sResources.getColor(R.color.high));
pbage.setText(careportalEvent.age());
} else {
pbage.setText(careportalEvent.age());
}
} else { } else {
pbage.setText(notavailable); pbage.setText(notavailable);
} }
@ -322,5 +292,15 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
} }
} }
public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold){
if(careportalEvent.isOlderThan(urgentThreshold)){
return MainApp.sResources.getColor(R.color.low);
} else if(careportalEvent.isOlderThan( warnThreshold)) {
return MainApp.sResources.getColor(R.color.high);
} else {
return Color.WHITE;
}
}
} }