コード例 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.CompleteRecycler, container, false);

            view.FindViewById(Resource.Id.loading).Visibility = ViewStates.Visible;
            EmptyView = view.FindViewById <TextView>(Resource.Id.empty);
            ListView  = view.FindViewById <RecyclerView>(Resource.Id.recycler);
            ListView.SetLayoutManager(new LinearLayoutManager(Android.App.Application.Context));
            ListView.SetItemAnimator(new DefaultItemAnimator());
            adapter = new BrowseAdapter((song, position) =>
            {
                song = LocalManager.CompleteItem(song);
                SongManager.Play(song);
            }, (song, position) =>
            {
                MainActivity.instance.More(song);
            }, (position) =>
            {
                LocalManager.ShuffleAll();
            });
            ListView.SetAdapter(adapter);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            PopulateList();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            return(view);
        }
コード例 #2
0
        public async void DownloadPlaylist(List <DownloadFile> files, long LocalID, bool keepDeleted)
        {
            if (LocalID != -1)
            {
                List <Song> songs = await PlaylistManager.GetTracksFromLocalPlaylist(LocalID);

                await Task.Run(() =>
                {
                    foreach (Song song in songs)
                    {
                        LocalManager.CompleteItem(song);
                    }
                });

                for (int i = 0; i < files.Count; i++)
                {
                    Song song = songs.Find(x => x.YoutubeID == files[i].YoutubeID);
                    if (song != null)
                    {
                        //Video is already in the playlist, we want to check if this item has been reordered.
                        if (int.Parse(song.TrackID) != i)
                        {
                            //The plus one is because android playlists have one-based indexes.
                            PlaylistManager.SetQueueSlot(LocalID, song.LocalID, i + 1);
                        }

                        //Video is already downloaded:
                        if (files[i].State == DownloadState.None)
                        {
                            files[i].State = DownloadState.UpToDate;
                        }

                        currentStrike++;
                        songs.Remove(song);
                    }
                }

                queue.RemoveAll(x => x.State == DownloadState.Completed || x.State == DownloadState.UpToDate || x.State == DownloadState.Canceled);
                if (files.Count(x => x.State == DownloadState.None) > 0)
                {
                    queue.AddRange(files);
                    StartDownload();
                }
                else
                {
                    Toast.MakeText(MainActivity.instance, Resource.String.playlist_uptodate, ToastLength.Long).Show();
                }

                await Task.Run(() =>
                {
                    if (Looper.MyLooper() == null)
                    {
                        Looper.Prepare();
                    }

                    for (int i = 0; i < songs.Count; i++)
                    {
                        //Video has been removed from the playlist but still exist on local storage
                        ContentResolver resolver = Application.ContentResolver;
                        Uri uri = Playlists.Members.GetContentUri("external", LocalID);
                        resolver.Delete(uri, Playlists.Members.Id + "=?", new string[] { songs[i].LocalID.ToString() });

                        if (!keepDeleted)
                        {
                            File.Delete(songs[i].Path);
                        }
                    }
                });
            }

            await Task.Delay(1000);

            Playlist.instance?.CheckForSync();
        }