mirror of
https://github.com/cwinfo/envayasms.git
synced 2025-07-03 05:37:44 +00:00
add settings screen for ignored phone numbers; allow user to specify if they want to ignore non-numeric senders and shortcodes
This commit is contained in:
@ -430,6 +430,16 @@ public final class App extends Application {
|
||||
{
|
||||
return settings.getBoolean("keep_in_inbox", false);
|
||||
}
|
||||
|
||||
public boolean ignoreShortcodes()
|
||||
{
|
||||
return settings.getBoolean("ignore_shortcodes", true);
|
||||
}
|
||||
|
||||
public boolean ignoreNonNumeric()
|
||||
{
|
||||
return settings.getBoolean("ignore_non_numeric", true);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return settings.getString("password", "");
|
||||
@ -551,70 +561,134 @@ public final class App extends Application {
|
||||
return mmsUtils;
|
||||
}
|
||||
|
||||
private List<String> testPhoneNumbers;
|
||||
|
||||
public List<String> getTestPhoneNumbers()
|
||||
{
|
||||
private List<String> testPhoneNumbers;
|
||||
public synchronized List<String> getTestPhoneNumbers()
|
||||
{
|
||||
if (testPhoneNumbers == null)
|
||||
{
|
||||
testPhoneNumbers = new ArrayList<String>();
|
||||
String phoneNumbersJson = settings.getString("test_phone_numbers", "");
|
||||
|
||||
if (phoneNumbersJson.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONArray arr = new JSONArray(phoneNumbersJson);
|
||||
int numSenders = arr.length();
|
||||
for (int i = 0; i < numSenders; i++)
|
||||
{
|
||||
testPhoneNumbers.add(arr.getString(i));
|
||||
}
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
logError("Error parsing test phone numbers", ex);
|
||||
}
|
||||
}
|
||||
testPhoneNumbers = loadStringListSetting("test_phone_numbers");
|
||||
}
|
||||
return testPhoneNumbers;
|
||||
}
|
||||
|
||||
public void addTestPhoneNumber(String phoneNumber)
|
||||
public synchronized void addTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getTestPhoneNumbers();
|
||||
log("Added test phone number: " + phoneNumber);
|
||||
phoneNumbers.add(phoneNumber);
|
||||
saveTestPhoneNumbers(phoneNumbers);
|
||||
saveStringListSetting("test_phone_numbers", phoneNumbers);
|
||||
}
|
||||
|
||||
public void removeTestPhoneNumber(String phoneNumber)
|
||||
public synchronized void removeTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getTestPhoneNumbers();
|
||||
phoneNumbers.remove(phoneNumber);
|
||||
log("Removed test phone number: " + phoneNumber);
|
||||
saveTestPhoneNumbers(phoneNumbers);
|
||||
saveStringListSetting("test_phone_numbers", phoneNumbers);
|
||||
}
|
||||
|
||||
private void saveTestPhoneNumbers(List<String> phoneNumbers)
|
||||
private List<String> ignoredPhoneNumbers;
|
||||
public synchronized List<String> getIgnoredPhoneNumbers()
|
||||
{
|
||||
settings.edit().putString("test_phone_numbers",
|
||||
new JSONArray(phoneNumbers).toString()
|
||||
if (ignoredPhoneNumbers == null)
|
||||
{
|
||||
ignoredPhoneNumbers = loadStringListSetting("ignored_phone_numbers");
|
||||
}
|
||||
return ignoredPhoneNumbers;
|
||||
}
|
||||
|
||||
public synchronized void addIgnoredPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getIgnoredPhoneNumbers();
|
||||
log("Added ignored phone number: " + phoneNumber);
|
||||
phoneNumbers.add(phoneNumber);
|
||||
saveStringListSetting("ignored_phone_numbers", phoneNumbers);
|
||||
}
|
||||
|
||||
public synchronized void removeIgnoredPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getIgnoredPhoneNumbers();
|
||||
phoneNumbers.remove(phoneNumber);
|
||||
log("Removed ignored phone number: " + phoneNumber);
|
||||
saveStringListSetting("ignored_phone_numbers", phoneNumbers);
|
||||
}
|
||||
|
||||
public synchronized void saveStringListSetting(String key, List<String> values)
|
||||
{
|
||||
settings.edit().putString(key,
|
||||
new JSONArray(values).toString()
|
||||
).commit();
|
||||
}
|
||||
|
||||
public boolean isTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
for (String testNumber : getTestPhoneNumbers())
|
||||
public synchronized void saveBooleanSetting(String key, boolean value)
|
||||
{
|
||||
settings.edit().putBoolean(key, value).commit();
|
||||
}
|
||||
|
||||
private List<String> loadStringListSetting(String key)
|
||||
{
|
||||
List<String> values = new ArrayList<String>();
|
||||
String valuesJson = settings.getString(key, "");
|
||||
|
||||
if (valuesJson.length() > 0)
|
||||
{
|
||||
// handle inexactness due to various different ways of formatting numbers
|
||||
if (testNumber.contains(phoneNumber) || phoneNumber.contains(testNumber))
|
||||
try
|
||||
{
|
||||
JSONArray arr = new JSONArray(valuesJson);
|
||||
int numSenders = arr.length();
|
||||
for (int i = 0; i < numSenders; i++)
|
||||
{
|
||||
values.add(arr.getString(i));
|
||||
}
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
return true;
|
||||
logError("Error parsing setting " + key, ex);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public boolean isForwardablePhoneNumber(String phoneNumber)
|
||||
{
|
||||
if (isTestMode())
|
||||
{
|
||||
return getTestPhoneNumbers().contains(phoneNumber);
|
||||
}
|
||||
|
||||
if (getIgnoredPhoneNumbers().contains(phoneNumber))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int numDigits = 0;
|
||||
int length = phoneNumber.length();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (Character.isDigit(phoneNumber.charAt(i)))
|
||||
{
|
||||
numDigits++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (numDigits == 0)
|
||||
{
|
||||
if (ignoreNonNumeric())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (numDigits < 7)
|
||||
{
|
||||
if (ignoreShortcodes())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private HttpClient httpClient;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class CheckMmsInboxService extends IntentService
|
||||
mmsUtils.markOldMms(mms);
|
||||
|
||||
if (mms.isForwardable())
|
||||
{
|
||||
{
|
||||
app.inbox.forwardMessage(mms);
|
||||
}
|
||||
else
|
||||
|
@ -40,38 +40,10 @@ public abstract class IncomingMessage extends QueuedMessage {
|
||||
{
|
||||
this.state = status;
|
||||
}
|
||||
|
||||
|
||||
public boolean isForwardable()
|
||||
{
|
||||
if (app.isTestMode() && !app.isTestPhoneNumber(from))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't forward messages from shortcodes or users with
|
||||
* addresses like 'Vodacom' because they're likely to be
|
||||
* messages from network, or spam. At least for network
|
||||
* messages we should let them go in to the Messaging inbox
|
||||
* because the person managing this phone needs to know
|
||||
* when they're out of credit, etc.
|
||||
*
|
||||
* The minimum length of normal subscriber numbers doesn't
|
||||
* seem to be specified, but in practice seems to be
|
||||
* at least 7 digits everywhere.
|
||||
*/
|
||||
int fromDigits = 0;
|
||||
int fromLength = from.length();
|
||||
|
||||
for (int i = 0; i < fromLength; i++)
|
||||
{
|
||||
if (Character.isDigit(from.charAt(i)))
|
||||
{
|
||||
fromDigits++;
|
||||
}
|
||||
}
|
||||
|
||||
return fromDigits >= 7;
|
||||
return app.isForwardablePhoneNumber(from);
|
||||
}
|
||||
|
||||
public String getFrom()
|
||||
|
@ -143,12 +143,12 @@ public class Outbox {
|
||||
return;
|
||||
}
|
||||
|
||||
if (app.isTestMode() && !app.isTestPhoneNumber(to))
|
||||
if (!app.isForwardablePhoneNumber(to))
|
||||
{
|
||||
// this is mostly to prevent accidentally sending real messages to
|
||||
// random people while testing...
|
||||
// random people while testing...
|
||||
notifyMessageStatus(sms, App.STATUS_FAILED,
|
||||
"Destination number is not in list of test senders");
|
||||
"Destination address is not allowed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
131
src/org/envaya/sms/ui/IgnoredPhoneNumbers.java
Executable file
131
src/org/envaya/sms/ui/IgnoredPhoneNumbers.java
Executable file
@ -0,0 +1,131 @@
|
||||
package org.envaya.sms.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import org.envaya.sms.App;
|
||||
import org.envaya.sms.R;
|
||||
|
||||
public class IgnoredPhoneNumbers extends ListActivity {
|
||||
|
||||
private App app;
|
||||
|
||||
private CheckBox ignoreNonNumeric;
|
||||
private CheckBox ignoreShortcodes;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.ignored_phone_numbers);
|
||||
|
||||
app = (App)getApplication();
|
||||
|
||||
ignoreNonNumeric = (CheckBox)findViewById(R.id.ignore_non_numeric);
|
||||
ignoreNonNumeric.setChecked(app.ignoreNonNumeric());
|
||||
|
||||
ignoreShortcodes = (CheckBox)findViewById(R.id.ignore_shortcodes);
|
||||
ignoreShortcodes.setChecked(app.ignoreShortcodes());
|
||||
|
||||
ListView lv = getListView();
|
||||
lv.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id)
|
||||
{
|
||||
final String phoneNumber = ((TextView) view).getText().toString();
|
||||
|
||||
new AlertDialog.Builder(IgnoredPhoneNumbers.this)
|
||||
.setTitle("Remove Ignored Phone")
|
||||
.setMessage("Do you want to remove "+phoneNumber
|
||||
+" from the list of ignored phone numbers?")
|
||||
.setPositiveButton("OK",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
app.removeIgnoredPhoneNumber(phoneNumber);
|
||||
updateIgnoredPhoneNumbers();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNegativeButton("Cancel",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
updateIgnoredPhoneNumbers();
|
||||
}
|
||||
|
||||
public void updateIgnoredPhoneNumbers()
|
||||
{
|
||||
String[] ignoredNumbers = app.getIgnoredPhoneNumbers().toArray(new String[]{});
|
||||
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
|
||||
R.layout.phone_number,
|
||||
ignoredNumbers);
|
||||
|
||||
setListAdapter(arrayAdapter);
|
||||
}
|
||||
|
||||
public void ignoreShortcodesClicked(View v)
|
||||
{
|
||||
boolean checked = ignoreShortcodes.isChecked();
|
||||
app.log("Ignore all shortcodes set to " + (checked ? "ON" : "OFF"));
|
||||
app.saveBooleanSetting("ignore_shortcodes", checked);
|
||||
}
|
||||
|
||||
public void ignoreNonNumericClicked(View v)
|
||||
{
|
||||
boolean checked = ignoreNonNumeric.isChecked();
|
||||
app.log("Ignore all non-numeric senders set to " + (checked ? "ON" : "OFF"));
|
||||
app.saveBooleanSetting("ignore_non_numeric", checked);
|
||||
}
|
||||
|
||||
public void addIgnoredPhoneNumber(View v)
|
||||
{
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
final EditText textEntryView =
|
||||
(EditText)factory.inflate(R.layout.add_phone_number, null);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Add Ignored Phone")
|
||||
.setMessage("Enter the phone number that you want to ignore:")
|
||||
.setView(textEntryView)
|
||||
.setPositiveButton("OK",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
app.addIgnoredPhoneNumber(textEntryView.getText().toString());
|
||||
updateIgnoredPhoneNumbers();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNegativeButton("Cancel",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.show();
|
||||
}
|
||||
}
|
@ -68,17 +68,17 @@ public class TestPhoneNumbers extends ListActivity {
|
||||
String[] senders = app.getTestPhoneNumbers().toArray(new String[]{});
|
||||
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
|
||||
R.layout.test_phone_number,
|
||||
R.layout.phone_number,
|
||||
senders);
|
||||
|
||||
setListAdapter(arrayAdapter);
|
||||
}
|
||||
|
||||
public void addTestSender(View v)
|
||||
public void addTestPhoneNumber(View v)
|
||||
{
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
final EditText textEntryView =
|
||||
(EditText)factory.inflate(R.layout.add_test_phone_number, null);
|
||||
(EditText)factory.inflate(R.layout.add_phone_number, null);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Add Test Phone")
|
||||
|
Reference in New Issue
Block a user