11package io.music_assistant.client.ui.compose.item
22
3- import androidx.compose.foundation.clickable
3+ import androidx.compose.foundation.layout.Arrangement
44import androidx.compose.foundation.layout.Box
55import androidx.compose.foundation.layout.Column
66import androidx.compose.foundation.layout.Row
@@ -12,18 +12,24 @@ import androidx.compose.foundation.shape.RoundedCornerShape
1212import androidx.compose.material.icons.Icons
1313import androidx.compose.material.icons.automirrored.filled.ArrowBack
1414import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
15+ import androidx.compose.material.icons.automirrored.filled.ViewList
1516import androidx.compose.material.icons.filled.AddToQueue
1617import androidx.compose.material.icons.filled.ExpandMore
18+ import androidx.compose.material.icons.filled.GridView
19+ import androidx.compose.material.icons.filled.MoreVert
1720import androidx.compose.material.icons.filled.PlayArrow
1821import androidx.compose.material.icons.filled.PlaylistAddCircle
1922import androidx.compose.material.icons.filled.QueuePlayNext
2023import androidx.compose.material.icons.filled.Radio
2124import androidx.compose.material3.AlertDialog
22- import androidx.compose.material3.Button
2325import androidx.compose.material3.CircularProgressIndicator
26+ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
2427import androidx.compose.material3.Icon
2528import androidx.compose.material3.IconButton
2629import androidx.compose.material3.MaterialTheme
30+ import androidx.compose.material3.SplitButtonDefaults.LeadingButton
31+ import androidx.compose.material3.SplitButtonDefaults.TrailingButton
32+ import androidx.compose.material3.SplitButtonLayout
2733import androidx.compose.material3.Text
2834import androidx.compose.material3.TextButton
2935import androidx.compose.runtime.Composable
@@ -56,18 +62,41 @@ import io.music_assistant.client.ui.compose.common.viewmodel.ActionsViewModel
5662import kotlinx.coroutines.launch
5763import org.jetbrains.compose.ui.tooling.preview.Preview
5864
65+ @OptIn(ExperimentalMaterial3ExpressiveApi ::class )
5966@Composable
6067fun ItemHeader (
6168 item : AppMediaItem ,
6269 serverUrl : String? = null,
70+ isRowMode : Boolean = true,
6371 onBack : () -> Unit = {},
6472 onPlayClick : (QueueOption , Boolean ) -> Unit = { _, _ -> },
6573 libraryAction : ActionsViewModel .LibraryActions ? = null,
66- playlistActions : ActionsViewModel .PlaylistActions ? = null
74+ playlistActions : ActionsViewModel .PlaylistActions ? = null,
75+ onToggleViewMode : () -> Unit = {}
6776) {
6877 Column (modifier = Modifier .fillMaxWidth()) {
69- IconButton (onClick = onBack) {
70- Icon (Icons .AutoMirrored .Filled .ArrowBack , " Back" )
78+ Row (
79+ modifier = Modifier .fillMaxWidth(),
80+ verticalAlignment = Alignment .CenterVertically ,
81+ horizontalArrangement = Arrangement .SpaceBetween
82+ ) {
83+ IconButton (onClick = onBack) {
84+ Icon (Icons .AutoMirrored .Filled .ArrowBack , " Back" )
85+ }
86+
87+ OverflowMenu (
88+ options = listOf (
89+ OverflowMenuOption (
90+ title = " Toggle view mode" ,
91+ icon = if (isRowMode) Icons .Default .GridView else Icons .AutoMirrored .Filled .ViewList ,
92+ onClick = onToggleViewMode
93+ )
94+ )
95+ ) { onClick ->
96+ IconButton (onClick = onClick) {
97+ Icon (imageVector = Icons .Default .MoreVert , null )
98+ }
99+ }
71100 }
72101
73102 Column (
@@ -111,21 +140,37 @@ fun ItemHeader(
111140 verticalAlignment = Alignment .CenterVertically ,
112141 modifier = Modifier .padding(top = 16 .dp)
113142 ) {
114- Button (
115- modifier = Modifier .semantics { contentDescription = " Play now" },
116- onClick = { onPlayClick(QueueOption .REPLACE , false ) }) {
117- Row (verticalAlignment = Alignment .CenterVertically ) {
118- Icon (imageVector = Icons .Default .PlayArrow , contentDescription = null )
119- Text (modifier = Modifier .padding(start = 8 .dp), text = " Play" )
143+ SplitButtonLayout (
144+ leadingButton = {
145+ LeadingButton (
146+ modifier = Modifier .semantics { contentDescription = " Play now" },
147+ onClick = { onPlayClick(QueueOption .REPLACE , false ) }) {
148+ Row (verticalAlignment = Alignment .CenterVertically ) {
149+ Icon (
150+ imageVector = Icons .Default .PlayArrow ,
151+ contentDescription = null
152+ )
153+ Text (modifier = Modifier .padding(start = 8 .dp), text = " Play" )
154+ }
155+ }
156+ },
157+ trailingButton = {
158+ ItemOverflowMenu (
159+ item = item,
160+ onPlayClick = onPlayClick,
161+ libraryActions = libraryAction,
162+ playlistActions = playlistActions
163+ ) { onClick ->
164+ TrailingButton (
165+ onClick = onClick
166+ ) {
167+ Icon (
168+ imageVector = Icons .Default .ExpandMore ,
169+ contentDescription = null
170+ )
171+ }
172+ }
120173 }
121- }
122-
123- ItemOverflowMenu (
124- item = item,
125- modifier = Modifier .padding(start = 4 .dp),
126- onPlayClick = onPlayClick,
127- libraryActions = libraryAction,
128- playlistActions = playlistActions
129174 )
130175 }
131176 }
@@ -135,25 +180,17 @@ fun ItemHeader(
135180@Composable
136181private fun ItemOverflowMenu (
137182 item : AppMediaItem ,
138- modifier : Modifier ,
139183 onPlayClick : (QueueOption , Boolean ) -> Unit ,
140184 libraryActions : ActionsViewModel .LibraryActions ? ,
141- playlistActions : ActionsViewModel .PlaylistActions ?
185+ playlistActions : ActionsViewModel .PlaylistActions ? ,
186+ button : @Composable (() -> Unit ) -> Unit
142187) {
143188 val coroutineScope = rememberCoroutineScope()
144189 var showPlaylistDialog by rememberSaveable { mutableStateOf(false ) }
145190 var playlists by remember { mutableStateOf<List <AppMediaItem .Playlist >>(emptyList()) }
146191 var isLoadingPlaylists by remember { mutableStateOf(false ) }
147192
148193 OverflowMenu (
149- modifier = modifier,
150- buttonContent = { onClick ->
151- Icon (
152- modifier = Modifier .clickable { onClick() },
153- imageVector = Icons .Default .ExpandMore ,
154- contentDescription = null
155- )
156- },
157194 options = buildList {
158195 add(
159196 OverflowMenuOption (
@@ -221,7 +258,8 @@ private fun ItemOverflowMenu(
221258 }
222259 })
223260 }
224- }
261+ },
262+ buttonContent = button
225263 )
226264
227265 if (showPlaylistDialog) {
@@ -279,7 +317,7 @@ private fun ItemOverflowMenu(
279317@Preview
280318@Composable
281319private fun Preview (item : AppMediaItem .Album = AppMediaItemFixtures .album()) {
282- ItemHeader (item)
320+ ItemHeader (item, )
283321}
284322
285323@Preview
0 commit comments