From 4b98fbcdaa12dd9f50e1d31030819fad41c03e32 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Thu, 23 Aug 2018 23:33:23 +0200 Subject: [PATCH] Releasing v1.9 --- MusicApp/Assets/Version.txt | 2 +- MusicApp/Properties/AndroidManifest.xml | 2 +- MusicApp/Resources/Portable Class/Home.cs | 4 + .../Resources/Portable Class/HomeAdapter.cs | 32 +++-- .../Resources/Portable Class/LineAdapter.cs | 14 ++- .../Resources/Portable Class/MusicPlayer.cs | 116 +++++++----------- .../Resources/Portable Class/YoutubeEngine.cs | 2 + 7 files changed, 91 insertions(+), 81 deletions(-) diff --git a/MusicApp/Assets/Version.txt b/MusicApp/Assets/Version.txt index 5eb481d..a630485 100644 --- a/MusicApp/Assets/Version.txt +++ b/MusicApp/Assets/Version.txt @@ -1,2 +1,2 @@ -Version: 1.8.0 +Version: 1.9.0 Link: https://github.com/AnonymusRaccoon/MusicApp/releases/download/1.8/MusicApp.v1.8.apk diff --git a/MusicApp/Properties/AndroidManifest.xml b/MusicApp/Properties/AndroidManifest.xml index 9bbe43e..b495017 100644 --- a/MusicApp/Properties/AndroidManifest.xml +++ b/MusicApp/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/MusicApp/Resources/Portable Class/Home.cs b/MusicApp/Resources/Portable Class/Home.cs index aec3e2d..e5ab1e5 100644 --- a/MusicApp/Resources/Portable Class/Home.cs +++ b/MusicApp/Resources/Portable Class/Home.cs @@ -459,6 +459,10 @@ namespace MusicApp.Resources.Portable_Class MainActivity.parcelable = null; MainActivity.parcelableSender = null; } + + adapterItems[0].recycler?.GetAdapter()?.NotifyDataSetChanged(); + if (MusicPlayer.CurrentID() != -1 && MusicPlayer.CurrentID() <= MusicPlayer.queue.Count) + adapterItems[0].recycler?.ScrollToPosition(MusicPlayer.CurrentID()); } } } \ No newline at end of file diff --git a/MusicApp/Resources/Portable Class/HomeAdapter.cs b/MusicApp/Resources/Portable Class/HomeAdapter.cs index d3f4bb7..0a2082a 100644 --- a/MusicApp/Resources/Portable Class/HomeAdapter.cs +++ b/MusicApp/Resources/Portable Class/HomeAdapter.cs @@ -69,16 +69,30 @@ namespace MusicApp.Resources.Portable_Class LineSongHolder holder = (LineSongHolder)viewHolder; holder.title.Text = items[position].SectionTitle; holder.recycler.SetLayoutManager(new LinearLayoutManager(MainActivity.instance, LinearLayoutManager.Horizontal, false)); - holder.recycler.SetAdapter(new LineAdapter(items[position].contentValue.GetRange(0, items[position].contentValue.Count > 20 ? 20 : items[position].contentValue.Count), holder.recycler)); - holder.more.Click += (sender, e) => + if (items[position].SectionTitle == "Queue") { - MainActivity.instance.SupportActionBar.SetHomeButtonEnabled(true); - MainActivity.instance.SupportActionBar.SetDisplayHomeAsUpEnabled(true); - MainActivity.instance.SupportActionBar.Title = items[position].SectionTitle; - MainActivity.instance.contentRefresh.Refresh -= Home.instance.OnRefresh; - Home.instance = null; - MainActivity.instance.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, PlaylistTracks.NewInstance(items[position].contentValue, items[position].SectionTitle)).AddToBackStack(null).Commit(); - }; + holder.recycler.SetAdapter(new LineAdapter(holder.recycler)); + holder.more.Click += (sender, e) => + { + Intent intent = new Intent(MainActivity.instance, typeof(Queue)); + MainActivity.instance.StartActivity(intent); + }; + if(MusicPlayer.CurrentID() != -1 && MusicPlayer.CurrentID() <= MusicPlayer.queue.Count) + holder.recycler.ScrollToPosition(MusicPlayer.CurrentID()); + } + else + { + holder.recycler.SetAdapter(new LineAdapter(items[position].contentValue.GetRange(0, items[position].contentValue.Count > 20 ? 20 : items[position].contentValue.Count), holder.recycler)); + holder.more.Click += (sender, e) => + { + MainActivity.instance.SupportActionBar.SetHomeButtonEnabled(true); + MainActivity.instance.SupportActionBar.SetDisplayHomeAsUpEnabled(true); + MainActivity.instance.SupportActionBar.Title = items[position].SectionTitle; + MainActivity.instance.contentRefresh.Refresh -= Home.instance.OnRefresh; + Home.instance = null; + MainActivity.instance.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, PlaylistTracks.NewInstance(items[position].contentValue, items[position].SectionTitle)).AddToBackStack(null).Commit(); + }; + } if (MainActivity.Theme == 1) holder.ItemView.SetBackgroundColor(Color.Argb(255, 62, 62, 62)); diff --git a/MusicApp/Resources/Portable Class/LineAdapter.cs b/MusicApp/Resources/Portable Class/LineAdapter.cs index 457b384..0111db3 100644 --- a/MusicApp/Resources/Portable Class/LineAdapter.cs +++ b/MusicApp/Resources/Portable Class/LineAdapter.cs @@ -14,6 +14,7 @@ namespace MusicApp.Resources.Portable_Class { public RecyclerView recycler; public int listPadding = 0; + private bool useQueue = false; private List songList; private readonly string[] actions = new string[] { "Play", "Play Next", "Play Last", "Add To Playlist" }; @@ -24,6 +25,15 @@ namespace MusicApp.Resources.Portable_Class this.recycler = recycler; this.songList = songList; } + /* + * Use this method if the songList is the queue + */ + public LineAdapter(RecyclerView recycler) + { + this.recycler = recycler; + useQueue = true; + songList = MusicPlayer.queue; + } public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { @@ -53,7 +63,9 @@ namespace MusicApp.Resources.Portable_Class void OnClick(int position) { - if (!songList[position].IsYt) + if (useQueue && MusicPlayer.instance != null) + MusicPlayer.instance.SwitchQueue(songList[position]); + else if (!songList[position].IsYt) Browse.Play(songList[position], recycler.GetLayoutManager().FindViewByPosition(position).FindViewById(Resource.Id.albumArt)); else YoutubeEngine.Play(songList[position].youtubeID, songList[position].Title, songList[position].Artist, songList[position].Album); diff --git a/MusicApp/Resources/Portable Class/MusicPlayer.cs b/MusicApp/Resources/Portable Class/MusicPlayer.cs index 8e2a507..ef41340 100644 --- a/MusicApp/Resources/Portable Class/MusicPlayer.cs +++ b/MusicApp/Resources/Portable Class/MusicPlayer.cs @@ -50,7 +50,7 @@ namespace MusicApp.Resources.Portable_Class private bool generating = false; public static int currentID = -1; public static bool repeat = false; - public static bool useAutoPlay = true; + public static bool useAutoPlay = false; private Notification notification; private const int notificationID = 1000; @@ -431,81 +431,58 @@ namespace MusicApp.Resources.Portable_Class } } - async void GenerateNext(int number) + /*async*/ void GenerateNext(int number) { if (generating == true) return; generating = true; - string youtubeID = null; - if (MainActivity.HasInternet()) - { - int i = 1; - while (youtubeID == null) - { - if (queue.Count >= i) - { - youtubeID = queue[queue.Count - i].youtubeID; - i++; - } - else - youtubeID = "local"; - } - } - else - youtubeID = "local"; + //string youtubeID = null; + //if (MainActivity.HasInternet()) + //{ + // int i = 1; + // while (youtubeID == null) + // { + // if (queue.Count >= i) + // { + // youtubeID = queue[queue.Count - i].youtubeID; + // i++; + // } + // else + // youtubeID = "local"; + // } + //} + //else + // youtubeID = "local"; - if (youtubeID != "local" && MainActivity.HasInternet() && !await MainActivity.instance.WaitForYoutube()) - { - //if (number < 4) - //{ - // SearchResource.ListRequest searchResult = YoutubeEngine.youtubeService.Search.List("snippet"); - // searchResult.Fields = "items(id/videoId,snippet/title,snippet/thumbnails/high/url,snippet/channelTitle)"; - // searchResult.Type = "video"; - // searchResult.MaxResults = number + 2; - // searchResult.RelatedToVideoId = youtubeID; + //if (youtubeID != "local" && !await MainActivity.instance.WaitForYoutube()) + //{ + // YoutubeClient client = new YoutubeClient(); + // Video video = await client.GetVideoAsync(youtubeID); + // var ytPlaylistRequest = YoutubeEngine.youtubeService.PlaylistItems.List("snippet, contentDetails"); + // ytPlaylistRequest.PlaylistId = video.GetVideoMixPlaylistId(); + // ytPlaylistRequest.MaxResults = number + 2; - // List songs = new List(); - // Google.Apis.YouTube.v3.Data.SearchListResponse response = await searchResult.ExecuteAsync(); - // foreach (Google.Apis.YouTube.v3.Data.SearchResult video in response.Items) - // { - // Song song = new Song(video.Snippet.Title, video.Snippet.ChannelTitle, video.Snippet.Thumbnails.High.Url, video.Id.VideoId, -1, -1, null, true, false); - // songs.Add(song); - // } - // songs = songs.Except(songs.Where(x => queue.Exists(y => x.youtubeID == y.youtubeID))).ToList(); - // if(songs.Count > 0) - // PlayLastInQueue(songs[0]); - //} - //else - //{ - YoutubeClient client = new YoutubeClient(); - Video video = await client.GetVideoAsync(youtubeID); + // var ytPlaylist = await ytPlaylistRequest.ExecuteAsync(); - var ytPlaylistRequest = YoutubeEngine.youtubeService.PlaylistItems.List("snippet, contentDetails"); - ytPlaylistRequest.PlaylistId = video.GetVideoMixPlaylistId(); - ytPlaylistRequest.MaxResults = number + 2; - - var ytPlaylist = await ytPlaylistRequest.ExecuteAsync(); - - foreach (var item in ytPlaylist.Items) - { - if (item.Snippet.Title != "[Deleted video]" && item.Snippet.Title != "Private video" && item.Snippet.Title != "Deleted video" && item.ContentDetails.VideoId != MusicPlayer.queue[MusicPlayer.CurrentID()].youtubeID) - { - Song song = new Song(item.Snippet.Title, "", item.Snippet.Thumbnails.Default__.Url, item.ContentDetails.VideoId, -1, -1, item.ContentDetails.VideoId, true, false); - if(!queue.Exists(x => x.youtubeID == song.youtubeID)) - { - PlayLastInQueue(song); - break; - } - } - } - //} - ParseNextSong(); - } - else - { + // foreach (var item in ytPlaylist.Items) + // { + // if (item.Snippet.Title != "[Deleted video]" && item.Snippet.Title != "Private video" && item.Snippet.Title != "Deleted video" && item.ContentDetails.VideoId != MusicPlayer.queue[MusicPlayer.CurrentID()].youtubeID) + // { + // Song song = new Song(item.Snippet.Title, "", item.Snippet.Thumbnails.Default__.Url, item.ContentDetails.VideoId, -1, -1, item.ContentDetails.VideoId, true, false); + // if(!queue.Exists(x => x.youtubeID == song.youtubeID)) + // { + // PlayLastInQueue(song); + // break; + // } + // } + // } + // ParseNextSong(); + //} + //else + //{ Uri musicUri = MediaStore.Audio.Media.ExternalContentUri; List allSongs = new List(); @@ -544,7 +521,7 @@ namespace MusicApp.Resources.Portable_Class List songList = allSongs.OrderBy(x => r.Next()).ToList(); for (int i = 0; i < (number > songList.Count ? songList.Count : number); i++) PlayLastInQueue(songList[i]); - } + //} Queue.instance?.Refresh(); generating = false; @@ -669,7 +646,7 @@ namespace MusicApp.Resources.Portable_Class Song next = queue[CurrentID() + 1]; SwitchQueue(next); - if (CurrentID() + 3 > queue.Count) + if (useAutoPlay && CurrentID() + 3 > queue.Count) { GenerateNext(1); } @@ -842,7 +819,8 @@ namespace MusicApp.Resources.Portable_Class if (CurrentID() + 1 > queue.Count - 1) { - instance.GenerateNext(1); + if(useAutoPlay) + instance.GenerateNext(1); return; } diff --git a/MusicApp/Resources/Portable Class/YoutubeEngine.cs b/MusicApp/Resources/Portable Class/YoutubeEngine.cs index 603cc37..e3999bd 100644 --- a/MusicApp/Resources/Portable Class/YoutubeEngine.cs +++ b/MusicApp/Resources/Portable Class/YoutubeEngine.cs @@ -408,6 +408,8 @@ namespace MusicApp.Resources.Portable_Class for (int i = 1; i < files.Length; i++) MusicPlayer.instance.AddToQueue(files[i]); + + Player.instance?.UpdateNext(); }