Fixed Account Switcher/Drawer dismiss/close behavior.
MAILAND-1867
This commit is contained in:
parent
33a90c6d72
commit
9853a73ac6
|
@ -414,7 +414,7 @@ public abstract class BaseActivity extends AppCompatActivity implements INetwork
|
|||
Button btnLogout = dialogView.findViewById(R.id.logout);
|
||||
|
||||
btnLogout.setOnClickListener(v -> {
|
||||
accountStateManager.logoutPrimary().invokeOnCompletion(throwable -> {
|
||||
accountStateManager.signOutPrimary().invokeOnCompletion(throwable -> {
|
||||
finish();
|
||||
return null;
|
||||
});
|
||||
|
|
|
@ -181,20 +181,37 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
accountPrimaryView.setViewModel(accountSwitcherViewModel)
|
||||
accountSwitcherViewModel.onDefaultAction(authOrchestrator)
|
||||
accountSwitcherViewModel.onAction()
|
||||
.flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
|
||||
// Handle Dialog/Drawer state.
|
||||
.onEach {
|
||||
val primaryUserId = accountStateManager.getPrimaryUserId().value
|
||||
|
||||
fun dismiss() { closeDrawerAndDialog() }
|
||||
|
||||
fun dismissIfPrimary(userId: UserId) {
|
||||
if (primaryUserId == userId) dismiss()
|
||||
}
|
||||
|
||||
when (it) {
|
||||
is AccountSwitcherViewModel.Action.Add,
|
||||
is AccountSwitcherViewModel.Action.SetPrimary,
|
||||
is AccountSwitcherViewModel.Action.SignIn -> {
|
||||
accountPrimaryView.dismissDialog()
|
||||
closeDrawer(animate = false)
|
||||
}
|
||||
is AccountSwitcherViewModel.Action.Remove,
|
||||
is AccountSwitcherViewModel.Action.SignOut -> Unit
|
||||
is AccountSwitcherViewModel.Action.SignIn -> dismiss()
|
||||
is AccountSwitcherViewModel.Action.Remove -> dismissIfPrimary(it.account.userId)
|
||||
is AccountSwitcherViewModel.Action.SignOut -> dismissIfPrimary(it.account.userId)
|
||||
}
|
||||
}.launchIn(lifecycleScope)
|
||||
}
|
||||
// Handle action.
|
||||
.onEach {
|
||||
when (it) {
|
||||
is AccountSwitcherViewModel.Action.Add -> accountStateManager.signIn()
|
||||
is AccountSwitcherViewModel.Action.SetPrimary -> accountStateManager.switch(it.account.userId)
|
||||
is AccountSwitcherViewModel.Action.SignIn -> accountStateManager.signIn(it.account.userId)
|
||||
is AccountSwitcherViewModel.Action.Remove -> accountStateManager.remove(it.account.userId)
|
||||
is AccountSwitcherViewModel.Action.SignOut -> accountStateManager.signOut(it.account.userId)
|
||||
}
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
sideDrawer.setOnItemClick { drawerItem ->
|
||||
// Header clicked
|
||||
|
@ -210,6 +227,8 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
drawerLayout.closeDrawer(GravityCompat.START)
|
||||
}
|
||||
}
|
||||
|
||||
setUpDrawer()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -231,6 +250,8 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
mJobManager.addJobInBackground(FetchUpdatesJob())
|
||||
val alarmReceiver = AlarmReceiver()
|
||||
alarmReceiver.setAlarm(this)
|
||||
|
||||
closeDrawerAndDialog()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -248,13 +269,18 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
// Requested UserId match the current ?
|
||||
intent.extras?.getString(EXTRA_USER_ID)?.let { extraUserId ->
|
||||
val requestedUserId = UserId(extraUserId)
|
||||
if (requestedUserId != accountStateManager.getPrimaryUserIdValue()) {
|
||||
if (requestedUserId != accountStateManager.getPrimaryUserId().value) {
|
||||
accountStateManager.switch(requestedUserId)
|
||||
}
|
||||
intent.extras?.remove(EXTRA_USER_ID)
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeDrawerAndDialog() {
|
||||
closeDrawer(animate = false)
|
||||
accountPrimaryView.dismissDialog()
|
||||
}
|
||||
|
||||
protected fun closeDrawer(animate: Boolean = true): Boolean {
|
||||
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
drawerLayout.closeDrawer(GravityCompat.START, animate)
|
||||
|
@ -359,7 +385,7 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
fun onSignOutSelected() {
|
||||
|
||||
fun onLogoutConfirmed(currentUserId: Id) {
|
||||
accountStateManager.logout(currentUserId)
|
||||
accountStateManager.signOut(currentUserId)
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
@ -367,10 +393,10 @@ abstract class NavigationActivity : BaseActivity() {
|
|||
|
||||
val (title, message) = if (nextLoggedInUserId != null) {
|
||||
val next = userManager.getUser(nextLoggedInUserId)
|
||||
getString(R.string.logout) to getString(R.string.logout_question_next_account, next.name.s)
|
||||
getString(R.string.sign_out) to getString(R.string.logout_question_next_account, next.name.s)
|
||||
} else {
|
||||
val current = checkNotNull(userManager.currentUser)
|
||||
getString(R.string.log_out, current.name.s) to getString(R.string.logout_question)
|
||||
getString(R.string.sign_out, current.name.s) to getString(R.string.sign_out_question)
|
||||
}
|
||||
|
||||
showTwoButtonInfoDialog(
|
||||
|
|
|
@ -58,7 +58,7 @@ class SplashActivity : AppCompatActivity() {
|
|||
AccountStateManager.State.Processing ->
|
||||
Unit
|
||||
AccountStateManager.State.AccountNeeded ->
|
||||
login()
|
||||
signIn()
|
||||
AccountStateManager.State.PrimaryExist -> {
|
||||
delay(resources.getInteger(R.integer.splash_transition_millis).toLong())
|
||||
startMailboxActivity()
|
||||
|
|
|
@ -164,15 +164,15 @@ class AccountStateManager @Inject constructor(
|
|||
|
||||
suspend fun getAccountOrNull(userId: UserId) = getAccount(userId).firstOrNull()
|
||||
|
||||
fun logout(userId: UserId) = scope.launch {
|
||||
fun signOut(userId: UserId) = scope.launch {
|
||||
accountManager.disableAccount(userId)
|
||||
}
|
||||
|
||||
fun logoutPrimary() = scope.launch {
|
||||
getPrimaryUserId().first()?.let { logout(it) }
|
||||
fun signOutPrimary() = scope.launch {
|
||||
getPrimaryUserId().first()?.let { signOut(it) }
|
||||
}
|
||||
|
||||
fun login(userId: UserId? = null) = scope.launch {
|
||||
fun signIn(userId: UserId? = null) = scope.launch {
|
||||
val account = userId?.let { getAccountOrNull(it) }
|
||||
currentAuthOrchestrator.startLoginWorkflow(
|
||||
requiredAccountType = requiredAccountType,
|
||||
|
@ -191,6 +191,10 @@ class AccountStateManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun remove(userId: UserId) = scope.launch {
|
||||
accountManager.removeAccount(userId)
|
||||
}
|
||||
|
||||
data class AccountSwitch(val previous: Account? = null, val current: Account? = null)
|
||||
|
||||
fun onAccountSwitched() = getPrimaryUserId().scan(AccountSwitch()) { previous, currentUserId ->
|
||||
|
@ -205,8 +209,6 @@ class AccountStateManager @Inject constructor(
|
|||
// Currently, Old UserManager is the source of truth for current primary user id.
|
||||
fun getPrimaryUserId() = oldUserManager.primaryUserId
|
||||
|
||||
fun getPrimaryUserIdValue() = oldUserManager.primaryUserId.value
|
||||
|
||||
// endregion
|
||||
|
||||
// region Deprecated
|
||||
|
@ -219,9 +221,9 @@ class AccountStateManager @Inject constructor(
|
|||
|
||||
@Deprecated(
|
||||
message = "Use UserId version of the function",
|
||||
replaceWith = ReplaceWith("logout(UserId(userId.s))", "me.proton.core.domain.entity.UserId")
|
||||
replaceWith = ReplaceWith("signOut(UserId(userId.s))", "me.proton.core.domain.entity.UserId")
|
||||
)
|
||||
fun logout(userId: Id) = logout(UserId(userId.s))
|
||||
fun signOut(userId: Id) = signOut(UserId(userId.s))
|
||||
|
||||
// endregion
|
||||
|
||||
|
|
|
@ -300,7 +300,6 @@ class MailboxActivity :
|
|||
|
||||
checkUserAndFetchNews()
|
||||
|
||||
setUpDrawer()
|
||||
setTitle()
|
||||
|
||||
mailboxRecyclerView.adapter = mailboxAdapter
|
||||
|
@ -366,7 +365,6 @@ class MailboxActivity :
|
|||
}
|
||||
|
||||
checkRegistration()
|
||||
closeDrawer(animate = false)
|
||||
|
||||
mailboxRecyclerView.addOnScrollListener(listScrollListener)
|
||||
|
||||
|
@ -761,8 +759,6 @@ class MailboxActivity :
|
|||
if (mailboxLocation == MessageLocationType.INBOX) {
|
||||
AppUtil.clearNotifications(this, userManager.requireCurrentUserId())
|
||||
}
|
||||
setUpDrawer()
|
||||
closeDrawer()
|
||||
|
||||
if (shouldShowSwipeGesturesChangedDialog()) {
|
||||
showSwipeGesturesChangedDialog()
|
||||
|
|
|
@ -112,7 +112,7 @@ class ChangePinActivity : BaseActivity(),
|
|||
savePin("")
|
||||
resetPinAttempts()
|
||||
}
|
||||
accountStateManager.logout(mUserManager.requireCurrentUserId()).invokeOnCompletion {
|
||||
accountStateManager.signOut(mUserManager.requireCurrentUserId()).invokeOnCompletion {
|
||||
val intent = Intent()
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
|
|
|
@ -200,7 +200,7 @@ class ValidatePinActivity : BaseActivity(),
|
|||
savePin("")
|
||||
resetPinAttempts()
|
||||
}
|
||||
accountStateManager.logout(mUserManager.requireCurrentUserId()).invokeOnCompletion {
|
||||
accountStateManager.signOut(mUserManager.requireCurrentUserId()).invokeOnCompletion {
|
||||
val intent = Intent()
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
|
|
Loading…
Reference in New Issue