From af0140f6b926aa5fccabc313e04561169cc0f585 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 4 Apr 2018 12:11:29 +0300 Subject: [PATCH 1/2] Get thresholds from NS --- .../Careportal/CareportalFragment.java | 266 +++++++++++------- 1 file changed, 166 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java index 2353fa6645..3c6d80df8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java @@ -3,9 +3,7 @@ package info.nightscout.androidaps.plugins.Careportal; import android.app.Activity; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,22 +12,27 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.Overview.OverviewFragment; +import info.nightscout.utils.FabricPrivacy; public class CareportalFragment extends SubscriberFragment implements View.OnClickListener { - - static CareportalPlugin careportalPlugin; - + private static Logger log = LoggerFactory.getLogger(CareportalFragment.class); TextView iage; TextView cage; TextView sage; @@ -39,85 +42,85 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli LinearLayout butonsLayout; View noProfileView; - static public CareportalPlugin getPlugin() { - if (careportalPlugin == null) { - careportalPlugin = new CareportalPlugin(); - } - return careportalPlugin; - } - - // bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget - public static final OptionsToShow bgcheck = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck, true, true, true, false, false, false, false, false, false, false); - public static final OptionsToShow snackbolus = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow mealbolus = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow correctionbolus = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus, true, true, true, true, false, false, false, false, false, false); - public static final OptionsToShow carbcorrection = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection, true, false, true, false, false, false, false, false, false, false); - public static final OptionsToShow combobolus = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus, true, true, true, true, true, false, false, false, true, false); - public static final OptionsToShow announcement = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow note = new OptionsToShow(R.id.careportal_note, R.string.careportal_note, true, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow question = new OptionsToShow(R.id.careportal_question, R.string.careportal_question, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow exercise = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise, false, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow sitechange = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange, true, true, false, false, false, false, false, false, false, false); - public static final OptionsToShow sensorstart = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow sensorchange = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow insulinchange = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow pumpbatterychange = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow tempbasalstart = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart, true, false, false, false, true, true, true, false, false, false); - public static final OptionsToShow tempbasalend = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend, true, false, false, false, false, false, false, false, false, false); - public static final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, true, false, false, true, false, false); - public static final OptionsToShow openapsoffline = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline, false, false, false, false, true, false, false, false, false, false); - public static final OptionsToShow temptarget = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget, false, false, false, false, true, false, false, false, false, true); + // date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget + public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg(); + public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow MEALBOLUS = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow CORRECTIONBOLUS = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus).date().bg().insulin().carbs().prebolus(); + public static final OptionsToShow CARBCORRECTION = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection).date().bg().carbs(); + public static final OptionsToShow COMBOBOLUS = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus).date().bg().insulin().carbs().prebolus().duration().split(); + public static final OptionsToShow ANNOUNCEMENT = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement).date().bg(); + public static final OptionsToShow NOTE = new OptionsToShow(R.id.careportal_note, R.string.careportal_note).date().bg().duration(); + public static final OptionsToShow QUESTION = new OptionsToShow(R.id.careportal_question, R.string.careportal_question).date().bg(); + public static final OptionsToShow EXERCISE = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise).date().duration(); + public static final OptionsToShow SITECHANGE = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange).date().bg(); + public static final OptionsToShow SENSORSTART = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart).date().bg(); + public static final OptionsToShow SENSORCHANGE = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert).date().bg(); + public static final OptionsToShow INSULINCHANGE = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange).date().bg(); + public static final OptionsToShow PUMPBATTERYCHANGE = new OptionsToShow(R.id.careportal_pumpbatterychange, R.string.careportal_pumpbatterychange).date().bg(); + public static final OptionsToShow TEMPBASALSTART = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart).date().bg().duration().percent().absolute(); + public static final OptionsToShow TEMPBASALEND = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend).date().bg(); + public static final OptionsToShow PROFILESWITCH = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).date().duration().profile(); + public static final OptionsToShow PROFILESWITCHDIRECT = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch).duration().profile(); + public static final OptionsToShow OPENAPSOFFLINE = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline).date().duration(); + public static final OptionsToShow TEMPTARGET = new OptionsToShow(R.id.careportal_temporarytarget, R.string.careportal_temporarytarget).date().duration().tempTarget(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.careportal_fragment, container, false); + try { + View view = inflater.inflate(R.layout.careportal_fragment, container, false); - view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); - view.findViewById(R.id.careportal_announcement).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); - view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); - view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); - view.findViewById(R.id.careportal_exercise).setOnClickListener(this); - view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); - view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_note).setOnClickListener(this); - view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); - view.findViewById(R.id.careportal_question).setOnClickListener(this); - view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); - view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); - view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); + view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); + view.findViewById(R.id.careportal_announcement).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); + view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); + view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); + view.findViewById(R.id.careportal_exercise).setOnClickListener(this); + view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); + view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_note).setOnClickListener(this); + view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); + view.findViewById(R.id.careportal_question).setOnClickListener(this); + view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); + view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); + view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); - iage = (TextView) view.findViewById(R.id.careportal_insulinage); - cage = (TextView) view.findViewById(R.id.careportal_canulaage); - sage = (TextView) view.findViewById(R.id.careportal_sensorage); - pbage = (TextView) view.findViewById(R.id.careportal_pbage); + iage = (TextView) view.findViewById(R.id.careportal_insulinage); + cage = (TextView) view.findViewById(R.id.careportal_canulaage); + sage = (TextView) view.findViewById(R.id.careportal_sensorage); + pbage = (TextView) view.findViewById(R.id.careportal_pbage); - statsLayout = (View) view.findViewById(R.id.careportal_stats); + statsLayout = view.findViewById(R.id.careportal_stats); - noProfileView = (View) view.findViewById(R.id.profileview_noprofile); - butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); + noProfileView = view.findViewById(R.id.profileview_noprofile); + butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); - ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); - if (profileStore == null) { - noProfileView.setVisibility(View.VISIBLE); - butonsLayout.setVisibility(View.GONE); - } else { - noProfileView.setVisibility(View.GONE); - butonsLayout.setVisibility(View.VISIBLE); + ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); + if (profileStore == null) { + noProfileView.setVisibility(View.VISIBLE); + butonsLayout.setVisibility(View.GONE); + } else { + noProfileView.setVisibility(View.GONE); + butonsLayout.setVisibility(View.VISIBLE); + } + + if (Config.NSCLIENT || Config.G5UPLOADER) + statsLayout.setVisibility(View.GONE); // visible on overview + + updateGUI(); + return view; + } catch (Exception e) { + FabricPrivacy.logException(e); } - if (BuildConfig.NSCLIENTOLNY) - statsLayout.setVisibility(View.GONE); // visible on overview - - updateGUI(); - return view; + return null; } @Override @@ -129,66 +132,66 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); switch (id) { case R.id.careportal_bgcheck: - newDialog.setOptions(bgcheck, R.string.careportal_bgcheck); + newDialog.setOptions(BGCHECK, R.string.careportal_bgcheck); break; case R.id.careportal_announcement: - newDialog.setOptions(announcement, R.string.careportal_announcement); + newDialog.setOptions(ANNOUNCEMENT, R.string.careportal_announcement); break; case R.id.careportal_cgmsensorinsert: - newDialog.setOptions(sensorchange, R.string.careportal_cgmsensorinsert); + newDialog.setOptions(SENSORCHANGE, R.string.careportal_cgmsensorinsert); break; case R.id.careportal_cgmsensorstart: - newDialog.setOptions(sensorstart, R.string.careportal_cgmsensorstart); + newDialog.setOptions(SENSORSTART, R.string.careportal_cgmsensorstart); break; case R.id.careportal_combobolus: - newDialog.setOptions(combobolus, R.string.careportal_combobolus); + newDialog.setOptions(COMBOBOLUS, R.string.careportal_combobolus); break; case R.id.careportal_correctionbolus: - newDialog.setOptions(correctionbolus, R.string.careportal_correctionbolus); + newDialog.setOptions(CORRECTIONBOLUS, R.string.careportal_correctionbolus); break; case R.id.careportal_carbscorrection: - newDialog.setOptions(carbcorrection, R.string.careportal_carbscorrection); + newDialog.setOptions(CARBCORRECTION, R.string.careportal_carbscorrection); break; case R.id.careportal_exercise: - newDialog.setOptions(exercise, R.string.careportal_exercise); + newDialog.setOptions(EXERCISE, R.string.careportal_exercise); break; case R.id.careportal_insulincartridgechange: - newDialog.setOptions(insulinchange, R.string.careportal_insulincartridgechange); + newDialog.setOptions(INSULINCHANGE, R.string.careportal_insulincartridgechange); break; case R.id.careportal_pumpbatterychange: - newDialog.setOptions(pumpbatterychange, R.string.careportal_pumpbatterychange); + newDialog.setOptions(PUMPBATTERYCHANGE, R.string.careportal_pumpbatterychange); break; case R.id.careportal_mealbolus: - newDialog.setOptions(mealbolus, R.string.careportal_mealbolus); + newDialog.setOptions(MEALBOLUS, R.string.careportal_mealbolus); break; case R.id.careportal_note: - newDialog.setOptions(note, R.string.careportal_note); + newDialog.setOptions(NOTE, R.string.careportal_note); break; case R.id.careportal_profileswitch: - profileswitch.executeProfileSwitch = false; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); + PROFILESWITCH.executeProfileSwitch = false; + newDialog.setOptions(PROFILESWITCH, R.string.careportal_profileswitch); break; case R.id.careportal_pumpsitechange: - newDialog.setOptions(sitechange, R.string.careportal_pumpsitechange); + newDialog.setOptions(SITECHANGE, R.string.careportal_pumpsitechange); break; case R.id.careportal_question: - newDialog.setOptions(question, R.string.careportal_question); + newDialog.setOptions(QUESTION, R.string.careportal_question); break; case R.id.careportal_snackbolus: - newDialog.setOptions(snackbolus, R.string.careportal_snackbolus); + newDialog.setOptions(SNACKBOLUS, R.string.careportal_snackbolus); break; case R.id.careportal_tempbasalstart: - newDialog.setOptions(tempbasalstart, R.string.careportal_tempbasalstart); + newDialog.setOptions(TEMPBASALSTART, R.string.careportal_tempbasalstart); break; case R.id.careportal_tempbasalend: - newDialog.setOptions(tempbasalend, R.string.careportal_tempbasalend); + newDialog.setOptions(TEMPBASALEND, R.string.careportal_tempbasalend); break; case R.id.careportal_openapsoffline: - newDialog.setOptions(openapsoffline, R.string.careportal_openapsoffline); + newDialog.setOptions(OPENAPSOFFLINE, R.string.careportal_openapsoffline); break; case R.id.careportal_temporarytarget: - temptarget.executeTempTarget = false; - newDialog.setOptions(temptarget, R.string.careportal_temporarytarget); + TEMPTARGET.executeTempTarget = false; + newDialog.setOptions(TEMPTARGET, R.string.careportal_temporarytarget); break; default: newDialog = null; @@ -215,22 +218,84 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli @Override public void run() { CareportalEvent careportalEvent; + NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + JSONObject extendedSettings = nsSettings.getExtendedSettings(); + // Thresholds in NS are in hours + double iageThreshold = 7*24; + double cageThreshold = 3*24; + double sageThreshold = 7*24; + double pbageThreshold = 15*24; + log.debug("NSExtendedSettings are "+extendedSettings.toString()); +// try { + JSONObject iageSettings = extendedSettings.optJSONObject("iage"); + if(iageSettings != null) + iageThreshold = iageSettings.optDouble("urgent", 7*24); + JSONObject cageSettings = extendedSettings.optJSONObject("cage"); + if(cageSettings != null) + cageThreshold = cageSettings.optDouble("urgent", 3*24); + log.debug("cageThreshold is "+cageThreshold); + JSONObject sageSettings = extendedSettings.optJSONObject("sage"); + if(sageSettings != null) + sageThreshold = sageSettings.optDouble("urgent", 7*24); +// } catch (JSONException e) { +// log.error("Unhandled exception", e); +// } String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.sResources.getString(R.string.notavailable); if (sage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); - sage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan( sageThreshold/24)){ + sage.setTextColor(MainApp.sResources.getColor(R.color.low)); + sage.setText(careportalEvent.age()); + } else { + sage.setText(careportalEvent.age()); + } + + } else { + sage.setText(notavailable); + } } if (iage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); - iage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan(iageThreshold/24)){ + iage.setTextColor(MainApp.sResources.getColor(R.color.low)); + iage.setText(careportalEvent.age()); + } else { + iage.setText(careportalEvent.age()); + } + + } else { + iage.setText(notavailable); + } } if (cage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); - cage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if (careportalEvent != null) { + if(careportalEvent.isOlderThan(cageThreshold/24)){ + cage.setTextColor(MainApp.sResources.getColor(R.color.low)); + cage.setText(careportalEvent.age()); + } else { + cage.setText(careportalEvent.age()); + } + + } else { + cage.setText(notavailable); + } } if (pbage != null) { careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE); - pbage.setText(careportalEvent != null ? careportalEvent.age() : notavailable); + if(careportalEvent != null) { + if(careportalEvent.isOlderThan(pbageThreshold/24)){ + pbage.setTextColor(MainApp.sResources.getColor(R.color.low)); + pbage.setText(careportalEvent.age()); + } else { + pbage.setText(careportalEvent.age()); + } + + } else { + pbage.setText(notavailable); + } } } } @@ -239,3 +304,4 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli } } + From 2eca7f0a026b35d2c8685291a6eefb2eaf190da4 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 4 Apr 2018 12:13:07 +0300 Subject: [PATCH 2/2] int to double in the isOlderThan() --- .../androidaps/db/CareportalEvent.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index b80f4f932e..643b5d066c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -5,6 +5,7 @@ import android.graphics.Color; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import org.apache.commons.lang3.StringUtils; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -97,6 +98,14 @@ public class CareportalEvent implements DataPointWithLabelInterface { return diff.get(TimeUnit.DAYS) + " " + MainApp.sResources.getString(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.sResources.getString(R.string.hours); } + public boolean isOlderThan(double threshold) { + Map diff = computeDiff(date, System.currentTimeMillis()); + if(diff.get(TimeUnit.DAYS) > threshold) + return true; + else + return false; + } + public String log() { return "CareportalEvent{" + "date= " + date + @@ -184,13 +193,24 @@ public class CareportalEvent implements DataPointWithLabelInterface { try { JSONObject object = new JSONObject(json); if (object.has("notes")) - return object.getString("notes"); + return StringUtils.abbreviate(object.getString("notes"), 40); } catch (JSONException e) { log.error("Unhandled exception", e); } return Translator.translate(eventType); } + public String getNotes() { + try { + JSONObject object = new JSONObject(json); + if (object.has("notes")) + return object.getString("notes"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return ""; + } + @Override public long getDuration() { try { @@ -242,4 +262,10 @@ public class CareportalEvent implements DataPointWithLabelInterface { return Color.GRAY; return Color.GRAY; } + + @Override + public int getSecondColor() { + return 0; + } + }