remove direct access to sResources 3

This commit is contained in:
AdrianLxM 2018-05-02 13:42:50 +02:00
parent a8382daefd
commit 2af62d8e4e
9 changed files with 89 additions and 89 deletions

View file

@ -32,12 +32,12 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
@Override @Override
public String getFriendlyName() { public String getFriendlyName() {
return MainApp.sResources.getString(R.string.rapid_acting_oref); return MainApp.gs(R.string.rapid_acting_oref);
} }
@Override @Override
public String commentStandardText() { public String commentStandardText() {
return MainApp.sResources.getString(R.string.fastactinginsulincomment); return MainApp.gs(R.string.fastactinginsulincomment);
} }
@Override @Override

View file

@ -258,7 +258,7 @@ public class LoopPlugin extends PluginBase {
Constraint<Boolean> loopEnabled = MainApp.getConstraintChecker().isLoopInvokationAllowed(); Constraint<Boolean> loopEnabled = MainApp.getConstraintChecker().isLoopInvokationAllowed();
if (!loopEnabled.value()) { if (!loopEnabled.value()) {
String message = MainApp.sResources.getString(R.string.loopdisabled) + "\n" + loopEnabled.getReasons(); String message = MainApp.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
log.debug(message); log.debug(message);
MainApp.bus().post(new EventLoopSetLastRunGui(message)); MainApp.bus().post(new EventLoopSetLastRunGui(message));
return; return;
@ -272,8 +272,8 @@ public class LoopPlugin extends PluginBase {
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (!MainApp.getConfigBuilder().isProfileValid("Loop")) { if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
log.debug(MainApp.sResources.getString(R.string.noprofileselected)); log.debug(MainApp.gs(R.string.noprofileselected));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected))); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected)));
return; return;
} }
@ -288,7 +288,7 @@ public class LoopPlugin extends PluginBase {
// Check if we have any result // Check if we have any result
if (result == null) { if (result == null) {
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noapsselected))); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noapsselected)));
return; return;
} }
@ -317,14 +317,14 @@ public class LoopPlugin extends PluginBase {
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
if (isSuspended()) { if (isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.loopsuspended)); log.debug(MainApp.gs(R.string.loopsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopsuspended))); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.loopsuspended)));
return; return;
} }
if (pump.isSuspended()) { if (pump.isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.pumpsuspended)); log.debug(MainApp.gs(R.string.pumpsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended))); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.pumpsuspended)));
return; return;
} }
@ -376,7 +376,7 @@ public class LoopPlugin extends PluginBase {
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(MainApp.instance().getApplicationContext(), CHANNEL_ID); new NotificationCompat.Builder(MainApp.instance().getApplicationContext(), CHANNEL_ID);
builder.setSmallIcon(R.drawable.notif_icon) builder.setSmallIcon(R.drawable.notif_icon)
.setContentTitle(MainApp.sResources.getString(R.string.openloop_newsuggestion)) .setContentTitle(MainApp.gs(R.string.openloop_newsuggestion))
.setContentText(resultAfterConstraints.toString()) .setContentText(resultAfterConstraints.toString())
.setAutoCancel(true) .setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)

View file

@ -60,7 +60,7 @@ public class NotificationStore {
} }
store.add(n); store.add(n);
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_raise_notifications_as_android_notifications), false)) { if (SP.getBoolean(MainApp.gs(R.string.key_raise_notifications_as_android_notifications), false)) {
raiseSystemNotification(n); raiseSystemNotification(n);
} else { } else {
if (n.soundId != null) { if (n.soundId != null) {
@ -105,7 +105,7 @@ public class NotificationStore {
public void unSnooze() { public void unSnooze() {
if (Notification.isAlarmForStaleData()) { if (Notification.isAlarmForStaleData()) {
Notification notification = new Notification(Notification.NSALARM, MainApp.sResources.getString(R.string.nsalarm_staledata), Notification.URGENT); Notification notification = new Notification(Notification.NSALARM, MainApp.gs(R.string.nsalarm_staledata), Notification.URGENT);
SP.putLong("snoozedTo", System.currentTimeMillis()); SP.putLong("snoozedTo", System.currentTimeMillis());
add(notification); add(notification);
log.debug("Snoozed to current time and added back notification!"); log.debug("Snoozed to current time and added back notification!");
@ -126,11 +126,11 @@ public class NotificationStore {
.setDeleteIntent(DismissNotificationService.deleteIntent(n.id)); .setDeleteIntent(DismissNotificationService.deleteIntent(n.id));
if (n.level == Notification.URGENT) { if (n.level == Notification.URGENT) {
notificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000}) notificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000})
.setContentTitle(MainApp.sResources.getString(R.string.urgent_alarm)) .setContentTitle(MainApp.gs(R.string.urgent_alarm))
.setSound(sound, AudioAttributes.USAGE_ALARM); .setSound(sound, AudioAttributes.USAGE_ALARM);
} else { } else {
notificationBuilder.setVibrate(new long[]{0, 100, 50, 100, 50}) notificationBuilder.setVibrate(new long[]{0, 100, 50, 100, 50})
.setContentTitle(MainApp.sResources.getString(R.string.info)) .setContentTitle(MainApp.gs(R.string.info))
; ;
} }
mgr.notify(n.id, notificationBuilder.build()); mgr.notify(n.id, notificationBuilder.build());

View file

@ -25,19 +25,19 @@ public class MsgError extends MessageBase {
case 1: case 1:
case 2: case 2:
case 3: // Pump error case 3: // Pump error
errorString = MainApp.sResources.getString(R.string.pumperror) + " " + errorCode; errorString = MainApp.gs(R.string.pumperror) + " " + errorCode;
break; break;
case 4: // Shutdown case 4: // Shutdown
errorString = MainApp.sResources.getString(R.string.pumpshutdown); errorString = MainApp.gs(R.string.pumpshutdown);
break; break;
case 5: // Occlusion case 5: // Occlusion
errorString = MainApp.sResources.getString(R.string.occlusion); errorString = MainApp.gs(R.string.occlusion);
break; break;
case 7: // Low Battery case 7: // Low Battery
errorString = MainApp.sResources.getString(R.string.lowbattery); errorString = MainApp.gs(R.string.lowbattery);
break; break;
case 8: // Battery 0% case 8: // Battery 0%
errorString = MainApp.sResources.getString(R.string.batterydischarged); errorString = MainApp.gs(R.string.batterydischarged);
break; break;
} }

View file

@ -105,7 +105,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public void connect() { public void connect() {
if (mDanaRPump.password != -1 && mDanaRPump.password != SP.getInt(R.string.key_danar_password, -1)) { if (mDanaRPump.password != -1 && mDanaRPump.password != SP.getInt(R.string.key_danar_password, -1)) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.wrongpumppassword), R.raw.error);
return; return;
} }
@ -146,7 +146,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public void getPumpStatus() { public void getPumpStatus() {
try { try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
//MsgStatus_k statusMsg = new MsgStatus_k(); //MsgStatus_k statusMsg = new MsgStatus_k();
MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k(); MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
@ -162,15 +162,15 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
//mSerialIOThread.sendMessage(statusMsg); //mSerialIOThread.sendMessage(statusMsg);
mSerialIOThread.sendMessage(statusBasicMsg); mSerialIOThread.sendMessage(statusBasicMsg);
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingtempbasalstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingtempbasalstatus)));
mSerialIOThread.sendMessage(tempStatusMsg); mSerialIOThread.sendMessage(tempStatusMsg);
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus)));
mSerialIOThread.sendMessage(exStatusMsg); mSerialIOThread.sendMessage(exStatusMsg);
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isInitialized()) { if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isInitialized()) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingMeal()); mSerialIOThread.sendMessage(new MsgSettingMeal());
mSerialIOThread.sendMessage(new MsgSettingBasal_k()); mSerialIOThread.sendMessage(new MsgSettingBasal_k());
@ -178,7 +178,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingMaxValues()); mSerialIOThread.sendMessage(new MsgSettingMaxValues());
mSerialIOThread.sendMessage(new MsgSettingGlucose()); mSerialIOThread.sendMessage(new MsgSettingGlucose());
mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumptime))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L;
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
@ -197,9 +197,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) { if (mDanaRPump.dailyTotalUnits > mDanaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits); log.debug("Approaching daily limit: " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits);
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT); Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(reportFail)); MainApp.bus().post(new EventNewNotification(reportFail));
NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U"); NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + mDanaRPump.dailyTotalUnits + "/" + mDanaRPump.maxDailyTotalUnits + "U");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -209,11 +209,11 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean tempBasal(int percent, int durationInHours) { public boolean tempBasal(int percent, int durationInHours) {
if (!isConnected()) return false; if (!isConnected()) return false;
if (mDanaRPump.isTempBasalInProgress) { if (mDanaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500); SystemClock.sleep(500);
} }
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal()); mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
@ -222,7 +222,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean tempBasalStop() { public boolean tempBasalStop() {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
mSerialIOThread.sendMessage(new MsgStatusTempBasal()); mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
@ -231,7 +231,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) { public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
@ -240,7 +240,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolusStop() { public boolean extendedBolusStop() {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
@ -310,7 +310,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean updateBasalsInPump(final Profile profile) { public boolean updateBasalsInPump(final Profile profile) {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.buildDanaRProfileRecord(profile); double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal); MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet); mSerialIOThread.sendMessage(msgSet);

View file

@ -56,9 +56,9 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte
String age = SP.getString(R.string.key_age, ""); String age = SP.getString(R.string.key_age, "");
int defaultHours = 24; int defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; if (age.equals(MainApp.gs(R.string.key_adult))) defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; if (age.equals(MainApp.gs(R.string.key_teenage))) defaultHours = 4;
if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; if (age.equals(MainApp.gs(R.string.key_child))) defaultHours = 4;
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();

View file

@ -52,9 +52,9 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens
String age = SP.getString(R.string.key_age, ""); String age = SP.getString(R.string.key_age, "");
int defaultHours = 24; int defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; if (age.equals(MainApp.gs(R.string.key_adult))) defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; if (age.equals(MainApp.gs(R.string.key_teenage))) defaultHours = 4;
if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; if (age.equals(MainApp.gs(R.string.key_child))) defaultHours = 4;
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
if (autosensDataTable == null || autosensDataTable.size() < 4) { if (autosensDataTable == null || autosensDataTable.size() < 4) {

View file

@ -206,24 +206,24 @@ public class SmsCommunicatorPlugin extends PluginBase {
String units = MainApp.getConfigBuilder().getProfileUnits(); String units = MainApp.getConfigBuilder().getProfileUnits();
if (actualBG != null) { if (actualBG != null) {
reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
} else if (lastBG != null) { } else if (lastBG != null) {
Long agoMsec = System.currentTimeMillis() - lastBG.date; Long agoMsec = System.currentTimeMillis() - lastBG.date;
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
reply = MainApp.sResources.getString(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.sResources.getString(R.string.sms_minago), agoMin) + ", "; reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", ";
} }
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
if (glucoseStatus != null) if (glucoseStatus != null)
reply += MainApp.sResources.getString(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); TreatmentsPlugin.getPlugin().updateTotalIOBTreatments();
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round();
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" reply += MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ MainApp.sResources.getString(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)"; + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
receivedSms.processed = true; receivedSms.processed = true;
@ -241,8 +241,8 @@ public class SmsCommunicatorPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
String reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled) + " " + String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " +
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
}); });
@ -255,7 +255,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginType.LOOP, true); loopPlugin.setPluginEnabled(PluginType.LOOP, true);
reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeenenabled); reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
} }
@ -267,11 +267,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (loopPlugin != null) { if (loopPlugin != null) {
if (loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (loopPlugin.isSuspended()) if (loopPlugin.isSuspended())
reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); reply = String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend());
else else
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisenabled); reply = MainApp.gs(R.string.smscommunicator_loopisenabled);
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisdisabled); reply = MainApp.gs(R.string.smscommunicator_loopisdisabled);
} }
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
@ -282,7 +282,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
LoopPlugin.getPlugin().suspendTo(0); LoopPlugin.getPlugin().suspendTo(0);
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME"));
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
reply = MainApp.sResources.getString(R.string.smscommunicator_loopresumed); reply = MainApp.gs(R.string.smscommunicator_loopresumed);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
break; break;
@ -292,18 +292,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
duration = Math.max(0, duration); duration = Math.max(0, duration);
duration = Math.min(180, duration); duration = Math.min(180, duration);
if (duration == 0) { if (duration == 0) {
reply = MainApp.sResources.getString(R.string.smscommunicator_wrongduration); reply = MainApp.gs(R.string.smscommunicator_wrongduration);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else if (remoteCommandsAllowed) { } else if (remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_suspendreplywithcode), duration, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
suspendWaitingForConfirmation.duration = duration; suspendWaitingForConfirmation.duration = duration;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend"));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotecommandnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
break; break;
@ -350,7 +350,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} else { } else {
String reply = MainApp.sResources.getString(R.string.readstatusfailed); String reply = MainApp.gs(R.string.readstatusfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} }
@ -363,33 +363,33 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) { if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
if (remoteCommandsAllowed) { if (remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_basalstopreplywithcode), passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebasalnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} else { } else {
tempBasal = SafeParse.stringToDouble(splited[1]); tempBasal = SafeParse.stringToDouble(splited[1]);
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) { if (profile == null) {
reply = MainApp.sResources.getString(R.string.noprofile); reply = MainApp.gs(R.string.noprofile);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value(); tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
if (remoteCommandsAllowed) { if (remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
tempBasalWaitingForConfirmation.tempBasal = tempBasal; tempBasalWaitingForConfirmation.tempBasal = tempBasal;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebasalnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} }
@ -398,24 +398,24 @@ public class SmsCommunicatorPlugin extends PluginBase {
break; break;
case "BOLUS": case "BOLUS":
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) { if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebolusnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else if (ConfigBuilderPlugin.getActivePump().isSuspended()) { } else if (ConfigBuilderPlugin.getActivePump().isSuspended()) {
reply = MainApp.sResources.getString(R.string.pumpsuspended); reply = MainApp.gs(R.string.pumpsuspended);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else if (splited.length > 1) { } else if (splited.length > 1) {
amount = SafeParse.stringToDouble(splited[1]); amount = SafeParse.stringToDouble(splited[1]);
amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value(); amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
if (amount > 0d && remoteCommandsAllowed) { if (amount > 0d && remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
bolusWaitingForConfirmation.bolusRequested = amount; bolusWaitingForConfirmation.bolusRequested = amount;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus"));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebolusnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} }
@ -425,14 +425,14 @@ public class SmsCommunicatorPlugin extends PluginBase {
amount = SafeParse.stringToDouble(splited[1]); amount = SafeParse.stringToDouble(splited[1]);
if (amount > 0d && remoteCommandsAllowed) { if (amount > 0d && remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
calibrationWaitingForConfirmation.calibrationRequested = amount; calibrationWaitingForConfirmation.calibrationRequested = amount;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal"));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_remotecalibrationnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} }
@ -449,13 +449,13 @@ public class SmsCommunicatorPlugin extends PluginBase {
public void run() { public void run() {
PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
if (result.success) { if (result.success) {
String reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered); String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
if (pump != null) if (pump != null)
reply += "\n" + pump.shortStatus(true); reply += "\n" + pump.shortStatus(true);
lastRemoteBolusTime = new Date(); lastRemoteBolusTime = new Date();
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
String reply = MainApp.sResources.getString(R.string.smscommunicator_bolusfailed); String reply = MainApp.gs(R.string.smscommunicator_bolusfailed);
if (pump != null) if (pump != null)
reply += "\n" + pump.shortStatus(true); reply += "\n" + pump.shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
@ -471,11 +471,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (result.success) { if (result.success) {
String reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); String reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
@ -488,11 +488,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (result.success) { if (result.success) {
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
@ -503,10 +503,10 @@ public class SmsCommunicatorPlugin extends PluginBase {
calibrationWaitingForConfirmation.processed = true; calibrationWaitingForConfirmation.processed = true;
boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
if (result) { if (result) {
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationsent); reply = MainApp.gs(R.string.smscommunicator_calibrationsent);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed); reply = MainApp.gs(R.string.smscommunicator_calibrationfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed && } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
@ -519,18 +519,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60); NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
String reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " + String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
} else { } else {
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} }
}); });
} else { } else {
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date())); sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand), new Date()));
} }
resetWaitingMessages(); resetWaitingMessages();
break; break;
@ -563,10 +563,10 @@ public class SmsCommunicatorPlugin extends PluginBase {
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null); smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
messages.add(sms); messages.add(sms);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.sResources.getString(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
} catch (java.lang.SecurityException e) { } catch (java.lang.SecurityException e) {
Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.sResources.getString(R.string.smscommunicator_missingsmspermission), Notification.NORMAL); Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
} }
} }

View file

@ -26,21 +26,21 @@ public class LocalAlertUtils {
private static Logger log = LoggerFactory.getLogger(LocalAlertUtils.class); private static Logger log = LoggerFactory.getLogger(LocalAlertUtils.class);
public static long missedReadingsThreshold() { public static long missedReadingsThreshold() {
return T.mins(SP.getInt(MainApp.sResources.getString(R.string.key_missed_bg_readings_threshold), 30)).msecs(); return T.mins(SP.getInt(MainApp.gs(R.string.key_missed_bg_readings_threshold), 30)).msecs();
} }
private static long pumpUnreachableThreshold() { private static long pumpUnreachableThreshold() {
return T.mins(SP.getInt(MainApp.sResources.getString(R.string.key_pump_unreachable_threshold), 30)).msecs(); return T.mins(SP.getInt(MainApp.gs(R.string.key_pump_unreachable_threshold), 30)).msecs();
} }
public static void checkPumpUnreachableAlarm(Date lastConnection, boolean isStatusOutdated) { public static void checkPumpUnreachableAlarm(Date lastConnection, boolean isStatusOutdated) {
boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis(); boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis();
boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis(); boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis();
if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true) if (Config.APS && SP.getBoolean(MainApp.gs(R.string.key_enable_pump_unreachable_alert), true)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !LoopPlugin.getPlugin().isDisconnected()) { && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !LoopPlugin.getPlugin().isDisconnected()) {
log.debug("Generating pump unreachable alarm. lastConnection: " + DateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated); log.debug("Generating pump unreachable alarm. lastConnection: " + DateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated);
Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT); Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.gs(R.string.pump_unreachable), Notification.URGENT);
n.soundId = R.raw.alarm; n.soundId = R.raw.alarm;
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()); SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold());
MainApp.bus().post(new EventNewNotification(n)); MainApp.bus().post(new EventNewNotification(n));
@ -91,10 +91,10 @@ public class LocalAlertUtils {
public static void checkStaleBGAlert() { public static void checkStaleBGAlert() {
BgReading bgReading = DatabaseHelper.lastBg(); BgReading bgReading = DatabaseHelper.lastBg();
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_missed_bg_readings_alert), false) if (SP.getBoolean(MainApp.gs(R.string.key_enable_missed_bg_readings_alert), false)
&& bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis() && bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis()
&& SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) { && SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.sResources.getString(R.string.missed_bg_readings), Notification.URGENT); Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.gs(R.string.missed_bg_readings), Notification.URGENT);
n.soundId = R.raw.alarm; n.soundId = R.raw.alarm;
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()); SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold());
MainApp.bus().post(new EventNewNotification(n)); MainApp.bus().post(new EventNewNotification(n));