From d3030570efd04e861baa5e404c3a31de3e06ae46 Mon Sep 17 00:00:00 2001 From: brahmkshatriya <69040506+brahmkshatriya@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:06:29 +0530 Subject: [PATCH] Change to tracks in album --- .../echo/ui/adapters/PlaylistAdapter.kt | 11 ++- .../echo/ui/album/AlbumFragment.kt | 23 ++++-- app/src/main/res/layout/item_track_small.xml | 82 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/layout/item_track_small.xml diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/PlaylistAdapter.kt index 582e5526..47421ad6 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/PlaylistAdapter.kt @@ -10,6 +10,7 @@ import dev.brahmkshatriya.echo.R import dev.brahmkshatriya.echo.common.models.Track import dev.brahmkshatriya.echo.databinding.ItemPlaylistItemBinding import dev.brahmkshatriya.echo.player.Global +import dev.brahmkshatriya.echo.player.PlayerHelper.Companion.toTimeString import dev.brahmkshatriya.echo.utils.loadInto class PlaylistAdapter( @@ -52,8 +53,16 @@ class PlaylistAdapter( val track = list[position].second binding.playlistItemTitle.text = track.title track.cover.loadInto(binding.playlistItemImageView, R.drawable.art_music) - binding.playlistItemAuthor.text = track.artists.joinToString(", ") { it.name } binding.playlistCurrentItem.isVisible = position == currentPosition + var subtitle = "" + track.duration?.toTimeString()?.let { + subtitle += it + } + track.artists.joinToString(", ") { it.name }.let { + if (it.isNotBlank()) subtitle += if (subtitle.isNotBlank()) " • $it" else it + } + binding.playlistItemAuthor.isVisible = subtitle.isNotEmpty() + binding.playlistItemAuthor.text = subtitle } private fun submitList(list: List>) { diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/album/AlbumFragment.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/album/AlbumFragment.kt index dbf46009..43586684 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/album/AlbumFragment.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/album/AlbumFragment.kt @@ -22,7 +22,8 @@ import dev.brahmkshatriya.echo.common.models.Album import dev.brahmkshatriya.echo.common.models.EchoMediaItem.Companion.toMediaItem import dev.brahmkshatriya.echo.common.models.Track import dev.brahmkshatriya.echo.databinding.FragmentCollapsingBarBinding -import dev.brahmkshatriya.echo.databinding.ItemTrackBinding +import dev.brahmkshatriya.echo.databinding.ItemTrackSmallBinding +import dev.brahmkshatriya.echo.player.PlayerHelper.Companion.toTimeString import dev.brahmkshatriya.echo.ui.MediaItemClickListener import dev.brahmkshatriya.echo.ui.adapters.MediaItemsContainerAdapter import dev.brahmkshatriya.echo.ui.extension.ExtensionViewModel @@ -98,7 +99,8 @@ class TrackAdapter( var list: List? = null - inner class ViewHolder(val binding: ItemTrackBinding) : RecyclerView.ViewHolder(binding.root) { + inner class ViewHolder(val binding: ItemTrackSmallBinding) : + RecyclerView.ViewHolder(binding.root) { init { binding.root.setOnClickListener { val track = list?.get(bindingAdapterPosition) ?: return@setOnClickListener @@ -108,7 +110,7 @@ class TrackAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( - ItemTrackBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ItemTrackSmallBinding.inflate(LayoutInflater.from(parent.context), parent, false) ) override fun getItemCount() = list?.count() ?: 0 @@ -116,10 +118,19 @@ class TrackAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { val binding = holder.binding val track = list?.get(position) ?: return - binding.title.text = track.title + binding.itemNumber.text = + binding.root.context.getString(R.string.number_dot, (position + 1)) + binding.itemTitle.text = track.title track.cover.loadInto(binding.imageView, R.drawable.art_music) - binding.artist.text = track.artists.joinToString(", ") { it.name } - binding.album.isVisible = albumVisible + var subtitle = "" + track.duration?.toTimeString()?.let { + subtitle += it + } + track.artists.joinToString(", ") { it.name }.let { + if (it.isNotBlank()) subtitle += if (subtitle.isNotBlank()) " • $it" else it + } + binding.itemSubtitle.isVisible = subtitle.isNotEmpty() + binding.itemSubtitle.text = subtitle } @SuppressLint("NotifyDataSetChanged") diff --git a/app/src/main/res/layout/item_track_small.xml b/app/src/main/res/layout/item_track_small.xml new file mode 100644 index 00000000..794b0822 --- /dev/null +++ b/app/src/main/res/layout/item_track_small.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd0a3a7d..626a6c85 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,5 +28,6 @@ Playlist Loading… Album + %1$d. \ No newline at end of file