mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-11 01:46:24 +00:00
Event->Connectivity changed: store lastMessageDate to shared preferences
This commit is contained in:
parent
6292011e9b
commit
504eb1baca
@ -38,6 +38,10 @@
|
||||
<string name="target_package">fr.unix_experience.owncloud_sms</string>
|
||||
<string name="login_logo">Login logo</string>
|
||||
|
||||
<!-- System strings: preferences -->
|
||||
<string name="shared_preference_file">ownCloudSMSPrefs</string>
|
||||
<string name="pref_lastmsgdate">last_message_date</string>
|
||||
|
||||
<!-- Translations must begin there -->
|
||||
<!-- Preferences -->
|
||||
<string name="pref_title_sync">SMS - Fast</string>
|
||||
|
@ -32,6 +32,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
@ -89,7 +90,10 @@ public class OCSMSOwnCloudClient {
|
||||
}
|
||||
}
|
||||
|
||||
public void doPushRequestV1(JSONArray smsList) throws OCSyncException {
|
||||
public void doPushRequestV1(JSONArray smsList) throws OCSyncException {
|
||||
// We need to save this date as a step for connectivity change
|
||||
Long lastMsgDate = (long) 0;
|
||||
|
||||
if (smsList == null) {
|
||||
GetMethod get = createGetSmsIdListRequest();
|
||||
JSONObject smsGetObj = doHttpRequest(get);
|
||||
@ -134,6 +138,9 @@ public class OCSMSOwnCloudClient {
|
||||
fetcher.setExistingDraftsMessages(draftsSmsList);
|
||||
|
||||
smsList = fetcher.fetchAllMessages();
|
||||
|
||||
// Get maximum message date present in smsList to keep a step when connectivity changes
|
||||
lastMsgDate = fetcher.getLastMessageDate();
|
||||
}
|
||||
|
||||
if (smsList.length() == 0) {
|
||||
@ -164,6 +171,12 @@ public class OCSMSOwnCloudClient {
|
||||
throw new OCSyncException(R.string.err_sync_push_request_resp, OCSyncErrorType.PARSE);
|
||||
}
|
||||
|
||||
// Push was OK, we can save the lastMessageDate which was saved to server
|
||||
SharedPreferences sharedPref = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putLong(_context.getString(R.string.pref_lastmsgdate), lastMsgDate);
|
||||
editor.commit();
|
||||
|
||||
Log.d(TAG, "SMS Push request said: status " + pushStatus + " - " + pushMessage);
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@ import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
||||
import fr.unix_experience.owncloud_sms.providers.SmsDataProvider;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
public class SmsFetcher {
|
||||
public SmsFetcher(Context ct) {
|
||||
_lastMsgDate = (long) 0;
|
||||
_context = ct;
|
||||
|
||||
_existingInboxMessages = null;
|
||||
@ -111,6 +111,13 @@ public class SmsFetcher {
|
||||
entry.put(colName, c.getInt(idx) > 0 ? "true" : "false");
|
||||
}
|
||||
else {
|
||||
// Special case for date, we need to record last without searching
|
||||
if (colName.equals(new String("date"))) {
|
||||
final Long tmpDate = c.getLong(idx);
|
||||
if (tmpDate > _lastMsgDate) {
|
||||
_lastMsgDate = tmpDate;
|
||||
}
|
||||
}
|
||||
entry.put(colName, c.getString(idx));
|
||||
}
|
||||
}
|
||||
@ -234,13 +241,17 @@ public class SmsFetcher {
|
||||
_existingDraftsMessages = draftMessages;
|
||||
}
|
||||
|
||||
public Long getLastMessageDate() {
|
||||
return _lastMsgDate;
|
||||
}
|
||||
|
||||
private Context _context;
|
||||
private JSONArray _jsonDataDump;
|
||||
private JSONArray _existingInboxMessages;
|
||||
private JSONArray _existingSentMessages;
|
||||
private JSONArray _existingDraftsMessages;
|
||||
|
||||
private static final String TAG = SmsFetcher.class.getSimpleName();
|
||||
|
||||
private Long _lastMsgDate;
|
||||
|
||||
private static final String TAG = SmsFetcher.class.getSimpleName();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user