"Fix" Google signin style
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user