Browse Source

Remove saved drafts when logging out

pull/61/merge
Ezerous 6 years ago
parent
commit
894381a33c
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 3
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  2. 5
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

3
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -72,6 +72,7 @@ public class BaseApplication extends Application {
//Shared Preferences
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences settingsSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences draftsPrefs = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
if (settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), false))
startFirebaseCrashlyticsCollection();
@ -106,7 +107,7 @@ public class BaseApplication extends Application {
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs);
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs,draftsPrefs);
Picasso picasso = new Picasso.Builder(getApplicationContext())
.downloader(new OkHttp3Downloader(client))
.build();

5
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -57,6 +57,7 @@ public class SessionManager {
//Shared Preferences & its keys
private final SharedPreferences sharedPrefs;
private final SharedPreferences draftsPrefs;
private static final String USERNAME = "Username";
private static final String USER_ID = "UserID";
private static final String AVATAR_LINK = "AvatarLink";
@ -67,11 +68,12 @@ public class SessionManager {
//Constructor
public SessionManager(OkHttpClient client, PersistentCookieJar cookieJar,
SharedPrefsCookiePersistor cookiePersistor, SharedPreferences sharedPrefs) {
SharedPrefsCookiePersistor cookiePersistor, SharedPreferences sharedPrefs, SharedPreferences draftsPrefs) {
this.client = client;
this.cookiePersistor = cookiePersistor;
this.cookieJar = cookieJar;
this.sharedPrefs = sharedPrefs;
this.draftsPrefs = draftsPrefs;
}
//------------------------------------AUTH BEGINS----------------------------------------------
@ -309,6 +311,7 @@ public class SessionManager {
sharedPrefs.edit().putString(USERNAME, guestName).apply();
sharedPrefs.edit().putInt(USER_ID, -1).apply();
sharedPrefs.edit().putBoolean(LOGGED_IN, false).apply(); //User logs out
draftsPrefs.edit().clear().apply(); //Clear saved drafts
Timber.i("Session data cleared.");
}

Loading…
Cancel
Save