mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Making queue current click.
This commit is contained in:
@@ -12,9 +12,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class CurrentItemDecoration : RecyclerView.ItemDecoration
|
||||
{
|
||||
public IItemTouchAdapter adapter;
|
||||
public QueueAdapter adapter;
|
||||
|
||||
public CurrentItemDecoration(IItemTouchAdapter adapter) { this.adapter = adapter; }
|
||||
public CurrentItemDecoration(QueueAdapter adapter) { this.adapter = adapter; }
|
||||
|
||||
public override void OnDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
|
||||
{
|
||||
@@ -46,6 +46,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
header.FindViewById(Resource.Id.topDivider).Visibility = ViewStates.Gone;
|
||||
BindHolder(new RecyclerHolder(header, null, null));
|
||||
Queue.instance.HeaderHeight = header.MeasuredHeight;
|
||||
|
||||
c.Save();
|
||||
c.Translate(0, 0);
|
||||
@@ -66,6 +67,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
header.FindViewById(Resource.Id.bottomDivider).Visibility = ViewStates.Gone;
|
||||
BindHolder(new RecyclerHolder(header, null, null));
|
||||
Queue.instance.HeaderHeight = -header.MeasuredHeight;
|
||||
|
||||
c.Save();
|
||||
c.Translate(0, parentHeight - header.MeasuredHeight);
|
||||
@@ -75,6 +77,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Queue.instance.HeaderHeight = 0;
|
||||
parent.SetPadding(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
holder.recycler.SetAdapter(adapter);
|
||||
holder.more.Click += (sender, e) =>
|
||||
{
|
||||
Intent intent = new Intent(MainActivity.instance, typeof(Queue));
|
||||
MainActivity.instance.StartActivity(intent);
|
||||
MainActivity.instance.ShowPlayer();
|
||||
Player.instance.ShowQueue();
|
||||
};
|
||||
if(MusicPlayer.CurrentID() != -1 && MusicPlayer.CurrentID() <= MusicPlayer.queue.Count)
|
||||
holder.recycler.ScrollToPosition(MusicPlayer.CurrentID());
|
||||
|
||||
@@ -405,7 +405,11 @@ namespace MusicApp
|
||||
|
||||
private void ShowQueue_Click(object sender, EventArgs e)
|
||||
{
|
||||
Queue.instance?.Refresh();
|
||||
ShowQueue();
|
||||
}
|
||||
|
||||
public void ShowQueue()
|
||||
{
|
||||
DrawerLayout.OpenDrawer((int)GravityFlags.Start);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,13 @@ using Fragment = Android.Support.V4.App.Fragment;
|
||||
|
||||
[Activity(Label = "Queue", Theme = "@style/Theme", ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
[Register("MusicApp/Queue")]
|
||||
public class Queue : Fragment
|
||||
public class Queue : Fragment, RecyclerView.IOnItemTouchListener
|
||||
{
|
||||
public static Queue instance;
|
||||
public RecyclerView ListView;
|
||||
private QueueAdapter adapter;
|
||||
public ItemTouchHelper itemTouchHelper;
|
||||
public int HeaderHeight;
|
||||
public IMenu menu;
|
||||
|
||||
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
@@ -40,6 +41,7 @@ public class Queue : Fragment
|
||||
adapter.ItemLongCLick += ListView_ItemLongCLick;
|
||||
ListView.SetItemAnimator(new DefaultItemAnimator());
|
||||
ListView.AddItemDecoration(new CurrentItemDecoration(adapter));
|
||||
ListView.AddOnItemTouchListener(this);
|
||||
ListView.ScrollChange += Scroll;
|
||||
|
||||
ItemTouchHelper.Callback callback = new ItemTouchCallback(adapter, true);
|
||||
@@ -92,6 +94,8 @@ public class Queue : Fragment
|
||||
|
||||
public void RefreshCurrent()
|
||||
{
|
||||
ListView.InvalidateItemDecorations();
|
||||
|
||||
int first = ((LinearLayoutManager)ListView.GetLayoutManager()).FindFirstVisibleItemPosition();
|
||||
int last = ((LinearLayoutManager)ListView.GetLayoutManager()).FindLastVisibleItemPosition() - 1;
|
||||
for (int i = first; i <= last; i++)
|
||||
@@ -260,6 +264,13 @@ public class Queue : Fragment
|
||||
bottomSheet.Show();
|
||||
}
|
||||
|
||||
void HeaderClick()
|
||||
{
|
||||
Intent intent = new Intent(Activity, typeof(MusicPlayer));
|
||||
intent.SetAction("Pause");
|
||||
Activity.StartService(intent);
|
||||
}
|
||||
|
||||
public static void InsertToQueue(int position, Song item)
|
||||
{
|
||||
if (MusicPlayer.CurrentID() >= position)
|
||||
@@ -290,4 +301,29 @@ public class Queue : Fragment
|
||||
base.OnResume();
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public bool OnInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent)
|
||||
{
|
||||
if (HeaderHeight == 0)
|
||||
return false;
|
||||
|
||||
if (motionEvent.GetY() <= HeaderHeight)
|
||||
{
|
||||
if (motionEvent.ActionMasked == MotionEventActions.Down) //The up motion is never triggered so i use the down here.
|
||||
HeaderClick();
|
||||
return true;
|
||||
}
|
||||
if(motionEvent.GetY() >= recyclerView.Height + HeaderHeight) //When the header is at the bottom, the HeaderHeight is negative
|
||||
{
|
||||
if (motionEvent.ActionMasked == MotionEventActions.Down)
|
||||
HeaderClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnRequestDisallowInterceptTouchEvent(bool disallow) { }
|
||||
|
||||
public void OnTouchEvent(RecyclerView recyclerView, MotionEvent @event) { }
|
||||
}
|
||||
Reference in New Issue
Block a user