Merge pull request #1290 from vector-im/feature/cleanup_ui_state
Clear preferences when user logs out
This commit is contained in:
commit
df335c7aa3
|
@ -34,8 +34,10 @@ import im.vector.riotx.core.utils.deleteAllFiles
|
|||
import im.vector.riotx.features.home.HomeActivity
|
||||
import im.vector.riotx.features.login.LoginActivity
|
||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import im.vector.riotx.features.signout.hard.SignedOutActivity
|
||||
import im.vector.riotx.features.signout.soft.SoftLogoutActivity
|
||||
import im.vector.riotx.features.ui.UiStateRepository
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
@ -78,6 +80,8 @@ class MainActivity : VectorBaseActivity() {
|
|||
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
||||
@Inject lateinit var sessionHolder: ActiveSessionHolder
|
||||
@Inject lateinit var errorFormatter: ErrorFormatter
|
||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||
@Inject lateinit var uiStateRepository: UiStateRepository
|
||||
|
||||
override fun injectWith(injector: ScreenComponent) {
|
||||
injector.inject(this)
|
||||
|
@ -127,7 +131,7 @@ class MainActivity : VectorBaseActivity() {
|
|||
// Just do the local cleanup
|
||||
Timber.w("Account deactivated, start app")
|
||||
sessionHolder.clearActiveSession()
|
||||
doLocalCleanup()
|
||||
doLocalCleanup(clearPreferences = true)
|
||||
startNextActivityAndFinish()
|
||||
}
|
||||
args.clearCredentials -> session.signOut(
|
||||
|
@ -136,7 +140,7 @@ class MainActivity : VectorBaseActivity() {
|
|||
override fun onSuccess(data: Unit) {
|
||||
Timber.w("SIGN_OUT: success, start app")
|
||||
sessionHolder.clearActiveSession()
|
||||
doLocalCleanup()
|
||||
doLocalCleanup(clearPreferences = true)
|
||||
startNextActivityAndFinish()
|
||||
}
|
||||
|
||||
|
@ -147,7 +151,7 @@ class MainActivity : VectorBaseActivity() {
|
|||
args.clearCache -> session.clearCache(
|
||||
object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
doLocalCleanup()
|
||||
doLocalCleanup(clearPreferences = false)
|
||||
session.startSyncing(applicationContext)
|
||||
startNextActivityAndFinish()
|
||||
}
|
||||
|
@ -164,10 +168,15 @@ class MainActivity : VectorBaseActivity() {
|
|||
Timber.w("Ignoring invalid token global error")
|
||||
}
|
||||
|
||||
private fun doLocalCleanup() {
|
||||
private fun doLocalCleanup(clearPreferences: Boolean) {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
// On UI Thread
|
||||
Glide.get(this@MainActivity).clearMemory()
|
||||
|
||||
if (clearPreferences) {
|
||||
vectorPreferences.clearPreferences()
|
||||
uiStateRepository.reset()
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
// On BG thread
|
||||
Glide.get(this@MainActivity).clearDiskCache()
|
||||
|
|
|
@ -201,6 +201,11 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY,
|
||||
SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY,
|
||||
|
||||
SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY,
|
||||
SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY,
|
||||
SETTINGS_LABS_ALLOW_EXTENDED_LOGS,
|
||||
SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY,
|
||||
|
||||
SETTINGS_USE_RAGE_SHAKE_KEY,
|
||||
SETTINGS_SECURITY_USE_FLAG_SECURE
|
||||
)
|
||||
|
|
|
@ -26,6 +26,12 @@ import javax.inject.Inject
|
|||
*/
|
||||
class SharedPreferencesUiStateRepository @Inject constructor(private val sharedPreferences: SharedPreferences) : UiStateRepository {
|
||||
|
||||
override fun reset() {
|
||||
sharedPreferences.edit {
|
||||
remove(KEY_DISPLAY_MODE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDisplayMode(): RoomListDisplayMode {
|
||||
return when (sharedPreferences.getInt(KEY_DISPLAY_MODE, VALUE_DISPLAY_MODE_CATCHUP)) {
|
||||
VALUE_DISPLAY_MODE_PEOPLE -> RoomListDisplayMode.PEOPLE
|
||||
|
|
|
@ -23,6 +23,11 @@ import im.vector.riotx.features.home.RoomListDisplayMode
|
|||
*/
|
||||
interface UiStateRepository {
|
||||
|
||||
/**
|
||||
* Reset all the saved data
|
||||
*/
|
||||
fun reset()
|
||||
|
||||
fun getDisplayMode(): RoomListDisplayMode
|
||||
|
||||
fun storeDisplayMode(displayMode: RoomListDisplayMode)
|
||||
|
|
Loading…
Reference in New Issue