allow clicking on songs
This commit is contained in:
parent
f56192145d
commit
a346b21c01
2 changed files with 23 additions and 9 deletions
|
@ -19,10 +19,8 @@ import android.view.MotionEvent
|
|||
import android.view.View
|
||||
import android.widget.SeekBar
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.adapters.SongAdapter
|
||||
import com.simplemobiletools.musicplayer.dialogs.EditDialog
|
||||
import com.simplemobiletools.musicplayer.extensions.getColoredIcon
|
||||
import com.simplemobiletools.musicplayer.extensions.getTimeString
|
||||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
|
@ -161,7 +159,7 @@ class MainActivity : SimpleActivity(), View.OnTouchListener, MediaScannerConnect
|
|||
private fun fillSongsListView(songs: ArrayList<Song>) {
|
||||
mSongs = songs
|
||||
val adapter = SongAdapter(this, songs) {
|
||||
|
||||
songPicked(it)
|
||||
}
|
||||
songs_list.adapter = adapter
|
||||
}
|
||||
|
@ -292,10 +290,6 @@ class MainActivity : SimpleActivity(), View.OnTouchListener, MediaScannerConnect
|
|||
mToBeDeleted!!.clear()
|
||||
}
|
||||
|
||||
/*override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||
songPicked(position)
|
||||
}*/
|
||||
|
||||
private val undoDeletion = View.OnClickListener {
|
||||
mToBeDeleted!!.clear()
|
||||
mSnackbar!!.dismiss()
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.simplemobiletools.musicplayer.models.Song
|
|||
import kotlinx.android.synthetic.main.song.view.*
|
||||
import java.util.*
|
||||
|
||||
class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val itemClick: (Song) -> Unit) : RecyclerView.Adapter<SongAdapter.ViewHolder>() {
|
||||
class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<SongAdapter.ViewHolder>() {
|
||||
val multiSelector = MultiSelector()
|
||||
val views = ArrayList<View>()
|
||||
|
||||
|
@ -70,12 +70,32 @@ class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val
|
|||
|
||||
override fun getItemCount() = songs.size
|
||||
|
||||
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (Song) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (Int) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, song: Song, pos: Int): View {
|
||||
itemView.song_title.text = song.title
|
||||
itemView.song_artist.text = song.artist
|
||||
|
||||
itemView.setOnClickListener { viewClicked(multiSelector, pos) }
|
||||
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(multiSelector: MultiSelector, pos: Int) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
|
||||
multiSelector.setSelected(this, !isSelected)
|
||||
toggleItemSelection(itemView, !isSelected, pos)
|
||||
|
||||
val selectedCnt = multiSelector.selectedPositions.size
|
||||
if (selectedCnt == 0) {
|
||||
actMode?.finish()
|
||||
} else {
|
||||
actMode?.title = selectedCnt.toString()
|
||||
}
|
||||
actMode?.invalidate()
|
||||
} else {
|
||||
itemClick(pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue