From 8c02daf39dfafe14eadb75a1c586184ca8a406c6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 15 Jan 2020 11:18:25 +0100 Subject: [PATCH] Fix NPE --- .../androidaps/db/DatabaseHelper.java | 8 ++++-- .../general/overview/OverviewFragment.java | 28 ++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 9fc3431068..a8812335d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1437,7 +1437,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { QueryBuilder queryBuilder = getDaoCareportalEvents().queryBuilder(); queryBuilder.orderBy("date", ascending); Where where = queryBuilder.where(); - where.ge("date", mills).and().isNotNull("json"); + where.ge("date", mills).and().isNotNull("json").and().isNotNull("eventType"); PreparedQuery preparedQuery = queryBuilder.prepare(); careportalEvents = getDaoCareportalEvents().query(preparedQuery); preprocessOpenAPSOfflineEvents(careportalEvents); @@ -1454,7 +1454,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { QueryBuilder queryBuilder = getDaoCareportalEvents().queryBuilder(); queryBuilder.orderBy("date", ascending); Where where = queryBuilder.where(); - where.between("date", start, end); + where.between("date", start, end).and().isNotNull("json").and().isNotNull("eventType"); PreparedQuery preparedQuery = queryBuilder.prepare(); careportalEvents = getDaoCareportalEvents().query(preparedQuery); preprocessOpenAPSOfflineEvents(careportalEvents); @@ -1481,7 +1481,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { QueryBuilder queryBuilder = getDaoCareportalEvents().queryBuilder(); queryBuilder.orderBy("date", ascending); Where where = queryBuilder.where(); - where.ge("date", mills).and().eq("eventType", type); + where.ge("date", mills).and().eq("eventType", type).and().isNotNull("json"); PreparedQuery preparedQuery = queryBuilder.prepare(); careportalEvents = getDaoCareportalEvents().query(preparedQuery); preprocessOpenAPSOfflineEvents(careportalEvents); @@ -1497,6 +1497,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { List careportalEvents; QueryBuilder queryBuilder = getDaoCareportalEvents().queryBuilder(); queryBuilder.orderBy("date", ascending); + Where where = queryBuilder.where(); + where.isNotNull("json").and().isNotNull("eventType"); PreparedQuery preparedQuery = queryBuilder.prepare(); careportalEvents = getDaoCareportalEvents().query(preparedQuery); preprocessOpenAPSOfflineEvents(careportalEvents); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 2a246c596c..9bffc90892 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -1183,23 +1183,19 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final ExtendedBolus extendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); String extendedBolusText = ""; if (extendedBolusView != null) { // must not exists in all layouts - if (shorttextmode) { - if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) { - extendedBolusText = DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h"; - } - } else { - if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) { - extendedBolusText = extendedBolus.toStringMedium(); - } - } + if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) + extendedBolusText = shorttextmode ? DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h" : extendedBolus.toStringMedium(); extendedBolusView.setText(extendedBolusText); - extendedBolusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.extended_bolus), extendedBolus.toString())); - if (extendedBolusText.equals("")) { - extendedBolusLayout.setVisibility(View.GONE); - if (extendedBolusLayout != null) extendedBolusView.setVisibility(Config.NSCLIENT ? View.INVISIBLE : View.GONE); - } else { - extendedBolusView.setVisibility(View.VISIBLE); - if (extendedBolusLayout != null) extendedBolusLayout.setVisibility(View.VISIBLE); + extendedBolusView.setOnClickListener(v -> { + if (extendedBolus != null) + OKDialog.show(getActivity(), MainApp.gs(R.string.extended_bolus), extendedBolus.toString()); + }); + // hide whole line for APS mode + if (extendedBolusLayout != null) { + if (extendedBolusText.equals("")) + extendedBolusLayout.setVisibility(View.GONE); + else + extendedBolusLayout.setVisibility(View.VISIBLE); } }