diff --git a/src/fr/unix_experience/owncloud_sms/engine/OCSMSOwnCloudClient.java b/src/fr/unix_experience/owncloud_sms/engine/OCSMSOwnCloudClient.java index dbf3221..9440aea 100644 --- a/src/fr/unix_experience/owncloud_sms/engine/OCSMSOwnCloudClient.java +++ b/src/fr/unix_experience/owncloud_sms/engine/OCSMSOwnCloudClient.java @@ -43,6 +43,7 @@ import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType; import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; +import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; public class OCSMSOwnCloudClient { @@ -172,10 +173,7 @@ public class OCSMSOwnCloudClient { } // 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(); + (new OCSMSSharedPrefs(_context)).setLastMessageDate(lastMsgDate); Log.d(TAG, "SMS Push request said: status " + pushStatus + " - " + pushMessage); } diff --git a/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java b/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java new file mode 100644 index 0000000..a1890be --- /dev/null +++ b/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java @@ -0,0 +1,27 @@ +package fr.unix_experience.owncloud_sms.prefs; + +import fr.unix_experience.owncloud_sms.R; +import android.content.Context; +import android.content.SharedPreferences; + +public class OCSMSSharedPrefs { + + public OCSMSSharedPrefs(Context context) { + _context = context; + + _sPrefs = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE); + } + + public void setLastMessageDate(Long msgDate) { + SharedPreferences.Editor editor = _sPrefs.edit(); + editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate); + editor.commit(); + } + + public Long getLastMessageDate() { + return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0); + } + + private SharedPreferences _sPrefs; + private Context _context; +}