Skip to content

Commit 99c333c

Browse files
committed
Implement EmptyRoomContent
1 parent c7cc75f commit 99c333c

File tree

1 file changed

+67
-37
lines changed
  • feature/rooms/ui/src/main/java/io/jja08111/gemini/feature/rooms/ui

1 file changed

+67
-37
lines changed

feature/rooms/ui/src/main/java/io/jja08111/gemini/feature/rooms/ui/RoomsScreen.kt

+67-37
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.size
1414
import androidx.compose.foundation.lazy.LazyColumn
1515
import androidx.compose.material.icons.Icons
1616
import androidx.compose.material.icons.filled.Add
17+
import androidx.compose.material.icons.filled.Star
1718
import androidx.compose.material3.FloatingActionButton
1819
import androidx.compose.material3.Icon
1920
import androidx.compose.material3.LargeTopAppBar
@@ -66,51 +67,56 @@ fun RoomsScreen(
6667
) {
6768
val rooms = uiState.roomStream.collectAsLazyPagingItems()
6869
val loadState = rooms.loadState
69-
LazyColumn(modifier = Modifier.fillMaxSize()) {
70-
when (val refreshState = loadState.refresh) {
71-
is LoadState.Loading -> {
72-
items(count = 5) { RoomTileSkeleton() }
73-
}
7470

75-
is LoadState.Error -> {
76-
item {
77-
Text(
78-
modifier = Modifier.fillParentMaxSize(),
79-
text = refreshState.error.localizedMessage ?: stringResource(
80-
R.string.feature_rooms_ui_failed_to_load,
81-
),
82-
)
71+
if (loadState.refresh is LoadState.NotLoading && rooms.itemCount == 0) {
72+
EmptyRoomContent(modifier = Modifier.fillMaxSize())
73+
} else {
74+
LazyColumn(modifier = Modifier.fillMaxSize()) {
75+
when (val refreshState = loadState.refresh) {
76+
is LoadState.Loading -> {
77+
items(count = 5) { RoomTileSkeleton() }
8378
}
84-
}
8579

86-
is LoadState.NotLoading -> {
87-
items(count = rooms.itemCount) { index ->
88-
val room = checkNotNull(rooms[index])
89-
RoomTile(
90-
modifier = Modifier.fillMaxWidth(),
91-
room = room,
92-
onClick = { onRoomClick(room.id) },
93-
)
80+
is LoadState.Error -> {
81+
item {
82+
Text(
83+
modifier = Modifier.fillParentMaxSize(),
84+
text = refreshState.error.localizedMessage ?: stringResource(
85+
R.string.feature_rooms_ui_failed_to_load,
86+
),
87+
)
88+
}
9489
}
95-
}
96-
}
97-
when (val appendState = loadState.append) {
98-
is LoadState.Loading -> {
99-
item { RoomTileSkeleton() }
100-
}
10190

102-
is LoadState.Error -> {
103-
item {
104-
Text(
105-
modifier = Modifier,
106-
text = appendState.error.localizedMessage ?: stringResource(
107-
R.string.feature_rooms_ui_failed_to_load,
108-
),
109-
)
91+
is LoadState.NotLoading -> {
92+
items(count = rooms.itemCount) { index ->
93+
val room = checkNotNull(rooms[index])
94+
RoomTile(
95+
modifier = Modifier.fillMaxWidth(),
96+
room = room,
97+
onClick = { onRoomClick(room.id) },
98+
)
99+
}
110100
}
111101
}
102+
when (val appendState = loadState.append) {
103+
is LoadState.Loading -> {
104+
item { RoomTileSkeleton() }
105+
}
106+
107+
is LoadState.Error -> {
108+
item {
109+
Text(
110+
modifier = Modifier,
111+
text = appendState.error.localizedMessage ?: stringResource(
112+
R.string.feature_rooms_ui_failed_to_load,
113+
),
114+
)
115+
}
116+
}
112117

113-
is LoadState.NotLoading -> {}
118+
is LoadState.NotLoading -> {}
119+
}
114120
}
115121
}
116122
FloatingActionButton(
@@ -125,6 +131,30 @@ fun RoomsScreen(
125131
}
126132
}
127133

134+
@Composable
135+
private fun EmptyRoomContent(modifier: Modifier = Modifier) {
136+
val color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.3f)
137+
138+
Box(modifier = modifier) {
139+
Column(modifier = Modifier.align(Alignment.Center)) {
140+
Icon(
141+
modifier = Modifier
142+
.align(Alignment.CenterHorizontally)
143+
.size(96.dp),
144+
imageVector = Icons.Default.Star,
145+
tint = color,
146+
contentDescription = null,
147+
)
148+
Spacer(modifier = Modifier.height(16.dp))
149+
Text(
150+
modifier = Modifier.align(Alignment.CenterHorizontally),
151+
text = "Empty chat room",
152+
style = MaterialTheme.typography.titleLarge.copy(color = color),
153+
)
154+
}
155+
}
156+
}
157+
128158
@Composable
129159
internal fun RoomTopBar(
130160
scrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(),

0 commit comments

Comments
 (0)