private object ReadList(JsonReader reader)
	{
		IList<object> list = new SearchableList<object>(); // it is quite unfortunate to have to reimplement all class just because of this one line.
		while (reader.Read())
		{
			switch (reader.TokenType)
			{
				case JsonToken.EndArray:
					return list;
				case JsonToken.Comment:
					continue;
			}
			object item = ReadValue(reader);
			list.Add(item);
		}
		throw new JsonSerializationException("Unexpected end when reading ExpandoObject.");
	}
Ejemplo n.º 2
0
        async Task PopulateList()
        {
            if (item.LocalID == -1 && item.YoutubeID == null && adapter?.tracks.Count == 0)
            {
                return;
            }

            if (item.LocalID != -1)
            {
                if (await MainActivity.instance.GetReadPermission() == false)
                {
                    MainActivity.instance.FindViewById(Resource.Id.loading).Visibility = ViewStates.Gone;
                    return;
                }

                adapter = new PlaylistTrackAdapter();
                ListView.SetAdapter(adapter);

                Android.Support.V7.Widget.Helper.ItemTouchHelper.Callback callback = new ItemTouchCallback(adapter, false);
                itemTouchHelper = new Android.Support.V7.Widget.Helper.ItemTouchHelper(callback);
                itemTouchHelper.AttachToRecyclerView(ListView);

                LoaderManager.GetInstance(this).InitLoader(0, null, this);
            }
            else if (item.YoutubeID != null)
            {
                fullyLoadded = false;
                SearchableList <Song> tracks = new SearchableList <Song>();
                adapter = new PlaylistTrackAdapter(tracks);
                ListView.SetAdapter(adapter);

                Android.Support.V7.Widget.Helper.ItemTouchHelper.Callback callback = new ItemTouchCallback(adapter, false);
                itemTouchHelper = new Android.Support.V7.Widget.Helper.ItemTouchHelper(callback);
                itemTouchHelper.AttachToRecyclerView(ListView);

                try
                {
                    var ytPlaylistRequest = YoutubeManager.YoutubeService.PlaylistItems.List("snippet, contentDetails");
                    ytPlaylistRequest.PlaylistId = item.YoutubeID;
                    ytPlaylistRequest.MaxResults = 50;

                    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")
                        {
                            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,
                                ChannelID = item.Snippet.ChannelId
                            };
                            tracks.Add(song);
                        }
                    }

                    nextPageToken = ytPlaylist.NextPageToken;
                    if (nextPageToken == null)
                    {
                        fullyLoadded = true;
                    }

                    tracks.Invalidate();
                    adapter.NotifyDataSetChanged();

                    if (item?.ImageURL == null)
                    {
                        Picasso.With(Android.App.Application.Context).Load(tracks[0].Album).Placeholder(Resource.Drawable.noAlbum).Transform(new RemoveBlackBorder(true)).Into(Activity.FindViewById <ImageView>(Resource.Id.headerArt));
                    }
                }
                catch (System.Net.Http.HttpRequestException) { }
            }
            else if (adapter?.tracks.Count != 0)
            {
                ListView.SetAdapter(adapter);
            }
        }