SMS logging and resource refactor
This commit is contained in:
parent
666874c6c4
commit
87ad140eb5
4 changed files with 31 additions and 25 deletions
|
@ -140,7 +140,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
.setMessage(R.string.reset_db_confirm)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override public void onClick(DialogInterface dialog, int which) {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MainApp.getDbHelper().resetDatabases();
|
||||
}
|
||||
})
|
||||
|
@ -208,31 +209,31 @@ public class MainActivity extends AppCompatActivity {
|
|||
//check for sms permission if enable in prefernces
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
if (ev.isChanged(R.string.key_smscommunicator_remotecommandsallowed)) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
synchronized (this){
|
||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||
synchronized (this) {
|
||||
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
||||
setAskForSMS();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void setAskForSMS() {
|
||||
askForSMS = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
askForSMSPermissions();
|
||||
}
|
||||
|
||||
private synchronized void askForSMSPermissions(){
|
||||
private synchronized void askForSMSPermissions() {
|
||||
if (askForSMS) { //only when settings were changed an MainActivity resumes.
|
||||
askForSMS = false;
|
||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||
if (SP.getBoolean(R.string.smscommunicator_remotecommandsallowed, false)) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
||||
Manifest.permission.SEND_SMS,
|
||||
|
@ -244,7 +245,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
private void askForPermission(String[] permission, Integer requestCode) {
|
||||
boolean test = false;
|
||||
for (int i=0; i < permission.length; i++) {
|
||||
for (int i = 0; i < permission.length; i++) {
|
||||
test = test || (ContextCompat.checkSelfPermission(this, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
||||
}
|
||||
if (test) {
|
||||
|
@ -276,10 +277,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View v = getCurrentFocus();
|
||||
if ( v instanceof EditText) {
|
||||
if (v instanceof EditText) {
|
||||
Rect outRect = new Rect();
|
||||
v.getGlobalVisibleRect(outRect);
|
||||
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
|
||||
if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
||||
v.clearFocus();
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
|
|
|
@ -160,7 +160,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
|
||||
@Subscribe
|
||||
public void processSettings(final EventPreferenceChange ev) {
|
||||
String settings = SP.getString("smscommunicator_allowednumbers", "");
|
||||
if (ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
|
||||
String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
|
||||
|
||||
String pattern = ";";
|
||||
|
||||
|
@ -171,6 +172,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
log.debug("Found allowed number: " + cleaned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAllowedNumber(String number) {
|
||||
for (String num : allowedNumbers) {
|
||||
|
@ -317,7 +319,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
break;
|
||||
case "BASAL":
|
||||
if (splited.length > 1) {
|
||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
||||
if (remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
|
@ -353,7 +355,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
} else if (splited.length > 1) {
|
||||
amount = SafeParse.stringToDouble(splited[1]);
|
||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (amount > 0d && remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
|
||||
|
@ -370,7 +372,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
case "CAL":
|
||||
if (splited.length > 1) {
|
||||
amount = SafeParse.stringToDouble(splited[1]);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean("smscommunicator_remotecommandsallowed", false);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (amount > 0d && remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
|
||||
|
@ -478,6 +480,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
sms.text = stripAccents(sms.text);
|
||||
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
||||
try {
|
||||
log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text);
|
||||
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
|
||||
messages.add(sms);
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -542,4 +542,6 @@
|
|||
<string name="wear_detailedIOB_summary">Break down IOB into bolus and basal IOB on the watchface</string>
|
||||
<string name="nosuccess">not successful - please check phone</string>
|
||||
<string name="notavailable">Not available</string>
|
||||
<string name="key_smscommunicator_allowednumbers" translatable="false">smscommunicator_allowednumbers</string>
|
||||
<string name="key_smscommunicator_remotecommandsallowed" translatable="false">smscommunicator_remotecommandsallowed</string>
|
||||
</resources>
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
<EditTextPreference
|
||||
android:title="@string/smscommunicator_allowednumbers"
|
||||
android:summary="@string/smscommunicator_allowednumbers_summary"
|
||||
android:key="smscommunicator_allowednumbers"
|
||||
android:key="@string/smscommunicator_allowednumbers"
|
||||
android:defaultValue="">
|
||||
</EditTextPreference>
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="smscommunicator_remotecommandsallowed"
|
||||
android:key="@string/key_smscommunicator_remotecommandsallowed"
|
||||
android:title="@string/smscommunicator_remotecommandsallowed" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
|
Loading…
Reference in a new issue