/// <summary> /// Конструктор по умолчанию. /// </summary> public AudiosViewModel(string uniqueKey, long ownerID) : base(uniqueKey) { _audios = new AudiosCollection(ownerID); _recommendations = new RecommendedAudiosCollection((ulong)ownerID); _popular = new PopularAudiosCollection(); _albums = new AudioAlbumsCollection(ownerID); Refresh = new RelayCommand(() => Audios.Refresh()); RefreshAlbums = new RelayCommand(() => Albums.Refresh()); RefreshPopular = new RelayCommand(() => Popular.Refresh()); RefreshRecommended = new RelayCommand(() => Recommendations.Refresh()); DeleteCommand = new RelayCommand <VKAudio>(async audio => { var request = new Request.DeleteAudioRequest(audio.ID, audio.OwnerID); var response = await request.ExecuteAsync(); if (response.Error.ErrorType == VKErrors.None) { Audios.Remove(audio); } else { await ServiceHelper.DialogService.ShowMessageBox("Произошла ошибка: " + response.Error.ErrorType.ToString(), "Не удалось удалить аудиозапись."); } }); DownloadAudio = new RelayCommand <VKAudio>(async audio => { var command = new VKSaverDownloadCommand(); command.Downloads.Add(CoreHelper.GetDownload(audio)); await command.TryExecute(); }); #if DEBUG if (ViewModelBase.IsInDesignModeStatic) { for (int i = 0; i < 71; i++) { Audios.Add(DesignDataHelper.GetAudio()); Recommendations.Add(DesignDataHelper.GetAudio()); Popular.Add(DesignDataHelper.GetAudio()); } } #endif }
/// <summary> /// Конструктор по умолчанию. /// </summary> public PlayerViewModel() { #if DEBUG if (IsInDesignModeStatic) { CurrentTrack = new VKAudio { Title = "Poker Face", Artist = "Lady Gaga", LyricsID = 1 }; DurationStart = TimeSpan.FromSeconds(0); DurationEnd = TimeSpan.FromSeconds(123); ArtistImage = new BitmapImage(new Uri("http://userserve-ak.last.fm/serve/500/60890169/Lady+Gaga+Gaga.png")); return; } #endif NextTrack = new RelayCommand(() => { if (Tracks == null || Tracks.Count == 0) { return; } ServiceHelper.PlayerService.NextTrack(); Duration = TimeSpan.Zero; DurationStart = TimeSpan.Zero; DurationEnd = TimeSpan.Zero; if (_currentTrackID + 1 == Tracks.Count) { _currentTrackID = 0; } else { _currentTrackID++; } }); PreviousTrack = new RelayCommand(() => { if (CurrentTrack == null || Tracks == null || Tracks.Count == 0) { return; } ServiceHelper.PlayerService.PreviousTrack(); DurationStart = TimeSpan.Zero; DurationEnd = TimeSpan.Zero; if (_currentTrackID - 1 == -1) { _currentTrackID = Tracks.Count - 1; } else { _currentTrackID--; } }); PlayTrack = new RelayCommand <IAudioTrack>(a => SetNewTrack(a)); PlayResume = new RelayCommand(() => ServiceHelper.PlayerService.ResumePause()); DownloadTrack = new RelayCommand(async() => { var command = new VKSaverDownloadCommand(); //command.Downloads.Add(CoreHelper.GetDownload(CurrentTrack)); await command.TryExecute(); }, () => CurrentTrack != null && !String.IsNullOrEmpty(CurrentTrack.Source)); ShowTrackLyrics = new RelayCommand(() => { NavigationHelper.Navigate(AppViews.TrackLyricsView, CurrentTrack); }, () => CurrentTrack != null && CurrentTrack.LyricsID != 0); _timer.Tick += (s, e) => { if (ServiceHelper.PlayerService.CurrentState == PlayerState.Playing) { try { DurationStart = ServiceHelper.PlayerService.CurrentPosition; DurationEnd = DurationStart - Duration; } catch (Exception) { } } }; _timer.Start(); Messenger.Default.Register <PlayTrackMessage>(this, OnPlayTrackMessageReceived); }