use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class WatchUpdaterService method sendAlertTypeData.
private void sendAlertTypeData() {
// KS
try {
forceGoogleApiConnect();
List<AlertType> alerts = AlertType.getAllActive();
if (alerts != null) {
if (wear_integration) {
Log.d(TAG, "sendAlertTypeData latest count = " + alerts.size());
final DataMap entries = new DataMap();
final ArrayList<DataMap> dataMaps = new ArrayList<>(alerts.size());
for (AlertType alert : alerts) {
if (alert != null) {
dataMaps.add(dataMap(alert, "alert"));
}
}
// MOST IMPORTANT LINE FOR TIMESTAMP
entries.putLong("time", new Date().getTime());
entries.putDataMapArrayList("entries", dataMaps);
new SendToDataLayerThread(WEARABLE_ALERTTYPE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
} else
Log.d(TAG, "sendAlertTypeData latest count = 0");
}
} catch (NullPointerException e) {
Log.e(TAG, "Nullpointer exception in sendAlertTypeData: " + e);
}
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class SnoozeActivity method setOnClickListenerOnDisableButton.
/**
* Functionality used at least three times moved to a function. Adds an onClickListener that will disable the identified alert<br>
* Depending on type of disable, also active alarms will be set to inactive<br>
* - if alert = "alerts_disabled_until" then the active bg alert will be deleted if any<br>
* - if alert = "low_alerts_disabled_until" and if active low bg alert exists then it will be deleted<br>
* - if alert = "high_alerts_disabled_until" and if active high bg alert exists then it will be deleted<br>
* @param button to which onclicklistener should be added
* @param alert identifies the alert, the text string used in the preferences ie alerts_disabled_until, low_alerts_disabled_until or high_alerts_disabled_until
*/
private void setOnClickListenerOnDisableButton(Button button, String alert) {
final String disableType = alert;
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Dialog d = new Dialog(SnoozeActivity.this);
d.setTitle(R.string.default_snooze);
d.setTitle(R.string.default_snooze);
d.setContentView(R.layout.snooze_picker);
Button b1 = (Button) d.findViewById(R.id.button1);
Button b2 = (Button) d.findViewById(R.id.button2);
final NumberPicker snoozeValue = (NumberPicker) d.findViewById(R.id.numberPicker1);
// don't use SetSnoozePickerValues because an additional value must be added
// adding place for "until you re-enable"
String[] values = new String[snoozeValues.length + 1];
for (int i = 0; i < values.length - 1; i++) values[i] = getNameFromTime(snoozeValues[i]);
values[values.length - 1] = getString(R.string.until_you_reenable);
snoozeValue.setMaxValue(values.length - 1);
snoozeValue.setMinValue(0);
snoozeValue.setDisplayedValues(values);
snoozeValue.setWrapSelectorWheel(false);
snoozeValue.setValue(getSnoozeLocatoin(60));
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Long disableUntil = new Date().getTime() + (snoozeValue.getValue() == snoozeValue.getMaxValue() ? infiniteSnoozeValueInMinutes : +(SnoozeActivity.getTimeFromSnoozeValue(snoozeValue.getValue()))) * 1000 * 60;
prefs.edit().putLong(disableType, disableUntil).apply();
// check if active bg alert exists and delete it depending on type of alert
ActiveBgAlert aba = ActiveBgAlert.getOnly();
if (aba != null) {
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
if (disableType.equalsIgnoreCase("alerts_disabled_until") || (activeBgAlert.above && disableType.equalsIgnoreCase("high_alerts_disabled_until")) || (!activeBgAlert.above && disableType.equalsIgnoreCase("low_alerts_disabled_until"))) {
// active bg alert exists which is a type that is being disabled so let's remove it completely from the database
ActiveBgAlert.ClearData();
}
}
if (disableType.equalsIgnoreCase("alerts_disabled_until")) {
// disabling all , after the Snooze time set, all alarms will be re-enabled, inclusive low and high bg alarms
prefs.edit().putLong("high_alerts_disabled_until", 0).apply();
prefs.edit().putLong("low_alerts_disabled_until", 0).apply();
}
d.dismiss();
// also make sure the text in the Activity is changed
displayStatus();
showDisableEnableButtons();
recheckAlerts();
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
showDisableEnableButtons();
}
});
d.show();
}
});
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class SnoozeActivity method displayStatus.
void displayStatus() {
ActiveBgAlert aba = ActiveBgAlert.getOnly();
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
// aba and activeBgAlert should both either exist ot not exist. all other cases are a bug in another place
if (aba == null && activeBgAlert != null) {
Log.wtf(TAG, "ERRRO displayStatus: aba == null, but activeBgAlert != null exiting...");
return;
}
if (aba != null && activeBgAlert == null) {
Log.wtf(TAG, "ERRRO displayStatus: aba != null, but activeBgAlert == null exiting...");
return;
}
long now = new Date().getTime();
if (activeBgAlert == null) {
sendRemoteSnooze.setVisibility(Pref.getBooleanDefaultFalse("send_snooze_to_remote") ? View.VISIBLE : View.GONE);
if (prefs.getLong("alerts_disabled_until", 0) > now || (prefs.getLong("low_alerts_disabled_until", 0) > now && prefs.getLong("high_alerts_disabled_until", 0) > now)) {
// not useful to show now that there's no active alert because either all alerts are disabled or high and low alerts are disabled
// there can not be any active alert
status = "";
} else {
status = getString(R.string.no_active_alert_exists);
}
buttonSnooze.setVisibility(View.GONE);
snoozeValue.setVisibility(View.GONE);
} else {
sendRemoteSnooze.setVisibility(View.GONE);
if (!aba.ready_to_alarm()) {
status = "Active alert exists named \"" + activeBgAlert.name + (aba.is_snoozed ? "\" Alert snoozed until " : "\" Alert will rerise at ") + DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(aba.next_alert_at)) + " (" + (aba.next_alert_at - now) / 60000 + " minutes left)";
} else {
status = getString(R.string.active_alert_exists_named) + " \"" + activeBgAlert.name + "\" " + getString(R.string.bracket_not_snoozed);
}
SetSnoozePickerValues(snoozeValue, activeBgAlert.above, activeBgAlert.default_snooze);
}
// check if there are disabled alerts and if yes add warning
if (prefs.getLong("alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("alerts_disabled_until", 0)));
status = getString(R.string.all_alerts_disabled_until) + textToAdd;
} else {
if (prefs.getLong("low_alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("low_alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if low alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("low_alerts_disabled_until", 0)));
status += "\n\n" + getString(R.string.low_alerts_disabled_until) + textToAdd;
}
if (prefs.getLong("high_alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("high_alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if high alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("high_alerts_disabled_until", 0)));
status += "\n\n" + getString(R.string.high_alerts_disabled_until) + textToAdd;
}
}
alertStatus.setText(status);
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class AlertPlayer method Snooze.
public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) {
Log.i(TAG, "Snooze called repeatTime = " + repeatTime);
stopAlert(ctx, false, false);
ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
if (activeBgAlert == null) {
Log.e(TAG, "Error, snooze was called but no alert is active.");
// KS TODO if (from_interactive) GcmActivity.sendSnoozeToRemote();
return;
}
if (repeatTime == -1) {
// try to work out default
AlertType alert = ActiveBgAlert.alertTypegetOnly();
if (alert != null) {
repeatTime = alert.default_snooze;
Log.d(TAG, "Selecting default snooze time: " + repeatTime);
} else {
// pick a number if we cannot even find the default
repeatTime = 30;
Log.e(TAG, "Cannot even find default snooze time so going with: " + repeatTime);
}
}
activeBgAlert.snooze(repeatTime);
// KS if (from_interactive) GcmActivity.sendSnoozeToRemote();
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class SnoozeOnNotificationDismissService method snoozeBgAlert.
private void snoozeBgAlert() {
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
int snooze = 30;
if (activeBgAlert != null) {
if (activeBgAlert.default_snooze != 0) {
snooze = activeBgAlert.default_snooze;
} else {
snooze = SnoozeActivity.getDefaultSnooze(activeBgAlert.above);
}
}
AlertPlayer.getPlayer().Snooze(getApplicationContext(), snooze);
}
Aggregations