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

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

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

Loading…
Cancel
Save