Skip to content

Commit

Permalink
Merge pull request #77 from opatry/better-authorize-button-layout
Browse files Browse the repository at this point in the history
Better `AuthorizeGoogleTasksButton` layout
  • Loading branch information
opatry authored Oct 28, 2024
2 parents 6e0d758 + d33ff7f commit 212815e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MainActivity : AppCompatActivity() {
when (userState) {
null -> LoadingPane()

is UserState.Unsigned,
UserState.Unsigned,
is UserState.SignedIn -> {
val aboutApp = AboutApp(
name = getString(R.string.app_name),
Expand All @@ -77,7 +77,7 @@ class MainActivity : AppCompatActivity() {
TasksApp(aboutApp, userViewModel, tasksViewModel)
}

is UserState.Newcomer -> AuthorizationScreen(
UserState.Newcomer -> AuthorizationScreen(
onSkip = userViewModel::skipSignIn,
onSuccess = userViewModel::signIn,
)
Expand Down
4 changes: 2 additions & 2 deletions tasks-app-desktop/src/main/kotlin/mainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fun main() {
when (userState) {
null -> LoadingPane()

is UserState.Unsigned,
UserState.Unsigned,
is UserState.SignedIn -> {
val aboutApp = AboutApp(
name = appName,
Expand All @@ -136,7 +136,7 @@ fun main() {
TasksApp(aboutApp, userViewModel, tasksViewModel)
}

is UserState.Newcomer -> AuthorizationScreen(
UserState.Newcomer -> AuthorizationScreen(
onSkip = userViewModel::skipSignIn,
onSuccess = userViewModel::signIn,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -95,12 +96,7 @@ actual fun AuthorizeGoogleTasksButton(
}
}

Row(modifier, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (ongoingAuth) {
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp)
} else {
Spacer(Modifier.size(24.dp))
}
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
Button(
onClick = {
ongoingAuth = true
Expand All @@ -127,11 +123,20 @@ actual fun AuthorizeGoogleTasksButton(
},
enabled = !ongoingAuth
) {
Text(stringResource(Res.string.onboarding_screen_authorize_cta))
Box(modifier, contentAlignment = Alignment.Center) {
AnimatedContent(ongoingAuth, label = "authorize_button_content") { ongoing ->
if (ongoing) {
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp)
} else {
Text(stringResource(Res.string.onboarding_screen_authorize_cta))
}
}
}
}

AnimatedContent(error, label = "authorize_error_message") { message ->
Text(message ?: "", color = MaterialTheme.colorScheme.error)
}
}
AnimatedContent(error, label = "authorize_error_message") {
Text(it ?: "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ package net.opatry.tasks.app.ui.component

import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -60,12 +61,7 @@ actual fun AuthorizeGoogleTasksButton(
var ongoingAuth by remember { mutableStateOf(false) }
var error by remember { mutableStateOf<String?>(null) }

Row(modifier, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (ongoingAuth) {
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp)
} else {
Spacer(Modifier.size(24.dp))
}
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
Button(
onClick = {
ongoingAuth = true
Expand All @@ -88,10 +84,19 @@ actual fun AuthorizeGoogleTasksButton(
},
enabled = !ongoingAuth
) {
Text(stringResource(Res.string.onboarding_screen_authorize_cta))
Box(modifier, contentAlignment = Alignment.Center) {
AnimatedContent(ongoingAuth, label = "authorize_button_content") { ongoing ->
if (ongoing) {
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp)
} else {
Text(stringResource(Res.string.onboarding_screen_authorize_cta))
}
}
}
}

AnimatedContent(error, label = "authorize_error_message") { message ->
Text(message ?: "", color = MaterialTheme.colorScheme.error)
}
}
AnimatedContent(error, label = "authorize_error_message") {
Text(it ?: "")
}
}

0 comments on commit 212815e

Please sign in to comment.