Skip to content

Commit 34ad7e4

Browse files
author
Mihai-Cristian Condrea
committed
feat: Added retry functionality to NoLessonsScreen
- Modified `NoLessonsScreen` to optionally display a retry button. - Added a `showRetry` parameter to control the visibility of the button. - Added an `onRetry` callback function to handle retry actions. - Updated `HomeScreen` to use the new retry functionality, triggering `getHomeLessons` on retry. - Added "try again" button.
1 parent e79db9a commit 34ad7e4

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

app/src/main/kotlin/com/d4rk/androidtutorials/ui/components/layouts/NoLessonsScreen.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package com.d4rk.androidtutorials.ui.components.layouts
33
import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.foundation.layout.Box
55
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Spacer
67
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.foundation.layout.height
79
import androidx.compose.foundation.layout.padding
810
import androidx.compose.foundation.layout.size
911
import androidx.compose.foundation.layout.wrapContentSize
1012
import androidx.compose.material.icons.Icons
1113
import androidx.compose.material.icons.filled.Info
14+
import androidx.compose.material3.Button
1215
import androidx.compose.material3.Icon
1316
import androidx.compose.material3.MaterialTheme
1417
import androidx.compose.material3.Text
@@ -23,32 +26,40 @@ import com.d4rk.androidtutorials.R
2326

2427
@Composable
2528
fun NoLessonsScreen(
26-
text : Int = R.string.no_lessons_found ,
27-
icon : ImageVector = Icons.Default.Info ,
28-
iconDescription : String = "No lessons icon"
29+
text: Int = R.string.no_lessons_found,
30+
icon: ImageVector = Icons.Default.Info,
31+
iconDescription: String = "No lessons icon",
32+
showRetry: Boolean = false,
33+
onRetry: () -> Unit = {}
2934
) {
3035
Box(
3136
modifier = Modifier
3237
.fillMaxSize()
3338
.wrapContentSize(align = Alignment.Center)
3439
) {
3540
Column(
36-
horizontalAlignment = Alignment.CenterHorizontally ,
41+
horizontalAlignment = Alignment.CenterHorizontally,
3742
verticalArrangement = Arrangement.Center
3843
) {
3944
Icon(
40-
imageVector = icon ,
41-
contentDescription = iconDescription ,
45+
imageVector = icon,
46+
contentDescription = iconDescription,
4247
modifier = Modifier
43-
.size(size = 58.dp)
44-
.padding(bottom = 16.dp) ,
48+
.size(58.dp)
49+
.padding(bottom = 16.dp),
4550
tint = MaterialTheme.colorScheme.primary
4651
)
4752
Text(
48-
text = stringResource(id = text) ,
49-
style = MaterialTheme.typography.displaySmall.copy(textAlign = TextAlign.Center) ,
53+
text = stringResource(id = text),
54+
style = MaterialTheme.typography.displaySmall.copy(textAlign = TextAlign.Center),
5055
color = MaterialTheme.colorScheme.onBackground
5156
)
57+
if (showRetry) {
58+
Spacer(modifier = Modifier.height(height = 16.dp))
59+
Button(onClick = onRetry) {
60+
Text(text = stringResource(id = R.string.try_again))
61+
}
62+
}
5263
}
5364
}
5465
}

app/src/main/kotlin/com/d4rk/androidtutorials/ui/screens/home/HomeScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun HomeScreen() {
5454
}
5555

5656
else -> {
57-
NoLessonsScreen()
57+
NoLessonsScreen(showRetry = true , onRetry = { viewModel.getHomeLessons() })
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)