Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 16768c8e authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Change AccountAutoDiscoveryContent to ContentLoadingErrorView

parent 180b6af2
Loading
Loading
Loading
Loading
+34 −22
Original line number Diff line number Diff line
@@ -8,18 +8,21 @@ import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import app.k9mail.core.ui.compose.common.DevicePreviews
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingErrorState
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingErrorView
import app.k9mail.core.ui.compose.designsystem.molecule.ErrorView
import app.k9mail.core.ui.compose.designsystem.molecule.LoadingView
import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
import app.k9mail.feature.account.common.ui.item.ErrorItem
import app.k9mail.feature.account.common.ui.item.LoadingItem
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract
import app.k9mail.feature.account.oauth.ui.preview.PreviewAccountOAuthViewModel
import app.k9mail.feature.account.setup.R
@@ -43,28 +46,37 @@ internal fun AccountAutoDiscoveryContent(
            .then(modifier),
    ) {
        val resources = LocalContext.current.resources
        val cleState = remember(key1 = state.isLoading, key2 = state.error) {
            when {
                state.isLoading -> ContentLoadingErrorState.Loading
                state.error != null -> ContentLoadingErrorState.Error
                else -> ContentLoadingErrorState.Content
            }
        }

        ContentLoadingErrorView(
            state = cleState,
            loading = {
                LoadingView(
                    message = stringResource(id = R.string.account_setup_auto_discovery_loading_message),
                    modifier = Modifier.fillMaxSize(),
                )
            },
            error = {
                ErrorView(
                    title = stringResource(id = R.string.account_setup_auto_discovery_loading_error),
                    message = state.error?.toResourceString(resources),
                    onRetry = { onEvent(Event.OnRetryClicked) },
                    modifier = Modifier.fillMaxSize(),
                )
            },
        ) {
            LazyColumn(
                modifier = Modifier
                    .fillMaxSize()
                    .imePadding(),
                verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.double, Alignment.CenterVertically),
            ) {
            if (state.isLoading) {
                item(key = "loading") {
                    LoadingItem(
                        message = stringResource(id = R.string.account_setup_auto_discovery_loading_message),
                    )
                }
            } else if (state.error != null) {
                item(key = "error") {
                    ErrorItem(
                        title = stringResource(id = R.string.account_setup_auto_discovery_loading_error),
                        message = state.error.toResourceString(resources),
                        onRetry = { onEvent(Event.OnRetryClicked) },
                    )
                }
            } else {
                contentItems(
                    state = state,
                    onEvent = onEvent,