updating the playlists adapter

This commit is contained in:
tibbi 2017-06-25 23:47:41 +02:00
parent 852547e734
commit d6e1f4c80b
3 changed files with 21 additions and 20 deletions

View file

@ -47,6 +47,7 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
fun updateTitle(cnt: Int) {
actMode?.title = "$cnt / $itemCnt"
actMode?.invalidate()
}
}
@ -129,47 +130,39 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_playlist, parent, false)
return ViewHolder(activity, view, itemClick)
return ViewHolder(view, activity, multiSelectorMode, multiSelector, itemClick)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
views.add(holder.bindView(multiSelectorMode, multiSelector, mItems[position], position))
views.add(holder.bindView(mItems[position]))
}
override fun getItemCount() = mItems.size
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (Playlist) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, playlist: Playlist, pos: Int): View {
class ViewHolder(view: View, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, val multiSelector: MultiSelector,
val itemClick: (Playlist) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
fun bindView(playlist: Playlist): View {
itemView.apply {
playlist_title.text = playlist.title
toggleItemSelection(this, markedItems.contains(pos), pos)
toggleItemSelection(this, markedItems.contains(layoutPosition), layoutPosition)
playlist_title.setTextColor(textColor)
playlist_icon.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
playlist_icon.beInvisibleIf(playlist.id != context.config.currentPlaylist)
setOnClickListener { viewClicked(multiSelector, playlist, pos) }
setOnLongClickListener {
if (!multiSelector.isSelectable) {
activity.startSupportActionMode(multiSelectorCallback)
multiSelector.setSelected(this@ViewHolder, true)
updateTitle(multiSelector.selectedPositions.size)
toggleItemSelection(itemView, true, pos)
actMode?.invalidate()
}
true
}
setOnClickListener { viewClicked(playlist) }
setOnLongClickListener { viewLongClicked(); true }
}
return itemView
}
fun viewClicked(multiSelector: MultiSelector, playlist: Playlist, pos: Int) {
fun viewClicked(playlist: Playlist) {
if (multiSelector.isSelectable) {
val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
multiSelector.setSelected(this, !isSelected)
toggleItemSelection(itemView, !isSelected, pos)
toggleItemSelection(itemView, !isSelected, layoutPosition)
val selectedCnt = multiSelector.selectedPositions.size
if (selectedCnt == 0) {
@ -182,5 +175,14 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
itemClick(playlist)
}
}
private fun viewLongClicked() {
if (!multiSelector.isSelectable) {
activity.startSupportActionMode(multiSelectorCallback)
multiSelector.setSelected(this@ViewHolder, true)
updateTitle(multiSelector.selectedPositions.size)
toggleItemSelection(itemView, true, layoutPosition)
}
}
}
}

View file

@ -263,7 +263,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
}
}
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
class ViewHolder(view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
val multiSelector: MultiSelector, val listener: ItemOperationsListener?, val itemClick: (Int) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
fun bindView(song: Song, currentSongIndex: Int, textColor: Int): View {
itemView.apply {

View file

@ -16,7 +16,6 @@
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/remove_playlist_description"
android:textSize="@dimen/bigger_text_size"/>