diff --git a/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt b/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt index 1e90742b0..42f75ab9c 100644 --- a/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt +++ b/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt @@ -124,7 +124,7 @@ class DownloadUtil @Inject constructor( } val downloads = MutableStateFlow>(emptyMap()) - fun getDownload(songId: String): Flow = downloads.map { it[songId] } + fun getDownload(songId: String?): Flow = downloads.map { it[songId] } init { val result = mutableMapOf() diff --git a/app/src/main/java/com/zionhuang/music/ui/component/Items.kt b/app/src/main/java/com/zionhuang/music/ui/component/Items.kt index b48b05def..48f382ed5 100644 --- a/app/src/main/java/com/zionhuang/music/ui/component/Items.kt +++ b/app/src/main/java/com/zionhuang/music/ui/component/Items.kt @@ -587,7 +587,20 @@ fun PlaylistGridItem( @Composable fun MediaMetadataListItem( mediaMetadata: MediaMetadata, - modifier: Modifier, + modifier: Modifier = Modifier, + badges: @Composable RowScope.() -> Unit = { + val database = LocalDatabase.current + val song by database.song(mediaMetadata.id).collectAsState(initial = null) + + if (song?.song?.liked == true) { + Icon.Favorite() + } + if (song?.song?.inLibrary != null) { + Icon.Library() + } + val download by LocalDownloadUtil.current.getDownload(song?.id).collectAsState(initial = null) + Icon.Download(download?.state) + }, isActive: Boolean = false, isPlaying: Boolean = false, trailingContent: @Composable RowScope.() -> Unit = {}, @@ -597,6 +610,7 @@ fun MediaMetadataListItem( mediaMetadata.artists.joinToString { it.name }, makeTimeString(mediaMetadata.duration * 1000L) ), + badges = badges, thumbnailContent = { ItemThumbnail( thumbnailUrl = mediaMetadata.thumbnailUrl, diff --git a/app/src/main/java/com/zionhuang/music/ui/menu/PlayerMenu.kt b/app/src/main/java/com/zionhuang/music/ui/menu/PlayerMenu.kt index 27f36b90d..ccea6b0a3 100644 --- a/app/src/main/java/com/zionhuang/music/ui/menu/PlayerMenu.kt +++ b/app/src/main/java/com/zionhuang/music/ui/menu/PlayerMenu.kt @@ -21,8 +21,10 @@ import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.items import androidx.compose.material3.AlertDialog +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -56,6 +58,7 @@ import com.zionhuang.music.LocalDownloadUtil import com.zionhuang.music.LocalPlayerConnection import com.zionhuang.music.R import com.zionhuang.music.constants.ListItemHeight +import com.zionhuang.music.db.entities.SongEntity import com.zionhuang.music.models.MediaMetadata import com.zionhuang.music.playback.ExoDownloadService import com.zionhuang.music.ui.component.BigSeekBar @@ -64,6 +67,7 @@ import com.zionhuang.music.ui.component.DownloadGridMenu import com.zionhuang.music.ui.component.GridMenu import com.zionhuang.music.ui.component.GridMenuItem import com.zionhuang.music.ui.component.ListDialog +import com.zionhuang.music.ui.component.MediaMetadataListItem import java.time.LocalDateTime import kotlin.math.log2 import kotlin.math.pow @@ -174,6 +178,35 @@ fun PlayerMenu( modifier = Modifier.weight(1f) ) } + } else { + MediaMetadataListItem( + mediaMetadata = mediaMetadata, + badges = {}, + trailingContent = { + val song by database.song(mediaMetadata.id).collectAsState(initial = null) + + IconButton( + onClick = { + database.query { + val currentSong = song + if (currentSong == null) { + insert(mediaMetadata, SongEntity::toggleLike) + } else { + update(currentSong.song.toggleLike()) + } + } + } + ) { + Icon( + painter = painterResource(if (song?.song?.liked == true) R.drawable.favorite else R.drawable.favorite_border), + tint = if (song?.song?.liked == true) MaterialTheme.colorScheme.error else LocalContentColor.current, + contentDescription = null + ) + } + } + ) + + HorizontalDivider() } GridMenu(