From be51a17315404ad161e6302065e7f42e3cc51f3e Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 29 Aug 2022 09:33:48 -0700 Subject: [PATCH] extracy logout button to it's own comosable function --- .../app/omnivore/omnivore/ui/home/HomeView.kt | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeView.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeView.kt index da1c0e4d9..0fcb81a21 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeView.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeView.kt @@ -20,8 +20,6 @@ import com.google.android.gms.auth.api.signin.GoogleSignInOptions @Composable fun HomeView(viewModel: LoginViewModel) { - val context = LocalContext.current - Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, @@ -31,18 +29,24 @@ fun HomeView(viewModel: LoginViewModel) { .padding(horizontal = 6.dp) ) { Text("You have a valid auth token. Nice. Go save something in Chrome!") - - Button(onClick = { - // Sign out google users - val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) - .build() - - val googleSignIn = GoogleSignIn.getClient(context, signInOptions) - googleSignIn.signOut() - - viewModel.logout() - }) { - Text(text = "Logout") - } + LogoutButton { viewModel.logout() } + } +} + +@Composable +fun LogoutButton(actionHandler: () -> Unit) { + val context = LocalContext.current + + Button(onClick = { + // Sign out google users + val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .build() + + val googleSignIn = GoogleSignIn.getClient(context, signInOptions) + googleSignIn.signOut() + + actionHandler() + }) { + Text(text = "Logout") } }