Skip to content

Commit

Permalink
Refactor: Improve content error handling and presentation
Browse files Browse the repository at this point in the history
-   Extracted subtitle and title logic to the `ContentError` composable
-   Used optional `contentErrorConfig` for title in the `ContentScreen` composable
-   Removed unnecessary `ErrorTitle` composable
-   Renamed `doAll` to `signAndSaveDocument` in `SuccessViewModel` and `SuccessInteractor`.
-   Updated `SuccessInteractorDoAllPartialState` to `SuccessInteractorSignAndSaveDocumentPartialState`.
-   Updated `Event.DoAll` to `Event.SignAndSaveDocument`.
-   Updated `SuccessScreen` to use the new event name.
-   Removed unnecessary `isLoading` property in the `State` class of `ViewDocumentViewModel`.
-    Removed unused `LoadingStateChanged` class in `Event` of `ViewDocumentViewModel`
  • Loading branch information
stzouvaras committed Feb 24, 2025
1 parent f52260b commit 8413430
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package eu.europa.ec.eudi.rqesui.presentation.ui.component.content

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
Expand All @@ -35,7 +34,6 @@ import eu.europa.ec.eudi.rqesui.infrastructure.provider.ResourceProvider
import eu.europa.ec.eudi.rqesui.presentation.ui.component.preview.PreviewTheme
import eu.europa.ec.eudi.rqesui.presentation.ui.component.preview.ThemeModePreviews
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.SIZE_MEDIUM
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.VSpacer
import eu.europa.ec.eudi.rqesui.presentation.ui.component.wrap.WrapPrimaryButton
import org.koin.compose.koinInject

Expand All @@ -51,18 +49,28 @@ internal fun ContentError(
config: ContentErrorConfig,
paddingValues: PaddingValues,
resourceProvider: ResourceProvider = koinInject(),
subtitleStyle: TextStyle = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurface
),
subTitleMaxLines: Int = Int.MAX_VALUE
) {

val subtitle = config.errorSubTitle ?: resourceProvider.getLocalizedString(
LocalizableKey.GenericErrorDescription
)

Column(
Modifier
.fillMaxSize()
.padding(paddingValues),
.padding(paddingValues)
) {
ErrorTitle(
title = config.errorTitle
?: resourceProvider.getLocalizedString(LocalizableKey.GenericErrorMessage),
subtitle = config.errorSubTitle
?: resourceProvider.getLocalizedString(LocalizableKey.GenericErrorDescription),
subTitleMaxLines = 10

Text(
modifier = Modifier.fillMaxWidth(),
text = subtitle,
style = subtitleStyle,
maxLines = subTitleMaxLines,
overflow = TextOverflow.Ellipsis
)

Spacer(modifier = Modifier.weight(1f))
Expand All @@ -82,67 +90,6 @@ internal fun ContentError(
}
}

@Composable
private fun ErrorTitle(
modifier: Modifier = Modifier,
title: String,
subtitle: String? = null,
titleStyle: TextStyle = MaterialTheme.typography.headlineSmall.copy(
color = MaterialTheme.colorScheme.onSurface
),
subtitleStyle: TextStyle = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurface
),
subTitleMaxLines: Int = Int.MAX_VALUE,
) {
Column(
modifier = modifier,
verticalArrangement = Arrangement.Top
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = title,
style = titleStyle,
)

VSpacer.Large()

subtitle?.let { safeSubtitle ->
Text(
modifier = Modifier.fillMaxWidth(),
text = safeSubtitle,
style = subtitleStyle,
maxLines = subTitleMaxLines,
overflow = TextOverflow.Ellipsis
)
}
}
}

@ThemeModePreviews
@Composable
private fun PreviewErrorTitle() {
PreviewTheme {
ErrorTitle(
modifier = Modifier.fillMaxWidth(),
title = "Title",
subtitle = "Subtitle"
)
}
}

@ThemeModePreviews
@Composable
private fun PreviewErrorTitleNoSubtitle() {
PreviewTheme {
ErrorTitle(
modifier = Modifier.fillMaxWidth(),
title = "Title",
subtitle = null
)
}
}

/**
* Preview composable of [ContentError].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ internal fun ContentScreen(
onBack = contentErrorConfig?.onCancel ?: onBack,
keyboardController = keyboardController,
toolbarConfig = toolBarConfig,
contentErrorConfig = contentErrorConfig
)
}
},
Expand Down Expand Up @@ -212,8 +213,11 @@ private fun DefaultToolBar(
onBack: (() -> Unit)?,
keyboardController: SoftwareKeyboardController?,
toolbarConfig: ToolbarConfig?,
contentErrorConfig: ContentErrorConfig?
) {
val isTitlePresent = !toolbarConfig?.title.isNullOrEmpty()

val title = contentErrorConfig?.errorTitle ?: toolbarConfig?.title
val isTitlePresent = !title.isNullOrEmpty()

val modifier = Modifier
.fillMaxWidth()
Expand All @@ -235,7 +239,7 @@ private fun DefaultToolBar(
title = {
if (isTitlePresent) {
Text(
text = toolbarConfig.title,
text = title,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 2,
overflow = TextOverflow.Ellipsis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ import org.koin.core.annotation.InjectedParam

internal data class State(
val config: ViewDocumentUiConfig,

val isLoading: Boolean = false,
val buttonText: String,
) : ViewState

internal sealed class Event : ViewEvent {
data object Pop : Event()
data object BottomBarButtonPressed : Event()

data class LoadingStateChanged(val isLoading: Boolean) : Event()
}

Expand Down

0 comments on commit 8413430

Please sign in to comment.