Skip to content

Commit

Permalink
Change quick picks grid's column to 4, Fix player state
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Jul 23, 2024
1 parent 933b67c commit 19c16b1
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/extension/AllExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.maxrave.kotlinytmusicscraper.models.response.spotify.SpotifyLyricsRes
import com.maxrave.kotlinytmusicscraper.models.youtube.Transcript
import com.maxrave.kotlinytmusicscraper.models.youtube.YouTubeInitialPage
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.DownloadState
import com.maxrave.simpmusic.common.SETTINGS_FILENAME
import com.maxrave.simpmusic.data.db.entities.AlbumEntity
import com.maxrave.simpmusic.data.db.entities.LyricsEntity
Expand Down Expand Up @@ -507,6 +508,7 @@ fun PlaylistBrowse.toPlaylistEntity(): PlaylistEntity {
trackCount = this.trackCount,
tracks = this.tracks.toListVideoId(),
year = this.year,
downloadState = DownloadState.STATE_NOT_DOWNLOADED
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import com.maxrave.simpmusic.ui.widget.BasicWidget
import com.maxrave.simpmusic.utils.Resource
import com.maxrave.simpmusic.viewModel.FilterState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -390,7 +389,6 @@ class SimpleMediaServiceHandler(
stopProgressUpdate()
} else {
player.play()
_simpleMediaState.value = SimpleMediaState.Playing(isPlaying = true)
startProgressUpdate()
}
}
Expand Down Expand Up @@ -540,18 +538,31 @@ class SimpleMediaServiceHandler(
updateNotification()
}

@SuppressLint("SwitchIntDef")
override fun onPlaybackStateChanged(playbackState: Int) {
super.onPlaybackStateChanged(playbackState)
when (playbackState) {
ExoPlayer.STATE_IDLE -> _simpleMediaState.value = SimpleMediaState.Initial
ExoPlayer.STATE_ENDED -> _simpleMediaState.value = SimpleMediaState.Ended
ExoPlayer.STATE_BUFFERING ->
_simpleMediaState.value =
SimpleMediaState.Buffering(player.currentPosition)
Player.STATE_IDLE -> {
_simpleMediaState.value = SimpleMediaState.Initial
Log.d(TAG, "onPlaybackStateChanged: Idle")
}
Player.STATE_ENDED -> {
_simpleMediaState.value = SimpleMediaState.Ended
Log.d(TAG, "onPlaybackStateChanged: Ended")
}
Player.STATE_BUFFERING -> {
_simpleMediaState.value = SimpleMediaState.Buffering(player.currentPosition)
Log.d(TAG, "onPlaybackStateChanged: Buffering")
}
Player.STATE_READY -> {
Log.d(TAG, "onPlaybackStateChanged: Ready")
_simpleMediaState.value = SimpleMediaState.Ready(player.duration)

ExoPlayer.STATE_READY ->
}
else -> {
Log.d(TAG, "onPlaybackStateChanged: $playbackState")
_simpleMediaState.value =
SimpleMediaState.Ready(player.duration)
SimpleMediaState.Buffering(player.currentPosition)
}
}
}

Expand Down Expand Up @@ -579,7 +590,6 @@ class SimpleMediaServiceHandler(
}

override fun onIsPlayingChanged(isPlaying: Boolean) {
_simpleMediaState.value = SimpleMediaState.Playing(isPlaying = isPlaying)
_controlState.value = _controlState.value.copy(isPlaying = isPlaying)
basicWidget.updatePlayingState(
context,
Expand Down Expand Up @@ -719,7 +729,6 @@ class SimpleMediaServiceHandler(

private fun stopProgressUpdate() {
job?.cancel()
_simpleMediaState.value = SimpleMediaState.Playing(isPlaying = false)
}

private fun stopBufferedUpdate() {
Expand All @@ -728,7 +737,6 @@ class SimpleMediaServiceHandler(
SimpleMediaState.Loading(player.bufferedPercentage, player.duration)
}

@OptIn(DelicateCoroutinesApi::class)
override fun onIsLoadingChanged(isLoading: Boolean) {
super.onIsLoadingChanged(isLoading)
_simpleMediaState.value =
Expand Down Expand Up @@ -1582,8 +1590,6 @@ sealed class SimpleMediaState {
data class Progress(val progress: Long) : SimpleMediaState()

data class Buffering(val position: Long) : SimpleMediaState()

data class Playing(val isPlaying: Boolean) : SimpleMediaState()
}

data class NowPlayingTrackState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -27,6 +29,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.CardDefaults
Expand All @@ -48,6 +51,7 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.media3.common.util.UnstableApi
import androidx.navigation.NavController
Expand Down Expand Up @@ -77,6 +81,7 @@ import com.skydoves.landscapist.animation.crossfade.CrossfadePlugin
import com.skydoves.landscapist.coil.CoilImage
import com.skydoves.landscapist.components.rememberImageComponent

@OptIn(ExperimentalFoundationApi::class)
@UnstableApi
@Composable
fun HomeItem(
Expand All @@ -87,6 +92,10 @@ fun HomeItem(
) {
val coroutineScope = rememberCoroutineScope()
var bottomSheetShow by remember { mutableStateOf(false) }

val lazyListState = rememberLazyListState()
val snapperFlingBehavior = rememberSnapFlingBehavior(SnapLayoutInfoProvider(lazyListState = lazyListState))

if (bottomSheetShow) {
NowPlayingBottomSheet(
isBottomSheetVisible = bottomSheetShow,
Expand Down Expand Up @@ -172,7 +181,9 @@ fun HomeItem(
LazyRow(
modifier = Modifier.padding(
vertical = 15.dp
)
),
state = lazyListState,
flingBehavior = snapperFlingBehavior
) {
items(data.contents) { temp ->
if (temp != null) {
Expand Down Expand Up @@ -352,12 +363,14 @@ fun HomeItemContentPlaylist(
@Composable
fun QuickPicksItem(
onClick: () -> Unit,
widthDp: Dp,
data: Content
) {
val configuration = LocalConfiguration.current
Box(
modifier = Modifier
.wrapContentSize()
.wrapContentHeight()
.width(widthDp)
.focusable(true)
.clickable {
onClick()
Expand Down Expand Up @@ -799,7 +812,8 @@ fun ItemVideoChart(
fun ItemArtistChart(
onClick: () -> Unit,
data: ItemArtist,
context: Context
context: Context,
widthDp: Dp
) {
Box(
Modifier
Expand All @@ -810,7 +824,7 @@ fun ItemArtistChart(
}
) {
Row(
modifier = Modifier.padding(10.dp),
modifier = Modifier.padding(10.dp).width(widthDp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
Expand Down Expand Up @@ -875,9 +889,9 @@ fun ItemArtistChart(
fun ItemTrackChart(
onClick: () -> Unit,
data: Track,
position: Int?
position: Int?,
widthDp: Dp
) {
val configuration = LocalConfiguration.current
Box(
modifier = Modifier
.wrapContentSize()
Expand All @@ -888,7 +902,7 @@ fun ItemTrackChart(
) {
Row(
modifier = Modifier
.width(configuration.screenWidthDp.dp)
.width(widthDp)
.padding(10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.viewinterop.AndroidView
Expand Down Expand Up @@ -106,7 +107,7 @@ fun MediaPlayerView(
}

// Use AndroidView to embed an Android View (PlayerView) into Compose
Box(modifier = modifier) {
Box(modifier = modifier.graphicsLayer { clip = true }) {
AndroidView(
factory = { ctx ->
TextureView(ctx).also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fun QuickPicksShimmer() {
.shimmer()
)
LazyColumn(userScrollEnabled = false) {
items(3) {
items(4) {
QuickPicksShimmerItem()
}
}
Expand Down
Loading

0 comments on commit 19c16b1

Please sign in to comment.