From c31a16f0e811941fbba45c172303e6eb054b8457 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Sun, 30 Jun 2019 15:11:00 +0200 Subject: [PATCH] Adding open channels features where possible. --- Opus/Code/Api/YoutubeManager.cs | 10 ++++++++-- Opus/Code/DataStructure/Song.cs | 8 ++++---- Opus/Code/UI/Adapter/LineAdapter.cs | 18 ++++++++++++++++++ Opus/Code/UI/Fragments/PlaylistTracks.cs | 15 +++++++++++++-- Opus/Code/UI/Fragments/Queue.cs | 11 +++++++++-- Opus/Code/UI/Fragments/YoutubeSearch.cs | 4 ++-- Opus/Code/UI/Views/Player.cs | 9 +++++++++ Opus/Opus.csproj | 4 ++-- Opus/packages.config | 2 +- 9 files changed, 66 insertions(+), 15 deletions(-) diff --git a/Opus/Code/Api/YoutubeManager.cs b/Opus/Code/Api/YoutubeManager.cs index 0a9acf8..2989abf 100644 --- a/Opus/Code/Api/YoutubeManager.cs +++ b/Opus/Code/Api/YoutubeManager.cs @@ -358,7 +358,10 @@ namespace Opus.Api { if (ytItem.Snippet.Title != "[Deleted video]" && ytItem.Snippet.Title != "Private video" && ytItem.Snippet.Title != "Deleted video" && !MusicPlayer.queue.Exists(x => x.YoutubeID == ytItem.ContentDetails.VideoId)) { - Song song = new Song(System.Net.WebUtility.HtmlDecode(ytItem.Snippet.Title), ytItem.Snippet.ChannelTitle, ytItem.Snippet.Thumbnails.High.Url, ytItem.ContentDetails.VideoId, -1, -1, ytItem.ContentDetails.VideoId, true, false); + Song song = new Song(WebUtility.HtmlDecode(ytItem.Snippet.Title), ytItem.Snippet.ChannelTitle, ytItem.Snippet.Thumbnails.High.Url, ytItem.ContentDetails.VideoId, -1, -1, ytItem.ContentDetails.VideoId, true, false) + { + ChannelID = ytItem.Snippet.ChannelId + }; tracks.Add(song); } } @@ -413,7 +416,10 @@ namespace Opus.Api foreach (var video in searchReponse.Items) { - Song song = new Song(WebUtility.HtmlDecode(video.Snippet.Title), video.Snippet.ChannelTitle, video.Snippet.Thumbnails.High.Url, video.Id.VideoId, -1, -1, null, true, false); + Song song = new Song(WebUtility.HtmlDecode(video.Snippet.Title), video.Snippet.ChannelTitle, video.Snippet.Thumbnails.High.Url, video.Id.VideoId, -1, -1, null, true, false) + { + ChannelID = video.Snippet.ChannelId + }; songs.Add(song); } } diff --git a/Opus/Code/DataStructure/Song.cs b/Opus/Code/DataStructure/Song.cs index 039b102..cbb7976 100644 --- a/Opus/Code/DataStructure/Song.cs +++ b/Opus/Code/DataStructure/Song.cs @@ -27,11 +27,11 @@ namespace Opus.DataStructure public string Path { get; set; } public bool? IsParsed { get; set; } public bool IsYt { get; set; } + public string ChannelID { get; set; } public DateTimeOffset? ExpireDate { get; set;} public int Duration { get; set; } public bool IsLiveStream = false; public string TrackID; - public string channelID; public Song() { } @@ -60,9 +60,9 @@ namespace Opus.DataStructure int albumID = cursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Album); int thisID = cursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Id); int pathID = cursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data); - int playOrderID = cursor.GetColumnIndex(MediaStore.Audio.Playlists.Members.PlayOrder); + //int playOrderID = cursor.GetColumnIndex(MediaStore.Audio.Playlists.Members.PlayOrder); - string playOrder = PlaylistTracks.instance != null ? cursor.GetString(playOrderID) : null; + //string playOrder = PlaylistTracks.instance != null ? cursor.GetString(playOrderID) : null; string Artist = cursor.GetString(artistID); string Title = cursor.GetString(titleID); string Album = cursor.GetString(albumID); @@ -77,7 +77,7 @@ namespace Opus.DataStructure if (Album == null) Album = "Unknow Album"; - return new Song(Title, playOrder ?? Artist, Album, null, AlbumArt, id, path); + return new Song(Title, /*playOrder ?? */Artist, Album, null, AlbumArt, id, path); } public static explicit operator Song(YoutubeExplode.Models.Video video) diff --git a/Opus/Code/UI/Adapter/LineAdapter.cs b/Opus/Code/UI/Adapter/LineAdapter.cs index c1837ba..353304d 100644 --- a/Opus/Code/UI/Adapter/LineAdapter.cs +++ b/Opus/Code/UI/Adapter/LineAdapter.cs @@ -210,6 +210,15 @@ namespace Opus.Adapter bottomSheet.Dismiss(); }) }); + + if(item.ChannelID != null) + { + actions.Add(new BottomSheetAction(Resource.Drawable.account, MainActivity.instance.Resources.GetString(Resource.String.goto_channel), (sender, eventArg) => + { + ChannelManager.OpenChannelTab(item.ChannelID); + bottomSheet.Dismiss(); + })); + } } else { @@ -289,6 +298,15 @@ namespace Opus.Adapter bottomSheet.Dismiss(); }) }); + + if (item.ChannelID != null) + { + actions.Add(new BottomSheetAction(Resource.Drawable.account, MainActivity.instance.Resources.GetString(Resource.String.goto_channel), (sender, eventArg) => + { + ChannelManager.OpenChannelTab(item.ChannelID); + bottomSheet.Dismiss(); + })); + } } bottomSheet.FindViewById(Resource.Id.bsItems).Adapter = new BottomSheetAdapter(MainActivity.instance, Resource.Layout.BottomSheetText, actions); diff --git a/Opus/Code/UI/Fragments/PlaylistTracks.cs b/Opus/Code/UI/Fragments/PlaylistTracks.cs index 336a484..f814ca0 100644 --- a/Opus/Code/UI/Fragments/PlaylistTracks.cs +++ b/Opus/Code/UI/Fragments/PlaylistTracks.cs @@ -312,7 +312,8 @@ namespace Opus.Fragments { Song song = new Song(item.Snippet.Title, item.Snippet.ChannelTitle, item.Snippet.Thumbnails.High.Url, item.ContentDetails.VideoId, -1, -1, item.ContentDetails.VideoId, true, false) { - TrackID = item.Id + TrackID = item.Id, + ChannelID = item.Snippet.ChannelId }; tracks.Add(song); } @@ -401,7 +402,8 @@ namespace Opus.Fragments { Song song = new Song(item.Snippet.Title, item.Snippet.ChannelTitle, item.Snippet.Thumbnails.Default__.Url, item.ContentDetails.VideoId, -1, -1, item.ContentDetails.VideoId, true, false) { - TrackID = item.Id + TrackID = item.Id, + ChannelID = item.Snippet.ChannelId }; adapter.tracks.Add(song); } @@ -532,6 +534,15 @@ namespace Opus.Fragments bottomSheet.Dismiss(); }) }); + + if (song.ChannelID != null) + { + actions.Add(new BottomSheetAction(Resource.Drawable.account, Resources.GetString(Resource.String.goto_channel), (sender, eventArg) => + { + ChannelManager.OpenChannelTab(song.ChannelID); + bottomSheet.Dismiss(); + })); + } } bottomSheet.FindViewById(Resource.Id.bsItems).Adapter = new BottomSheetAdapter(MainActivity.instance, Resource.Layout.BottomSheetText, actions); diff --git a/Opus/Code/UI/Fragments/Queue.cs b/Opus/Code/UI/Fragments/Queue.cs index 3971abf..b9806f1 100644 --- a/Opus/Code/UI/Fragments/Queue.cs +++ b/Opus/Code/UI/Fragments/Queue.cs @@ -146,8 +146,6 @@ public class Queue : Fragment, RecyclerView.IOnItemTouchListener, PopupMenu.IOnM private void ListView_ItemClick(object sender, int Position) { - Song item = MusicPlayer.queue[Position]; - if (Position == MusicPlayer.CurrentID()) { Intent intent = new Intent(Activity, typeof(MusicPlayer)); @@ -213,6 +211,15 @@ public class Queue : Fragment, RecyclerView.IOnItemTouchListener, PopupMenu.IOnM bottomSheet.Dismiss(); }) }); + + if (item.ChannelID != null) + { + actions.Add(new BottomSheetAction(Resource.Drawable.account, Resources.GetString(Resource.String.goto_channel), (sender, eventArg) => + { + ChannelManager.OpenChannelTab(item.ChannelID); + bottomSheet.Dismiss(); + })); + } } else { diff --git a/Opus/Code/UI/Fragments/YoutubeSearch.cs b/Opus/Code/UI/Fragments/YoutubeSearch.cs index 3745286..8b4ac19 100644 --- a/Opus/Code/UI/Fragments/YoutubeSearch.cs +++ b/Opus/Code/UI/Fragments/YoutubeSearch.cs @@ -307,7 +307,7 @@ namespace Opus.Fragments case "youtube#video": Song videoInfo = new Song(System.Net.WebUtility.HtmlDecode(result.Snippet.Title), result.Snippet.ChannelTitle, result.Snippet.Thumbnails.High.Url, result.Id.VideoId, -1, -1, null, true, false) { - channelID = result.Snippet.ChannelId + ChannelID = result.Snippet.ChannelId }; if (result.Snippet.LiveBroadcastContent == "live") videoInfo.IsLiveStream = true; @@ -413,7 +413,7 @@ namespace Opus.Fragments MainActivity.instance.menu.FindItem(Resource.Id.search).CollapseActionView(); MainActivity.instance.menu.FindItem(Resource.Id.search).ActionView.Focusable = true; MainActivity.instance.FindViewById(Resource.Id.tabs).Visibility = ViewStates.Gone; - ChannelManager.OpenChannelTab(item.channelID); + ChannelManager.OpenChannelTab(item.ChannelID); bottomSheet.Dismiss(); }) }); diff --git a/Opus/Code/UI/Views/Player.cs b/Opus/Code/UI/Views/Player.cs index d513f6d..8534bb4 100644 --- a/Opus/Code/UI/Views/Player.cs +++ b/Opus/Code/UI/Views/Player.cs @@ -448,6 +448,15 @@ namespace Opus bottomSheet.Dismiss(); }) }); + + if (item.ChannelID != null) + { + actions.Add(new BottomSheetAction(Resource.Drawable.account, Resources.GetString(Resource.String.goto_channel), (sender, eventArg) => + { + ChannelManager.OpenChannelTab(item.ChannelID); + bottomSheet.Dismiss(); + })); + } } else { diff --git a/Opus/Opus.csproj b/Opus/Opus.csproj index 979b396..eb64507 100644 --- a/Opus/Opus.csproj +++ b/Opus/Opus.csproj @@ -319,8 +319,8 @@ ..\packages\Xamarin.GooglePlayServices.Tasks.70.1501.0-preview2\lib\MonoAndroid80\Xamarin.GooglePlayServices.Tasks.dll - - ..\packages\YoutubeExplode.4.7.3\lib\netstandard2.0\YoutubeExplode.dll + + ..\packages\YoutubeExplode.4.7.4\lib\netstandard2.0\YoutubeExplode.dll diff --git a/Opus/packages.config b/Opus/packages.config index 218d3bb..6ad6151 100644 --- a/Opus/packages.config +++ b/Opus/packages.config @@ -125,5 +125,5 @@ - + \ No newline at end of file