1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2026-08-21 13:22:55 +00:00

Refactor and fix a problem when changing preferences.

Prepare a new setting to send bulk messages with a message limit
This commit is contained in:
Loic Blot
2015-11-04 00:32:12 +01:00
parent 9d61d6c732
commit c72a897f81
10 changed files with 79 additions and 8 deletions
@@ -56,13 +56,14 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_others", DefaultPrefs.syncOthers));
// Bind our string preferences
NrzSettingsActivity._stringPrefs.add(new BindObjectPref("sync_frequency", ""));
NrzSettingsActivity._stringPrefs.add(new BindObjectPref("sync_frequency", "15"));
NrzSettingsActivity._intPrefs.add(new BindObjectPref("sync_bulk_messages", -1));
// Must be at the end, after preference bind
super.onPostCreate(savedInstanceState);
}
protected static void handleCheckboxPreference(String key, Boolean value) {
protected void handleCheckboxPreference(String key, Boolean value) {
// Network types allowed for sync
if("push_on_receive".equals(key) ||
"sync_wifi".equals(key) || "sync_2g".equals(key) ||
@@ -75,7 +76,7 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
}
}
protected static void handleListPreference(String key, String value,
protected void handleListPreference(String key, String value,
ListPreference preference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
@@ -86,6 +87,10 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
.setSummary((index >= 0) ? preference.getEntries()[index]
: null);
Log.d(TAG, "Modifying listPreference " + key);
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(NrzSettingsActivity._context);
// Handle sync frequency change
if ("sync_frequency".equals(key)) {
Account[] myAccountList = GeneralSettingsActivity._accountMgr.getAccountsByType(GeneralSettingsActivity._accountType);
@@ -114,7 +119,12 @@ public class GeneralSettingsActivity extends NrzSettingsActivity {
ContentResolver.addPeriodicSync(myAccountList[i],
GeneralSettingsActivity._accountAuthority, b, syncFreq * 60);
}
prefs.putLong(key, syncFreq);
}
}
else if ("sync_bulk_messages".equals(key)) {
prefs.putInteger(key, Integer.parseInt(value));
}
}
}
@@ -194,7 +194,7 @@ public class SmsFetcher {
return;
}
Cursor c = new SmsDataProvider(_context).query(mbURI, "date > ?", new String[] { sinceDate.toString() });
Cursor c = new SmsDataProvider(_context).queryMessagesSinceDate(mbURI, sinceDate);
// Reading mailbox
if ((c != null) && (c.getCount() > 0)) {
@@ -66,4 +66,8 @@ public class OCSMSSharedPrefs extends SharedPrefs {
public Boolean syncInOtherModes() {
return _sPrefs.getBoolean("sync_others", DefaultPrefs.syncOthers);
}
public Integer getSyncBulkLimit() {
return _sPrefs.getInt("sync_bulk_messages", -1);
}
}
@@ -23,6 +23,9 @@ import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
public class SmsDataProvider extends ContentProvider {
public SmsDataProvider () {}
@@ -52,13 +55,23 @@ public class SmsDataProvider extends ContentProvider {
}
public Cursor queryNonExistingMessages(String mailBox, String existingIds) {
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
Integer bulkLimit = prefs.getSyncBulkLimit();
Log.d(TAG, "Bulk limit is " + bulkLimit.toString());
if (!existingIds.isEmpty()) {
return query(mailBox, "_id NOT IN (" + existingIds + ")");
return query(mailBox, "_id NOT IN (" + existingIds + ")");
}
return query(mailBox);
}
public Cursor queryMessagesSinceDate(String mailBox, Long sinceDate) {
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
Integer bulkLimit = prefs.getSyncBulkLimit();
Log.d(TAG, "Bulk limit is " + bulkLimit.toString());
return query(mailBox, "date > ?", new String[] { sinceDate.toString() });
}
public Cursor query(String mailBox, String selection, String[] selectionArgs) {
return query(Uri.parse(mailBox),
new String[] { "read", "date", "address", "seen", "body", "_id", "type", },
@@ -102,4 +115,5 @@ public class SmsDataProvider extends ContentProvider {
}
private Context _context;
private static final String TAG = SmsDataProvider.class.getSimpleName();
}