diff --git a/songfinder-app/src/main/kotlin/mikufan/cx/songfinder/ui/component/main/ResultGridCell.kt b/songfinder-app/src/main/kotlin/mikufan/cx/songfinder/ui/component/main/ResultGridCell.kt index f3b647c..c755e9a 100644 --- a/songfinder-app/src/main/kotlin/mikufan/cx/songfinder/ui/component/main/ResultGridCell.kt +++ b/songfinder-app/src/main/kotlin/mikufan/cx/songfinder/ui/component/main/ResultGridCell.kt @@ -1,36 +1,60 @@ package mikufan.cx.songfinder.ui.component.main import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.LazyGridItemScope +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Card +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import kotlinx.coroutines.launch import mikufan.cx.songfinder.backend.model.SongSearchResult +import mikufan.cx.songfinder.ui.theme.spacing @OptIn(ExperimentalFoundationApi::class) @Composable fun LazyGridItemScope.ResultGridCell(result: SongSearchResult) { - DebugUsedCell(result, Modifier.animateItemPlacement()) + ResultGridCell(result, Modifier.animateItemPlacement()) } @Composable fun DebugUsedCell(result: SongSearchResult, modifier: Modifier = Modifier) { - Text(result.toString(), modifier = modifier) } @Composable fun LazyGridItemScope.ResultGridCell(result: SongSearchResult, modifier: Modifier = Modifier) { - + MusicCardTemplate({}, modifier) { + Text(result.toString()) + } } /* --- Utils ---*/ -//@Composable -//fun GridCellCard( -// @Composable content: @Composable () -> Unit, -// modifier: Modifier = Modifier, -//) { -// Card( -// -// ) -//} \ No newline at end of file + +@Composable +fun MusicCardTemplate(onCardClicked: suspend () -> Unit, modifier: Modifier = Modifier, content: @Composable () -> Unit) { + val scope = rememberCoroutineScope() + Card( + shape = RoundedCornerShape(MaterialTheme.spacing.cornerShapeLarge), + modifier = Modifier.then(modifier).clickable { + scope.launch { + onCardClicked() + } + } + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.spacingLarge), + modifier = Modifier.padding(MaterialTheme.spacing.paddingLarge) + ) { + content() + } + } +} \ No newline at end of file