From 1536cb7365c1415e3b6f6bfecece98c3c5716160 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 3 Sep 2022 12:47:34 +0200 Subject: [PATCH] "Fix" Google signin style --- .../src/main/res/drawable/ic_google_g.xml | 30 ++++++ .../accounts/AccountsSettingsScreen.kt | 96 +++++++++++++++---- 2 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 g-services/src/main/res/drawable/ic_google_g.xml diff --git a/g-services/src/main/res/drawable/ic_google_g.xml b/g-services/src/main/res/drawable/ic_google_g.xml new file mode 100644 index 00000000..75879004 --- /dev/null +++ b/g-services/src/main/res/drawable/ic_google_g.xml @@ -0,0 +1,30 @@ + + + + + + diff --git a/ui/src/main/java/de/mm20/launcher2/ui/settings/accounts/AccountsSettingsScreen.kt b/ui/src/main/java/de/mm20/launcher2/ui/settings/accounts/AccountsSettingsScreen.kt index 983554b2..e4e4e9cd 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/settings/accounts/AccountsSettingsScreen.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/settings/accounts/AccountsSettingsScreen.kt @@ -1,16 +1,28 @@ package de.mm20.launcher2.ui.settings.accounts import androidx.appcompat.app.AppCompatActivity -import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.LinearProgressIndicator +import androidx.compose.material3.Surface +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.viewmodel.compose.viewModel @@ -104,7 +116,10 @@ fun AccountsSettingsScreen() { if (account != null) { viewModel.signOut(AccountType.Microsoft) } else { - viewModel.signIn(context as AppCompatActivity, AccountType.Microsoft) + viewModel.signIn( + context as AppCompatActivity, + AccountType.Microsoft + ) } } ) @@ -115,25 +130,70 @@ fun AccountsSettingsScreen() { item { PreferenceCategory(title = stringResource(R.string.preference_category_services_google)) { val account by viewModel.googleUser.observeAsState() - Preference( - title = if (account != null) { - stringResource(R.string.preference_signin_logout) - } else { - stringResource(R.string.preference_google_signin) - }, - summary = account?.let { - stringResource(R.string.preference_signin_user, it.userName) - } ?: stringResource(R.string.preference_google_signin_summary), - onClick = { - if (account != null) { - viewModel.signOut(AccountType.Google) - } else { - viewModel.signIn(context as AppCompatActivity, AccountType.Google) - } + if (account == null) { + Box(modifier = Modifier + .padding(start = 56.dp) + .padding(16.dp)) { + GoogleSigninButton( + onClick = { + viewModel.signIn( + context as AppCompatActivity, + AccountType.Google + ) + } + ) } - ) + } else { + Preference( + title = stringResource(R.string.preference_signin_logout), + summary = account?.userName?.let { + stringResource(R.string.preference_signin_user, it) + }, + onClick = { + viewModel.signOut(AccountType.Google) + } + ) + } } } } } +} + +@Composable +fun GoogleSigninButton( + onClick: () -> Unit, +) { + Surface( + modifier = Modifier.height(40.dp), + shadowElevation = 1.dp, + color = Color.White, + shape = RoundedCornerShape(2.dp), + onClick = onClick + ) { + Row( + verticalAlignment = Alignment.CenterVertically + ) { + Box( + modifier = Modifier + .size(40.dp) + .background(Color.White), + contentAlignment = Alignment.Center + ) { + Image( + modifier = Modifier.size(18.dp), + painter = painterResource(id = R.drawable.ic_google_g), + contentDescription = null + ) + } + Text( + modifier = Modifier.padding(start = 13.dp, end = 8.dp), + text = stringResource(id = R.string.preference_google_signin), + fontFamily = FontFamily.SansSerif, + color = Color(0f, 0f, 0f, 0.54f), + fontSize = 14.sp, + fontWeight = FontWeight.Medium + ) + } + } } \ No newline at end of file