Add LoadingErrorState to remove some boilerplate from AccountAutoDiscoveryContent
This commit is contained in:
parent
40f1520294
commit
f0632d6c9a
3 changed files with 34 additions and 20 deletions
|
@ -0,0 +1,21 @@
|
|||
package app.k9mail.feature.account.common.ui.loadingerror
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import app.k9mail.core.ui.compose.designsystem.molecule.ContentLoadingErrorState
|
||||
|
||||
interface LoadingErrorState<ERROR> {
|
||||
val isLoading: Boolean
|
||||
val error: ERROR?
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <ERROR> rememberContentLoadingErrorViewState(
|
||||
state: LoadingErrorState<ERROR>,
|
||||
) = remember(key1 = state.isLoading, key2 = state.error) {
|
||||
when {
|
||||
state.isLoading -> ContentLoadingErrorState.Loading
|
||||
state.error != null -> ContentLoadingErrorState.Error
|
||||
else -> ContentLoadingErrorState.Content
|
||||
}
|
||||
}
|
|
@ -8,14 +8,12 @@ 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
|
||||
|
@ -23,6 +21,7 @@ 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.loadingerror.rememberContentLoadingErrorViewState
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract
|
||||
import app.k9mail.feature.account.oauth.ui.preview.PreviewAccountOAuthViewModel
|
||||
import app.k9mail.feature.account.setup.R
|
||||
|
@ -46,16 +45,9 @@ internal fun AccountAutoDiscoveryContent(
|
|||
.then(modifier),
|
||||
) {
|
||||
val resources = LocalContext.current.resources
|
||||
val viewState = remember(key1 = state.isLoading, key2 = state.error) {
|
||||
when {
|
||||
state.isLoading -> ContentLoadingErrorState.Loading
|
||||
state.error != null -> ContentLoadingErrorState.Error
|
||||
else -> ContentLoadingErrorState.Content
|
||||
}
|
||||
}
|
||||
|
||||
ContentLoadingErrorView(
|
||||
state = viewState,
|
||||
state = rememberContentLoadingErrorViewState(state),
|
||||
loading = {
|
||||
LoadingView(
|
||||
message = stringResource(id = R.string.account_setup_auto_discovery_loading_message),
|
||||
|
|
|
@ -6,6 +6,7 @@ import app.k9mail.core.ui.compose.common.mvi.UnidirectionalViewModel
|
|||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.input.BooleanInputField
|
||||
import app.k9mail.feature.account.common.domain.input.StringInputField
|
||||
import app.k9mail.feature.account.common.ui.loadingerror.LoadingErrorState
|
||||
import app.k9mail.feature.account.oauth.domain.entity.OAuthResult
|
||||
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract
|
||||
|
||||
|
@ -32,11 +33,11 @@ interface AccountAutoDiscoveryContract {
|
|||
val authorizationState: AuthorizationState? = null,
|
||||
|
||||
val isSuccess: Boolean = false,
|
||||
val error: Error? = null,
|
||||
val isLoading: Boolean = false,
|
||||
override val error: Error? = null,
|
||||
override val isLoading: Boolean = false,
|
||||
|
||||
val isNextButtonVisible: Boolean = true,
|
||||
)
|
||||
) : LoadingErrorState<Error>
|
||||
|
||||
sealed interface Event {
|
||||
data class EmailAddressChanged(val emailAddress: String) : Event
|
||||
|
@ -44,16 +45,16 @@ interface AccountAutoDiscoveryContract {
|
|||
data class ResultApprovalChanged(val confirmed: Boolean) : Event
|
||||
data class OnOAuthResult(val result: OAuthResult) : Event
|
||||
|
||||
object OnNextClicked : Event
|
||||
object OnBackClicked : Event
|
||||
object OnRetryClicked : Event
|
||||
object OnEditConfigurationClicked : Event
|
||||
data object OnNextClicked : Event
|
||||
data object OnBackClicked : Event
|
||||
data object OnRetryClicked : Event
|
||||
data object OnEditConfigurationClicked : Event
|
||||
}
|
||||
|
||||
sealed class Effect {
|
||||
data class NavigateNext(val isAutomaticConfig: Boolean) : Effect()
|
||||
|
||||
object NavigateBack : Effect()
|
||||
data object NavigateBack : Effect()
|
||||
}
|
||||
|
||||
interface Validator {
|
||||
|
@ -63,7 +64,7 @@ interface AccountAutoDiscoveryContract {
|
|||
}
|
||||
|
||||
sealed interface Error {
|
||||
object NetworkError : Error
|
||||
object UnknownError : Error
|
||||
data object NetworkError : Error
|
||||
data object UnknownError : Error
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue