Added swipe songs
This commit is contained in:
parent
7289b271dc
commit
d2076fc1d4
5 changed files with 196 additions and 94 deletions
|
@ -25,11 +25,12 @@ import androidx.annotation.Nullable;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
|
||||
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil;
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
|
||||
public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHolder implements View.OnLongClickListener, View.OnClickListener {
|
||||
@Nullable
|
||||
public TextView title;
|
||||
|
||||
|
@ -71,6 +72,8 @@ public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements Vie
|
|||
|
||||
@Nullable
|
||||
public ImageView image;
|
||||
@Nullable
|
||||
public View dummyContainer;
|
||||
|
||||
public MediaEntryViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -91,6 +94,7 @@ public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements Vie
|
|||
recyclerView = itemView.findViewById(R.id.recycler_view);
|
||||
mask = itemView.findViewById(R.id.mask);
|
||||
playSongs = itemView.findViewById(R.id.playSongs);
|
||||
dummyContainer = itemView.findViewById(R.id.dummy_view);
|
||||
|
||||
if (imageContainerCard != null) {
|
||||
imageContainerCard.setCardBackgroundColor(ATHUtil.INSTANCE.resolveColor(itemView.getContext(), R.attr.colorSurface));
|
||||
|
@ -99,6 +103,11 @@ public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements Vie
|
|||
itemView.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return false;
|
||||
|
|
|
@ -8,15 +8,24 @@ import android.widget.ImageView
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.isPlaying
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.playNextSong
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.removeFromQueue
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemViewHolder
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableItemStateFlags
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionDefault
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionRemoveItem
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.annotation.SwipeableItemResults
|
||||
import java.util.*
|
||||
|
||||
|
||||
class PlayingQueueAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
|
@ -24,9 +33,10 @@ class PlayingQueueAdapter(
|
|||
itemLayoutRes: Int
|
||||
) : SongAdapter(
|
||||
activity, dataSet, itemLayoutRes, false, null
|
||||
), DraggableItemAdapter<PlayingQueueAdapter.ViewHolder> {
|
||||
), DraggableItemAdapter<PlayingQueueAdapter.ViewHolder>, SwipeableItemAdapter<PlayingQueueAdapter.ViewHolder> {
|
||||
|
||||
private var color = -1
|
||||
private var songToRemove: Song? = null
|
||||
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
|
@ -125,7 +135,11 @@ class PlayingQueueAdapter(
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView), DraggableItemViewHolder {
|
||||
fun setSongToRemove(song: Song) {
|
||||
songToRemove = song
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView) {
|
||||
|
||||
@DraggableItemStateFlags
|
||||
private var mDragStateFlags: Int = 0
|
||||
|
@ -159,6 +173,10 @@ class PlayingQueueAdapter(
|
|||
override fun setDragStateFlags(@DraggableItemStateFlags flags: Int) {
|
||||
mDragStateFlags = flags
|
||||
}
|
||||
|
||||
override fun getSwipeableContainerView(): View? {
|
||||
return dummyContainer
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -167,4 +185,51 @@ class PlayingQueueAdapter(
|
|||
private const val CURRENT = 1
|
||||
private const val UP_NEXT = 2
|
||||
}
|
||||
|
||||
override fun onSwipeItem(holder: ViewHolder?, position: Int, @SwipeableItemResults result: Int): SwipeResultAction {
|
||||
return if (result === SwipeableItemConstants.RESULT_CANCELED) {
|
||||
SwipeResultActionDefault()
|
||||
} else {
|
||||
SwipedResultActionRemoveItem(this, position, activity)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onGetSwipeReactionType(holder: ViewHolder?, position: Int, x: Int, y: Int): Int {
|
||||
return if (onCheckCanStartDrag(holder!!, position, x, y)) {
|
||||
SwipeableItemConstants.REACTION_CAN_NOT_SWIPE_BOTH_H;
|
||||
} else {
|
||||
SwipeableItemConstants.REACTION_CAN_SWIPE_BOTH_H;
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSwipeItemStarted(p0: ViewHolder?, p1: Int) {
|
||||
}
|
||||
|
||||
override fun onSetSwipeBackground(holder: ViewHolder?, position: Int, result: Int) {
|
||||
|
||||
}
|
||||
|
||||
internal class SwipedResultActionRemoveItem(private val adapter: PlayingQueueAdapter,
|
||||
private val position: Int,
|
||||
private val activity: AppCompatActivity) : SwipeResultActionRemoveItem() {
|
||||
private var songToRemove: Song? = null
|
||||
private val isPlaying: Boolean = MusicPlayerRemote.isPlaying
|
||||
private val songProgressMillis = 0
|
||||
override fun onPerformAction() {
|
||||
//currentlyShownSnackbar = null
|
||||
}
|
||||
|
||||
override fun onSlideAnimationEnd() {
|
||||
//initializeSnackBar(adapter, position, activity, isPlaying)
|
||||
songToRemove = adapter.dataSet[position]
|
||||
//If song removed was the playing song, then play the next song
|
||||
if (isPlaying(songToRemove!!)) {
|
||||
playNextSong()
|
||||
}
|
||||
//Swipe animation is much smoother when we do the heavy lifting after it's completed
|
||||
adapter.setSongToRemove(songToRemove!!)
|
||||
removeFromQueue(songToRemove!!)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue