mirror of
https://github.com/zoriya/Opus.git
synced 2026-06-01 13:45:08 +00:00
Finishing the core function of the new add to playlist. Working with the create new playlsit dialog.
This commit is contained in:
@@ -268,6 +268,7 @@
|
||||
<Compile Include="Resources\Portable Class\DownloadQueueAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\FixedLinearLayoutManager.cs" />
|
||||
<Compile Include="Resources\Portable Class\PlaylistHolder.cs" />
|
||||
<Compile Include="Resources\Portable Class\PlaylistLocationAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\PlaylistTrackAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\SearchableActivity.cs" />
|
||||
<Compile Include="Resources\Portable Class\Downloader.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Android.App;
|
||||
using Android.Content.Res;
|
||||
using Android.Graphics;
|
||||
using Android.Support.V7.Widget;
|
||||
using Android.Views;
|
||||
@@ -36,9 +37,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
if (Playlists[position].SyncState == SyncState.True)
|
||||
{
|
||||
holder.SyncLoading.Visibility = ViewStates.Gone;
|
||||
holder.Status.Visibility = ViewStates.Visible;
|
||||
holder.Status.SetImageResource(Resource.Drawable.Sync);
|
||||
}
|
||||
else if(Playlists[position].SyncState == SyncState.Loading)
|
||||
{
|
||||
holder.Status.Visibility = ViewStates.Gone;
|
||||
holder.SyncLoading.Visibility = ViewStates.Visible;
|
||||
if (MainActivity.Theme == 1)
|
||||
holder.SyncLoading.IndeterminateTintList = ColorStateList.ValueOf(Color.White);
|
||||
}
|
||||
else if(Playlists[position].YoutubeID != null)
|
||||
{
|
||||
holder.Status.Visibility = ViewStates.Visible;
|
||||
@@ -47,6 +56,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
else
|
||||
{
|
||||
holder.Status.Visibility = ViewStates.Gone;
|
||||
holder.SyncLoading.Visibility = ViewStates.Gone;
|
||||
}
|
||||
|
||||
if (MainActivity.Theme == 1)
|
||||
@@ -89,12 +99,14 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public TextView Title;
|
||||
public CheckBox Added;
|
||||
public ImageView Status;
|
||||
public ProgressBar SyncLoading;
|
||||
|
||||
public AddToPlaylistHolder(View itemView, Action<int> listener) : base(itemView)
|
||||
{
|
||||
Title = itemView.FindViewById<TextView>(Resource.Id.title);
|
||||
Added = itemView.FindViewById<CheckBox>(Resource.Id.added);
|
||||
Status = itemView.FindViewById<ImageView>(Resource.Id.status);
|
||||
SyncLoading = itemView.FindViewById<ProgressBar>(Resource.Id.syncLoading);
|
||||
|
||||
itemView.Click += (sender, e) => listener(AdapterPosition);
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
context.StartService(intent);
|
||||
}
|
||||
|
||||
public static bool SongIsContained(long audioID, long playlistID)
|
||||
private static bool SongIsContained(long audioID, long playlistID)
|
||||
{
|
||||
Uri uri = MediaStore.Audio.Playlists.Members.GetContentUri("external", playlistID);
|
||||
CursorLoader loader = new CursorLoader(Android.App.Application.Context, uri, null, null, null, null);
|
||||
@@ -352,8 +352,37 @@ namespace MusicApp.Resources.Portable_Class
|
||||
return false;
|
||||
}
|
||||
|
||||
private async static Task<bool> SongIsContained(string audioID, string playlistID)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = YoutubeEngine.youtubeService.PlaylistItems.List("snippet, contentDetails");
|
||||
request.PlaylistId = playlistID;
|
||||
request.VideoId = audioID;
|
||||
request.MaxResults = 1;
|
||||
|
||||
var response = await request.ExecuteAsync();
|
||||
if (response.Items.Count > 0)
|
||||
return true;
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
MainActivity.instance.Timout();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async void GetPlaylist(Song item)
|
||||
{
|
||||
List<PlaylistItem> SyncedPlaylists = new List<PlaylistItem>();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
|
||||
db.CreateTable<PlaylistItem>();
|
||||
|
||||
SyncedPlaylists = db.Table<PlaylistItem>().ToList();
|
||||
});
|
||||
|
||||
List<PlaylistItem> Playlists = new List<PlaylistItem>();
|
||||
|
||||
Uri uri = MediaStore.Audio.Playlists.ExternalContentUri;
|
||||
@@ -373,6 +402,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
SongContained = SongIsContained(item.Id, id)
|
||||
};
|
||||
PlaylistItem synced = SyncedPlaylists.Find(x => x.LocalID == id);
|
||||
if (synced != null)
|
||||
{
|
||||
if (synced.YoutubeID == null)
|
||||
playlist.SyncState = SyncState.Loading;
|
||||
else
|
||||
{
|
||||
playlist.SyncState = SyncState.True;
|
||||
playlist.YoutubeID = synced.YoutubeID;
|
||||
}
|
||||
}
|
||||
Playlists.Add(playlist);
|
||||
}
|
||||
while (cursor.MoveToNext());
|
||||
@@ -405,6 +445,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
if (playlist.LocalID != 0)
|
||||
AddToPlaylist(item, playlist.Name, playlist.LocalID);
|
||||
if (playlist.YoutubeID != null)
|
||||
YoutubeEngine.AddToPlaylist(item, playlist.YoutubeID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -427,20 +469,24 @@ namespace MusicApp.Resources.Portable_Class
|
||||
Layout.FindViewById<LinearLayout>(Resource.Id.CreatePlaylist).Click += (sender, e) => { dialog.Dismiss(); CreatePlalistDialog(item); };
|
||||
dialog.Show();
|
||||
|
||||
|
||||
if(item.youtubeID == null)
|
||||
{
|
||||
item = CompleteItem(item);
|
||||
if (item.youtubeID == null)
|
||||
{
|
||||
Toast.MakeText(MainActivity.instance, "Song can't be found on youtube, can't add it to a youtube playlist.", ToastLength.Long).Show();
|
||||
Playlists.Remove(Loading);
|
||||
adapter.NotifyItemRemoved(Playlists.Count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!await MainActivity.instance.WaitForYoutube())
|
||||
{
|
||||
Toast.MakeText(MainActivity.instance, "Error while loading.\nCheck your internet connection and check if your logged in.", ToastLength.Long).Show();
|
||||
Playlists.Remove(Loading);
|
||||
adapter.NotifyItemRemoved(Playlists.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -453,8 +499,29 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
foreach(var playlist in response.Items)
|
||||
{
|
||||
Playlists.Insert(Playlists.Count - 1, new PlaylistItem(playlist.Snippet.Title, playlist.Id));
|
||||
adapter.NotifyItemInserted(Playlists.Count - 1);
|
||||
if (SyncedPlaylists.Find(x => x.Name == playlist.Snippet.Title) != null)
|
||||
{
|
||||
int position = Playlists.FindIndex(x => x.Name == playlist.Snippet.Title && x.SyncState == SyncState.Loading);
|
||||
if(position != -1)
|
||||
{
|
||||
Playlists[position].SyncState = SyncState.True;
|
||||
Playlists[position].YoutubeID = playlist.Id;
|
||||
|
||||
AddToPlaylistHolder holder = (AddToPlaylistHolder)ListView.GetChildViewHolder(ListView.GetChildAt(position));
|
||||
holder.SyncLoading.Visibility = ViewStates.Gone;
|
||||
holder.Status.Visibility = ViewStates.Visible;
|
||||
holder.Status.SetImageResource(Resource.Drawable.Sync);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PlaylistItem YtPlaylist = new PlaylistItem(playlist.Snippet.Title, playlist.Id)
|
||||
{
|
||||
SongContained = await SongIsContained(item.youtubeID, playlist.Id)
|
||||
};
|
||||
Playlists.Insert(Playlists.Count - 1, YtPlaylist);
|
||||
adapter.NotifyItemInserted(Playlists.Count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
@@ -481,7 +548,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
return;
|
||||
}
|
||||
|
||||
public async static void AddToPlaylist(Song item, string playList, long LocalID, int position = -1, bool SyncBehave = true, bool saveAsSynced = false)
|
||||
public async static void AddToPlaylist(Song item, string playList, long LocalID, bool saveAsSynced = false)
|
||||
{
|
||||
if(LocalID == -1)
|
||||
{
|
||||
@@ -489,7 +556,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
if (LocalID == -1)
|
||||
CreatePlaylist(playList, item, saveAsSynced);
|
||||
else
|
||||
AddToPlaylist(item, playList, LocalID, position);
|
||||
AddToPlaylist(item, playList, LocalID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -501,32 +568,32 @@ namespace MusicApp.Resources.Portable_Class
|
||||
value.Put(MediaStore.Audio.Playlists.Members.PlayOrder, 0);
|
||||
resolver.Insert(MediaStore.Audio.Playlists.Members.GetContentUri("external", LocalID), value);
|
||||
|
||||
//Check if this playlist is synced, if it his, add the song to the youtube playlist
|
||||
if (SyncBehave)
|
||||
{
|
||||
PlaylistItem SyncedPlaylist = null;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
SQLiteConnection db = new SQLiteConnection(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
|
||||
db.CreateTable<PlaylistItem>();
|
||||
////Check if this playlist is synced, if it his, add the song to the youtube playlist
|
||||
//if (SyncBehave)
|
||||
//{
|
||||
// PlaylistItem SyncedPlaylist = null;
|
||||
// await Task.Run(() =>
|
||||
// {
|
||||
// SQLiteConnection db = new SQLiteConnection(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
|
||||
// db.CreateTable<PlaylistItem>();
|
||||
|
||||
SyncedPlaylist = db.Table<PlaylistItem>().ToList().Find(x => x.LocalID == LocalID);
|
||||
});
|
||||
// SyncedPlaylist = db.Table<PlaylistItem>().ToList().Find(x => x.LocalID == LocalID);
|
||||
// });
|
||||
|
||||
if (SyncedPlaylist != null)
|
||||
{
|
||||
if (SyncedPlaylist.YoutubeID != null && SyncedPlaylist.HasWritePermission)
|
||||
{
|
||||
Song song = CompleteItem(item);
|
||||
if (song.youtubeID != null)
|
||||
YoutubeEngine.AddToPlaylist(song, playList, SyncedPlaylist.YoutubeID, MainActivity.instance, false);
|
||||
else
|
||||
Toast.MakeText(MainActivity.instance, "Can't find this song on youtube, it has only been added to the local playlist.", ToastLength.Long).Show();
|
||||
}
|
||||
else
|
||||
Toast.MakeText(MainActivity.instance, "Playlist has not finished syncing yet, can't add this song to the youtube playlist (but has been added locally). Please check on the playlist view for more details.", ToastLength.Long).Show();
|
||||
}
|
||||
}
|
||||
// if (SyncedPlaylist != null)
|
||||
// {
|
||||
// if (SyncedPlaylist.YoutubeID != null && SyncedPlaylist.HasWritePermission)
|
||||
// {
|
||||
// Song song = CompleteItem(item);
|
||||
// if (song.youtubeID != null)
|
||||
// YoutubeEngine.AddToPlaylist(song, playList, SyncedPlaylist.YoutubeID, MainActivity.instance, false);
|
||||
// else
|
||||
// Toast.MakeText(MainActivity.instance, "Can't find this song on youtube, it has only been added to the local playlist.", ToastLength.Long).Show();
|
||||
// }
|
||||
// else
|
||||
// Toast.MakeText(MainActivity.instance, "Playlist has not finished syncing yet, can't add this song to the youtube playlist (but has been added locally). Please check on the playlist view for more details.", ToastLength.Long).Show();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,10 +603,28 @@ namespace MusicApp.Resources.Portable_Class
|
||||
builder.SetTitle("Playlist name");
|
||||
View view = inflater.Inflate(Resource.Layout.CreatePlaylistDialog, null);
|
||||
builder.SetView(view);
|
||||
PlaylistLocationAdapter adapter = new PlaylistLocationAdapter(MainActivity.instance, Android.Resource.Layout.SimpleSpinnerItem, new string[] { "Local playlist", "Youtube playlist", "Synced playlist (both local and youtube)" })
|
||||
{
|
||||
YoutubeWorkflow = item.youtubeID != null
|
||||
};
|
||||
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
|
||||
view.FindViewById<Spinner>(Resource.Id.playlistLocation).Adapter = adapter;
|
||||
builder.SetNegativeButton("Cancel", (senderAlert, args) => { });
|
||||
builder.SetPositiveButton("Create", (senderAlert, args) =>
|
||||
{
|
||||
CreatePlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item);
|
||||
switch (view.FindViewById<Spinner>(Resource.Id.playlistLocation).SelectedItemPosition)
|
||||
{
|
||||
case 0:
|
||||
CreatePlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item);
|
||||
break;
|
||||
case 1:
|
||||
YoutubeEngine.CreatePlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item);
|
||||
break;
|
||||
case 2:
|
||||
CreatePlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item, true);
|
||||
YoutubeEngine.CreatePlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item);
|
||||
break;
|
||||
}
|
||||
});
|
||||
builder.Show();
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
handler.Post(() =>
|
||||
{
|
||||
Browse.act = MainActivity.instance;
|
||||
Browse.AddToPlaylist(Browse.GetSong(path), playlist, -1, queue.FindIndex(x => x.path == path), false, true);
|
||||
Browse.AddToPlaylist(Browse.GetSong(path), playlist, -1, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +127,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (item.IsYt)
|
||||
YoutubeEngine.GetPlaylists(item, MainActivity.instance);
|
||||
else
|
||||
Browse.GetPlaylist(item);
|
||||
Browse.GetPlaylist(item);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
|
||||
@@ -403,16 +403,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
private void AddToPlaylist_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MusicPlayer.queue[MusicPlayer.CurrentID()].IsYt)
|
||||
{
|
||||
YoutubeEngine.GetPlaylists(MusicPlayer.queue[MusicPlayer.CurrentID()], MainActivity.instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
Browse.act = MainActivity.instance;
|
||||
Browse.inflater = LayoutInflater;
|
||||
Browse.GetPlaylist(MusicPlayer.queue[MusicPlayer.CurrentID()]);
|
||||
}
|
||||
Browse.act = MainActivity.instance;
|
||||
Browse.inflater = LayoutInflater;
|
||||
Browse.GetPlaylist(MusicPlayer.queue[MusicPlayer.CurrentID()]);
|
||||
}
|
||||
|
||||
public void UpdateSeekBar()
|
||||
|
||||
@@ -509,7 +509,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
else if (local)
|
||||
{
|
||||
builder.SetItems(new string[] { "Play in order", "Random play", "Add To Queue", "Rename", "Sync Playlist" }, (senderAlert, args) =>
|
||||
builder.SetItems(new string[] { "Play in order", "Random play", "Add To Queue", "Rename", "Delete" }, (senderAlert, args) =>
|
||||
{
|
||||
switch (args.Which)
|
||||
{
|
||||
@@ -981,8 +981,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
void RemoveYoutubePlaylist(int position, string playlistID)
|
||||
{
|
||||
System.Console.WriteLine("&1: Removing playlist at position " + position + " with local playlist count: " + LocalPlaylists.Count + ", playlist name: " + YoutubePlaylists[position - LocalPlaylists.Count].Name);
|
||||
AlertDialog dialog = new AlertDialog.Builder(MainActivity.instance, MainActivity.dialogTheme)
|
||||
.SetTitle("Do you want to delete the playlist \"" + YoutubePlaylists[position].Name + "\"?")
|
||||
.SetTitle("Do you want to delete the playlist \"" + YoutubePlaylists[position - LocalPlaylists.Count].Name + "\"?")
|
||||
.SetPositiveButton("Yes", async (sender, e) =>
|
||||
{
|
||||
try
|
||||
@@ -990,6 +991,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
PlaylistsResource.DeleteRequest deleteRequest = YoutubeEngine.youtubeService.Playlists.Delete(playlistID);
|
||||
await deleteRequest.ExecuteAsync();
|
||||
|
||||
System.Console.WriteLine("&2: Removing playlist at position " + position + " with local playlist count: " + LocalPlaylists.Count + ", playlist name: " + YoutubePlaylists[position - LocalPlaylists.Count].Name);
|
||||
YoutubePlaylists.RemoveAt(position - LocalPlaylists.Count);
|
||||
adapter.NotifyItemRemoved(position - LocalPlaylists.Count);
|
||||
|
||||
|
||||
@@ -94,13 +94,11 @@ namespace MusicApp.Resources.Portable_Class
|
||||
holder.Line1.Text = LocalPlaylists[position].Name;
|
||||
holder.Line2.Text = LocalPlaylists[position].Count.ToString() + ((LocalPlaylists[position].Count > 1) ? " elements" : " element");
|
||||
|
||||
holder.more.Tag = position;
|
||||
if (!holder.more.HasOnClickListeners)
|
||||
{
|
||||
holder.more.Click += (sender, e) =>
|
||||
{
|
||||
int tagPosition = (int)((ImageView)sender).Tag;
|
||||
Playlist.instance.More(tagPosition);
|
||||
Playlist.instance.More(holder.AdapterPosition);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Java.Lang;
|
||||
|
||||
namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class PlaylistLocationAdapter : ArrayAdapter
|
||||
{
|
||||
public bool YoutubeWorkflow;
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource) : base(context, resource) { }
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource, int textViewResourceId) : base(context, resource, textViewResourceId) { }
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource, IList objects) : base(context, resource, objects) { }
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource, Java.Lang.Object[] objects) : base(context, resource, objects) { }
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource, int textViewResourceId, IList objects) : base(context, resource, textViewResourceId, objects) { }
|
||||
|
||||
public PlaylistLocationAdapter(Context context, int resource, int textViewResourceId, Java.Lang.Object[] objects) : base(context, resource, textViewResourceId, objects) { }
|
||||
|
||||
protected PlaylistLocationAdapter(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { }
|
||||
|
||||
public override bool AreAllItemsEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsEnabled(int position)
|
||||
{
|
||||
if (position == 0)
|
||||
return true;
|
||||
else if (YoutubeWorkflow)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -725,10 +725,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (item.IsYt)
|
||||
YoutubeEngine.GetPlaylists(item, Activity);
|
||||
else
|
||||
Browse.GetPlaylist(item);
|
||||
Browse.GetPlaylist(item);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
@@ -769,10 +766,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (item.IsYt)
|
||||
YoutubeEngine.GetPlaylists(item, Activity);
|
||||
else
|
||||
Browse.GetPlaylist(item);
|
||||
Browse.GetPlaylist(item);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
||||
@@ -373,7 +373,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
PlayLast(item.youtubeID, item.Title, item.Artist, item.Album);
|
||||
break;
|
||||
case 3:
|
||||
GetPlaylists(item, Activity);
|
||||
Browse.GetPlaylist(item);
|
||||
break;
|
||||
case 4:
|
||||
Download(item.Title, item.youtubeID);
|
||||
@@ -656,7 +656,6 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public static async void RemoveFromPlaylist(string TrackID)
|
||||
{
|
||||
System.Console.WriteLine("&Deleting trackID: " + TrackID);
|
||||
try
|
||||
{
|
||||
await youtubeService.PlaylistItems.Delete(TrackID).ExecuteAsync();
|
||||
@@ -667,108 +666,52 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
public static async void GetPlaylists(Song item, Context context)
|
||||
public async static void AddToPlaylist(Song item, string YoutubeID)
|
||||
{
|
||||
if(!await MainActivity.instance.WaitForYoutube())
|
||||
{
|
||||
Toast.MakeText(context, "Error while loading.\nCheck your internet connection and check if your logged in.", ToastLength.Long).Show();
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> playList = new List<string>();
|
||||
List<string> playListId = new List<string>();
|
||||
playList.Add("Create a playlist");
|
||||
playListId.Add("newPlaylist");
|
||||
|
||||
try
|
||||
{
|
||||
PlaylistsResource.ListRequest ytPlaylists = youtubeService.Playlists.List("snippet,contentDetails");
|
||||
ytPlaylists.Mine = true;
|
||||
ytPlaylists.MaxResults = 25;
|
||||
PlaylistListResponse response = await ytPlaylists.ExecuteAsync();
|
||||
|
||||
for (int i = 0; i < response.Items.Count; i++)
|
||||
Console.WriteLine("&Adding song: " + item.Title + "(" + item.youtubeID + "), PlaylistID: " + YoutubeID);
|
||||
Google.Apis.YouTube.v3.Data.PlaylistItem playlistItem = new Google.Apis.YouTube.v3.Data.PlaylistItem();
|
||||
PlaylistItemSnippet snippet = new PlaylistItemSnippet
|
||||
{
|
||||
Google.Apis.YouTube.v3.Data.Playlist playlist = response.Items[i];
|
||||
playList.Add(playlist.Snippet.Title);
|
||||
playListId.Add(playlist.Id);
|
||||
}
|
||||
PlaylistId = YoutubeID
|
||||
};
|
||||
ResourceId resourceId = new ResourceId
|
||||
{
|
||||
Kind = "youtube#video",
|
||||
VideoId = item.youtubeID
|
||||
};
|
||||
snippet.ResourceId = resourceId;
|
||||
playlistItem.Snippet = snippet;
|
||||
|
||||
var insertRequest = youtubeService.PlaylistItems.Insert(playlistItem, "snippet");
|
||||
await insertRequest.ExecuteAsync();
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
MainActivity.instance.Timout();
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, MainActivity.dialogTheme);
|
||||
builder.SetTitle("Add to a playlist");
|
||||
builder.SetItems(playList.ToArray(), (senderAlert, args) =>
|
||||
{
|
||||
AddToPlaylist(item, playList[args.Which], playListId[args.Which], context);
|
||||
});
|
||||
builder.Show();
|
||||
////Check if this playlist is synced, if it his, add the song to the local playlist
|
||||
//if (SyncBehave)
|
||||
//{
|
||||
// PlaylistItem SyncedPlaylist = null;
|
||||
// await Task.Run(() =>
|
||||
// {
|
||||
// SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
|
||||
// db.CreateTable<PlaylistItem>();
|
||||
|
||||
// SyncedPlaylist = db.Table<PlaylistItem>().ToList().Find(x => x.YoutubeID == YoutubeID);
|
||||
// });
|
||||
|
||||
// if (SyncedPlaylist != null)
|
||||
// {
|
||||
// Download(item.Title, item.youtubeID, playlistName);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public async static void AddToPlaylist(Song item, string playlistName, string YoutubeID, Context context, bool SyncBehave = true)
|
||||
{
|
||||
if(YoutubeID == "newPlaylist")
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, MainActivity.dialogTheme);
|
||||
builder.SetTitle("Playlist name");
|
||||
View view = MainActivity.instance.LayoutInflater.Inflate(Resource.Layout.CreatePlaylistDialog, null);
|
||||
builder.SetView(view);
|
||||
builder.SetNegativeButton("Cancel", (senderAlert, args) => { });
|
||||
builder.SetPositiveButton("Create", (senderAlert, args) =>
|
||||
{
|
||||
NewPlaylist(view.FindViewById<EditText>(Resource.Id.playlistName).Text, item.youtubeID);
|
||||
});
|
||||
builder.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Google.Apis.YouTube.v3.Data.PlaylistItem playlistItem = new Google.Apis.YouTube.v3.Data.PlaylistItem();
|
||||
PlaylistItemSnippet snippet = new PlaylistItemSnippet
|
||||
{
|
||||
PlaylistId = YoutubeID
|
||||
};
|
||||
ResourceId resourceId = new ResourceId
|
||||
{
|
||||
Kind = "youtube#video",
|
||||
VideoId = item.youtubeID
|
||||
};
|
||||
snippet.ResourceId = resourceId;
|
||||
playlistItem.Snippet = snippet;
|
||||
|
||||
var insertRequest = youtubeService.PlaylistItems.Insert(playlistItem, "snippet");
|
||||
insertRequest.Execute();
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
MainActivity.instance.Timout();
|
||||
}
|
||||
|
||||
//Check if this playlist is synced, if it his, add the song to the local playlist
|
||||
if (SyncBehave)
|
||||
{
|
||||
PlaylistItem SyncedPlaylist = null;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
|
||||
db.CreateTable<PlaylistItem>();
|
||||
|
||||
SyncedPlaylist = db.Table<PlaylistItem>().ToList().Find(x => x.YoutubeID == YoutubeID);
|
||||
});
|
||||
|
||||
if (SyncedPlaylist != null)
|
||||
{
|
||||
Download(item.Title, item.youtubeID, playlistName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async static void NewPlaylist(string playlistName, string videoID)
|
||||
public async static void CreatePlaylist(string playlistName, Song item)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -782,22 +725,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
var createRequest = youtubeService.Playlists.Insert(playlist, "snippet, status");
|
||||
Google.Apis.YouTube.v3.Data.Playlist response = await createRequest.ExecuteAsync();
|
||||
|
||||
|
||||
Google.Apis.YouTube.v3.Data.PlaylistItem playlistItem = new Google.Apis.YouTube.v3.Data.PlaylistItem();
|
||||
PlaylistItemSnippet snippetItem = new PlaylistItemSnippet
|
||||
{
|
||||
PlaylistId = response.Id
|
||||
};
|
||||
ResourceId resourceId = new ResourceId
|
||||
{
|
||||
Kind = "youtube#video",
|
||||
VideoId = videoID
|
||||
};
|
||||
snippetItem.ResourceId = resourceId;
|
||||
playlistItem.Snippet = snippetItem;
|
||||
|
||||
var insertRequest = youtubeService.PlaylistItems.Insert(playlistItem, "snippet");
|
||||
insertRequest.ExecuteAsync();
|
||||
AddToPlaylist(item, playlistName);
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
|
||||
Generated
+363
-360
File diff suppressed because it is too large
Load Diff
@@ -25,4 +25,14 @@
|
||||
android:paddingRight="15dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
<ProgressBar
|
||||
android:id="@+id/syncLoading"
|
||||
android:layout_width="29dp"
|
||||
android:layout_height="29dp"
|
||||
android:padding="5dp"
|
||||
android:indeterminate="true"
|
||||
android:indeterminateTint="@android:color/black"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
||||
@@ -14,4 +14,8 @@
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:hint="Playlist Name" />
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/playlistLocation" />
|
||||
</LinearLayout>
|
||||
@@ -69,8 +69,6 @@
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:padding="5dp"
|
||||
android:background="@null"
|
||||
android:src="@drawable/Sync"
|
||||
android:visibility="gone" />
|
||||
<ImageView
|
||||
android:id="@+id/moreButton"
|
||||
|
||||
Reference in New Issue
Block a user