Skip to content

Commit

Permalink
Change to tracks in album
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Feb 28, 2024
1 parent c0f297a commit d303057
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<Pair<String, Track>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,7 +99,8 @@ class TrackAdapter(

var list: List<Track>? = 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
Expand All @@ -108,18 +110,27 @@ 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

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")
Expand Down
82 changes: 82 additions & 0 deletions app/src/main/res/layout/item_track_small.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp">

<TextView
android:id="@+id/itemNumber"
android:layout_width="52dp"
android:gravity="center"
android:layout_height="match_parent"
android:padding="8dp"
android:textStyle="bold"
tools:text="1" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="8dp"
android:paddingStart="36dp"
android:paddingEnd="0dp"
android:layout_gravity="center"
android:paddingBottom="8dp">

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imageView"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="16dp"
android:background="?attr/colorSurfaceContainerHigh"
android:scaleType="fitCenter"
app:shapeAppearance="@style/ShapeAppearance.Material3.Corner.ExtraSmall" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="64dp"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="24dp"
android:layout_weight="1"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textStyle="bold"
tools:text="Nice Track Title" />

<TextView
android:id="@+id/itemSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
tools:text="Author" />
</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/itemClose"
style="?attr/materialIconButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:contentDescription="@string/next"
android:padding="8dp"
app:icon="@drawable/ic_more_vert"
app:iconSize="24dp"
app:iconTint="@color/button_player" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
<string name="playlist">Playlist</string>
<string name="loading">Loading…</string>
<string name="album">Album</string>
<string name="number_dot">%1$d.</string>

</resources>

0 comments on commit d303057

Please sign in to comment.