diff --git a/app/src/main/java/illyan/jay/domain/interactor/AuthInteractor.kt b/app/src/main/java/illyan/jay/domain/interactor/AuthInteractor.kt index 80da8091..ee0dd6f8 100644 --- a/app/src/main/java/illyan/jay/domain/interactor/AuthInteractor.kt +++ b/app/src/main/java/illyan/jay/domain/interactor/AuthInteractor.kt @@ -85,9 +85,9 @@ class AuthInteractor @Inject constructor( init { addAuthStateListener { if (it.currentUser != null) { - Timber.i("User ${it.currentUser!!.uid.take(4)} signed in to Firebase") + Timber.i("User ${it.currentUser!!.uid.take(4)} signed into Firebase") } else { - Timber.i("User ${userUUID?.take(4)} signed out from Firebase") + Timber.i("User ${userUUID?.take(4)} signed out of Firebase") } _currentUserStateFlow.value = it.currentUser _isUserSignedInStateFlow.value = it.currentUser != null @@ -96,18 +96,22 @@ class AuthInteractor @Inject constructor( } fun signOut() { + Timber.i("Sign out requested for user ${userUUID?.take(4)}") _isSigningOut.value = true val size = onSignOutListeners.size if (size == 0) { + Timber.i("No sign out listeners detected, signing out user ${userUUID?.take(4)}") auth.signOut() googleSignInClient.value?.signOut() _isSigningOut.value = false } else { + Timber.i("Notifying sign out listeners") val approvedListeners = MutableStateFlow(0) onSignOutListeners.forEach { coroutineScopeIO.launch { it(auth).first { approvedListeners.value++ + Timber.d("${approvedListeners.value++} listeners approved sign out") true } } @@ -115,6 +119,7 @@ class AuthInteractor @Inject constructor( coroutineScopeIO.launch { approvedListeners.first { if (it >= size) { + Timber.i("All listeners notified, signing out user ${userUUID?.take(4)}") auth.signOut() googleSignInClient.value?.signOut() _isSigningOut.value = false diff --git a/app/src/main/java/illyan/jay/ui/profile/Profile.kt b/app/src/main/java/illyan/jay/ui/profile/Profile.kt index 4a2cf5e3..1dbea878 100644 --- a/app/src/main/java/illyan/jay/ui/profile/Profile.kt +++ b/app/src/main/java/illyan/jay/ui/profile/Profile.kt @@ -72,8 +72,8 @@ fun ProfileDialog( viewModel: ProfileViewModel = hiltViewModel(), ) { val screenWidthDp = LocalConfiguration.current.screenWidthDp.dp - val isUserSignedIn by viewModel.isUserSignedIn.collectAsStateWithLifecycle() var showLoginDialog by remember { mutableStateOf(false) } + val isUserSignedIn by viewModel.isUserSignedIn.collectAsStateWithLifecycle() val isUserSigningOut by viewModel.isUserSigningOut.collectAsStateWithLifecycle() val userPhotoUrl by viewModel.userPhotoUrl.collectAsStateWithLifecycle() val email by viewModel.userEmail.collectAsStateWithLifecycle() @@ -131,20 +131,19 @@ fun ProfileDialogScreen( ) }, confirmButton = { - Crossfade(targetState = isUserSignedIn) { - if (it) { - TextButton( - enabled = !isUserSigningOut, - onClick = onSignOut - ) { - Text(text = stringResource(R.string.sign_out)) - } - } else { - Button( - onClick = onShowLoginDialog - ) { - Text(text = stringResource(R.string.sign_in)) - } + // FIXME: find out why Crossfade does not work here + if (isUserSignedIn) { + TextButton( + enabled = !isUserSigningOut, + onClick = onSignOut + ) { + Text(text = stringResource(R.string.sign_out)) + } + } else { + Button( + onClick = onShowLoginDialog + ) { + Text(text = stringResource(R.string.sign_in)) } } }, diff --git a/app/src/main/java/illyan/jay/ui/profile/ProfileViewModel.kt b/app/src/main/java/illyan/jay/ui/profile/ProfileViewModel.kt index b1a9e201..0f65e5c5 100644 --- a/app/src/main/java/illyan/jay/ui/profile/ProfileViewModel.kt +++ b/app/src/main/java/illyan/jay/ui/profile/ProfileViewModel.kt @@ -60,4 +60,4 @@ class ProfileViewModel @Inject constructor( ) fun signOut() = authInteractor.signOut() -} \ No newline at end of file +}