LocalRandomAlbumsScreen.kt
Each line, with the release that last changed it.
| 0.5.0 | 1 | package dev.stave.ui.local |
| 2 | ||
| 3 | import androidx.compose.foundation.layout.Column | |
| 4 | import androidx.compose.foundation.layout.Spacer | |
| 5 | import androidx.compose.foundation.layout.fillMaxSize | |
| 6 | import androidx.compose.foundation.layout.height | |
| 7 | import androidx.compose.foundation.layout.padding | |
| 8 | import androidx.compose.runtime.Composable | |
| 9 | import androidx.compose.runtime.LaunchedEffect | |
| 10 | import androidx.compose.runtime.getValue | |
| 11 | import androidx.compose.runtime.mutableStateOf | |
| 12 | import androidx.compose.runtime.remember | |
| 13 | import androidx.compose.runtime.setValue | |
| 14 | import androidx.compose.ui.Modifier | |
| 15 | import androidx.compose.ui.unit.dp | |
| 16 | import androidx.hilt.navigation.compose.hiltViewModel | |
| 17 | import androidx.tv.material3.MaterialTheme | |
| 18 | import androidx.tv.material3.Text | |
| 19 | import dev.stave.local.LocalMediaScanner | |
| 20 | import dev.stave.ui.theme.OnMuted | |
| 21 | import dev.stave.ui.theme.OnPrimary | |
| 22 | import dev.stave.ui.theme.adaptiveScreenPaddingHorizontal | |
| 23 | import 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 | |
| 30 | fun 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 | } |


