Reworking the begening of the playlist sync process.

This commit is contained in:
Anonymus Raccoon
2019-06-10 01:31:45 +02:00
parent decc538db8
commit 133862bf9a
6 changed files with 16 additions and 17 deletions

View File

@@ -1027,7 +1027,6 @@ namespace Opus.Api
}
}
/// <summary>
/// Will create a youtube playlist and add an array of songs in this playlist
/// </summary>

View File

@@ -132,11 +132,10 @@ namespace Opus.Api
/// <summary>
/// Download a playlist or update the local playlist with new songs.
/// </summary>
/// <param name="playlistName">The name of the playlist (local one)</param>
/// <param name="YoutubeID">The youtube id of your playlist</param>
/// <param name="playlist">The playlist you want to download.</param>
/// <param name="keepPlaylistSynced">True if you want to add the playlist in the keep synced database (warning, this wont add the playlist to the saved ones) </param>
/// <param name="showToast">True if you want this method to display that the download has started</param>
public static async void DownloadPlaylist(string playlistName, string YoutubeID, bool keepPlaylistSynced, bool showToast)
public static async void DownloadPlaylist(PlaylistItem playlist, bool keepPlaylistSynced, bool showToast)
{
if (!await MainActivity.instance.WaitForYoutube())
return;
@@ -151,17 +150,18 @@ namespace Opus.Api
Toast.MakeText(Android.App.Application.Context, Resource.String.syncing, ToastLength.Short).Show();
long LocalID = await PlaylistManager.GetPlaylistID(playlistName);
long LocalID = playlist.LocalID != 0 ? playlist.LocalID : await PlaylistManager.GetPlaylistID(playlist.Name);
if(LocalID == -1)
{
ContentValues value = new ContentValues();
value.Put(Playlists.InterfaceConsts.Name, playlistName);
value.Put(Playlists.InterfaceConsts.Name, playlist.Name);
MainActivity.instance.ContentResolver.Insert(Playlists.ExternalContentUri, value);
LocalID = await PlaylistManager.GetPlaylistID(playlistName);
LocalID = await PlaylistManager.GetPlaylistID(playlist.Name);
}
playlist.LocalID = LocalID;
Playlist.instance?.StartSyncing(playlistName);
Playlist.instance?.StartSyncing(playlist.Name);
if (keepPlaylistSynced)
{
@@ -169,7 +169,7 @@ namespace Opus.Api
{
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "SyncedPlaylists.sqlite"));
db.CreateTable<PlaylistItem>();
db.InsertOrReplace(new PlaylistItem(playlistName, LocalID, YoutubeID));
db.InsertOrReplace(playlist);
});
}
@@ -179,7 +179,7 @@ namespace Opus.Api
while (nextPageToken != null)
{
var ytPlaylistRequest = YoutubeService.PlaylistItems.List("snippet, contentDetails");
ytPlaylistRequest.PlaylistId = YoutubeID;
ytPlaylistRequest.PlaylistId = playlist.YoutubeID;
ytPlaylistRequest.MaxResults = 50;
ytPlaylistRequest.PageToken = nextPageToken;
@@ -202,7 +202,7 @@ namespace Opus.Api
for (int i = 0; i < names.Count; i++)
{
if (videoIDs[i] != null && videoIDs[i] != "")
files.Add(new DownloadFile(names[i], videoIDs[i], playlistName));
files.Add(new DownloadFile(names[i], videoIDs[i], playlist.Name));
}
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
@@ -240,7 +240,7 @@ namespace Opus.Api
{
if (item.YoutubeID != null)
{
DownloadPlaylist(item.Name, item.YoutubeID, false, false);
DownloadPlaylist(item, false, false);
}
}
}

View File

@@ -198,7 +198,7 @@ namespace Opus
searchView.ClearFocus();
searchView.Focusable = false;
if(SearchableActivity.instance.SearchQuery != YoutubeSearch.instances[0].querryType) //We don't want to redo the query if the user already searched for the exact same query.
if(YoutubeSearch.instances == null || SearchableActivity.instance.SearchQuery != YoutubeSearch.instances[0].querryType) //We don't want to redo the query if the user already searched for the exact same query.
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, Pager.NewInstance(SearchableActivity.instance.SearchQuery, 0)).AddToBackStack("Youtube").Commit();
SearchableActivity.instance = null;
}

View File

@@ -451,7 +451,7 @@ namespace Opus.Fragments
{
actions.AddRange(new BottomSheetAction[]{ new BottomSheetAction(Resource.Drawable.Sync, Resources.GetString(Resource.String.sync_now), (sender, eventArg) =>
{
YoutubeManager.DownloadPlaylist(item.Name, item.YoutubeID, true, true);
YoutubeManager.DownloadPlaylist(item, true, true);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.SyncDisabled, Resources.GetString(Resource.String.stop_sync), (sender, eventArg) =>
@@ -481,7 +481,7 @@ namespace Opus.Fragments
{
actions.Add(new BottomSheetAction(Resource.Drawable.Sync, Resources.GetString(Resource.String.sync), (sender, eventArg) =>
{
YoutubeManager.DownloadPlaylist(item.Name, item.YoutubeID, true, true);
YoutubeManager.DownloadPlaylist(item, true, true);
bottomSheet.Dismiss();
}));

View File

@@ -172,7 +172,7 @@ namespace Opus.Fragments
switch (menuItem.ItemId)
{
case Resource.Id.download:
YoutubeManager.DownloadPlaylist(item.Name, item.YoutubeID, true, true);
YoutubeManager.DownloadPlaylist(item, true, true);
break;
case Resource.Id.fork:

View File

@@ -440,7 +440,7 @@ namespace Opus.Fragments
}),
new BottomSheetAction(Resource.Drawable.Download, MainActivity.instance.Resources.GetString(Resource.String.download), (sender, eventArg) =>
{
YoutubeManager.DownloadPlaylist(item.Name, item.YoutubeID, true, false);
YoutubeManager.DownloadPlaylist(item, true, false);
bottomSheet.Dismiss();
})
};