-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made play button in album playable, shuffle is uhhh
- Loading branch information
1 parent
8fac817
commit 554f3c6
Showing
8 changed files
with
169 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/TrackAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dev.brahmkshatriya.echo.ui.adapters | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.recyclerview.widget.RecyclerView | ||
import dev.brahmkshatriya.echo.R | ||
import dev.brahmkshatriya.echo.common.models.EchoMediaItem.Companion.toMediaItem | ||
import dev.brahmkshatriya.echo.common.models.Track | ||
import dev.brahmkshatriya.echo.databinding.ItemTrackSmallBinding | ||
import dev.brahmkshatriya.echo.player.PlayerHelper.Companion.toTimeString | ||
import dev.brahmkshatriya.echo.ui.MediaItemClickListener | ||
import dev.brahmkshatriya.echo.utils.loadInto | ||
|
||
class TrackAdapter( | ||
private val callback: MediaItemClickListener, | ||
private val albumVisible: Boolean = true, | ||
) : RecyclerView.Adapter<TrackAdapter.ViewHolder>() { | ||
|
||
var list: List<Track>? = null | ||
|
||
inner class ViewHolder(val binding: ItemTrackSmallBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
init { | ||
binding.root.setOnClickListener { | ||
val track = list?.get(bindingAdapterPosition) ?: return@setOnClickListener | ||
callback.onClick(binding.imageView to track.toMediaItem()) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( | ||
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.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) | ||
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") | ||
fun submitList(tracks: List<Track>) { | ||
list = tracks | ||
notifyDataSetChanged() | ||
} | ||
} |
Oops, something went wrong.