コード例 #1
0
ファイル: RadioViewModel.cs プロジェクト: justdude/meridian
        private void InitializeCommands()
        {
            CreateStationCommand = new RelayCommand(async () =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new CreateRadioStationView();
                var artists = await flyout.ShowAsync() as IList<EchoArtist>;

                if (artists != null)
                {
                    AddStation(artists);
                }
            });

            PlayStationCommand = new RelayCommand<RadioStation>(station =>
            {
                RadioService.PlayRadio(station);
                MessengerInstance.Send(new NavigateToPageMessage() { Page = "/Main.NowPlayingView" });
            });

            RemoveStationCommand = new RelayCommand<RadioStation>(station =>
            {
                Stations.Remove(station);
                RadioService.SaveStations(Stations);
            });

            EditStationCommand = new RelayCommand<RadioStation>(async station =>
            {
                var createRadioStationView = new CreateRadioStationView();
                createRadioStationView.Artists = new ObservableCollection<EchoArtist>(station.Artists);

                var flyout = new FlyoutControl();
                flyout.FlyoutContent = createRadioStationView;
                var artists = await flyout.ShowAsync() as IList<EchoArtist>;

                if (artists != null)
                {
                    var titleArtist = station.Artists.First();
                    station.Artists = artists.ToList();


                    //update image and title
                    station.Title = string.Join(", ", station.Artists.Select(s => s.Name));

                    if (station.Artists.First().Name != titleArtist.Name)
                    {
                        station.ImageUrl = null;

                        try
                        {
                            var artistImage = await DataService.GetArtistImage(station.Artists.First().Name, false);
                            if (artistImage != null)
                                station.ImageUrl = artistImage.OriginalString;
                        }
                        catch (Exception ex)
                        {
                            LoggingService.Log(ex);
                        }
                    }

                    RadioService.SaveStations(Stations);
                }
            });
        }
コード例 #2
0
        private void InitializeCommands()
        {
            CreateStationCommand = new RelayCommand(async() =>
            {
                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = new CreateRadioStationView();
                var artists          = await flyout.ShowAsync() as IList <EchoArtist>;

                if (artists != null)
                {
                    AddStation(artists);
                }
            });

            PlayStationCommand = new RelayCommand <RadioStation>(station =>
            {
                RadioService.PlayRadio(station);
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Main.NowPlayingView"
                });
            });

            RemoveStationCommand = new RelayCommand <RadioStation>(station =>
            {
                Stations.Remove(station);
                RadioService.SaveStations(Stations);
            });

            EditStationCommand = new RelayCommand <RadioStation>(async station =>
            {
                var createRadioStationView     = new CreateRadioStationView();
                createRadioStationView.Artists = new ObservableCollection <EchoArtist>(station.Artists);

                var flyout           = new FlyoutControl();
                flyout.FlyoutContent = createRadioStationView;
                var artists          = await flyout.ShowAsync() as IList <EchoArtist>;

                if (artists != null)
                {
                    var titleArtist = station.Artists.First();
                    station.Artists = artists.ToList();


                    //update image and title
                    station.Title = string.Join(", ", station.Artists.Select(s => s.Name));

                    if (station.Artists.First().Name != titleArtist.Name)
                    {
                        station.ImageUrl = null;

                        try
                        {
                            var artistImage = await DataService.GetArtistImage(station.Artists.First().Name, false);
                            if (artistImage != null)
                            {
                                station.ImageUrl = artistImage.OriginalString;
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggingService.Log(ex);
                        }
                    }

                    RadioService.SaveStations(Stations);
                }
            });
        }