Skip to content

Commit

Permalink
GT-2200 Create No Internet Error
Browse files Browse the repository at this point in the history
  • Loading branch information
gyasistory committed Oct 22, 2024
1 parent d48e0f5 commit 26ede8c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions app/src/main/kotlin/org/cru/godtools/ui/login/LoginLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.ccci.gto.android.common.androidx.compose.foundation.layout.padding
import org.ccci.gto.android.common.kotlin.coroutines.flow.net.isConnectedFlow
import org.cru.godtools.R
import org.cru.godtools.account.AccountType
import org.cru.godtools.account.LoginResponse
Expand All @@ -48,7 +52,11 @@ private val FACEBOOK_BLUE = Color(red = 0x18, green = 0x77, blue = 0xf2)

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEvent) -> Unit) {
fun LoginLayout(
modifier: Modifier = Modifier,
createAccount: Boolean = false,
onEvent: (event: LoginLayoutEvent) -> Unit = {},
) {
var loginError: LoginResponse.Error? by rememberSaveable { mutableStateOf(null) }
val loginLauncher = rememberLoginLauncher(createAccount) {
when (it) {
Expand All @@ -61,7 +69,7 @@ fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEven

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
modifier = modifier
.fillMaxSize()
.background(GodToolsTheme.GT_BLUE)
.verticalScroll(rememberScrollState())
Expand Down Expand Up @@ -145,14 +153,26 @@ fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEven

@Composable
private fun LoginError(error: LoginResponse.Error?, onDismiss: () -> Unit) {
val context = LocalContext.current
val isConnected by remember { context.isConnectedFlow() }.collectAsState(true)
if (error != null) {
AlertDialog(
title = {
Text(
if (!isConnected) {
stringResource(R.string.account_error_no_internet_title)
} else {
stringResource(R.string.account_error_title)
}
)
},
text = {
Text(
stringResource(
when (error) {
LoginResponse.Error.UserAlreadyExists -> R.string.account_error_user_already_exists
LoginResponse.Error.UserNotFound -> R.string.account_error_user_not_found
when {
!isConnected -> R.string.account_error_no_internet
error == LoginResponse.Error.UserAlreadyExists -> R.string.account_error_user_already_exists
error == LoginResponse.Error.UserNotFound -> R.string.account_error_user_not_found
else -> R.string.account_error_unknown
}
)
Expand All @@ -167,3 +187,4 @@ private fun LoginError(error: LoginResponse.Error?, onDismiss: () -> Unit) {
)
}
}

0 comments on commit 26ede8c

Please sign in to comment.