Exemplo n.º 1
0
        //Header more click
        public bool OnMenuItemClick(IMenuItem menuItem)
        {
            switch (menuItem.ItemId)
            {
            case Resource.Id.download:
                YoutubeManager.DownloadPlaylist(item, true, true);
                break;

            case Resource.Id.fork:
                if (isForked)
                {
                    PlaylistManager.Unfork(item);
                }
                else
                {
                    PlaylistManager.ForkPlaylist(item);
                }

                isForked = !isForked;
                break;

            case Resource.Id.addToQueue:
                if (useHeader)
                {
                    PlaylistManager.AddToQueue(item);
                }
                else
                {
                    SongManager.AddToQueue(adapter.tracks);
                }
                break;

            case Resource.Id.name:
                PlaylistManager.Rename(item, () =>
                {
                    MainActivity.instance.FindViewById <TextView>(Resource.Id.headerTitle).Text = item.Name;
                });
                break;

            case Resource.Id.sync:
                PlaylistManager.StopSyncingDialog(item, () =>
                {
                    MainActivity.instance.SupportFragmentManager.PopBackStack();
                });
                break;

            case Resource.Id.delete:
                PlaylistManager.Delete(item, () =>
                {
                    MainActivity.instance.SupportFragmentManager.PopBackStack();
                });
                break;
            }
            return(true);
        }
Exemplo n.º 2
0
        public async void PlaylistMore(PlaylistItem item)
        {
            BottomSheetDialog bottomSheet = new BottomSheetDialog(MainActivity.instance);
            View bottomView = MainActivity.instance.LayoutInflater.Inflate(Resource.Layout.BottomSheet, null);

            bottomView.FindViewById <TextView>(Resource.Id.bsTitle).Text  = item.Name;
            bottomView.FindViewById <TextView>(Resource.Id.bsArtist).Text = item.Owner;
            Picasso.With(MainActivity.instance).Load(item.ImageURL).Placeholder(Resource.Color.background_material_dark).Transform(new RemoveBlackBorder(true)).Into(bottomView.FindViewById <ImageView>(Resource.Id.bsArt));
            bottomSheet.SetContentView(bottomView);

            List <BottomSheetAction> actions = new List <BottomSheetAction>
            {
                new BottomSheetAction(Resource.Drawable.Play, MainActivity.instance.Resources.GetString(Resource.String.play_in_order), (sender, eventArg) =>
                {
                    PlaylistManager.PlayInOrder(item);
                    bottomSheet.Dismiss();
                }),
                new BottomSheetAction(Resource.Drawable.Shuffle, MainActivity.instance.Resources.GetString(Resource.String.random_play), (sender, eventArg) =>
                {
                    PlaylistManager.Shuffle(item);
                    bottomSheet.Dismiss();
                }),
                new BottomSheetAction(Resource.Drawable.Queue, MainActivity.instance.Resources.GetString(Resource.String.add_to_queue), (sender, eventArg) =>
                {
                    PlaylistManager.AddToQueue(item);
                    bottomSheet.Dismiss();
                }),
                new BottomSheetAction(Resource.Drawable.Download, MainActivity.instance.Resources.GetString(Resource.String.download), (sender, eventArg) =>
                {
                    YoutubeManager.DownloadPlaylist(item, true, false);
                    bottomSheet.Dismiss();
                })
            };

            if (await PlaylistManager.IsForked(item))
            {
                actions.Add(new BottomSheetAction(Resource.Drawable.Delete, MainActivity.instance.Resources.GetString(Resource.String.unfork), (sender, eventArg) =>
                {
                    PlaylistManager.Unfork(item);
                    bottomSheet.Dismiss();
                }));
            }
            else
            {
                actions.Add(new BottomSheetAction(Resource.Drawable.LibraryAdd, MainActivity.instance.Resources.GetString(Resource.String.add_to_library), (sender, eventArg) =>
                {
                    PlaylistManager.ForkPlaylist(item);
                    bottomSheet.Dismiss();
                }));
            }

            bottomSheet.FindViewById <ListView>(Resource.Id.bsItems).Adapter = new BottomSheetAdapter(MainActivity.instance, Resource.Layout.BottomSheetText, actions);
            bottomSheet.Show();
        }
Exemplo n.º 3
0
        public void More(int Position)
        {
            bool         local = Position <= LocalPlaylists.Count;
            PlaylistItem item  = local ?
                                 LocalPlaylists[Position] :
                                 YoutubePlaylists[Position - LocalPlaylists.Count];

            BottomSheetDialog bottomSheet = new BottomSheetDialog(MainActivity.instance);
            View bottomView = LayoutInflater.Inflate(Resource.Layout.BottomSheet, null);

            bottomView.FindViewById <TextView>(Resource.Id.bsTitle).Text = item.Name;
            if (!local || item.SyncState != SyncState.False)
            {
                bottomView.FindViewById <TextView>(Resource.Id.bsArtist).Text = item.Owner;
                Picasso.With(MainActivity.instance).Load(item.ImageURL).Placeholder(Resource.Color.background_material_dark).Transform(new RemoveBlackBorder(true)).Into(bottomView.FindViewById <ImageView>(Resource.Id.bsArt));
            }
            else
            {
                bottomView.FindViewById <TextView>(Resource.Id.bsArtist).Text     = item.Count + " element" + (item.Count == 1 ? "" : "s");
                bottomView.FindViewById <ImageView>(Resource.Id.bsArt).Visibility = ViewStates.Gone;
            }
            bottomSheet.SetContentView(bottomView);

            if (item.SyncState == SyncState.Error)
            {
                bottomSheet.FindViewById <ListView>(Resource.Id.bsItems).Adapter = new BottomSheetAdapter(MainActivity.instance, Resource.Layout.BottomSheetText, new List <BottomSheetAction>
                {
                    //new BottomSheetAction(Resource.Drawable.SyncDisabled, Resources.GetString(Resource.String.stop_sync), (sender, eventArg) =>
                    //{
                    //    PlaylistManager.StopSyncingDialog(item, () =>
                    //    {
                    //        PlaylistItem LocalPlaylist = new PlaylistItem(YoutubePlaylists[Position - LocalPlaylists.Count].Name, item.LocalID, YoutubePlaylists[Position - LocalPlaylists.Count].Count);
                    //        LocalPlaylists.Add(LocalPlaylist);
                    //        if (LocalPlaylists.Count == 3 && LocalPlaylists[1].Name == "EMPTY")
                    //        {
                    //            LocalPlaylists.RemoveAt(1);
                    //            adapter.NotifyItemChanged(1);
                    //        }
                    //        else
                    //            adapter.NotifyItemInserted(LocalPlaylists.Count);

                    //        YoutubePlaylists[Position - LocalPlaylists.Count].LocalID = 0;
                    //        YoutubePlaylists[Position - LocalPlaylists.Count].SyncState = SyncState.False;
                    //        PlaylistHolder holder = (PlaylistHolder)ListView.GetChildViewHolder(ListView.GetChildAt(Position));
                    //        holder.sync.Visibility = ViewStates.Gone;
                    //        holder.SyncLoading.Visibility = ViewStates.Gone;
                    //    });
                    //    bottomSheet.Dismiss();
                    //}),
                    new BottomSheetAction(Resource.Drawable.Delete, Resources.GetString(Resource.String.delete), (sender, eventArg) =>
                    {
                        PlaylistManager.Delete(item, () =>
                        {
                            if (local)
                            {
                                LocalPlaylists.RemoveAt(Position);
                                adapter.NotifyItemRemoved(Position);

                                if (LocalPlaylists.Count == 1)
                                {
                                    LocalPlaylists.Add(new PlaylistItem("EMPTY", -1)
                                    {
                                        Owner = Resources.GetString(Resource.String.local_playlist_empty)
                                    });
                                    adapter.NotifyItemInserted(1);
                                }
                            }
                            else
                            {
                                YoutubePlaylists.RemoveAt(Position - LocalPlaylists.Count);
                                adapter.NotifyItemRemoved(Position);

                                if (YoutubePlaylists.Count == 1)
                                {
                                    YoutubePlaylists.Add(new PlaylistItem("EMPTY", null)
                                    {
                                        Owner = Resources.GetString(Resource.String.youtube_playlist_empty)
                                    });
                                    adapter.NotifyItemInserted(LocalPlaylists.Count + YoutubePlaylists.Count);
                                }
                            }
                        });
                        bottomSheet.Dismiss();
                    })
                });
                bottomSheet.Show();
                return;
            }


            List <BottomSheetAction> actions = new List <BottomSheetAction>
            {
                new BottomSheetAction(Resource.Drawable.Play, Resources.GetString(Resource.String.play_in_order), (sender, eventArg) =>
                {
                    PlaylistManager.PlayInOrder(item);
                    bottomSheet.Dismiss();
                }),
                new BottomSheetAction(Resource.Drawable.Shuffle, Resources.GetString(Resource.String.random_play), (sender, eventArg) =>
                {
                    PlaylistManager.Shuffle(item);
                    bottomSheet.Dismiss();
                }),
                new BottomSheetAction(Resource.Drawable.Queue, Resources.GetString(Resource.String.add_to_queue), (sender, eventArg) =>
                {
                    PlaylistManager.AddToQueue(item);
                    bottomSheet.Dismiss();
                })
            };

            if (local || item.HasWritePermission)
            {
                actions.AddRange(new BottomSheetAction[] { new BottomSheetAction(Resource.Drawable.Edit, Resources.GetString(Resource.String.rename), (sender, eventArg) =>
                    {
                        PlaylistManager.Rename(item, () =>
                        {
                            adapter.NotifyItemChanged(Position);
                        });
                        bottomSheet.Dismiss();
                    }),
                                                           new BottomSheetAction(Resource.Drawable.Delete, Resources.GetString(Resource.String.delete), (sender, eventArg) =>
                    {
                        PlaylistManager.Delete(item, () =>
                        {
                            if (local)
                            {
                                LocalPlaylists.RemoveAt(Position);
                                adapter.NotifyItemRemoved(Position);

                                if (LocalPlaylists.Count == 1)
                                {
                                    LocalPlaylists.Add(new PlaylistItem("EMPTY", -1)
                                    {
                                        Owner = Resources.GetString(Resource.String.local_playlist_empty)
                                    });
                                    adapter.NotifyItemInserted(1);
                                }
                            }
                            else
                            {
                                YoutubePlaylists.RemoveAt(Position - LocalPlaylists.Count);
                                adapter.NotifyItemRemoved(Position);

                                if (YoutubePlaylists.Count == 1)
                                {
                                    YoutubePlaylists.Add(new PlaylistItem("EMPTY", null)
                                    {
                                        Owner = Resources.GetString(Resource.String.youtube_playlist_empty)
                                    });
                                    adapter.NotifyItemInserted(LocalPlaylists.Count + YoutubePlaylists.Count);
                                }
                            }
                        });
                        bottomSheet.Dismiss();
                    }) });
            }

            if (item.SyncState == SyncState.True)
            {
                actions.AddRange(new BottomSheetAction[] { new BottomSheetAction(Resource.Drawable.Sync, Resources.GetString(Resource.String.sync_now), (sender, eventArg) =>
                    {
                        YoutubeManager.DownloadPlaylist(item, true, true);
                        bottomSheet.Dismiss();
                    }),
                                                           new BottomSheetAction(Resource.Drawable.SyncDisabled, Resources.GetString(Resource.String.stop_sync), (sender, eventArg) =>
                    {
                        PlaylistManager.StopSyncingDialog(item, () =>
                        {
                            PlaylistItem LocalPlaylist = new PlaylistItem(YoutubePlaylists[Position - LocalPlaylists.Count].Name, item.LocalID, YoutubePlaylists[Position - LocalPlaylists.Count].Count);
                            LocalPlaylists.Add(LocalPlaylist);
                            if (LocalPlaylists.Count == 3 && LocalPlaylists[1].Name == "EMPTY")
                            {
                                LocalPlaylists.RemoveAt(1);
                                adapter.NotifyItemChanged(1);
                            }
                            else
                            {
                                adapter.NotifyItemInserted(LocalPlaylists.Count);
                            }

                            YoutubePlaylists[Position - LocalPlaylists.Count].LocalID   = 0;
                            YoutubePlaylists[Position - LocalPlaylists.Count].SyncState = SyncState.False;
                            PlaylistHolder holder         = (PlaylistHolder)ListView.GetChildViewHolder(ListView.GetChildAt(Position));
                            holder.sync.Visibility        = ViewStates.Gone;
                            holder.SyncLoading.Visibility = ViewStates.Gone;
                        });
                        bottomSheet.Dismiss();
                    }) });
            }
            else if (!local)
            {
                actions.Add(new BottomSheetAction(Resource.Drawable.Sync, Resources.GetString(Resource.String.sync), (sender, eventArg) =>
                {
                    YoutubeManager.DownloadPlaylist(item, true, true);
                    bottomSheet.Dismiss();
                }));

                if (!item.HasWritePermission)
                {
                    actions.Add(new BottomSheetAction(Resource.Drawable.Delete, Resources.GetString(Resource.String.unfork), (sender, eventArg) =>
                    {
                        if (item.SyncState == SyncState.Error)
                        {
                            PlaylistManager.StopSyncing(item);
                        }

                        PlaylistManager.Unfork(item);
                        YoutubePlaylists.RemoveAt(Position - LocalPlaylists.Count);
                        adapter.NotifyItemRemoved(Position);
                        bottomSheet.Dismiss();
                    }));
                }
            }

            bottomSheet.FindViewById <ListView>(Resource.Id.bsItems).Adapter = new BottomSheetAdapter(MainActivity.instance, Resource.Layout.BottomSheetText, actions);
            bottomSheet.Show();
        }