Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from SuhasDissa/design
Browse files Browse the repository at this point in the history
Design improvements
  • Loading branch information
SuhasDissa authored Oct 28, 2023
2 parents 7831065 + d5d77ae commit 25ea636
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ data class Artist(
val id: String,
val artistsText: String,
val thumbnailUri: Uri? = null,
val description: String? = null
val description: String? = null,
val numberOfTracks: Int? = null,
val numberOfAlbums: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.text.format.DateUtils
import android.util.Log
import androidx.core.net.toUri
import app.suhasdissa.vibeyou.backend.data.Album
import app.suhasdissa.vibeyou.backend.data.Artist
Expand Down Expand Up @@ -47,7 +46,7 @@ class LocalMusicRepository(
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.DATE_MODIFIED,
MediaStore.Audio.Media.DATE_ADDED,
MediaStore.Audio.Media.DATE_ADDED
)

val sortOrder = "${MediaStore.Audio.Media.TITLE} ASC"
Expand All @@ -69,7 +68,9 @@ class LocalMusicRepository(
val artistColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)
val albumColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)
val artistIdColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID)
val creationDateColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_MODIFIED)
val creationDateColumn = cursor.getColumnIndexOrThrow(
MediaStore.Audio.Media.DATE_MODIFIED
)
val dateAddedColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_ADDED)

while (cursor.moveToNext()) {
Expand Down Expand Up @@ -180,7 +181,7 @@ class LocalMusicRepository(
val artists = mutableListOf<Artist>()

val collection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Audio.Albums.getContentUri(
MediaStore.Audio.Artists.getContentUri(
MediaStore.VOLUME_EXTERNAL
)
} else {
Expand All @@ -190,10 +191,11 @@ class LocalMusicRepository(
val projection = arrayOf(
MediaStore.Audio.Artists._ID,
MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.Artists.Albums.ALBUM_ID
MediaStore.Audio.Artists.NUMBER_OF_ALBUMS,
MediaStore.Audio.Artists.NUMBER_OF_TRACKS
)

val sortOrder = "${MediaStore.Audio.Albums.ALBUM} ASC"
val sortOrder = "${MediaStore.Audio.Artists.ARTIST} ASC"

val query = contentResolver.query(
collection,
Expand All @@ -205,8 +207,10 @@ class LocalMusicRepository(
query?.use { cursor ->
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID)
val artistColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST)
val albumIdColumn =
cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.Albums.ALBUM_ID)
val noOfAlbums =
cursor.getColumnIndexOrThrow(MediaStore.Audio.ArtistColumns.NUMBER_OF_ALBUMS)
val noOfTracks =
cursor.getColumnIndexOrThrow(MediaStore.Audio.ArtistColumns.NUMBER_OF_TRACKS)

while (cursor.moveToNext()) {
val id = cursor.getLong(idColumn)
Expand All @@ -215,7 +219,9 @@ class LocalMusicRepository(
Artist(
id = id.toString(),
artistsText = cursor.getString(artistColumn),
thumbnailUri = getAlbumArt(cursor.getLong(albumIdColumn))
thumbnailUri = null,
numberOfAlbums = cursor.getInt(noOfAlbums),
numberOfTracks = cursor.getInt(noOfTracks)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package app.suhasdissa.vibeyou.ui.components
import android.view.SoundEffectConstants
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
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.shape.CircleShape
import androidx.compose.material3.MaterialTheme
Expand All @@ -22,7 +23,6 @@ import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import app.suhasdissa.vibeyou.R
Expand All @@ -38,7 +38,7 @@ fun ArtistCard(
) {
val view = LocalView.current
val haptic = LocalHapticFeedback.current
Column(
Row(
Modifier
.fillMaxWidth()
.combinedClickable(
Expand All @@ -51,26 +51,44 @@ fun ArtistCard(
onLongPress()
}
),
horizontalAlignment = Alignment.CenterHorizontally
verticalAlignment = Alignment.CenterVertically
) {
AsyncImage(
modifier = Modifier
.size(148.dp)
.size(80.dp)
.padding(8.dp)
.aspectRatio(1f)
.clip(CircleShape),
model = artist.thumbnailUri,
contentDescription = stringResource(R.string.artist_avatar),
contentScale = ContentScale.Crop,
error = painterResource(id = R.drawable.music_placeholder)
)
Spacer(Modifier.height(8.dp))
Text(
artist.artistsText,
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Center
)
Spacer(Modifier.height(8.dp))
Column(
Modifier
.weight(1f)
.padding(8.dp)
) {
Text(
artist.artistsText,
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
artist.numberOfAlbums?.let {
Text(
text = "${stringResource(id = R.string.albums)} $it",
style = MaterialTheme.typography.bodyMedium
)
}
artist.numberOfTracks?.let {
Text(
text = "${stringResource(id = R.string.songs)} $it",
style = MaterialTheme.typography.bodyMedium
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package app.suhasdissa.vibeyou.ui.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.suhasdissa.vibeyou.R
import app.suhasdissa.vibeyou.backend.data.Artist
import my.nanihadesuka.compose.LazyColumnScrollbar

@Composable
fun ArtistList(
Expand All @@ -21,19 +23,26 @@ fun ArtistList(
if (items.isEmpty()) {
IllustratedMessageScreen(image = R.drawable.ic_launcher_monochrome)
}
LazyVerticalGrid(
columns = GridCells.Adaptive(180.dp),
modifier = Modifier.fillMaxSize(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp)
val state = rememberLazyListState()
LazyColumnScrollbar(
listState = state,
thumbColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f),
thumbSelectedColor = MaterialTheme.colorScheme.primary,
thickness = 8.dp
) {
items(items = items) { item ->
ArtistCard(
artist = item,
onClickCard = { onClickCard(item) },
onLongPress = { onLongPress(item) }
)
LazyColumn(
modifier = Modifier.fillMaxSize(),
state = state,
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp)
) {
items(items = items) { item ->
ArtistCard(
artist = item,
onClickCard = { onClickCard(item) },
onLongPress = { onLongPress(item) }
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -110,13 +111,15 @@ fun SongCardCompact(
title: String,
artist: String?,
active: Boolean = false,
inactive: Boolean = false,
onClickVideoCard: () -> Unit,
TrailingContent: @Composable () -> Unit,
modifier: Modifier = Modifier
) {
Row(
modifier
.fillMaxWidth()
.alpha(if (inactive) 0.5f else 1f)
.clickable { onClickVideoCard() },
verticalAlignment = Alignment.CenterVertically
) {
Expand Down Expand Up @@ -158,14 +161,16 @@ fun SongCardCompact(
title,
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
color = if (active) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground
)
artist?.let {
Text(
artist,
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
color = if (active) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import app.suhasdissa.vibeyou.R
import app.suhasdissa.vibeyou.backend.models.PlayerRepeatMode
import app.suhasdissa.vibeyou.backend.models.PlayerState
import app.suhasdissa.vibeyou.backend.viewmodel.PlayerViewModel
import app.suhasdissa.vibeyou.utils.IS_LOCAL_KEY
import app.suhasdissa.vibeyou.utils.isPlayingState
import app.suhasdissa.vibeyou.utils.maxResThumbnail
import app.suhasdissa.vibeyou.utils.mediaItemState
Expand Down Expand Up @@ -107,9 +108,15 @@ fun FullScreenPlayer(
val isFavourite = remember {
mutableStateOf(false)
}
var isLocal by remember {
mutableStateOf(false)
}
mediaItem?.let {
LaunchedEffect(mediaItem) {
isFavourite.value = playerViewModel.isFavourite(mediaItem!!.mediaId)
isLocal = mediaItem!!.mediaMetadata.extras?.getBoolean(IS_LOCAL_KEY) ?: false
if (!isLocal) {
isFavourite.value = playerViewModel.isFavourite(mediaItem!!.mediaId)
}
}
SubcomposeAsyncImage(
modifier = Modifier
Expand Down Expand Up @@ -153,6 +160,7 @@ fun FullScreenPlayer(
}
PlayerController(
isfavourite = isFavourite,
isLocal = isLocal,
onToggleFavourite = { playerViewModel.toggleFavourite(it.mediaId) }
)
}
Expand All @@ -177,6 +185,7 @@ fun FullScreenPlayer(
fun PlayerController(
playerViewModel: PlayerViewModel = viewModel(factory = PlayerViewModel.Factory),
isfavourite: MutableState<Boolean>,
isLocal: Boolean,
onToggleFavourite: () -> Unit
) {
val view = LocalView.current
Expand Down Expand Up @@ -215,7 +224,7 @@ fun PlayerController(
view.playSoundEffect(SoundEffectConstants.CLICK)
onToggleFavourite()
favouriteState = !favouriteState
}) {
}, enabled = !isLocal) {
if (favouriteState) {
Icon(Icons.Default.Favorite, contentDescription = null)
} else {
Expand Down Expand Up @@ -338,5 +347,9 @@ fun PlayerController(
@Preview(showBackground = true)
@Composable
private fun PlayerControllerPreview() {
PlayerController(isfavourite = remember { mutableStateOf(false) }, onToggleFavourite = {})
PlayerController(
isfavourite = remember { mutableStateOf(false) },
isLocal = false,
onToggleFavourite = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fun Queue(
title = mediaItem.mediaMetadata.title.toString(),
artist = mediaItem.mediaMetadata.artist.toString(),
active = queue.first == currentItemIndex,
inactive = queue.first < currentItemIndex,
TrailingContent = {
IconButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ExpandMore
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -56,7 +63,30 @@ fun QueueSheet(
contentDescription = stringResource(R.string.close_queue)
)
}
}, title = { Text(stringResource(R.string.player_queue)) })
}, title = { Text(stringResource(R.string.player_queue)) }, actions = {
var showDropdown by remember { mutableStateOf(false) }
IconButton({
view.playSoundEffect(SoundEffectConstants.CLICK)
showDropdown = true
}) {
Icon(
Icons.Rounded.MoreVert,
contentDescription = stringResource(R.string.close_queue)
)
}
DropdownMenu(expanded = showDropdown, onDismissRequest = { showDropdown = false }) {
DropdownMenuItem(text = {
Text(text = stringResource(R.string.clear_queue))
}, onClick = {
playerViewModel.controller?.clearMediaItems()
scope.launch {
playerSheetState.hide()
}.invokeOnCompletion {
onDismissRequest()
}
})
}
})
Divider(Modifier.fillMaxWidth())
playerViewModel.controller?.let { controller ->
Queue(controller)
Expand Down
Loading

0 comments on commit 25ea636

Please sign in to comment.