@@ -20,7 +20,6 @@ import androidx.compose.ui.Alignment
2020import androidx.compose.ui.Modifier
2121import androidx.compose.ui.graphics.Color
2222import androidx.compose.ui.graphics.painter.Painter
23- import androidx.compose.ui.graphics.vector.ImageVector
2423import androidx.compose.ui.graphics.vector.rememberVectorPainter
2524import androidx.compose.ui.res.painterResource
2625import androidx.compose.ui.res.stringResource
@@ -32,80 +31,67 @@ import com.anysoftkeyboard.janus.app.viewmodels.TranslateViewState
3231/* *
3332 * Generic empty state component with icon, title, and message.
3433 *
35- * @param icon Icon to display
34+ * @param iconContent Icon painter to display
3635 * @param title Main title text
3736 * @param message Detailed message text
3837 * @param iconTint Color tint for the icon
3938 */
4039@Composable
41- fun EmptyStateMessage (
42- icon : ImageVector ,
40+ private fun EmptyStateMessage (
4341 title : String ,
4442 message : String ,
45- iconTint : Color = MaterialTheme .colorScheme.onSurfaceVariant
46- ) {
47- EmptyStateMessage (
48- painter = rememberVectorPainter(icon), title = title, message = message, iconTint = iconTint)
49- }
50-
51- /* *
52- * Generic empty state component with icon, title, and message.
53- *
54- * @param painter Icon painter to display
55- * @param title Main title text
56- * @param message Detailed message text
57- * @param iconTint Color tint for the icon
58- */
59- @Composable
60- fun EmptyStateMessage (
61- painter : Painter ,
62- title : String ,
63- message : String ,
64- iconTint : Color = MaterialTheme .colorScheme.onSurfaceVariant
43+ iconTint : Color = MaterialTheme .colorScheme.onSurfaceVariant,
44+ iconContent : @Composable () -> Unit
6545) {
6646 Column (
6747 modifier = Modifier .fillMaxWidth().padding(28 .dp),
6848 horizontalAlignment = Alignment .CenterHorizontally ,
6949 verticalArrangement = Arrangement .Center ) {
70- Icon (
71- painter = painter,
72- contentDescription = title,
73- modifier = Modifier .size(128 .dp),
74- tint = iconTint)
50+ iconContent()
7551 Spacer (modifier = Modifier .height(4 .dp))
7652 Text (text = title, style = MaterialTheme .typography.titleMedium, color = iconTint)
77- Spacer (modifier = Modifier .height(4 .dp))
78- Text (
79- text = message,
80- style = MaterialTheme .typography.bodyMedium,
81- color = MaterialTheme .colorScheme.onSurfaceVariant)
53+ if (message.isNotEmpty()) {
54+ Spacer (modifier = Modifier .height(4 .dp))
55+ Text (
56+ text = message,
57+ style = MaterialTheme .typography.bodyMedium,
58+ color = MaterialTheme .colorScheme.onSurfaceVariant)
59+ }
8260 }
8361}
8462
63+ @Composable
64+ private fun EmptyStateMessageWithPainter (
65+ title : String ,
66+ message : String ,
67+ iconTint : Color = MaterialTheme .colorScheme.onSurfaceVariant,
68+ painter : Painter
69+ ) {
70+ EmptyStateMessage (title, message, iconTint) {
71+ Icon (
72+ painter = painter,
73+ contentDescription = title,
74+ modifier = Modifier .size(128 .dp),
75+ tint = iconTint)
76+ }
77+ }
78+
8579/* * Initial empty state shown when the app starts. */
8680@Composable
8781fun InitialEmptyState (welcomeMessage : String ) {
88- EmptyStateMessage (
89- painter = painterResource(R .mipmap.ic_launcher_foreground),
82+ EmptyStateMessageWithPainter (
9083 title = welcomeMessage,
9184 message = " " ,
92- iconTint = MaterialTheme .colorScheme.primary)
85+ iconTint = MaterialTheme .colorScheme.primary,
86+ painter = painterResource(R .mipmap.ic_launcher_foreground))
9387}
9488
9589/* * Loading state with a progress indicator. */
9690@Composable
9791fun LoadingState (message : String ) {
98- Column (
99- modifier = Modifier .fillMaxWidth(),
100- horizontalAlignment = Alignment .CenterHorizontally ,
101- verticalArrangement = Arrangement .Center ) {
102- JanusLoader (modifier = Modifier .size(64 .dp))
103- Spacer (modifier = Modifier .height(16 .dp))
104- Text (
105- text = message,
106- style = MaterialTheme .typography.bodyLarge,
107- color = MaterialTheme .colorScheme.onSurfaceVariant)
108- }
92+ EmptyStateMessage (title = message, message = " " , iconTint = MaterialTheme .colorScheme.primary) {
93+ JanusLoader (modifier = Modifier .size(128 .dp))
94+ }
10995}
11096
11197/* *
@@ -115,10 +101,10 @@ fun LoadingState(message: String) {
115101 */
116102@Composable
117103fun NoResultsState (searchTerm : String ) {
118- EmptyStateMessage (
119- icon = Icons .Default .Search ,
104+ EmptyStateMessageWithPainter (
120105 title = stringResource(R .string.empty_state_no_results_title),
121- message = stringResource(R .string.empty_state_no_results_message, searchTerm))
106+ message = stringResource(R .string.empty_state_no_results_message, searchTerm),
107+ painter = rememberVectorPainter(image = Icons .Default .Search ))
122108}
123109
124110/* *
@@ -135,25 +121,8 @@ fun ErrorStateDisplay(error: TranslateViewState.Error, snackbarHostState: Snackb
135121 LaunchedEffect (error) {
136122 snackbarHostState.showSnackbar(" ${error.errorType} : ${error.errorMessage} " )
137123 }
138-
139- Column (
140- modifier = Modifier .fillMaxWidth(),
141- horizontalAlignment = Alignment .CenterHorizontally ,
142- verticalArrangement = Arrangement .Center ) {
143- Icon (
144- imageVector = Icons .Default .Warning ,
145- contentDescription = stringResource(R .string.content_description_error),
146- tint = MaterialTheme .colorScheme.error,
147- modifier = Modifier .size(128 .dp))
148- Spacer (modifier = Modifier .height(8 .dp))
149- Text (
150- text = error.errorType,
151- style = MaterialTheme .typography.titleMedium,
152- color = MaterialTheme .colorScheme.error)
153- Spacer (modifier = Modifier .height(4 .dp))
154- Text (
155- text = error.errorMessage,
156- style = MaterialTheme .typography.bodyMedium,
157- color = MaterialTheme .colorScheme.onSurfaceVariant)
158- }
124+ EmptyStateMessageWithPainter (
125+ title = error.errorType,
126+ message = error.errorMessage,
127+ painter = rememberVectorPainter(image = Icons .Default .Warning ))
159128}
0 commit comments