Skip to content

Commit

Permalink
Removed Crossfade because it didn't work properly. Added log messag…
Browse files Browse the repository at this point in the history
…es in `AuthInteractor.kt`.
  • Loading branch information
HLCaptain committed Feb 9, 2023
1 parent a3dfc13 commit 1d3a8c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -96,25 +96,30 @@ 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
}
}
}
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
Expand Down
29 changes: 14 additions & 15 deletions app/src/main/java/illyan/jay/ui/profile/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ class ProfileViewModel @Inject constructor(
)

fun signOut() = authInteractor.signOut()
}
}

0 comments on commit 1d3a8c1

Please sign in to comment.