mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-07 16:06:18 +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:
parent
9d61d6c732
commit
c72a897f81
@ -6,7 +6,7 @@
|
||||
<uses-sdk
|
||||
android:maxSdkVersion="22"
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="22" />
|
||||
android:targetSdkVersion="23" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<!-- For SMS Broadcaster -->
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -163,5 +163,6 @@ Contributors and issue\'s reporters</string>
|
||||
<string name="contactinfos_title">Contact informations</string>
|
||||
<string name="choose_account">Choose account</string>
|
||||
<string name="subtitle_contact_phones">> Contact phones</string>
|
||||
<string name="pref_title_bulk_messages">Max messages to send per sync</string>
|
||||
|
||||
</resources>
|
||||
|
@ -91,6 +91,4 @@
|
||||
<string name="sync_title">Proceso de sincronización</string>
|
||||
<string name="sync_inprogress">Sincronización en progreso...</string>
|
||||
<string name="fatal_error">Error Fatal ! </string>
|
||||
<string name="choose_account">Choisissez un compte</string>
|
||||
<string name="contactinfos_title">Informations sur le contact</string>
|
||||
</resources>
|
||||
|
@ -70,6 +70,15 @@
|
||||
<item>1440</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
<string-array name="pref_sync_bulk_max_messages_titles">
|
||||
<item>100 SMS</item>
|
||||
<item>1000 SMS</item>
|
||||
<item>2000 SMS</item>
|
||||
<item>5000 SMS</item>
|
||||
<item>10000 SMS</item>
|
||||
<item>25000 SMS</item>
|
||||
<item>Tous les SMS non synchronisés</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_push_on_receive">Pousser le SMS à la réception</string>
|
||||
<string name="pref_sync_wifi">Synchroniser en Wi-Fi</string>
|
||||
@ -132,4 +141,12 @@ Les contributeurs et rapporteurs de bugs</string>
|
||||
<string name="err_sync_http_request_httpexception">Erreur #12: Impossible de se connecter à l\'instance ownCloud</string>
|
||||
<string name="err_sync_http_request_ioexception">Erreur #13: Impossible de se connecter à l\'instance ownCloud</string>
|
||||
<string name="subtitle_contact_phones">> Numéros de téléphone associés</string>
|
||||
<string name="choose_account">Choisissez un compte</string>
|
||||
<string name="ma_title_remote_account">Compte distant</string>
|
||||
<string name="title_activity_select_account">Chosissez un compte</string>
|
||||
<string name="title_activity_select_contact">Choisissez un contact</string>
|
||||
<string name="err_sync_push_request_resp">Erreur #4: Données invalides reçues lors de la synchronisation.</string>
|
||||
<string name="err_sync_create_json_request_encoding">Erreur #7: Encodage inconnu à la conversion</string>
|
||||
<string name="err_sync_craft_http_request">Erreur #2: Echec de la création de la requête</string>
|
||||
<string name="pref_title_bulk_messages">Nombre maximum de messages à envoyer par synchronisation</string>
|
||||
</resources>
|
||||
|
@ -79,6 +79,24 @@
|
||||
<item>1440</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
<string-array name="pref_sync_bulk_max_messages_titles">
|
||||
<item>100 SMS</item>
|
||||
<item>1000 SMS</item>
|
||||
<item>2000 SMS</item>
|
||||
<item>5000 SMS</item>
|
||||
<item>10000 SMS</item>
|
||||
<item>25000 SMS</item>
|
||||
<item>Every SMS not synced</item>
|
||||
</string-array>
|
||||
<string-array name="pref_sync_bulk_max_messages">
|
||||
<item>100</item>
|
||||
<item>1000</item>
|
||||
<item>2000</item>
|
||||
<item>5000</item>
|
||||
<item>10000</item>
|
||||
<item>25000</item>
|
||||
<item>-1</item>
|
||||
</string-array>
|
||||
<string-array name="pref_slow_sync_frequency_titles">
|
||||
<item>1 hour</item>
|
||||
<item>3 hours</item>
|
||||
@ -172,4 +190,5 @@ Contributors and issue\'s reporters</string>
|
||||
<string name="err_proto_v2">Server doesn\'t support this feature. Ensure server version is at least 1.6.</string>
|
||||
<string name="contactinfos_title">Contact informations</string>
|
||||
<string name="subtitle_contact_phones">> Contact phones</string>
|
||||
<string name="pref_title_bulk_messages">Max messages to send per sync</string>
|
||||
</resources>
|
||||
|
@ -9,6 +9,14 @@
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="@string/pref_title_sync_frequency" />
|
||||
<ListPreference
|
||||
android:defaultValue="1000"
|
||||
android:entries="@array/pref_sync_bulk_max_messages_titles"
|
||||
android:entryValues="@array/pref_sync_bulk_max_messages"
|
||||
android:key="sync_bulk_messages"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="@string/pref_title_bulk_messages" />
|
||||
<CheckBoxPreference android:id="@+id/checkbox_push_on_receive"
|
||||
android:defaultValue="true"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
x
Reference in New Issue
Block a user