1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-25 16:56:23 +00:00

Add prefs class to manage shared preferences

This commit is contained in:
Loïc Blot (@U-Exp) 2014-12-12 15:52:07 +01:00
parent 504eb1baca
commit 63bdbf35fd
2 changed files with 29 additions and 4 deletions

View File

@ -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);
}

View File

@ -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;
}