Skip to content

Commit

Permalink
update AlbumScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
dattrxng committed Dec 4, 2024
1 parent e21ec38 commit 235f270
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 4 deletions.
22 changes: 21 additions & 1 deletion app/src/main/java/com/example/harmonyhub/HarmonyHubApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.example.harmonyhub.ui.account.VerificationScreen
import com.example.harmonyhub.ui.components.Friend
import com.example.harmonyhub.ui.library.AddSongToPlaylistScreen
import com.example.harmonyhub.ui.library.AddToPlaylistFromSongScreen
import com.example.harmonyhub.ui.library.AlbumScreen
import com.example.harmonyhub.ui.library.ArtistScreen
import com.example.harmonyhub.ui.library.PlaylistSongListScreen
import com.example.harmonyhub.ui.play.NowPlayingBar
Expand Down Expand Up @@ -89,7 +90,8 @@ enum class HarmonyHubScreen(@StringRes val title: Int, val icon: ImageVector) {
title = R.string.add_to_playlist_from_song,
icon = Icons.Default.AccountBox
),
Friends(title = R.string.friends, icon = Icons.Default.AccountBox)
Friends(title = R.string.friends, icon = Icons.Default.AccountBox),
Album(title = R.string.album, icon = Icons.Default.AccountBox)
}

private val gradientBackground = Brush.verticalGradient(
Expand Down Expand Up @@ -461,6 +463,18 @@ fun HarmonyHubApp(
)

}
composable(route = HarmonyHubScreen.Album.name) {
AlbumScreen(
onShareClicked = {},
onDownloadClicked = {},
onSongClick = {
},
onBackButtonClicked = {},
onAddToPlaylistClicked = {},
onAddToFavoriteClicked = {}
)

}


}
Expand Down Expand Up @@ -508,6 +522,9 @@ fun Nav(
},
onDownloadClicked = {
// Xử lý logic tải về
},
onAlbumClicked = {
parentNavController.navigate(HarmonyHubScreen.Album.name)
}
)
}
Expand Down Expand Up @@ -627,6 +644,9 @@ fun Nav3(
},
onDownloadClicked = {
// Xử lý logic tải về
},
onAlbumClicked = {
parentNavController.navigate(HarmonyHubScreen.Album.name)
}
)
}
Expand Down
217 changes: 217 additions & 0 deletions app/src/main/java/com/example/harmonyhub/ui/library/AlbumScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package com.example.harmonyhub.ui.library

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.rememberAsyncImagePainter
import com.example.harmonyhub.R
import com.example.harmonyhub.ui.components.BottomSheetContent
import com.example.harmonyhub.ui.components.Song
import com.example.harmonyhub.ui.components.SongCard
import com.example.harmonyhub.ui.theme.NotoSans

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlbumScreen(
onSongClick: () -> Unit,
onBackButtonClicked: () -> Unit,
onAddToPlaylistClicked: () -> Unit,
onAddToFavoriteClicked: () -> Unit,
onShareClicked: () -> Unit,
onDownloadClicked: () -> Unit
) {
// Dữ liệu giả lập
val albumName = "The Best Hits"
val songs = listOf(
Song("1", "Song A", "Artist A", albumName, "https://example.com/song_a.jpg"),
Song("2", "Song B", "Artist B", albumName, "https://example.com/song_b.jpg"),
Song("3", "Song C", "Artist C", albumName, "https://example.com/song_c.jpg")
)

var isBottomSheetVisible by remember { mutableStateOf(false) }
var selectedSong by remember { mutableStateOf<Song?>(null) }

Column(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
) {
Box {
Image(
painter = painterResource(id = R.drawable.v),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth()
.height(240.dp)
)

// Gradient overlay để tăng độ rõ của chữ
Box(
modifier = Modifier
.fillMaxWidth()
.height(240.dp)
.background(
color = Color.Black.copy(alpha = 0.4f)
)
)

IconButton(
onClick = onBackButtonClicked,
modifier = Modifier
.align(Alignment.TopStart)
.padding(16.dp)
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back",
tint = Color.White,
modifier = Modifier.size(25.dp)
)
}

Column(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomStart)
.padding(16.dp)
.testTag("Album Name")
) {
Text(
text = albumName,
color = Color.White,
fontSize = 36.sp,
fontWeight = FontWeight.Bold
)
}
}

Spacer(modifier = Modifier.height(16.dp))

Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier
.border(1.dp, Color.White, RoundedCornerShape(16.dp))
.padding(8.dp)
.clickable { }
) {
Text(
text = "Follow",
color = Color.White,
fontFamily = NotoSans,
fontSize = 16.sp
)
}
Row {
IconButton(onClick = { /* Play Action */ }) {
Icon(
painter = painterResource(id = R.drawable.icons8_circled_play_64),
contentDescription = "Play",
tint = Color(0xFF00FAF2),
modifier = Modifier.size(50.dp)
)
}
}
}

Spacer(modifier = Modifier.height(24.dp))

if (songs.isNotEmpty()) {
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
.testTag("Song List")
) {
Text(
text = "Popular tracks",
color = Color.White,
fontFamily = NotoSans,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)

Spacer(modifier = Modifier.height(16.dp))

LazyColumn {
items(songs) { song ->
SongCard(
song = song,
more = Icons.Default.MoreVert,
onSongClick = onSongClick,
onMoreClick = {
selectedSong = song
isBottomSheetVisible = true
}
)
}
}
}
} else {
Text(
text = "No songs available",
color = Color.Gray,
fontSize = 16.sp,
modifier = Modifier.padding(16.dp)
)
}
}

if (isBottomSheetVisible) {
ModalBottomSheet(
onDismissRequest = { isBottomSheetVisible = false },
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
) {
BottomSheetContent(
onDismiss = { isBottomSheetVisible = false },
selectedSong = selectedSong,
screenType = "AlbumScreen",
onAddToPlaylistClicked = onAddToPlaylistClicked,
onAddToFavoriteClicked = onAddToFavoriteClicked,
onShareClicked = onShareClicked,
onDownloadClicked = onDownloadClicked,
onDeleteClicked = {},
favoriteSongsViewModel = null
)
}
}
}

@Preview(showBackground = true)
@Composable
fun AlbumScreenPreview() {
AlbumScreen(
onSongClick = {},
onBackButtonClicked = {},
onAddToPlaylistClicked = {},
onAddToFavoriteClicked = {},
onShareClicked = {},
onDownloadClicked = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.unit.dp
import com.example.harmonyhub.R
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -53,14 +54,23 @@ fun ArtistScreen(
onAddToPlaylistClicked: () -> Unit,
onAddToFavoriteClicked: () -> Unit,
onShareClicked: () -> Unit,
onDownloadClicked: () -> Unit
onDownloadClicked: () -> Unit,
onAlbumClicked:() -> Unit
) {
var isBottomSheetVisible by remember { mutableStateOf(false) }
var selectedSong by remember { mutableStateOf<Song?>(null) }

val songs = SongRepository.allSongs.filter { it.artist == myArtist }
val artistName = songs.firstOrNull()?.artist ?: "Unknown Artist"

// Thêm danh sách album giả lập
val albums = listOf(
"The Best Hits" to R.drawable.v,
"Acoustic Vibes" to R.drawable.v,
"Live Performances" to R.drawable.v,
"New Era" to R.drawable.v
)

Column(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -197,7 +207,69 @@ fun ArtistScreen(
modifier = Modifier.padding(16.dp)
)
}

// Hiển thị danh sách album dưới dạng LazyRow
Spacer(modifier = Modifier.height(24.dp))
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
) {
Text(
text = "Albums",
color = Color.White,
fontFamily = NotoSans,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)

Spacer(modifier = Modifier.height(16.dp))

LazyRow(
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
items(albums) { album ->
Card(
modifier = Modifier
.size(120.dp) // Kích thước hình vuông
.clip(RoundedCornerShape(12.dp))
.background(Color.DarkGray)
.clickable { onAlbumClicked() },
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
) {
Box(
modifier = Modifier.fillMaxSize()
) {
Image(
painter = painterResource(id = album.second),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(12.dp))
)

Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.3f))
)

Text(
text = album.first,
color = Color.White,
fontSize = 12.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier
.align(Alignment.BottomStart)
.padding(8.dp)
)
}
}
}
}
}
}

if (isBottomSheetVisible) {
ModalBottomSheet(
onDismissRequest = { isBottomSheetVisible = false },
Expand All @@ -218,6 +290,7 @@ fun ArtistScreen(
}
}


@Preview(showBackground = true)
@Composable
fun ArtistScreenPreview() {
Expand All @@ -228,7 +301,8 @@ fun ArtistScreenPreview() {
onAddToPlaylistClicked = {},
onAddToFavoriteClicked = {},
onShareClicked = {},
onDownloadClicked = {}
onDownloadClicked = {},
onAlbumClicked = {}
)
}

Loading

0 comments on commit 235f270

Please sign in to comment.