Skip to content

Commit

Permalink
Merge pull request #533 from GautamCoder4019k/null_song_is_coming_in_…
Browse files Browse the repository at this point in the history
…recent_played

Bugfix: null song is coming when we click on recently played
  • Loading branch information
07jasjeet authored Jan 26, 2025
2 parents de22834 + de34061 commit ba19e95
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.listenbrainz.android.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.listenbrainz.android.ui.theme.ListenBrainzTheme

@Composable
fun BrainzPlayerSeeAllCard(modifier: Modifier = Modifier,onCardClicked:()->Unit,cardText:String) {
Box(
modifier = modifier
.padding(10.dp)
.clip(RoundedCornerShape(15.dp))
.size(150.dp)
.clickable {
onCardClicked()
}
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(ListenBrainzTheme.colorScheme.placeHolderColor)
.padding(start = 5.dp, bottom = 20.dp),
verticalArrangement = Arrangement.Bottom
) {
Text(
cardText,
style = TextStyle(fontSize = 20.sp),
color = ListenBrainzTheme.colorScheme.lbSignature
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ fun BrainzPlayerScreen() {
albumSongsMap[albums[i - 1]] = albumSongs
}

val songsPlayedThisWeek =
brainzPlayerViewModel.songsPlayedThisWeek.collectAsState(initial = listOf()).value
topRecents.add(Song())
topArtists.add(Artist())
topAlbums.add(Album())
val songsPlayedThisWeek by brainzPlayerViewModel.songsPlayedThisWeek.collectAsState(initial = listOf())

Column(
modifier = Modifier.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ package org.listenbrainz.android.ui.screens.brainzplayer.overview

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand All @@ -30,6 +25,7 @@ import org.listenbrainz.android.model.Artist
import org.listenbrainz.android.model.PlayableType
import org.listenbrainz.android.model.Song
import org.listenbrainz.android.ui.components.BrainzPlayerActivityCards
import org.listenbrainz.android.ui.components.BrainzPlayerSeeAllCard
import org.listenbrainz.android.ui.theme.ListenBrainzTheme
import org.listenbrainz.android.viewmodel.BrainzPlayerViewModel

Expand Down Expand Up @@ -92,49 +88,31 @@ private fun RecentlyPlayedOverview(
.height(250.dp)
) {
items(items = recentlyPlayedSongs) { song ->
if (song.title != "") {
BrainzPlayerActivityCards(icon = song.albumArt,
errorIcon = R.drawable.ic_song,
title = song.artist,
subtitle = song.title,
modifier = Modifier
.clickable {
brainzPlayerViewModel.changePlayable(
recentlyPlayedSongs,
PlayableType.ALL_SONGS,
song.mediaID,
recentlyPlayedSongs.indexOf(song),
0L
)
brainzPlayerViewModel.playOrToggleSong(song, true)
}
)
} else {
Box(
modifier = Modifier
.padding(10.dp)
.clip(RoundedCornerShape(15.dp))
.size(150.dp)
.clickable {
goToRecentScreen()
}
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(ListenBrainzTheme.colorScheme.placeHolderColor)
.padding(start = 5.dp, bottom = 20.dp),
verticalArrangement = Arrangement.Bottom
) {
Text(
" All \n Recently\n Played",
style = TextStyle(fontSize = 20.sp),
color = ListenBrainzTheme.colorScheme.lbSignature
BrainzPlayerActivityCards(icon = song.albumArt,
errorIcon = R.drawable.ic_song,
title = song.artist,
subtitle = song.title,
modifier = Modifier
.clickable {
brainzPlayerViewModel.changePlayable(
recentlyPlayedSongs,
PlayableType.ALL_SONGS,
song.mediaID,
recentlyPlayedSongs.indexOf(song),
0L
)
brainzPlayerViewModel.playOrToggleSong(song, true)
}
}
}
)

}
if (recentlyPlayedSongs.isNotEmpty())
item {
BrainzPlayerSeeAllCard(
onCardClicked = goToRecentScreen,
cardText = " All \n Recently\n Played"
)
}
}
}
}
Expand Down Expand Up @@ -164,39 +142,20 @@ private fun ArtistsOverview(
.height(250.dp)
) {
items(items = artists) { artist ->
if (artist.name != "") {
BrainzPlayerActivityCards(
icon = "",
errorIcon = R.drawable.ic_artist,
title = "",
subtitle = artist.name,
BrainzPlayerActivityCards(
icon = "",
errorIcon = R.drawable.ic_artist,
title = "",
subtitle = artist.name,
)
}
if (artists.isNotEmpty())
item {
BrainzPlayerSeeAllCard(
onCardClicked = goToArtistScreen,
cardText = " All \n Artists"
)
} else {
Box(
modifier = Modifier
.padding(10.dp)
.clip(RoundedCornerShape(15.dp))
.size(150.dp)
.clickable {
goToArtistScreen()
}
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(ListenBrainzTheme.colorScheme.placeHolderColor)
.padding(start = 5.dp, bottom = 20.dp),
verticalArrangement = Arrangement.Bottom
) {
Text(
" All \n Artists",
style = TextStyle(fontSize = 20.sp),
color = ListenBrainzTheme.colorScheme.lbSignature
)
}
}
}
}
}
}
}
Expand Down Expand Up @@ -224,38 +183,18 @@ private fun AlbumsOverview(
.height(250.dp)
) {
items(items = albums) { album ->
if (album.title != "") {
BrainzPlayerActivityCards(
icon = album.albumArt,
errorIcon = R.drawable.ic_album,
title = album.artist,
subtitle = album.title,
)
} else {
Box(
modifier = Modifier
.padding(10.dp)
.clip(RoundedCornerShape(15.dp))
.size(150.dp)
.clickable {
goToAlbumScreen()
}
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(ListenBrainzTheme.colorScheme.placeHolderColor)
.padding(start = 5.dp, bottom = 20.dp),
verticalArrangement = Arrangement.Bottom
) {
Text(
" All \n Albums",
style = TextStyle(fontSize = 20.sp),
color = ListenBrainzTheme.colorScheme.lbSignature
)
}
}
}
BrainzPlayerActivityCards(
icon = album.albumArt,
errorIcon = R.drawable.ic_album,
title = album.artist,
subtitle = album.title,
)
}
item {
BrainzPlayerSeeAllCard(
onCardClicked = goToAlbumScreen,
cardText = " All \n Albums"
)
}
}
}
Expand Down

0 comments on commit ba19e95

Please sign in to comment.