2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.adapter.song
|
2018-11-30 01:06:16 +00:00
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
|
|
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
2020-04-26 10:59:35 +00:00
|
|
|
import com.google.android.material.button.MaterialButton
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-11-15 17:44:42 +00:00
|
|
|
class ShuffleButtonSongAdapter(
|
2020-01-17 17:19:06 +00:00
|
|
|
activity: AppCompatActivity,
|
2020-02-17 11:20:08 +00:00
|
|
|
dataSet: MutableList<Song>,
|
2020-01-17 17:19:06 +00:00
|
|
|
itemLayoutRes: Int,
|
|
|
|
cabHolder: CabHolder?
|
|
|
|
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, cabHolder) {
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-04-26 10:59:35 +00:00
|
|
|
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
2020-01-17 17:19:06 +00:00
|
|
|
return ViewHolder(view)
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
|
|
|
if (holder.itemViewType == OFFSET_ITEM) {
|
|
|
|
val viewHolder = holder as ViewHolder
|
2020-04-26 10:59:35 +00:00
|
|
|
viewHolder.playAction?.let {
|
|
|
|
it.setOnClickListener {
|
|
|
|
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
viewHolder.shuffleAction?.let {
|
|
|
|
it.setOnClickListener {
|
|
|
|
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
|
|
|
}
|
2020-02-20 15:09:47 +00:00
|
|
|
}
|
2020-01-17 17:19:06 +00:00
|
|
|
} else {
|
|
|
|
super.onBindViewHolder(holder, position - 1)
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-04-26 10:59:35 +00:00
|
|
|
inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
|
|
|
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
|
|
|
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
2020-04-26 10:17:09 +00:00
|
|
|
|
2020-04-26 10:59:35 +00:00
|
|
|
override fun onClick(v: View?) {
|
|
|
|
if (itemViewType == OFFSET_ITEM) {
|
|
|
|
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
|
|
|
return
|
2020-04-26 10:17:09 +00:00
|
|
|
}
|
2020-04-26 10:59:35 +00:00
|
|
|
super.onClick(v)
|
2020-01-17 17:19:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|