From d20af489d86d01c69b7fb38cb1ca52f6de8952aa Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Sun, 20 May 2018 00:14:39 +0200 Subject: [PATCH] Updating queue actions. --- MusicApp/Resources/Portable Class/Adapter.cs | 1 - .../Resources/Portable Class/MusicPlayer.cs | 21 ++++-- .../Portable Class/PlaylistTracks.cs | 53 +++++++-------- MusicApp/Resources/Portable Class/Queue.cs | 45 +++++++++---- .../Portable Class/RecyclerAdapter.cs | 20 ++++-- .../Portable Class/RecyclerHolder.cs | 2 + MusicApp/Resources/Resource.Designer.cs | 67 ++++++++++--------- MusicApp/Resources/layout/SongList.xml | 12 ++++ MusicApp/Resources/layout/player.xml | 11 --- MusicApp/Resources/menu/QueueItems.xml | 1 + 10 files changed, 142 insertions(+), 91 deletions(-) diff --git a/MusicApp/Resources/Portable Class/Adapter.cs b/MusicApp/Resources/Portable Class/Adapter.cs index ddf1327..503bfb2 100644 --- a/MusicApp/Resources/Portable Class/Adapter.cs +++ b/MusicApp/Resources/Portable Class/Adapter.cs @@ -101,7 +101,6 @@ namespace MusicApp.Resources.Portable_Class private void MoreClick(object sender, EventArgs e) { int position = (int)((ImageView)sender).Tag; - Queue.instance?.More(songList[position]); Browse.instance?.More(songList[position]); PlaylistTracks.instance?.More(songList[position], position); FolderTracks.instance?.More(songList[position]); diff --git a/MusicApp/Resources/Portable Class/MusicPlayer.cs b/MusicApp/Resources/Portable Class/MusicPlayer.cs index 83bebde..d55bdaf 100644 --- a/MusicApp/Resources/Portable Class/MusicPlayer.cs +++ b/MusicApp/Resources/Portable Class/MusicPlayer.cs @@ -10,6 +10,7 @@ using Android.Support.V4.App; using Android.Support.V4.Content; using Android.Support.V4.Media.Session; using Android.Support.V7.Preferences; +using Android.Support.V7.Widget; using Android.Widget; using Com.Google.Android.Exoplayer2; using Com.Google.Android.Exoplayer2.Extractor; @@ -467,6 +468,12 @@ namespace MusicApp.Resources.Portable_Class song.SetPath(streamInfo.Url); song.youtubeID = streamInfo.Url; song.isParsed = true; + if (Queue.instance != null) + { + ImageView youtubeIcon = Queue.instance.ListView.GetChildAt(queue.IndexOf(song) - ((LinearLayoutManager)Queue.instance.ListView.GetLayoutManager()).FindFirstVisibleItemPosition()).FindViewById(Resource.Id.youtubeIcon); + youtubeIcon.SetImageResource(Resource.Drawable.youtubeIcon); + youtubeIcon.ClearColorFilter(); + } } ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context); @@ -541,6 +548,12 @@ namespace MusicApp.Resources.Portable_Class song.SetPath(streamInfo.Url); song.isParsed = true; parsing = false; + if (Queue.instance != null) + { + ImageView youtubeIcon = Queue.instance.ListView.GetChildAt(queue.IndexOf(song) - ((LinearLayoutManager)Queue.instance.ListView.GetLayoutManager()).FindFirstVisibleItemPosition()).FindViewById(Resource.Id.youtubeIcon); + youtubeIcon.SetImageResource(Resource.Drawable.youtubeIcon); + youtubeIcon.ClearColorFilter(); + } } } @@ -706,10 +719,8 @@ namespace MusicApp.Resources.Portable_Class CoordinatorLayout smallPlayer = MainActivity.instance.FindViewById(Resource.Id.smallPlayer); smallPlayer.FindViewById(Resource.Id.spPlay).SetImageResource(Resource.Drawable.ic_play_arrow_black_24dp); - if (Player.instance != null) - { - Player.instance.playerView.FindViewById(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_play_arrow_black_24dp); - } + Player.instance?.playerView.FindViewById(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_play_arrow_black_24dp); + Queue.instance?.RefreshCurrent(); } } @@ -735,6 +746,8 @@ namespace MusicApp.Resources.Portable_Class Player.instance.playerView.FindViewById(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_pause_black_24dp); Player.instance.handler.PostDelayed(Player.instance.UpdateSeekBar, 1000); } + + Queue.instance?.RefreshCurrent(); } else { diff --git a/MusicApp/Resources/Portable Class/PlaylistTracks.cs b/MusicApp/Resources/Portable Class/PlaylistTracks.cs index 6358510..251ed76 100644 --- a/MusicApp/Resources/Portable Class/PlaylistTracks.cs +++ b/MusicApp/Resources/Portable Class/PlaylistTracks.cs @@ -212,33 +212,32 @@ namespace MusicApp.Resources.Portable_Class private async void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { - Song item = tracks[e.Position]; - List queue = tracks.GetRange(e.Position + 1, tracks.Count - e.Position - 1); + List songs = tracks.GetRange(e.Position + 1, tracks.Count - e.Position - 1); if (result != null && result.Count - 1 >= e.Position) - { - item = result[e.Position]; - queue = result.GetRange(e.Position + 1, result.Count - e.Position - 1); - } - queue.Reverse(); + songs = result.GetRange(e.Position + 1, result.Count - e.Position - 1); - if (!item.IsYt) + if (MusicPlayer.isRunning) + MusicPlayer.queue.Clear(); + + if (!songs[0].IsYt) { Browse.act = Activity; - Browse.Play(item); + Browse.Play(songs[0]); } else - { - YoutubeEngine.Play(item.youtubeID, item.GetName(), item.GetArtist(), item.GetAlbum()); - } + YoutubeEngine.Play(songs[0].youtubeID, songs[0].GetName(), songs[0].GetArtist(), songs[0].GetAlbum()); + + songs.RemoveAt(0); + songs.Reverse(); while (MusicPlayer.instance == null) await Task.Delay(10); - foreach (Song song in queue) + foreach (Song song in songs) { MusicPlayer.instance.AddToQueue(song); } - Player.instance.UpdateNext(); + Player.instance?.UpdateNext(); } private void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e) @@ -273,32 +272,32 @@ namespace MusicApp.Resources.Portable_Class { case 0: int Position = tracks.IndexOf(item); - List queue = tracks.GetRange(Position + 1, tracks.Count - Position - 1); + List songs = tracks.GetRange(Position + 1, tracks.Count - Position - 1); if (result != null && result.Count - 1 >= Position) - { - item = result[Position]; - queue = result.GetRange(Position + 1, result.Count - Position - 1); - } - queue.Reverse(); + songs = result.GetRange(Position + 1, result.Count - Position - 1); - if (!item.IsYt) + if (MusicPlayer.isRunning) + MusicPlayer.queue.Clear(); + + if (!songs[0].IsYt) { Browse.act = Activity; - Browse.Play(item); + Browse.Play(songs[0]); } else - { - YoutubeEngine.Play(item.youtubeID, item.GetName(), item.GetArtist(), item.GetAlbum()); - } + YoutubeEngine.Play(songs[0].youtubeID, songs[0].GetName(), songs[0].GetArtist(), songs[0].GetAlbum()); + + songs.RemoveAt(0); + songs.Reverse(); while (MusicPlayer.instance == null) await Task.Delay(10); - foreach (Song song in queue) + foreach (Song song in songs) { MusicPlayer.instance.AddToQueue(song); } - Player.instance.UpdateNext(); + Player.instance?.UpdateNext(); break; case 1: diff --git a/MusicApp/Resources/Portable Class/Queue.cs b/MusicApp/Resources/Portable Class/Queue.cs index 5f0e430..aa6acae 100644 --- a/MusicApp/Resources/Portable Class/Queue.cs +++ b/MusicApp/Resources/Portable Class/Queue.cs @@ -1,6 +1,7 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Android.Graphics; using Android.OS; using Android.Support.Design.Widget; using Android.Support.V7.App; @@ -81,12 +82,28 @@ namespace MusicApp.Resources.Portable_Class public void RefreshCurrent() { - + int first = ((LinearLayoutManager)ListView.GetLayoutManager()).FindFirstVisibleItemPosition(); + int last = ((LinearLayoutManager)ListView.GetLayoutManager()).FindLastVisibleItemPosition(); + for (int i = first; i <= last; i++) + { + Song song = MusicPlayer.queue[first + i]; + RecyclerHolder holder = (RecyclerHolder)ListView.GetChildViewHolder(((LinearLayoutManager)ListView.GetLayoutManager()).FindViewByPosition(i)); + if (song.queueSlot == MusicPlayer.CurrentID()) + { + holder.status.Text = MusicPlayer.isRunning ? "Playing" : "Paused"; + holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245)); + holder.status.Visibility = ViewStates.Visible; + } + else + holder.status.Visibility = ViewStates.Gone; + } } public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.QueueItems, menu); + if(MusicPlayer.repeat) + menu.FindItem(Resource.Id.repeat).Icon.SetColorFilter(Color.Argb(255, 62, 80, 180), PorterDuff.Mode.Multiply); return base.OnCreateOptionsMenu(menu); } @@ -102,7 +119,7 @@ namespace MusicApp.Resources.Portable_Class } else if(item.ItemId == Resource.Id.repeat) { - Repeat(); + Repeat(item); } return base.OnOptionsItemSelected(item); } @@ -114,9 +131,14 @@ namespace MusicApp.Resources.Portable_Class StartService(intent); } - void Repeat() + void Repeat(IMenuItem item) { - MusicPlayer.repeat = true; + MusicPlayer.repeat = !MusicPlayer.repeat; + + if (MusicPlayer.repeat) + item.Icon.SetColorFilter(Color.Argb(255, 62, 80, 180), PorterDuff.Mode.Multiply); + else + item.Icon.ClearColorFilter(); } public void LoadMore() @@ -124,19 +146,18 @@ namespace MusicApp.Resources.Portable_Class List songList = MusicPlayer.queue.Except(adapter.songList).ToList(); } - private async void ListView_ItemClick(object sender, int Position) + private void ListView_ItemClick(object sender, int Position) { Song item = MusicPlayer.queue[Position]; - MusicPlayer.instance.SwitchQueue(item); - - if (item.IsYt && !item.isParsed) + if (item.queueSlot == MusicPlayer.CurrentID()) { - while (MusicPlayer.queue[MusicPlayer.CurrentID()].GetName() != item.GetName()) - await Task.Delay(10); - - ListView.GetChildAt(Position - ((LinearLayoutManager)ListView.GetLayoutManager()).FindFirstVisibleItemPosition()).FindViewById(Resource.Id.youtubeIcon).SetImageResource(Resource.Drawable.youtubeIcon); + Intent intent = new Intent(this, typeof(MusicPlayer)); + intent.SetAction("Pause"); + StartService(intent); } + else + MusicPlayer.instance.SwitchQueue(item); } private void ListView_ItemLongCLick(object sender, int e) diff --git a/MusicApp/Resources/Portable Class/RecyclerAdapter.cs b/MusicApp/Resources/Portable Class/RecyclerAdapter.cs index 7d67493..8542fb2 100644 --- a/MusicApp/Resources/Portable Class/RecyclerAdapter.cs +++ b/MusicApp/Resources/Portable Class/RecyclerAdapter.cs @@ -100,16 +100,31 @@ namespace MusicApp.Resources.Portable_Class { holder.youtubeIcon.SetImageResource(Resource.Drawable.needProcessing); holder.youtubeIcon.Visibility = ViewStates.Visible; + + if(MainActivity.Theme == 1) + holder.youtubeIcon.SetColorFilter(Color.White); } else if (songList[position].IsYt) { holder.youtubeIcon.SetImageResource(Resource.Drawable.youtubeIcon); holder.youtubeIcon.Visibility = ViewStates.Visible; + + if (MainActivity.Theme == 1) + holder.youtubeIcon.ClearColorFilter(); } else { holder.youtubeIcon.Visibility = ViewStates.Gone; } + + if (songList[position].queueSlot == MusicPlayer.CurrentID()) + { + holder.status.Visibility = ViewStates.Visible; + holder.status.Text = MusicPlayer.isRunning ? "Playing" : "Paused"; + holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245)); + } + else + holder.status.Visibility = ViewStates.Gone; } else { @@ -118,7 +133,6 @@ namespace MusicApp.Resources.Portable_Class if (MainActivity.Theme == 1) { - holder.more.SetColorFilter(Color.White); holder.reorder.SetColorFilter(Color.White); holder.Title.SetTextColor(Color.White); @@ -126,9 +140,7 @@ namespace MusicApp.Resources.Portable_Class holder.Artist.Alpha = 0.7f; } - if (position == MusicPlayer.CurrentID()) - holder.ItemView.SetBackgroundColor(Color.DimGray); - else if (MainActivity.Theme == 0) + if (MainActivity.Theme == 0) holder.ItemView.SetBackgroundColor(Color.White); else holder.ItemView.SetBackgroundColor(Color.ParseColor("#424242")); diff --git a/MusicApp/Resources/Portable Class/RecyclerHolder.cs b/MusicApp/Resources/Portable Class/RecyclerHolder.cs index a739d74..7eea857 100644 --- a/MusicApp/Resources/Portable Class/RecyclerHolder.cs +++ b/MusicApp/Resources/Portable Class/RecyclerHolder.cs @@ -16,6 +16,7 @@ namespace MusicApp.Resources.Portable_Class public ImageView edit; public ImageView youtubeIcon; public ImageView more; + public TextView status; public RecyclerHolder(View itemView, Action listener, Action longListener) : base(itemView) { @@ -27,6 +28,7 @@ namespace MusicApp.Resources.Portable_Class edit = itemView.FindViewById(Resource.Id.edit); youtubeIcon = itemView.FindViewById(Resource.Id.youtubeIcon); more = itemView.FindViewById(Resource.Id.moreButton); + status = itemView.FindViewById(Resource.Id.status); itemView.Click += (sender, e) => listener(AdapterPosition); itemView.LongClick += (sender, e) => longListener(AdapterPosition); diff --git a/MusicApp/Resources/Resource.Designer.cs b/MusicApp/Resources/Resource.Designer.cs index d70581f..7d2b65c 100644 --- a/MusicApp/Resources/Resource.Designer.cs +++ b/MusicApp/Resources/Resource.Designer.cs @@ -3139,8 +3139,8 @@ namespace MusicApp // aapt resource value: 0x7f0a00d9 public const int bottomView = 2131362009; - // aapt resource value: 0x7f0a0123 - public const int browseLayout = 2131362083; + // aapt resource value: 0x7f0a0124 + public const int browseLayout = 2131362084; // aapt resource value: 0x7f0a00ac public const int browseList = 2131361964; @@ -3238,11 +3238,11 @@ namespace MusicApp // aapt resource value: 0x7f0a00ff public const int downFAB = 2131362047; - // aapt resource value: 0x7f0a0125 - public const int downloadMDfromYT = 2131362085; + // aapt resource value: 0x7f0a0126 + public const int downloadMDfromYT = 2131362086; - // aapt resource value: 0x7f0a011c - public const int edit = 2131362076; + // aapt resource value: 0x7f0a011d + public const int edit = 2131362077; // aapt resource value: 0x7f0a009e public const int edit_query = 2131361950; @@ -3337,8 +3337,8 @@ namespace MusicApp // aapt resource value: 0x7f0a0061 public const int fill_vertical = 2131361889; - // aapt resource value: 0x7f0a0129 - public const int filter = 2131362089; + // aapt resource value: 0x7f0a012a + public const int filter = 2131362090; // aapt resource value: 0x7f0a0074 public const int fit = 2131361908; @@ -3418,8 +3418,8 @@ namespace MusicApp // aapt resource value: 0x7f0a0017 public const int line1 = 2131361815; - // aapt resource value: 0x7f0a011f - public const int line2 = 2131362079; + // aapt resource value: 0x7f0a0120 + public const int line2 = 2131362080; // aapt resource value: 0x7f0a0018 public const int line3 = 2131361816; @@ -3439,8 +3439,8 @@ namespace MusicApp // aapt resource value: 0x7f0a00d1 public const int logButton = 2131362001; - // aapt resource value: 0x7f0a0121 - public const int masked = 2131362081; + // aapt resource value: 0x7f0a0122 + public const int masked = 2131362082; // aapt resource value: 0x7f0a0110 public const int maxValue = 2131362064; @@ -3448,8 +3448,8 @@ namespace MusicApp // aapt resource value: 0x7f0a00e2 public const int media_actions = 2131362018; - // aapt resource value: 0x7f0a011e - public const int message = 2131362078; + // aapt resource value: 0x7f0a011f + public const int message = 2131362079; // aapt resource value: 0x7f0a00c6 public const int metadataAlbum = 2131361990; @@ -3481,14 +3481,14 @@ namespace MusicApp // aapt resource value: 0x7f0a006c public const int mini = 2131361900; - // aapt resource value: 0x7f0a011d - public const int moreButton = 2131362077; + // aapt resource value: 0x7f0a011e + public const int moreButton = 2131362078; // aapt resource value: 0x7f0a0042 public const int multiply = 2131361858; - // aapt resource value: 0x7f0a0122 - public const int musicLayout = 2131362082; + // aapt resource value: 0x7f0a0123 + public const int musicLayout = 2131362083; // aapt resource value: 0x7f0a00ba public const int navigation_header_container = 2131361978; @@ -3571,8 +3571,8 @@ namespace MusicApp // aapt resource value: 0x7f0a00f7 public const int playerTitle = 2131362039; - // aapt resource value: 0x7f0a0124 - public const int playlistLayout = 2131362084; + // aapt resource value: 0x7f0a0125 + public const int playlistLayout = 2131362085; // aapt resource value: 0x7f0a00b1 public const int playlistName = 2131361969; @@ -3604,8 +3604,8 @@ namespace MusicApp // aapt resource value: 0x7f0a011a public const int reorder = 2131362074; - // aapt resource value: 0x7f0a0128 - public const int repeat = 2131362088; + // aapt resource value: 0x7f0a0129 + public const int repeat = 2131362089; // aapt resource value: 0x7f0a0063 public const int right = 2131361891; @@ -3685,8 +3685,8 @@ namespace MusicApp // aapt resource value: 0x7f0a00aa public const int select_dialog_listview = 2131361962; - // aapt resource value: 0x7f0a012a - public const int settings = 2131362090; + // aapt resource value: 0x7f0a012b + public const int settings = 2131362091; // aapt resource value: 0x7f0a0094 public const int shortcut = 2131361940; @@ -3703,8 +3703,8 @@ namespace MusicApp // aapt resource value: 0x7f0a003f public const int showTitle = 2131361855; - // aapt resource value: 0x7f0a0127 - public const int shuffle = 2131362087; + // aapt resource value: 0x7f0a0128 + public const int shuffle = 2131362088; // aapt resource value: 0x7f0a00b2 public const int smallLabel = 2131361970; @@ -3775,6 +3775,9 @@ namespace MusicApp // aapt resource value: 0x7f0a0064 public const int start = 2131361892; + // aapt resource value: 0x7f0a011b + public const int status = 2131362075; + // aapt resource value: 0x7f0a00e1 public const int status_bar_latest_event_content = 2131362017; @@ -3868,8 +3871,8 @@ namespace MusicApp // aapt resource value: 0x7f0a0013 public const int transition_transform = 2131361811; - // aapt resource value: 0x7f0a0126 - public const int undoChange = 2131362086; + // aapt resource value: 0x7f0a0127 + public const int undoChange = 2131362087; // aapt resource value: 0x7f0a0047 public const int uniform = 2131361863; @@ -3883,8 +3886,8 @@ namespace MusicApp // aapt resource value: 0x7f0a0016 public const int view_offset_helper = 2131361814; - // aapt resource value: 0x7f0a0120 - public const int visible = 2131362080; + // aapt resource value: 0x7f0a0121 + public const int visible = 2131362081; // aapt resource value: 0x7f0a0034 public const int wide = 2131361844; @@ -3895,8 +3898,8 @@ namespace MusicApp // aapt resource value: 0x7f0a0048 public const int wrap_content = 2131361864; - // aapt resource value: 0x7f0a011b - public const int youtubeIcon = 2131362075; + // aapt resource value: 0x7f0a011c + public const int youtubeIcon = 2131362076; // aapt resource value: 0x7f0a010b public const int ytPlay = 2131362059; diff --git a/MusicApp/Resources/layout/SongList.xml b/MusicApp/Resources/layout/SongList.xml index b02e348..87ae764 100644 --- a/MusicApp/Resources/layout/SongList.xml +++ b/MusicApp/Resources/layout/SongList.xml @@ -45,6 +45,18 @@ android:textSize="14dip" android:textColor="#000" /> + - \ No newline at end of file