EARHORNMUSIC UPnP · Android TV · Phones · Android Auto · GNU/Linux
Release 0.5.0

LocalRandomAlbumsScreen.kt

60 lines · 2.2 KB

Changed in: 0.5.0

1package dev.stave.ui.local
2
3import androidx.compose.foundation.layout.Column
4import androidx.compose.foundation.layout.Spacer
5import androidx.compose.foundation.layout.fillMaxSize
6import androidx.compose.foundation.layout.height
7import androidx.compose.foundation.layout.padding
8import androidx.compose.runtime.Composable
9import androidx.compose.runtime.LaunchedEffect
10import androidx.compose.runtime.getValue
11import androidx.compose.runtime.mutableStateOf
12import androidx.compose.runtime.remember
13import androidx.compose.runtime.setValue
14import androidx.compose.ui.Modifier
15import androidx.compose.ui.unit.dp
16import androidx.hilt.navigation.compose.hiltViewModel
17import androidx.tv.material3.MaterialTheme
18import androidx.tv.material3.Text
19import dev.stave.local.LocalMediaScanner
20import dev.stave.ui.theme.OnMuted
21import dev.stave.ui.theme.OnPrimary
22import dev.stave.ui.theme.adaptiveScreenPaddingHorizontal
23import dev.stave.ui.theme.adaptiveScreenPaddingVertical
24
25/**
26 * Displays a random selection of local albums in the album grid view.
27 * Used when the Random picker is invoked without an active UPnP server.
28 */
29@Composable
30fun LocalRandomAlbumsScreen(
31 count: Int,
32 onAlbumClick: (Long) -> Unit,
33 onBack: () -> Unit,
34 viewModel: LocalLibraryViewModel = hiltViewModel(),
35) {
36 var albums by remember { mutableStateOf<List<LocalMediaScanner.LocalAlbum>>(emptyList()) }
37 var loading by remember { mutableStateOf(true) }
38
39 LaunchedEffect(count) {
40 albums = viewModel.getRandomAlbums(count)
41 loading = false
42 }
43
44 Column(
45 Modifier
46 .fillMaxSize()
47 .padding(horizontal = adaptiveScreenPaddingHorizontal(), vertical = adaptiveScreenPaddingVertical())
48 ) {
49 Header("Random Albums", "${albums.size} albums", onBack)
50 Spacer(Modifier.height(20.dp))
51
52 if (loading) {
53 Text("Picking albums…", style = MaterialTheme.typography.bodyLarge, color = OnMuted)
54 } else if (albums.isEmpty()) {
55 Text("No albums found.", style = MaterialTheme.typography.bodyLarge, color = OnMuted)
56 } else {
57 LocalAlbumGrid(albums = albums, onAlbumClick = { onAlbumClick(it.id) })
58 }
59 }
60}