PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/adapter/song/ShuffleButtonSongAdapter.kt

67 lines
2.4 KiB
Kotlin
Raw Normal View History

2020-10-06 08:46:04 +00:00
/*
* Copyright (c) 2020 Hemanth Savarla.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
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.ICabHolder
2018-11-30 01:06:16 +00:00
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,
ICabHolder: ICabHolder?
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, ICabHolder) {
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-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
}
}
2020-10-06 08:46:04 +00:00
}