commit
2770e93ed4
|
@ -188,6 +188,10 @@ public class NSSettingsStatus {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
if (settingsO.has("alarmTimeagoWarnMins") && what == "alarmTimeagoWarnMins"){
|
||||
Double result = settingsO.getDouble(what);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -271,7 +275,6 @@ public class NSSettingsStatus {
|
|||
, warnBattP: sbx.extendedSettings.warnBattP || 30
|
||||
, urgentBattP: sbx.extendedSettings.urgentBattP || 20
|
||||
, enableAlerts: sbx.extendedSettings.enableAlerts || false
|
||||
|
||||
*/
|
||||
|
||||
public double extendedPumpSettings(String setting) {
|
||||
|
@ -301,6 +304,7 @@ public class NSSettingsStatus {
|
|||
return 0d;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public JSONObject extentendedPumpSettings() {
|
||||
try {
|
||||
|
@ -339,5 +343,16 @@ public class NSSettingsStatus {
|
|||
return "";
|
||||
}
|
||||
|
||||
public boolean openAPSEnabledAlerts() {
|
||||
try {
|
||||
JSONObject pump = extentendedPumpSettings();
|
||||
if (pump != null && pump.has("openaps")) {
|
||||
return pump.getBoolean("enableAlerts");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package info.nightscout.androidaps.plugins.Overview;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -9,11 +10,16 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
|
|||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
// Added by Rumen for debugging
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Created by mike on 03.12.2016.
|
||||
*/
|
||||
|
||||
public class Notification {
|
||||
private static Logger log = LoggerFactory.getLogger(Notification.class);
|
||||
|
||||
public static final int URGENT = 0;
|
||||
public static final int NORMAL = 1;
|
||||
public static final int LOW = 2;
|
||||
|
@ -93,7 +99,7 @@ public class Notification {
|
|||
this.id = NSALARM;
|
||||
this.level = NORMAL;
|
||||
this.text = nsAlarm.getTile();
|
||||
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false))
|
||||
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata,false))
|
||||
this.soundId = R.raw.alarm;
|
||||
break;
|
||||
case 2:
|
||||
|
@ -111,9 +117,11 @@ public class Notification {
|
|||
return true;
|
||||
if (level == ANNOUNCEMENT)
|
||||
return true;
|
||||
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false))
|
||||
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false))
|
||||
{
|
||||
return true;
|
||||
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false))
|
||||
}
|
||||
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_urgent_staledata, false))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -141,4 +149,35 @@ public class Notification {
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isAlarmForStaleData(){
|
||||
if(SP.getLong("snoozedTo", 0L) != 0L){
|
||||
if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
||||
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
||||
if (bgReading == null)
|
||||
return false;
|
||||
long bgReadingAgo = System.currentTimeMillis() - bgReading.date;
|
||||
int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60));
|
||||
// Added for testing
|
||||
//bgReadingAgoMin = 20;
|
||||
log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
|
||||
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
||||
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
|
||||
log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
||||
// if no thresshold from Ns get it loccally
|
||||
if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D);
|
||||
// No threshold of OpenAPS Alarm so using the one for BG
|
||||
// Added OpenAPSEnabledAlerts to alarm check
|
||||
if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){
|
||||
return true;
|
||||
}
|
||||
//snoozing for threshold
|
||||
SP.putLong("snoozedTo", (long) (bgReading.date+(threshold*1000*60L)));
|
||||
//log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.AlarmSoundService;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
|
||||
//Added by Rumen for snooze time
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 03.12.2016.
|
||||
|
@ -24,7 +25,7 @@ import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
|||
public class NotificationStore {
|
||||
private static Logger log = LoggerFactory.getLogger(NotificationStore.class);
|
||||
public List<Notification> store = new ArrayList<Notification>();
|
||||
|
||||
public long snoozedUntil = 0L;
|
||||
public NotificationStore() {
|
||||
}
|
||||
|
||||
|
@ -86,4 +87,18 @@ public class NotificationStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void snoozeTo(long timeToSnooze){
|
||||
log.debug("Snoozing alarm until: "+timeToSnooze);
|
||||
SP.putLong("snoozedTo", timeToSnooze);
|
||||
}
|
||||
|
||||
public void unSnooze(){
|
||||
if(Notification.isAlarmForStaleData()){
|
||||
Notification notification = new Notification(Notification.NSALARM, MainApp.sResources.getString(R.string.nsalarm_staledata), Notification.URGENT);
|
||||
SP.putLong("snoozedTo", System.currentTimeMillis());
|
||||
add(notification);
|
||||
log.debug("Snoozed to current time and added back notification!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,9 @@ import info.nightscout.utils.Profiler;
|
|||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
//Added By Rumen for staledata alarm
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
|
||||
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
|
||||
|
@ -1748,6 +1750,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
public void onBindViewHolder(NotificationsViewHolder holder, int position) {
|
||||
Notification notification = notificationsList.get(position);
|
||||
holder.dismiss.setTag(notification);
|
||||
if(notification.text == MainApp.sResources.getString(R.string.nsalarm_staledata))
|
||||
holder.dismiss.setText("snooze");
|
||||
holder.text.setText(notification.text);
|
||||
holder.time.setText(DateUtil.timeString(notification.date));
|
||||
if (notification.level == Notification.URGENT)
|
||||
|
@ -1796,6 +1800,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
if (notification.nsAlarm != null) {
|
||||
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
|
||||
}
|
||||
// Adding current time to snooze if we got staleData
|
||||
log.debug("Notification text is: "+notification.text);
|
||||
if(notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))){
|
||||
NotificationStore nstore = getPlugin().notificationStore;
|
||||
long msToSnooze = SP.getInt("nsalarm_staledatavalue",15)*60*1000L;
|
||||
log.debug("snooze nsalarm_staledatavalue in minutes is "+SP.getInt("nsalarm_staledatavalue",15)+"\n in ms is: "+msToSnooze+" currentTimeMillis is: "+System.currentTimeMillis());
|
||||
nstore.snoozeTo(System.currentTimeMillis()+(SP.getInt("nsalarm_staledatavalue",15)*60*1000L));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1810,6 +1822,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
public void run() {
|
||||
NotificationStore nstore = getPlugin().notificationStore;
|
||||
nstore.removeExpired();
|
||||
nstore.unSnooze();
|
||||
if (nstore.store.size() > 0) {
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(nstore.store);
|
||||
notificationsView.setAdapter(adapter);
|
||||
|
|
|
@ -459,4 +459,4 @@
|
|||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in a new issue