From f4138a2fc0f5b82521644501bd4358ad93a80b74 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 12 May 2019 10:43:32 +0200 Subject: [PATCH] fix index out of bouns --- .../general/overview/OverviewFragment.java | 23 +++---------------- .../notifications/NotificationStore.java | 21 +++++++++++++---- 2 files changed, 20 insertions(+), 24 deletions(-) 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 6d41303540..0b0724eefd 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 @@ -56,7 +56,6 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.QuickWizardEntry; @@ -94,19 +93,18 @@ import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; +import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity; import info.nightscout.androidaps.plugins.general.overview.dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.general.overview.dialogs.NewCarbsDialog; import info.nightscout.androidaps.plugins.general.overview.dialogs.NewInsulinDialog; import info.nightscout.androidaps.plugins.general.overview.dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.general.overview.dialogs.WizardDialog; -import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity; import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData; -import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationRecyclerViewAdapter; -import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore; import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress; @@ -1064,7 +1062,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, timeView.setText(DateUtil.timeString(new Date())); } - updateNotifications(); + OverviewPlugin.getPlugin().notificationStore.updateNotifications(notificationsView); pumpStatusLayout.setVisibility(View.GONE); loopStatusLayout.setVisibility(View.GONE); @@ -1603,21 +1601,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, Profiler.log(log, from, updateGUIStart); } - //Notifications - - void updateNotifications() { - NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore; - nstore.removeExpired(); - nstore.unSnooze(); - if (nstore.store.size() > 0) { - NotificationRecyclerViewAdapter adapter = new NotificationRecyclerViewAdapter(nstore.store); - notificationsView.setAdapter(adapter); - notificationsView.setVisibility(View.VISIBLE); - } else { - notificationsView.setVisibility(View.GONE); - } - } - public static void applyStatuslight(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) { Function check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold; if (value != invalid) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java index 8d327bf29f..16913d26ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.java @@ -12,6 +12,8 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.support.v4.app.NotificationCompat; +import android.support.v7.widget.RecyclerView; +import android.view.View; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,7 +23,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; @@ -97,7 +98,7 @@ public class NotificationStore { return false; } - public synchronized void removeExpired() { + private synchronized void removeExpired() { for (int i = 0; i < store.size(); i++) { Notification n = store.get(i); if (n.validTo.getTime() != 0 && n.validTo.getTime() < System.currentTimeMillis()) { @@ -107,13 +108,13 @@ public class NotificationStore { } } - public void snoozeTo(long timeToSnooze) { + void snoozeTo(long timeToSnooze) { if (L.isEnabled(L.NOTIFICATION)) log.debug("Snoozing alarm until: " + timeToSnooze); SP.putLong("snoozedTo", timeToSnooze); } - public void unSnooze() { + private void unSnooze() { if (Notification.isAlarmForStaleData()) { Notification notification = new Notification(Notification.NSALARM, MainApp.gs(R.string.nsalarm_staledata), Notification.URGENT); SP.putLong("snoozedTo", System.currentTimeMillis()); @@ -160,4 +161,16 @@ public class NotificationStore { } } + public synchronized void updateNotifications(RecyclerView notificationsView) { + removeExpired(); + unSnooze(); + if (store.size() > 0) { + NotificationRecyclerViewAdapter adapter = new NotificationRecyclerViewAdapter(store); + notificationsView.setAdapter(adapter); + notificationsView.setVisibility(View.VISIBLE); + } else { + notificationsView.setVisibility(View.GONE); + } + } + }