コード例 #1
0
        void BuildUI()
        {
            if (BottomBar.Children.Count > 0)
            {
                return;
            }
            ControlsStack.Children.Clear();

            ControlsStack.Children.Add(thumbsDownButton = CreateButton(Images.NowPlayingScreen.ThumbsDown, async(b) => {
                SetState();
                await ViewModel.ThumbsDown();
                SetState();
            }));

            ControlsStack.Children.Add(CreateButton(Images.NowPlayingScreen.Previous, async(b) => {
                PlaybackManager.Shared.Previous();
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            ControlsStack.Children.Add(playPauseButton = CreateButton(Images.NowPlayingScreen.Pause, Images.NowPlayingScreen.Play, (b) => {
                if (b.Toggled)
                {
                    PlaybackManager.Shared.Play();
                }
                else
                {
                    PlaybackManager.Shared.Pause();
                }
            }));
            ControlsStack.Children.Add(CreateButton(Images.NowPlayingScreen.Next, async(b) => {
                await PlaybackManager.Shared.NextTrack();
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            ControlsStack.Children.Add(thumbsUpButton = CreateButton(Images.NowPlayingScreen.ThumbsUp, async(b) => {
                SetState();
                await ViewModel.ThumbsUp();
                SetState();
            }));

            MiniPlayer.Children.Add(miniPlayPauseButton = CreateButton(Images.NowPlayingScreen.PauseBordered, Images.NowPlayingScreen.PlayBordered, (b) => {
                if (b.Toggled)
                {
                    PlaybackManager.Shared.Play();
                }
                else
                {
                    PlaybackManager.Shared.Pause();
                }
            }), 2, 0);

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.ShareButton, async(b) => {
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.ShuffleButton, (b) => {
                Settings.ShuffleSongs = b.Toggled;
                if (Settings.ShuffleSongs)
                {
                    PlaybackManager.Shared.ShuffleCurrentPlaylist();
                }
            }, Settings.ShuffleSongs));

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.RepeatButton, (b) => {
            }));

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.MoreButton, async(b) => {
                //TODO: Show popup
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));


            MiniPlayer.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command((obj) => {
                    NotificationManager.Shared.ProcToggleNowPlaying();
                })
            });

            navCloseButton.ImageSource = Images.NowPlayingScreen.NavBar.CloseButton;
            navCloseButton.Clicked    += (sender, e) => {
                NotificationManager.Shared.ProcCloseNowPlaying();
            };


            navCurrentPlayist.ImageSource = Images.NowPlayingScreen.NavBar.CurrentPlayistButton;
            navCurrentPlayist.Clicked    += (sender, e) => {
                this.Navigation.PushModalAsync(new NavigationPage(new CurrentPlaylistPage()));
            };



            SetState();
            NotificationManager.Shared.PlaybackStateChanged += Shared_PlaybackStateChanged;
            NotificationManager.Shared.SongDownloadPulsed   += Shared_SongDownloadPulsed;
            this.ViewModel.SubscribeToProperty(nameof(NowPlayingViewModel.TrackPosition),
                                               () => {
                ProgressBar.PlaybackProgress = ViewModel.TrackPosition.Percent;
            });

            UpdateVisibile(currentPercent);
        }
コード例 #2
0
        public NowPlayingPage()
        {
            this.BindingContext   = new NowPlayingViewModel();
            ViewModel.SongChanged = () => {
                SetState();
            };

            InitializeComponent();
            ControlsStack.Children.Clear();

            ControlsStack.Children.Add(thumbsDownButton = CreateButton(Images.NowPlayingScreen.ThumbsDown, async(b) => {
                SetState();
                await ViewModel.ThumbsDown();
                SetState();
            }));

            ControlsStack.Children.Add(CreateButton(Images.NowPlayingScreen.Previous, async(b) => {
                PlaybackManager.Shared.Previous();
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            ControlsStack.Children.Add(playPauseButton = CreateButton(Images.NowPlayingScreen.Pause, Images.NowPlayingScreen.Play, (b) => {
                if (b.Toggled)
                {
                    PlaybackManager.Shared.Play();
                }
                else
                {
                    PlaybackManager.Shared.Pause();
                }
            }));
            ControlsStack.Children.Add(CreateButton(Images.NowPlayingScreen.Next, async(b) => {
                await PlaybackManager.Shared.NextTrack();
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            ControlsStack.Children.Add(thumbsUpButton = CreateButton(Images.NowPlayingScreen.ThumbsUp, async(b) => {
                SetState();
                await ViewModel.ThumbsUp();
                SetState();
            }));

            MiniPlayer.Children.Add(miniPlayPauseButton = CreateButton(Images.NowPlayingScreen.PauseBordered, Images.NowPlayingScreen.PlayBordered, (b) => {
                if (b.Toggled)
                {
                    PlaybackManager.Shared.Play();
                }
                else
                {
                    PlaybackManager.Shared.Pause();
                }
            }), 2, 0);

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.ShareButton, async(b) => {
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));
            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.ShuffleButton, (b) => {
                Settings.ShuffleSongs = b.Toggled;
                if (Settings.ShuffleSongs)
                {
                    PlaybackManager.Shared.ShuffleCurrentPlaylist();
                }
            }, Settings.ShuffleSongs));

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.RepeatButton, (b) => {
            }));

            BottomBar.Children.Add(CreateButton(Images.NowPlayingScreen.BottomBar.MoreButton, async(b) => {
                //TODO: Show popup
                await Task.Delay(toggleDelay);
                b.Toggled = false;
            }));

            SetState();
            NotificationManager.Shared.PlaybackStateChanged += Shared_PlaybackStateChanged;
        }