Skip to content

Commit

Permalink
Implemented touch-to-play functionality for the BrainzPlayerListenCard
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyassp002 committed Jan 20, 2025
1 parent 9748d8e commit f85ff90
Showing 1 changed file with 5 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.listenbrainz.android.ui.components

import androidx.annotation.DrawableRes
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -20,8 +16,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -56,7 +50,6 @@ fun BrainzPlayerListenCard(
mediaId: Long? = null,
viewModel: BrainzPlayerViewModel = hiltViewModel()
) {
val isPlaying by viewModel.isPlaying.collectAsState()
val currentlyPlayingSong = viewModel.currentlyPlayingSong.collectAsStateWithLifecycle().value.toSong
val titleColor = if (currentlyPlayingSong.mediaID == mediaId) {
Color(0xFFB94FE5)
Expand All @@ -66,7 +59,8 @@ fun BrainzPlayerListenCard(

Surface(
modifier = modifier
.fillMaxWidth(),
.fillMaxWidth()
.clickable { onPlayIconClick() },
shape = ListenBrainzTheme.shapes.listenCardSmall,
shadowElevation = 4.dp,
color = ListenBrainzTheme.colorScheme.level1
Expand Down Expand Up @@ -100,19 +94,9 @@ fun BrainzPlayerListenCard(
Box(modifier = Modifier
.fillMaxWidth(0.275f)
.align(Alignment.CenterEnd)){
DropdownButton (modifier = Modifier.align(Alignment.Center), onDropdownIconClick = onDropdownIconClick)
DropdownButton (modifier = Modifier.align(Alignment.CenterEnd), onDropdownIconClick = onDropdownIconClick)
if(dropDownState) dropDown()
PlayButton(
modifier = Modifier.align(Alignment.CenterEnd),
isPlaying = currentlyPlayingSong.mediaID == mediaId && isPlaying,
onPlayIconClick = onPlayIconClick
)
}





}
}
}
Expand All @@ -134,28 +118,6 @@ private fun DropdownButton(modifier: Modifier = Modifier, onDropdownIconClick: (
}
}

@Composable
private fun PlayButton(modifier: Modifier = Modifier, onPlayIconClick: () -> Unit, isPlaying: Boolean) {
IconButton(
modifier = modifier,
onClick = onPlayIconClick
) {
AnimatedContent(
targetState = isPlaying,
transitionSpec = {
fadeIn(animationSpec = tween(200)) togetherWith fadeOut(animationSpec = tween(300))
}
) { targetState ->
Icon(
painter = painterResource(id = if (targetState) R.drawable.ic_pause else R.drawable.brainz_player_play_button),
contentDescription = "",
tint = ListenBrainzTheme.colorScheme.hint,
modifier = Modifier.padding(horizontal = ListenBrainzTheme.paddings.insideCard)
)
}
}
}

@Composable
private fun AlbumArt(
coverArtUrl: String?,
Expand All @@ -178,6 +140,4 @@ private fun AlbumArt(
filterQuality = FilterQuality.Low,
contentDescription = "Album Cover Art"
)
}


}

0 comments on commit f85ff90

Please sign in to comment.