Ejemplo n.º 1
0
        private static async Task TakeOffline(BaseItemDto item)
        {
            if (!item.CanTakeOffline())
            {
                return;
            }

            var name    = item.GetTvTypeName();
            var request = SyncRequestHelper.CreateRequest(item.Id, name);

            try
            {
                await SyncService.Current.AddJobAsync(request);
            }
            catch (HttpException ex)
            {
            }
        }
        private void WireCommands()
        {
            PageLoaded = new RelayCommand(async() =>
            {
                await GetEverything(false);

                if (!_hasLoaded)
                {
                    ReviewReminderService.Current.Notify();
                }
            });

            RefreshDataCommand = new RelayCommand(async() =>
            {
                await GetEverything(true);
            });

            ChangeProfileCommand = new RelayCommand(() =>
            {
                Log.Info("Signing out");

                AuthenticationService.Current.SignOut().ConfigureAwait(false);

                NavigationService.NavigateTo(Constants.Pages.ChooseProfileView);
            });

            PinCollectionCommand = new RelayCommand <BaseItemDto>(collection =>
            {
                var tileUrl      = string.Format(Constants.PhoneTileUrlFormat, "Collection", collection.Id, collection.Name);
                var existingTile = TileService.Current.GetTile(tileUrl);
                if (existingTile != default(ShellTileServiceTile))
                {
                    var result = MessageBox.Show(AppResources.MessageBoxUnpinText, AppResources.MessageAreYouSureTitle, MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        existingTile.Delete();
                        Messenger.Default.Send(new NotificationMessage(tileUrl, Constants.Messages.CollectionPinnedMsg));
                    }
                    return;
                }

                TileService.Current.PinCollection(collection.Name, collection.Id, App.SpecificSettings.UseTransparentTile, true);
                Messenger.Default.Send(new NotificationMessage(tileUrl, Constants.Messages.CollectionPinnedMsg));
            });

            PlayMovieCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                await PlayVideo(item);
            });

            ResumeMovieCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                await PlayVideo(item, true);
            });

            NavigateToPage = new RelayCommand <BaseItemDto>(NavigationService.NavigateTo);

            NavigateToAPage = new RelayCommand <string>(NavigationService.NavigateTo);

            NavigateToNotificationsCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(new NotificationMessage(Constants.Messages.NotifcationNavigationMsg));

                NavigationService.NavigateTo(Constants.Pages.NotificationsView);
            });

            ItemOfflineCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                if (!item.CanTakeOffline())
                {
                    return;
                }

                try
                {
                    var request = SyncRequestHelper.CreateRequest(item.Id, item.GetTvTypeName());
                    await SyncService.Current.AddJobAsync(request);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("ItemOfflineCommand", ex, NavigationService, Log);
                }
            });
        }
        private void WireCommands()
        {
            ArtistPageLoaded = new RelayCommand(async() =>
            {
                if (NavigationService.IsNetworkAvailable && !_gotAlbums)
                {
                    SetProgressBar(AppResources.SysTrayGettingAlbums);

                    await GetArtistInfo();

                    SetProgressBar();
                }
            });

            AlbumPageLoaded = new RelayCommand(async() =>
            {
                if (_artistTracks.IsNullOrEmpty())
                {
                    SetProgressBar(AppResources.SysTrayGettingTracks);

                    try
                    {
                        if (SelectedArtist != null)
                        {
                            await GetArtistInfo();

                            AlbumTracks = _artistTracks.Where(x => x.ParentId == SelectedAlbum.Id)
                                          .OrderBy(x => x.ParentIndexNumber)
                                          .ThenBy(x => x.IndexNumber).ToList();
                        }
                        else
                        {
                            await GetAlbumTracks();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorException("AlbumPageLoaded", ex);
                    }

                    SetProgressBar();
                }
            });

            AlbumTapped = new RelayCommand <BaseItemDto>(album =>
            {
                SelectedAlbum = album;
                AlbumTracks   = _artistTracks.Where(x => x.ParentId == SelectedAlbum.Id)
                                .OrderBy(x => x.IndexNumber)
                                .ToList();
            });

            AlbumPlayTapped = new RelayCommand <BaseItemDto>(async album =>
            {
                var albumTracks = _artistTracks.Where(x => x.ParentId == album.Id)
                                  .OrderBy(x => x.IndexNumber)
                                  .ToList();

                var newList = await albumTracks.ToPlayListItems(ApiClient, _playbackManager);

                Messenger.Default.Send(new NotificationMessage <List <PlaylistItem> >(newList, Constants.Messages.SetPlaylistAsMsg));
            });

            SelectionChangedCommand = new RelayCommand <SelectionChangedEventArgs>(args =>
            {
                if (args.AddedItems != null)
                {
                    foreach (var track in args.AddedItems.Cast <BaseItemDto>())
                    {
                        SelectedTracks.Add(track);
                    }
                }

                if (args.RemovedItems != null)
                {
                    foreach (var track in args.RemovedItems.Cast <BaseItemDto>())
                    {
                        SelectedTracks.Remove(track);
                    }
                }

                SelectedTracks = SelectedTracks.OrderBy(x => x.IndexNumber).ToList();
                SyncItemsCommand.RaiseCanExecuteChanged();
            });

            AddToNowPlayingCommand = new RelayCommand(async() =>
            {
                if (!SelectedTracks.Any())
                {
                    return;
                }

                var newList = await SelectedTracks.ToPlayListItems(ApiClient, _playbackManager);

                Messenger.Default.Send(new NotificationMessage <List <PlaylistItem> >(newList, Constants.Messages.AddToPlaylistMsg));

                SelectedTracks = new List <BaseItemDto>();

                App.ShowMessage(string.Format(AppResources.MessageTracksAddedSuccessfully, newList.Count));

                IsInSelectionMode = false;
            });

            SyncItemsCommand = new RelayCommand(async() =>
            {
                var trackIds = SelectedTracks.Select(x => x.Id).ToList();

                try
                {
                    var request = SyncRequestHelper.CreateRequest(trackIds);
                    await SyncService.Current.AddJobAsync(request);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("SyncItemsCommand", ex, NavigationService, Log);
                }
            }, () => SelectedTracks.Any());

            TakeOfflineCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                try
                {
                    var request = SyncRequestHelper.CreateRequest(item.Id, item.Name);
                    await SyncService.Current.AddJobAsync(request);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("TakeOfflineCommand", ex, NavigationService, Log);
                }
            });

            UnsyncCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                try
                {
                    await SyncService.Current.UnsyncItem(item.Id);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("UnsyncCommand", ex, NavigationService, Log);
                }
            });

            PlayItemsCommand = new RelayCommand(async() =>
            {
                var newList = await SelectedTracks.ToPlayListItems(ApiClient, _playbackManager);

                Messenger.Default.Send(new NotificationMessage <List <PlaylistItem> >(newList, Constants.Messages.SetPlaylistAsMsg));
            });

            PlaySongCommand = new RelayCommand <BaseItemDto>(async song =>
            {
                if (song == null)
                {
                    return;
                }

                var playlistItem = await song.ToPlaylistItem(ApiClient, _playbackManager);
                var playlist     = new List <PlaylistItem>
                {
                    playlistItem
                };

                Messenger.Default.Send(new NotificationMessage <List <PlaylistItem> >(playlist, Constants.Messages.SetPlaylistAsMsg));
            });

            AddRemoveFavouriteCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                try
                {
                    SetProgressBar(AppResources.SysTrayAddingToFavourites);

                    CanUpdateFavourites = false;

                    item.UserData = await ApiClient.UpdateFavoriteStatusAsync(item.Id, AuthenticationService.Current.LoggedInUserId, !item.UserData.IsFavorite);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("AddRemoveFavouriteCommand (Music)", ex, NavigationService, Log);
                    App.ShowMessage(AppResources.ErrorMakingChanges);
                }

                SetProgressBar();

                CanUpdateFavourites = true;
            });

            PlayAllItemsCommand = new RelayCommand(async() =>
            {
                if (_artistTracks.IsNullOrEmpty())
                {
                    return;
                }

                var playlist = await _artistTracks.ToPlayListItems(ApiClient, _playbackManager);

                Messenger.Default.Send(new NotificationMessage <List <PlaylistItem> >(playlist, Constants.Messages.SetPlaylistAsMsg));
            });
        }
Ejemplo n.º 4
0
        private void WireCommands()
        {
            TvSeriesPageLoaded = new RelayCommand(async() =>
            {
                DummyFolder = new BaseItemDto
                {
                    Type = "folder",
                    Name = string.Format(AppResources.TvShowRecentItemsTitle, SelectedTvSeries.Name.ToLower()),
                    Id   = SelectedTvSeries.Id
                };

                if (NavigationService.IsNetworkAvailable && !ShowDataLoaded)
                {
                    if (SelectedTvSeries != null)
                    {
                        SetProgressBar(AppResources.SysTrayGettingShowInformation);

                        try
                        {
                            Log.Info("Getting information for TV Series [{0}] ({1})", SelectedTvSeries.Name, SelectedTvSeries.Id);

                            SelectedTvSeries = await ApiClient.GetItemAsync(SelectedTvSeries.Id, AuthenticationService.Current.LoggedInUserId);
                            CastAndCrew      = Utils.GroupCastAndCrew(SelectedTvSeries.People);
                        }
                        catch (HttpException ex)
                        {
                            if (Utils.HandleHttpException("TvSeriesPageLoaded", ex, NavigationService, Log))
                            {
                                SetProgressBar();
                                return;
                            }
                        }

                        bool seasonsLoaded = await GetSeasons();

                        SetProgressBar(AppResources.SysTrayGettingRecentItems);

                        bool recentItems = await GetRecentItems().ConfigureAwait(true);

                        SetProgressBar();
                        ShowDataLoaded = (seasonsLoaded && recentItems);
                    }
                }
            });

            SeasonPageLoaded = new RelayCommand(async() =>
            {
                if (NavigationService.IsNetworkAvailable && !SeasonDataLoaded)
                {
                    if (SelectedSeason != null)
                    {
                        SetProgressBar(AppResources.SysTrayGettingEpisodes);

                        SeasonDataLoaded = await GetEpisodes();

                        SetProgressBar();
                    }
                }
            });

            EpisodePageLoaded = new RelayCommand(async() =>
            {
            });

            NextEpisodeCommand = new RelayCommand(() =>
            {
                if (Episodes.IsNullOrEmpty())
                {
                    return;
                }

                var episodeIndex = Episodes.IndexOf(SelectedEpisode);
                SelectedEpisode  = episodeIndex + 1 >= Episodes.Count ? Episodes[0] : Episodes[episodeIndex + 1];
                CanResume        = SelectedEpisode != null && SelectedEpisode.CanResume;
            });

            PreviousEpisodeCommand = new RelayCommand(() =>
            {
                if (Episodes.IsNullOrEmpty())
                {
                    return;
                }

                var episodeIndex = Episodes.IndexOf(SelectedEpisode);
                SelectedEpisode  = episodeIndex == 0 ? Episodes[Episodes.Count - 1] : Episodes[episodeIndex - 1];
                CanResume        = SelectedEpisode != null && SelectedEpisode.CanResume;
            });

            AddRemoveFavouriteCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                try
                {
                    SetProgressBar(AppResources.SysTrayAddingToFavourites);

                    CanUpdateFavourites = false;

                    item.UserData = await ApiClient.UpdateFavoriteStatusAsync(item.Id, AuthenticationService.Current.LoggedInUserId, !item.UserData.IsFavorite);
                }
                catch (HttpException ex)
                {
                    if (Utils.HandleHttpException("AddRemoveFavouriteCommand (TV)", ex, NavigationService, Log))
                    {
                        SetProgressBar();
                        return;
                    }
                    App.ShowMessage(AppResources.ErrorMakingChanges);
                }

                SetProgressBar();

                CanUpdateFavourites = true;
            });

            ShowOtherFilmsCommand = new RelayCommand <BaseItemPerson>(person =>
            {
                App.SelectedItem = person;
                NavigationService.NavigateTo(Constants.Pages.ActorView);
            });

            EpisodeOfflineCommand = new RelayCommand(async() =>
            {
                await TakeOffline(SelectedEpisode);
            });

            SeasonOfflineCommand = new RelayCommand(async() =>
            {
                await TakeOffline(SelectedSeason);
            });

            ShowOfflineCommand = new RelayCommand(async() =>
            {
                await TakeOffline(SelectedTvSeries);
            }, () => SelectedTvSeries.SupportsSync.HasValue && SelectedTvSeries.SupportsSync.Value);

            ItemOfflineCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                if (!item.CanTakeOffline())
                {
                    return;
                }

                try
                {
                    var request = SyncRequestHelper.CreateRequest(item.Id, item.GetTvTypeName());
                    await SyncService.Current.AddJobAsync(request);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("ItemOfflineCommand", ex, NavigationService, Log);
                }
            });

            UnsyncItemCommand = new RelayCommand <BaseItemDto>(async item =>
            {
                try
                {
                    if (item.IsSynced.HasValue && !item.IsSynced.Value)
                    {
                        return;
                    }

                    await SyncService.Current.UnsyncItem(item.Id);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("UnsyncItemCommand", ex, NavigationService, Log);
                }
            });

            NavigateTo = new RelayCommand <BaseItemDto>(NavigationService.NavigateTo);
        }
        private void WireCommands()
        {
            MoviePageLoaded = new RelayCommand(async() =>
            {
                if (SelectedMovie != null && NavigationService.IsNetworkAvailable)
                {
                    SetProgressBar(AppResources.SysTrayGettingMovieInfo);

                    await GetMovieDetails();

                    if (SelectedMovie.ProviderIds != null)
                    {
                        if (SelectedMovie != null && SelectedMovie.ProviderIds != null && SelectedMovie.ProviderIds.ContainsKey("Imdb"))
                        {
                            ImdbId = SelectedMovie.ProviderIds["Imdb"];
                        }
                    }

                    if (SelectedMovie.RunTimeTicks.HasValue)
                    {
                        var ts      = TimeSpan.FromTicks(SelectedMovie.RunTimeTicks.Value);
                        var runtime = ts.Hours == 0 ? string.Format("{0}m", ts.Minutes) : string.Format("{0}h {1}m", ts.Hours, ts.Minutes);
                        RunTime     = runtime;
                    }

                    if (SelectedMovie.UserData == null)
                    {
                        SelectedMovie.UserData = new UserItemDataDto();
                    }

                    SetProgressBar();
                }
            });

            AddRemoveFavouriteCommand = new RelayCommand(async() =>
            {
                try
                {
                    SetProgressBar(AppResources.SysTrayAddingToFavourites);

                    CanUpdateFavourites = false;

                    SelectedMovie.UserData = await ApiClient.UpdateFavoriteStatusAsync(SelectedMovie.Id, AuthenticationService.Current.LoggedInUserId, !SelectedMovie.UserData.IsFavorite);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("AddRemoveFavouriteCommand (Movies)", ex, NavigationService, Log);
                    App.ShowMessage(AppResources.ErrorMakingChanges);
                }

                SetProgressBar();

                CanUpdateFavourites = true;
            });

            ShowOtherFilmsCommand = new RelayCommand <BaseItemPerson>(person =>
            {
                App.SelectedItem = person;
                NavigationService.NavigateTo(Constants.Pages.ActorView);
            });

            NavigateTopage = new RelayCommand <BaseItemDto>(NavigationService.NavigateTo);

            SetPosterAsLockScreenCommand = new RelayCommand(async() =>
            {
                if (!LockScreenService.Current.IsProvidedByCurrentApplication)
                {
                    var result = await LockScreenService.Current.RequestAccessAsync();

                    if (result == LockScreenServiceRequestResult.Denied)
                    {
                        return;
                    }
                }

                var url = ApiClient.GetImageUrl(SelectedMovie, LockScreenService.Current.SinglePosterOptions);

                LockScreenService.Current.ManuallySet = true;
                await LockScreenService.Current.SetLockScreenImage(url);
            });

            SyncItemCommand = new RelayCommand(async() =>
            {
                if (!SelectedMovie.CanTakeOffline())
                {
                    return;
                }

                var request = SyncRequestHelper.CreateRequest(SelectedMovie.Id, SelectedMovie.Name);

                await SyncService.Current.AddJobAsync(request);
            }, () => SelectedMovie != null && SelectedMovie.SupportsSync.HasValue && SelectedMovie.SupportsSync.Value);

            UnsyncItemCommand = new RelayCommand(async() =>
            {
                try
                {
                    if (SelectedMovie.IsSynced.HasValue && !SelectedMovie.IsSynced.Value)
                    {
                        return;
                    }

                    await SyncService.Current.UnsyncItem(SelectedMovie.Id);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("UnsyncItemCommand", ex, NavigationService, Log);
                }
            });
        }