mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Solving bugs with queue remove and slide.
This commit is contained in:
@@ -12,13 +12,22 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class CurrentItemDecoration : RecyclerView.ItemDecoration
|
||||
{
|
||||
public CurrentItemDecoration() { }
|
||||
public IItemTouchAdapter adapter;
|
||||
|
||||
public CurrentItemDecoration(IItemTouchAdapter adapter) { this.adapter = adapter; }
|
||||
|
||||
public override void OnDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
|
||||
{
|
||||
base.OnDrawOver(c, parent, state);
|
||||
|
||||
if(parent.ChildCount > 1 && parent.Width > 0)
|
||||
if (adapter.IsSliding)
|
||||
{
|
||||
parent.SetPadding(0, 0, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (parent.ChildCount > 1 && parent.Width > 0)
|
||||
{
|
||||
int firstPos = parent.GetChildAdapterPosition(parent.GetChildAt(0));
|
||||
int lastPos = parent.GetChildAdapterPosition(parent.GetChildAt(parent.ChildCount - 1));
|
||||
|
||||
@@ -59,12 +59,12 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override bool OnMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target)
|
||||
{
|
||||
if (Queue.instance != null && target.AdapterPosition + 1 == ((QueueAdapter)adapter).ItemCount)
|
||||
adapter.IsSliding = true;
|
||||
|
||||
if (Queue.instance != null && (target.AdapterPosition + 1 == ((QueueAdapter)adapter).ItemCount || target.AdapterPosition == 0))
|
||||
return false;
|
||||
|
||||
if (from == -1)
|
||||
from = source.AdapterPosition;
|
||||
|
||||
from = source.AdapterPosition;
|
||||
to = target.AdapterPosition;
|
||||
adapter.ItemMoved(source.AdapterPosition, target.AdapterPosition);
|
||||
return true;
|
||||
@@ -119,13 +119,18 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public override void ClearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
|
||||
{
|
||||
base.ClearView(recyclerView, viewHolder);
|
||||
adapter.IsSliding = false;
|
||||
|
||||
viewHolder.ItemView.Alpha = 1;
|
||||
|
||||
MainActivity.instance.contentRefresh.Enabled = true;
|
||||
|
||||
if (from != -1 && to != -1 && from != to)
|
||||
{
|
||||
adapter.ItemMoveEnded(from, to);
|
||||
from = -1;
|
||||
to = -1;
|
||||
}
|
||||
|
||||
|
||||
if (viewHolder is IItemTouchHolder)
|
||||
@@ -135,6 +140,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public interface IItemTouchAdapter
|
||||
{
|
||||
bool IsSliding { get; set; }
|
||||
|
||||
void ItemMoved(int fromPosition, int toPosition);
|
||||
void ItemMoveEnded(int fromPosition, int toPosition);
|
||||
void ItemDismissed(int position);
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public event EventHandler<int> ItemLongClick;
|
||||
public int listPadding;
|
||||
public bool IsEmpty = false;
|
||||
public bool IsSliding { get; set; }
|
||||
|
||||
public PlaylistTrackAdapter(List<Song> songList)
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Queue : Fragment
|
||||
adapter.ItemClick += ListView_ItemClick;
|
||||
adapter.ItemLongCLick += ListView_ItemLongCLick;
|
||||
ListView.SetItemAnimator(new DefaultItemAnimator());
|
||||
ListView.AddItemDecoration(new CurrentItemDecoration());
|
||||
ListView.AddItemDecoration(new CurrentItemDecoration(adapter));
|
||||
ListView.ScrollChange += Scroll;
|
||||
|
||||
ItemTouchHelper.Callback callback = new ItemTouchCallback(adapter, true);
|
||||
@@ -282,7 +282,7 @@ public class Queue : Fragment
|
||||
MusicPlayer.RemoveFromQueue(position);
|
||||
|
||||
if (instance != null)
|
||||
instance.adapter.NotifyItemRemoved(position);
|
||||
instance.adapter.NotifyItemRemoved(position + 1);
|
||||
}
|
||||
|
||||
public override void OnResume()
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public event EventHandler<int> ItemClick;
|
||||
public event EventHandler<int> ItemLongCLick;
|
||||
|
||||
public bool IsSliding { get; set; }
|
||||
|
||||
|
||||
public QueueAdapter(List<Song> songList) { }
|
||||
|
||||
public override int ItemCount => MusicPlayer.UseCastPlayer ? MusicPlayer.RemotePlayer.MediaQueue.ItemCount + 2 : MusicPlayer.queue.Count + 2;
|
||||
@@ -353,18 +356,15 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void ItemMoved(int fromPosition, int toPosition)
|
||||
{
|
||||
fromPosition--;
|
||||
toPosition--;
|
||||
|
||||
if(fromPosition < toPosition)
|
||||
if (fromPosition < toPosition)
|
||||
{
|
||||
for(int i = fromPosition; i < toPosition; i++)
|
||||
MusicPlayer.queue = Swap(MusicPlayer.queue, i, i + 1);
|
||||
for (int i = fromPosition; i < toPosition; i++)
|
||||
MusicPlayer.queue = Swap(MusicPlayer.queue, i - 1, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = fromPosition; i > toPosition; i--)
|
||||
MusicPlayer.queue = Swap(MusicPlayer.queue, i, i - 1);
|
||||
for (int i = fromPosition; i > toPosition; i--)
|
||||
MusicPlayer.queue = Swap(MusicPlayer.queue, i - 1, i - 2);
|
||||
}
|
||||
|
||||
NotifyItemMoved(fromPosition, toPosition);
|
||||
@@ -394,8 +394,6 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
List<T> Swap<T>(List<T> list, int fromPosition, int toPosition)
|
||||
{
|
||||
fromPosition--;
|
||||
toPosition--;
|
||||
T item = list[fromPosition];
|
||||
list[fromPosition] = list[toPosition];
|
||||
list[toPosition] = item;
|
||||
@@ -408,7 +406,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
Song song = MusicPlayer.queue[position];
|
||||
Queue.RemoveFromQueue(position);
|
||||
Snackbar snackbar = Snackbar.Make(MainActivity.instance.FindViewById(Resource.Id.recycler), (song.Title.Length > 20 ? song.Title.Substring(0, 17) + "..." : song.Title) + Queue.instance.GetString(Resource.String.removed_from_queue), Snackbar.LengthShort)
|
||||
Snackbar snackbar = Snackbar.Make(Player.instance.View, (song.Title.Length > 20 ? song.Title.Substring(0, 17) + "..." : song.Title) + Queue.instance.GetString(Resource.String.removed_from_queue), Snackbar.LengthShort)
|
||||
.SetAction(Queue.instance.GetString(Resource.String.undo), (view) =>
|
||||
{
|
||||
Queue.InsertToQueue(position, song);
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical" >
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:fitsSystemWindows="true"
|
||||
android:elevation="8dp"
|
||||
app:title="@string/settings"
|
||||
android:background="?attr/colorPrimary"
|
||||
|
||||
Reference in New Issue
Block a user