Skip to content

Commit

Permalink
Show messages for empty states on home view (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp authored Aug 14, 2021
1 parent 5383c75 commit 2ec9af5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/src/main/java/me/vanpetegem/accentor/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,32 @@ fun Home(navController: NavController, homeViewModel: HomeViewModel = hiltViewMo
LazyColumn(modifier = Modifier.fillMaxSize()) {
item {
val albums by homeViewModel.recentlyReleasedAlbums.observeAsState()
if (albums != null) {
Text(stringResource(R.string.recently_released), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.recently_released), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (albums != null && albums!!.size > 0) {
LazyRow {
items(albums!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
AlbumCard(albums!![i], navController)
}
}
}
} else {
Text(stringResource(R.string.no_albums), modifier = Modifier.padding(horizontal = 8.dp))
}
}
item {
val albums by homeViewModel.recentlyAddedAlbums.observeAsState()
if (albums != null) {
Text(stringResource(R.string.recently_added_albums), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.recently_added_albums), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (albums != null && albums!!.size > 0) {
LazyRow {
items(albums!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
AlbumCard(albums!![i], navController)
}
}
}
} else {
Text(stringResource(R.string.no_albums), modifier = Modifier.padding(horizontal = 8.dp))
}
}
item {
Expand All @@ -56,54 +60,62 @@ fun Home(navController: NavController, homeViewModel: HomeViewModel = hiltViewMo
}
val currentDay by homeViewModel.currentDay.observeAsState()
val albums by homeViewModel.albumsForDay(currentDay!!).observeAsState()
if (albums != null) {
Text(stringResource(R.string.on_this_day), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.on_this_day), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (albums != null && albums!!.size > 0) {
LazyRow {
items(albums!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
AlbumCard(albums!![i], navController)
}
}
}
} else {
Text(stringResource(R.string.no_on_this_day), modifier = Modifier.padding(horizontal = 8.dp))
}
}
item {
val artists by homeViewModel.recentlyAddedArtists.observeAsState()
if (artists != null) {
Text(stringResource(R.string.recently_added_artists), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.recently_added_artists), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (artists != null && artists!!.size > 0) {
LazyRow {
items(artists!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
ArtistCard(navController, artists!![i])
}
}
}
} else {
Text(stringResource(R.string.no_artists), modifier = Modifier.padding(horizontal = 8.dp))
}
}
item {
val albums by homeViewModel.randomAlbums.observeAsState()
if (albums != null) {
Text(stringResource(R.string.random_albums), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.random_albums), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (albums != null && albums!!.size > 0) {
LazyRow {
items(albums!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
AlbumCard(albums!![i], navController)
}
}
}
} else {
Text(stringResource(R.string.no_albums), modifier = Modifier.padding(horizontal = 8.dp))
}
}
item {
val artists by homeViewModel.randomArtists.observeAsState()
if (artists != null) {
Text(stringResource(R.string.random_artists), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
Text(stringResource(R.string.random_artists), style = MaterialTheme.typography.h5, modifier = Modifier.padding(8.dp))
if (artists != null && artists!!.size > 0) {
LazyRow {
items(artists!!.size) { i ->
Box(modifier = Modifier.width(192.dp)) {
ArtistCard(navController, artists!![i])
}
}
}
} else {
Text(stringResource(R.string.no_artists), modifier = Modifier.padding(horizontal = 8.dp))
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@
<string name="go_to">Go to %s</string>
<string name="search">Search</string>
<string name="stop_searching">Stop searching</string>
<string name="no_albums">No albums could be found</string>
<string name="no_on_this_day">No albums were released on this day</string>
<string name="no_artists">No artists could be found</string>
</resources>

0 comments on commit 2ec9af5

Please sign in to comment.