11package com.ljyh.mei.ui.component.home
22
33import androidx.compose.foundation.clickable
4- import androidx.compose.foundation.layout.Arrangement
54import androidx.compose.foundation.layout.Box
65import androidx.compose.foundation.layout.Column
7- import androidx.compose.foundation.layout.IntrinsicSize
86import androidx.compose.foundation.layout.Row
97import androidx.compose.foundation.layout.Spacer
8+ import androidx.compose.foundation.layout.fillMaxWidth
109import androidx.compose.foundation.layout.height
1110import androidx.compose.foundation.layout.padding
1211import androidx.compose.foundation.layout.size
@@ -16,14 +15,12 @@ import androidx.compose.material.icons.Icons
1615import androidx.compose.material.icons.automirrored.rounded.PlaylistPlay
1716import androidx.compose.material.icons.filled.Headset
1817import androidx.compose.material3.Icon
19- import androidx.compose.material3.IconButton
2018import androidx.compose.material3.MaterialTheme
2119import androidx.compose.material3.Text
2220import androidx.compose.runtime.Composable
2321import androidx.compose.ui.Alignment
2422import androidx.compose.ui.Modifier
2523import androidx.compose.ui.draw.clip
26- import androidx.compose.ui.draw.shadow
2724import androidx.compose.ui.geometry.Offset
2825import androidx.compose.ui.graphics.Color
2926import androidx.compose.ui.graphics.Shadow
@@ -35,11 +32,8 @@ import androidx.compose.ui.unit.dp
3532import androidx.compose.ui.unit.sp
3633import coil3.compose.AsyncImage
3734import com.ljyh.mei.constants.PlaylistCardSize
38- import com.ljyh.mei.constants.PlaylistCardSpacing
39- import com.ljyh.mei.ui.local.LocalNavController
4035import com.ljyh.mei.utils.largeImage
4136
42-
4337@Composable
4438fun PlaylistCard (
4539 id : String ,
@@ -51,132 +45,104 @@ fun PlaylistCard(
5145 imageSize : Boolean = true,
5246 onClick : () -> Unit
5347) {
54- // val playerConnection = LocalPlayerConnection.current ?: return
55- // val isPlaying by playerConnection.isPlaying.collectAsState()
56- // val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
57- val context = LocalNavController .current.context
58- Row {
59- Column (modifier = Modifier
48+ // 常用阴影样式,提取出来复用
49+ val textShadow = Shadow (
50+ color = Color .Black .copy(alpha = 0.7f ),
51+ offset = Offset (2f , 2f ),
52+ blurRadius = 4f
53+ )
54+
55+ Column (
56+ modifier = Modifier
6057 .width(PlaylistCardSize )
61- .clickable { onClick() }) {
62- Box {
63- AsyncImage (
64- model = if (imageSize) {
65- coverImg.largeImage()
66- } else {
67- coverImg
68- },
58+ .clip(RoundedCornerShape (8 .dp)) // 整个组件裁切,防止水波纹溢出
59+ .clickable { onClick() }
60+ ) {
61+ Box (
62+ modifier = Modifier .size(PlaylistCardSize )
63+ ) {
64+ AsyncImage (
65+ model = if (imageSize) coverImg.largeImage() else coverImg,
66+ modifier = Modifier
67+ .matchParentSize()
68+ .clip(RoundedCornerShape (8 .dp)),
69+ contentDescription = null ,
70+ contentScale = ContentScale .Crop ,
71+ )
72+
73+ // 顶部播放量
74+ if (extInfo != null ) {
75+ Row (
6976 modifier = Modifier
70- .size(PlaylistCardSize )
71- .clip(RoundedCornerShape (8 .dp)),
72- contentDescription = null ,
73- contentScale = ContentScale .Crop ,
74- )
75- subTitle?.let {
76- Column (
77- modifier = Modifier
78- .align(Alignment .BottomStart )
79- .padding(4 .dp),
80- ) {
81- it.forEach { t ->
82- Text (
83- text = t,
84- fontSize = 12 .sp,
85- color = Color .White ,
86- fontWeight = FontWeight .ExtraBold ,
87- lineHeight = 16 .sp,
88- style = TextStyle (
89- shadow = Shadow (
90- color = Color .Black ,
91- offset = Offset (4f , 4f ),
92- blurRadius = 8f
93- )
94- )
95- )
96- }
97- }
77+ .align(Alignment .TopEnd )
78+ .padding(6 .dp),
79+ verticalAlignment = Alignment .CenterVertically
80+ ) {
81+ Icon (
82+ imageVector = Icons .Filled .Headset ,
83+ contentDescription = null ,
84+ modifier = Modifier .size(12 .dp),
85+ tint = Color .White
86+ )
87+ Spacer (Modifier .width(2 .dp))
88+ Text (
89+ text = extInfo,
90+ fontSize = 11 .sp,
91+ color = Color .White ,
92+ fontWeight = FontWeight .Bold ,
93+ style = TextStyle (shadow = textShadow)
94+ )
9895 }
96+ }
9997
100- extInfo?.let {
101-
102- Row (
103- Modifier
104- .height(IntrinsicSize .Min )
105- .align(Alignment .TopStart )
106- .padding(4 .dp),
107- verticalAlignment = Alignment .CenterVertically ,
108- horizontalArrangement = Arrangement .spacedBy(4 .dp)
109-
110- ) {
111- Icon (
112- imageVector = Icons .Filled .Headset ,
113- contentDescription = " Headset" ,
114- modifier = Modifier
115- .size(12 .dp)
116- .shadow(
117- 4 .dp,
118- RoundedCornerShape (4 .dp)
119- ),
120- tint = Color .White
121- )
98+ // 底部左侧副标题 (如果有)
99+ if (subTitle != null ) {
100+ Column (
101+ modifier = Modifier
102+ .align(Alignment .BottomStart )
103+ .padding(6 .dp)
104+ ) {
105+ subTitle.forEach { t ->
122106 Text (
123- text = it,
124- fontSize = 10 .sp,
125- maxLines = 1 ,
126- lineHeight = 16 .sp,
107+ text = t,
108+ fontSize = 11 .sp,
127109 color = Color .White ,
128- fontWeight = FontWeight .Bold ,
129- style = TextStyle (
130- shadow = Shadow (
131- color = Color .Black ,
132- offset = Offset (4f , 4f ),
133- blurRadius = 8f
134- )
135- )
110+ fontWeight = FontWeight .Medium ,
111+ style = TextStyle (shadow = textShadow)
136112 )
137113 }
138-
139114 }
115+ }
140116
141-
142-
143- if (showPlay) {
144- IconButton ( modifier = Modifier
117+ // 右下角播放按钮
118+ if (showPlay) {
119+ Box (
120+ modifier = Modifier
145121 .align(Alignment .BottomEnd )
146- .size(24 .dp)
147- .padding(4 .dp),
148- onClick = {
149- }
150- ) {
151- Icon (
152- imageVector = Icons .AutoMirrored .Rounded .PlaylistPlay ,
153- contentDescription = " Play" ,
154- tint = Color .White ,
155- modifier = Modifier .shadow(
156- 4 .dp,
157- RoundedCornerShape (4 .dp)
158- ),
159- )
160- }
122+ .padding(6 .dp)
123+ ) {
124+ Icon (
125+ imageVector = Icons .AutoMirrored .Rounded .PlaylistPlay ,
126+ contentDescription = " Play" ,
127+ tint = Color .White ,
128+ modifier = Modifier .size(24 .dp)
129+ )
161130 }
162-
163-
164131 }
165-
166- Spacer (Modifier .height(12 .dp))
167- Text (
168- text = title,
169- overflow = TextOverflow .Ellipsis ,
170- color = MaterialTheme .colorScheme.onSurface,
171- maxLines = 2 ,
172- fontSize = 14 .sp,
173- lineHeight = 16 .sp,
174- fontWeight = FontWeight .Bold
175- )
176132 }
177133
178- Spacer (Modifier .width(PlaylistCardSpacing ))
134+ Spacer (Modifier .height(8 .dp))
135+
136+ // 标题
137+ Text (
138+ text = title,
139+ overflow = TextOverflow .Ellipsis ,
140+ color = MaterialTheme .colorScheme.onSurface,
141+ maxLines = 2 ,
142+ fontSize = 13 .sp, // 调整字体大小,更精致
143+ lineHeight = 18 .sp,
144+ fontWeight = FontWeight .Medium ,
145+ modifier = Modifier .fillMaxWidth()
146+ )
179147 }
180-
181-
182148}
0 commit comments