From 0cc9ee4193b9487bd4a8a82811e83218727420e5 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 17 Aug 2017 21:24:31 +0200 Subject: [PATCH 1/6] Avoid npe if no string is assigned to the profile switch --- .../plugins/Treatments/fragments/ProfileViewerDialog.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index 0572bc936f..46decf0b77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -88,7 +88,7 @@ public class ProfileViewerDialog extends DialogFragment { private void setContent() { Profile profile = null; ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time); - if(profileSwitch!=null){ + if(profileSwitch!=null && profileSwitch.profileJson != null){ profile = profileSwitch.getProfileObject(); } if (profile != null) { @@ -105,9 +105,4 @@ public class ProfileViewerDialog extends DialogFragment { noProfile.setVisibility(View.VISIBLE); } } - - - - - } From 5d6327bfaa4c790ef30fa5613089156f5570777f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 17 Aug 2017 21:34:30 +0200 Subject: [PATCH 2/6] static variables -> object variables --- .../PumpDanaR/Dialogs/ProfileViewDialog.java | 18 +++++++------- .../fragments/ProfileViewerDialog.java | 24 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java index 4015b8856b..a20934fdb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java @@ -33,16 +33,16 @@ import info.nightscout.utils.DecimalFormatter; public class ProfileViewDialog extends DialogFragment { private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class); - private static TextView noProfile; - private static TextView units; - private static TextView dia; - private static TextView activeProfile; - private static TextView ic; - private static TextView isf; - private static TextView basal; - private static TextView target; + private TextView noProfile; + private TextView units; + private TextView dia; + private TextView activeProfile; + private TextView ic; + private TextView isf; + private TextView basal; + private TextView target; - private static Button refreshButton; + private Button refreshButton; Handler mHandler; static HandlerThread mHandlerThread; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index 46decf0b77..5fc19bc24d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -30,18 +30,18 @@ public class ProfileViewerDialog extends DialogFragment { private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class); - private static TextView noProfile; - private static TextView units; - private static TextView dia; - private static TextView activeProfile; - private static TextView ic; - private static TextView isf; - private static TextView basal; - private static TextView target; - private static View dateDelimiter; - private static LinearLayout dateLayout; - private static TextView dateTextView; - private static Button refreshButton; + private TextView noProfile; + private TextView units; + private TextView dia; + private TextView activeProfile; + private TextView ic; + private TextView isf; + private TextView basal; + private TextView target; + private View dateDelimiter; + private LinearLayout dateLayout; + private TextView dateTextView; + private Button refreshButton; static ProfileViewerDialog newInstance(long time) { ProfileViewerDialog dialog = new ProfileViewerDialog(); From 4f2357e9fbc04015ce40927de148416103a6acf2 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 17 Aug 2017 21:17:31 +0200 Subject: [PATCH 3/6] Use OK/Cancel buttons for profile removal dialog. --- .../fragments/TreatmentsProfileSwitchFragment.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java index 15fd3513e9..fc9d836b8b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -130,9 +130,11 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen final ProfileSwitch profileSwitch = (ProfileSwitch) v.getTag(); switch (v.getId()) { case R.id.profileswitch_remove: - OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.confirmation), MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(profileSwitch.date), new Runnable() { - @Override - public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); + builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(profileSwitch.date)); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { final String _id = profileSwitch._id; if (_id != null && !_id.equals("")) { NSUpload.removeCareportalEntryFromNS(_id); @@ -140,6 +142,8 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen MainApp.getDbHelper().delete(profileSwitch); } }); + builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null); + builder.show(); break; case R.id.profileswitch_date: case R.id.profileswitch_name: From a6351f44551ec6e623c2f503d230e4f34589b4ae Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 17 Aug 2017 21:17:52 +0200 Subject: [PATCH 4/6] Fix some warnings. --- .../plugins/ProfileNS/NSProfileFragment.java | 16 ++++++------- .../fragments/ProfileViewerDialog.java | 24 +++++++++---------- .../TreatmentsTempTargetFragment.java | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java index c8b5b2c5db..007c3dfbdf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java @@ -24,14 +24,14 @@ public class NSProfileFragment extends SubscriberFragment { return nsProfilePlugin; } - private static TextView noProfile; - private static TextView units; - private static TextView dia; - private static TextView activeProfile; - private static TextView ic; - private static TextView isf; - private static TextView basal; - private static TextView target; + private TextView noProfile; + private TextView units; + private TextView dia; + private TextView activeProfile; + private TextView ic; + private TextView isf; + private TextView basal; + private TextView target; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index 5fc19bc24d..b4461eabb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -30,18 +30,18 @@ public class ProfileViewerDialog extends DialogFragment { private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class); - private TextView noProfile; - private TextView units; - private TextView dia; - private TextView activeProfile; - private TextView ic; - private TextView isf; - private TextView basal; - private TextView target; - private View dateDelimiter; - private LinearLayout dateLayout; - private TextView dateTextView; - private Button refreshButton; + private TextView noProfile; + private TextView units; + private TextView dia; + private TextView activeProfile; + private TextView ic; + private TextView isf; + private TextView basal; + private TextView target; + private View dateDelimiter; + private LinearLayout dateLayout; + private TextView dateTextView; + private Button refreshButton; static ProfileViewerDialog newInstance(long time) { ProfileViewerDialog dialog = new ProfileViewerDialog(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java index 008c82e612..9e3836e118 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java @@ -141,7 +141,6 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements @Override public void onClick(View v) { final TempTarget tempTarget = (TempTarget) v.getTag(); - final Context finalContext = context; switch (v.getId()) { case R.id.temptargetrange_remove: AlertDialog.Builder builder = new AlertDialog.Builder(context); From 5991f307afb32feb883fd989d43dedd43e7d8b1c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 17 Aug 2017 21:43:16 +0200 Subject: [PATCH 5/6] Profile.getValuesList: don't add trailing newline. --- app/src/main/java/info/nightscout/androidaps/data/Profile.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 48081c956c..85b8355bf5 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -212,7 +212,8 @@ public class Profile { retValue += format.format(o2.getDouble("value")); } retValue += " " + units; - retValue += "\n"; + if (index + 1 < array.length()) + retValue += "\n"; } catch (JSONException e) { e.printStackTrace(); } From 6b8dd5868d242270f15bac41c5314ac3fe2cbd84 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 18 Aug 2017 11:46:04 +0200 Subject: [PATCH 6/6] fix displaying target in mmol --- .../main/java/info/nightscout/androidaps/data/Profile.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 85b8355bf5..ac7cc0edd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -393,8 +393,9 @@ public class Profile { else return DecimalFormatter.to1Decimal(valueInMmol); } + // targets are stored in mg/dl public static String toTargetRangeString(double low, double high, String units) { - if (low == high) return toUnitsString(low, low, units); - else return toUnitsString(low, low, units) + " - " + toUnitsString(high, high, units); + if (low == high) return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units); + else return toUnitsString(low, Profile.fromMgdlToUnits(low, Constants.MMOL), units) + " - " + toUnitsString(high, Profile.fromMgdlToUnits(high, Constants.MMOL), units); } }