From 894381a33c3e6b1cb1c34a1d041606519f00dd0e Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 21 Nov 2018 13:52:28 +0200 Subject: [PATCH] Remove saved drafts when logging out --- app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java | 3 ++- .../main/java/gr/thmmy/mthmmy/session/SessionManager.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 0c0eda0e..407409d9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/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(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index 4121c1de..42f02375 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/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."); }