示例#1
0
 /// <summary>
 /// Display download progress
 /// </summary>
 private void DisplayDownloadProgress()
 {
     if (Type == MediaType.Movie)
     {
         if (Progress >= Constants.MinimumMovieBuffering)
         {
             DisplayText.Text =
                 $"{LocalizationProviderHelper.GetLocalizedValue<string>("CurrentlyPlayingLabel")} : {Title}";
         }
         else
         {
             DisplayText.Text = Rate >= 1000.0
                 ? $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(Progress * (100d / Constants.MinimumMovieBuffering), 0)} % ({Rate / 1000d} MB/s)"
                 : $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(Progress * (100d / Constants.MinimumMovieBuffering), 0)} % ({Rate} kB/s)";
         }
     }
     else if (Type == MediaType.Show)
     {
         if (Progress >= Constants.MinimumShowBuffering)
         {
             DisplayText.Text =
                 $"{LocalizationProviderHelper.GetLocalizedValue<string>("CurrentlyPlayingLabel")} : {Title}";
         }
         else
         {
             DisplayText.Text = Rate >= 1000.0
                 ? $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(Progress * (100d / Constants.MinimumShowBuffering), 0)} % ({Rate / 1000d} MB/s)"
                 : $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(Progress * (100d / Constants.MinimumShowBuffering), 0)} % ({Rate} kB/s)";
         }
     }
 }
 /// <summary>
 /// Initializes a new instance of the PopularTabViewModel class.
 /// </summary>
 /// <param name="applicationState">Application state</param>
 /// <param name="movieService">Movie service</param>
 /// <param name="movieHistoryService">Movie history service</param>
 public PopularTabViewModel(IApplicationState applicationState, IMovieService movieService, IMovieHistoryService movieHistoryService)
     : base(applicationState, movieService, movieHistoryService)
 {
     RegisterMessages();
     RegisterCommands();
     TabName = LocalizationProviderHelper.GetLocalizedValue <string>("PopularTitleTab");
 }
示例#3
0
        /// <summary>
        /// Manage an exception
        /// </summary>
        /// <param name="exception">The exception to manage</param>
        private void ManageException(Exception exception)
        {
            if (_isManagingException)
            {
                return;
            }

            _isManagingException = true;
            IsMovieFlyoutOpen    = false;
            IsSettingsFlyoutOpen = false;

            if (exception is WebException || exception is SocketException)
            {
                _applicationService.IsConnectionInError = true;
            }

            DispatcherHelper.CheckBeginInvokeOnUI(async() =>
            {
                var exceptionDialog =
                    new ExceptionDialog(
                        new ExceptionDialogSettings(
                            LocalizationProviderHelper.GetLocalizedValue <string>("EmbarrassingError"), exception.Message));
                await _dialogCoordinator.ShowMetroDialogAsync(this, exceptionDialog);
                await exceptionDialog.WaitForButtonPressAsync();
                _isManagingException = false;
                await _dialogCoordinator.HideMetroDialogAsync(this, exceptionDialog);
            });
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the MediaPlayerViewModel class.
        /// </summary>
        /// <param name="subtitlesService"></param>
        /// <param name="cacheService">Caching service</param>
        /// <param name="mediaPath">Media path</param>
        /// <param name="mediaName">Media name</param>
        /// <param name="type">Media type</param>
        /// <param name="mediaStoppedAction">Media action to execute when media has been stopped</param>
        /// <param name="playingProgress">Media playing progress</param>
        /// <param name="bufferProgress">The buffer progress</param>
        /// <param name="bandwidthRate">THe bandwidth rate</param>
        /// <param name="currentSubtitle">Subtitle</param>
        /// <param name="subtitles">Subtitles</param>
        public MediaPlayerViewModel(ISubtitlesService subtitlesService,
                                    ICacheService cacheService,
                                    string mediaPath,
                                    string mediaName, MediaType type, Action mediaStoppedAction, IProgress <double> playingProgress = null,
                                    Progress <double> bufferProgress       = null,
                                    Progress <BandwidthRate> bandwidthRate = null, Subtitle currentSubtitle = null,
                                    IEnumerable <Subtitle> subtitles       = null)
        {
            Logger.Info(
                $"Loading media : {mediaPath}.");
            RegisterCommands();
            _subtitlesService   = subtitlesService;
            _cacheService       = cacheService;
            MediaPath           = mediaPath;
            MediaName           = mediaName;
            MediaType           = type;
            _mediaStoppedAction = mediaStoppedAction;
            BufferProgress      = bufferProgress;
            BandwidthRate       = bandwidthRate;
            ShowSubtitleButton  = MediaType != MediaType.Trailer;
            Volume           = 1d;
            _playingProgress = playingProgress;
            _subtitles       = new ObservableCollection <Subtitle>();
            if (subtitles != null)
            {
                _subtitles = new ObservableCollection <Subtitle>(subtitles);
            }

            if (currentSubtitle != null && currentSubtitle.LanguageName !=
                LocalizationProviderHelper.GetLocalizedValue <string>("NoneLabel") &&
                !string.IsNullOrEmpty(currentSubtitle.FilePath))
            {
                CurrentSubtitle = currentSubtitle;
            }
        }
 /// <summary>
 /// Initializes a new instance of the RecommendationsMovieTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="movieService">Movie service</param>
 /// <param name="userService">Movie history service</param>
 public RecommendationsMovieTabViewModel(IApplicationService applicationService, IMovieService movieService,
                                         IUserService userService)
     : base(applicationService, movieService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("RecommendationsTitleTab"))
 {
     SortBy = "seeds";
 }
 /// <summary>
 /// Initializes a new instance of the PopularShowTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="showService">Show service</param>
 public PopularShowTabViewModel(IApplicationService applicationService, IShowService showService)
     : base(applicationService, showService)
 {
     RegisterMessages();
     RegisterCommands();
     TabName = LocalizationProviderHelper.GetLocalizedValue <string>("PopularShowTitleTab");
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the GreatestMovieTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="movieService">Movie service</param>
 /// <param name="userService">Movie history service</param>
 public GreatestMovieTabViewModel(IApplicationService applicationService, IMovieService movieService,
                                  IUserService userService)
     : base(applicationService, movieService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("GreatestTitleTab"))
 {
     SortBy = "download_count";
 }
 /// <summary>
 /// Initializes a new instance of the UpdatedShowTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="showService">Show service</param>
 /// <param name="userService">The user service</param>
 public UpdatedShowTabViewModel(IApplicationService applicationService, IShowService showService,
                                IUserService userService)
     : base(applicationService, showService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("UpdatedTitleTab"))
 {
     SortBy = "date_added";
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the RecentShowTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="showService">Show service</param>
 /// <param name="userService">The user service</param>
 public RecentShowTabViewModel(IApplicationService applicationService, IShowService showService,
                               IUserService userService)
     : base(applicationService, showService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("RecentTitleTab"))
 {
     SortBy = "year";
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the PopularShowTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="showService">Show service</param>
 /// <param name="userService">The user service</param>
 public PopularShowTabViewModel(IApplicationService applicationService, IShowService showService,
                                IUserService userService)
     : base(applicationService, showService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("PopularTitleTab"))
 {
     SortBy = "watching";
 }
示例#11
0
        /// <summary>
        /// Register messages
        /// </summary>
        private void RegisterMessages()
        {
            Messenger.Default.Register <ChangeLanguageMessage>(
                this,
                language => TabName = LocalizationProviderHelper.GetLocalizedValue <string>("FavoritesTitleTab"));

            Messenger.Default.Register <ChangeFavoriteMovieMessage>(
                this,
                async message =>
            {
                StopLoadingMovies();
                await LoadMoviesAsync();
            });

            Messenger.Default.Register <PropertyChangedMessage <GenreJson> >(this, async e =>
            {
                if (e.PropertyName != GetPropertyName(() => Genre) && Genre.Equals(e.NewValue))
                {
                    return;
                }
                StopLoadingMovies();
                await LoadMoviesAsync();
            });

            Messenger.Default.Register <PropertyChangedMessage <double> >(this, async e =>
            {
                if (e.PropertyName != GetPropertyName(() => Rating) && Rating.Equals(e.NewValue))
                {
                    return;
                }
                StopLoadingMovies();
                await LoadMoviesAsync();
            });
        }
        /// <summary>
        /// Load the movie's subtitles asynchronously
        /// </summary>
        /// <param name="movie">The movie</param>
        private async Task LoadSubtitles(MovieJson movie)
        {
            Logger.Debug(
                $"Load subtitles for movie: {movie.Title}");
            Movie            = movie;
            LoadingSubtitles = true;
            await Task.Run(() =>
            {
                try
                {
                    var languages = _subtitlesService.GetSubLanguages().ToList();

                    var imdbId = 0;
                    if (int.TryParse(new string(movie.ImdbCode
                                                .SkipWhile(x => !char.IsDigit(x))
                                                .TakeWhile(char.IsDigit)
                                                .ToArray()), out imdbId))
                    {
                        var subtitles = _subtitlesService.SearchSubtitlesFromImdb(
                            languages.Select(lang => lang.SubLanguageID).Aggregate((a, b) => a + "," + b),
                            imdbId.ToString());
                        DispatcherHelper.CheckBeginInvokeOnUI(() =>
                        {
                            movie.AvailableSubtitles =
                                new ObservableCollection <Subtitle>(subtitles.OrderBy(a => a.LanguageName)
                                                                    .Select(sub => new Subtitle
                            {
                                Sub = sub
                            }).GroupBy(x => x.Sub.LanguageName,
                                       (k, g) =>
                                       g.Aggregate(
                                           (a, x) =>
                                           (Convert.ToDouble(x.Sub.Rating, CultureInfo.InvariantCulture) >=
                                            Convert.ToDouble(a.Sub.Rating, CultureInfo.InvariantCulture))
                                                        ? x
                                                        : a)));
                            movie.AvailableSubtitles.Insert(0, new Subtitle
                            {
                                Sub = new OSDBnet.Subtitle
                                {
                                    LanguageName = LocalizationProviderHelper.GetLocalizedValue <string>("NoneLabel")
                                }
                            });

                            movie.SelectedSubtitle = movie.AvailableSubtitles.FirstOrDefault();
                            LoadingSubtitles       = false;
                        });
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(
                        $"Failed loading subtitles for : {movie.Title}. {ex.Message}");
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        LoadingSubtitles = false;
                    });
                }
            });
        }
示例#13
0
        /// <summary>
        /// Register messages
        /// </summary>
        private void RegisterMessages()
        {
            Messenger.Default.Register <ChangeLanguageMessage>(
                this,
                language => { TabName = LocalizationProviderHelper.GetLocalizedValue <string>("SearchTitleTab"); });

            Messenger.Default.Register <PropertyChangedMessage <MovieGenre> >(this, async e =>
            {
                if (e.PropertyName != GetPropertyName(() => Genre) && Genre.Equals(e.NewValue))
                {
                    return;
                }
                StopLoadingMovies();
                Page = 0;
                Movies.Clear();
                await SearchMoviesAsync(SearchFilter);
            });

            Messenger.Default.Register <PropertyChangedMessage <double> >(this, async e =>
            {
                if (e.PropertyName != GetPropertyName(() => Rating) && Rating.Equals(e.NewValue))
                {
                    return;
                }
                StopLoadingMovies();
                Page = 0;
                Movies.Clear();
                await SearchMoviesAsync(SearchFilter);
            });
        }
示例#14
0
        private async Task LoadChromecasts()
        {
            try
            {
                LoadingChromecasts = true;
                var ip = LocalIPAddress().ToString();
                var foundChromecasts = await _chromecastService.StartLocatingDevices(ip);

                foreach (var foundChromecast in foundChromecasts)
                {
                    Chromecasts.Add(foundChromecast);
                }

                LoadingChromecasts = false;
                AnyChromecast      = Chromecasts.Any();
            }
            catch (Exception ex)
            {
                LoadingChromecasts = false;
                AnyChromecast      = false;
                Logger.Error(ex);
                Messenger.Default.Send(
                    new UnhandledExceptionMessage(
                        new PopcornException(LocalizationProviderHelper.GetLocalizedValue <string>("CastFailed"))));
                CancelCommand.Execute(null);
                CloseCommand.Execute(null);
            }
        }
示例#15
0
        /// <summary>
        /// Create an instance of <see cref="PagesViewModel"/>
        /// </summary>
        /// <param name="applicationSettingsViewModel">Application settings</param>
        /// <param name="aboutViewModel">About</param>
        /// <param name="helpViewModel">Help</param>
        public SettingsPageViewModel(ApplicationSettingsViewModel applicationSettingsViewModel, AboutViewModel aboutViewModel, HelpViewModel helpViewModel)
        {
            applicationSettingsViewModel.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("OptionsLabel");
            aboutViewModel.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("AboutLabel");
            helpViewModel.Caption  = LocalizationProviderHelper.GetLocalizedValue <string>("HelpLabel");
            Pages = new ObservableCollection <IPageViewModel>
            {
                applicationSettingsViewModel,
                aboutViewModel,
                helpViewModel
            };

            Messenger.Default.Register <ChangeLanguageMessage>(
                this,
                message =>
            {
                foreach (var page in Pages)
                {
                    if (page is ApplicationSettingsViewModel)
                    {
                        page.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("OptionsLabel");
                    }
                    else if (page is AboutViewModel)
                    {
                        page.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("AboutLabel");
                    }
                    else if (page is HelpViewModel)
                    {
                        page.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("HelpLabel");
                    }
                }
            });
        }
示例#16
0
 private async Task <object> OnFileServerError(object message)
 {
     Logger.Error(message.ToString);
     Messenger.Default.Send(
         new UnhandledExceptionMessage(
             new PopcornException(LocalizationProviderHelper.GetLocalizedValue <string>("CastFailed"))));
     return(await Task.FromResult <object>(null));
 }
 /// <summary>
 /// Initializes a new instance of the SearchTabViewModel class.
 /// </summary>
 public SearchTabViewModel()
 {
     RegisterMessages();
     RegisterCommands();
     CancellationSearchToken = new CancellationTokenSource();
     TabName = LocalizationProviderHelper.GetLocalizedValue <string>("SearchTitleTab");
     LastPageFilterMapping = new Dictionary <string, int>();
 }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the PopularMovieTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="movieService">Movie service</param>
 /// <param name="movieHistoryService">Movie history service</param>
 public PopularMovieTabViewModel(IApplicationService applicationService, IMovieService movieService,
                                 IMovieHistoryService movieHistoryService)
     : base(applicationService, movieService, movieHistoryService)
 {
     RegisterMessages();
     RegisterCommands();
     TabName = LocalizationProviderHelper.GetLocalizedValue <string>("PopularMovieTitleTab");
     Movies  = new ObservableCollection <MovieJson>();
 }
示例#19
0
        /// <summary>
        /// On player length changed, make sure player have enough space to show fully
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnLengthChanged(object sender, EventArgs e)
        {
            await semaphoreSlim.WaitAsync();

            try
            {
                if (_isPlayerFullyInitialised)
                {
                    return;
                }

                _isPlayerFullyInitialised = true;
                Player.Visibility         = Visibility.Hidden;

                bool wasMaximized = false;
                var  watcher      = new Stopwatch();
                watcher.Start();
                while (Player.ActualHeight < 1d)
                {
                    if (Application.Current.MainWindow.WindowState != WindowState.Maximized)
                    {
                        Application.Current.MainWindow.Width -= 0.1d;
                    }
                    else
                    {
                        wasMaximized = true;
                        Application.Current.MainWindow.WindowState = WindowState.Normal;
                        Application.Current.MainWindow.Width      -= 0.1d;
                    }

                    await Task.Delay(100);

                    // Check if we are waiting for more than 2 seconds for the player to initialize. If so, something weird happen, so break the loop
                    if (watcher.ElapsedMilliseconds > 2000)
                    {
                        watcher.Stop();
                        Messenger.Default.Send(
                            new ManageExceptionMessage(
                                new Exception(
                                    LocalizationProviderHelper.GetLocalizedValue <string>("TrailerNotAvailable"))));
                        Messenger.Default.Send(new StopPlayingTrailerMessage());
                        break;
                    }
                }

                if (wasMaximized)
                {
                    Application.Current.MainWindow.WindowState = WindowState.Maximized;
                }

                Player.Visibility = Visibility.Visible;
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
示例#20
0
 /// <summary>
 /// When an unhandled exception domain has been thrown, handle it
 /// </summary>
 /// <param name="sender"><see cref="App"/> instance</param>
 /// <param name="e">UnhandledExceptionEventArgs args</param>
 private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     if (e.ExceptionObject is Exception ex)
     {
         Logger.Fatal(ex);
         Messenger.Default.Send(
             new UnhandledExceptionMessage(
                 new PopcornException(LocalizationProviderHelper.GetLocalizedValue <string>("FatalError"))));
     }
 }
示例#21
0
        /// <summary>
        /// Display a dialog on unhandled exception
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = e.ExceptionObject as Exception;

            if (ex != null)
            {
                Logger.Fatal(ex);
                ManageException(new Exception(LocalizationProviderHelper.GetLocalizedValue <string>("FatalError")));
            }
        }
 /// <summary>
 /// Initializes a new instance of the FavoritesMovieTabViewModel class.
 /// </summary>
 /// <param name="applicationService">Application state</param>
 /// <param name="movieService">Movie service</param>
 /// <param name="userService">Movie history service</param>
 public FavoritesMovieTabViewModel(IApplicationService applicationService, IMovieService movieService,
                                   IUserService userService)
     : base(applicationService, movieService, userService,
            () => LocalizationProviderHelper.GetLocalizedValue <string>("FavoritesTitleTab"))
 {
     Messenger.Default.Register <ChangeFavoriteMovieMessage>(
         this,
         async message =>
     {
         await LoadMoviesAsync();
     });
 }
示例#23
0
 /// <summary>
 /// Create an instance of <see cref="PagesViewModel"/>
 /// </summary>
 /// <param name="moviePage">Movie page</param>
 /// <param name="animePage">Anime page</param>
 /// <param name="showPage">Show page</param>
 public PagesViewModel(MoviePageViewModel moviePage, AnimePageViewModel animePage, ShowPageViewModel showPage)
 {
     moviePage.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("MoviesLabel");
     animePage.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("AnimesLabel");
     showPage.Caption  = LocalizationProviderHelper.GetLocalizedValue <string>("ShowsLabel");
     Pages             = new ObservableCollection <IPageViewModel>
     {
         moviePage,
         showPage,
         animePage
     };
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double number = (double)value;
            double min    = 0;
            double max    = 100;

            // Get the value limits from parameter
            try
            {
                string[] limits = (parameter as string).Split(new char[] { '|' });
                min = double.Parse(limits[0], CultureInfo.InvariantCulture);
                max = double.Parse(limits[1], CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                throw new ArgumentException("Parameter not valid. Enter in format: 'MinDouble|MaxDouble'");
            }

            if (max <= min)
            {
                throw new ArgumentException("Parameter not valid. MaxDouble has to be greater then MinDouble.");
            }

            if (number >= min && number <= max)
            {
                if (number > 8)
                {
                    return(LocalizationProviderHelper.GetLocalizedValue <string>("VeryGoodLabel"));
                }

                if (number > 6)
                {
                    return(LocalizationProviderHelper.GetLocalizedValue <string>("GoodLabel"));
                }

                if (number > 4)
                {
                    return(LocalizationProviderHelper.GetLocalizedValue <string>("AverageLabel"));
                }

                if (number > 2)
                {
                    return(LocalizationProviderHelper.GetLocalizedValue <string>("BadLabel"));
                }

                if (number >= 0)
                {
                    return(LocalizationProviderHelper.GetLocalizedValue <string>("VeryBadLabel"));
                }
            }

            return(LocalizationProviderHelper.GetLocalizedValue <string>("UnknownLabel"));
        }
示例#25
0
        /// <summary>
        /// Load movie's trailer asynchronously
        /// </summary>
        /// <param name="movie">The movie</param>
        /// <param name="ct">Cancellation token</param>
        public async Task LoadTrailerAsync(MovieJson movie, CancellationToken ct)
        {
            try
            {
                var trailer = await _movieService.GetMovieTrailerAsync(movie, ct);

                var trailerUrl = await _movieService.GetVideoTrailerUrlAsync(trailer.Results.FirstOrDefault()?.Key, ct);

                if (string.IsNullOrEmpty(trailerUrl))
                {
                    Logger.Error(
                        $"Failed loading movie's trailer: {movie.Title}");
                    Messenger.Default.Send(
                        new ManageExceptionMessage(
                            new Exception(
                                LocalizationProviderHelper.GetLocalizedValue <string>("TrailerNotAvailable"))));
                    Messenger.Default.Send(new StopPlayingTrailerMessage());
                    return;
                }

                if (!ct.IsCancellationRequested)
                {
                    Logger.Debug(
                        $"Movie's trailer loaded: {movie.Title}");
                    Messenger.Default.Send(new PlayTrailerMessage(trailerUrl, movie.Title, () =>
                    {
                        Messenger.Default.Send(new StopPlayingTrailerMessage());
                    },
                                                                  () =>
                    {
                        Messenger.Default.Send(new StopPlayingTrailerMessage());
                    }));
                }
            }
            catch (Exception exception) when(exception is TaskCanceledException)
            {
                Logger.Debug(
                    "GetMovieTrailerAsync cancelled.");
                Messenger.Default.Send(new StopPlayingTrailerMessage());
            }
            catch (Exception exception)
            {
                Logger.Error(
                    $"GetMovieTrailerAsync: {exception.Message}");
                Messenger.Default.Send(
                    new ManageExceptionMessage(
                        new Exception(
                            LocalizationProviderHelper.GetLocalizedValue <string>(
                                "TrailerNotAvailable"))));
                Messenger.Default.Send(new StopPlayingTrailerMessage());
            }
        }
示例#26
0
        /// <summary>
        /// Register messages
        /// </summary>
        private void RegisterMessages()
        {
            Messenger.Default.Register <ChangeLanguageMessage>(
                this,
                language => { TabName = LocalizationProviderHelper.GetLocalizedValue <string>("FavoritesTitleTab"); });

            Messenger.Default.Register <ChangeFavoriteMovieMessage>(
                this,
                async message =>
            {
                await LoadMoviesAsync();
            });
        }
示例#27
0
        private async Task SyncUser()
        {
            User = new Models.User.User();
            try
            {
                var user = await BlobCache.UserAccount.GetObject <Models.User.User>("user");

                if (user != null)
                {
                    User = user;
                }
            }
            catch (Exception)
            {
            }

            if (User.Language == null)
            {
                User.Language = new Language();
            }

            if (User.MovieHistory == null)
            {
                User.MovieHistory = new List <MovieHistory>();
            }

            if (User.ShowHistory == null)
            {
                User.ShowHistory = new List <ShowHistory>();
            }

            if (User.CacheLocation == null)
            {
                User.CacheLocation = Path.GetTempPath() + @"Popcorn";
            }

            if (User.DefaultSubtitleSize == null)
            {
                User.DefaultSubtitleSize = new SubtitleSize
                {
                    Size  = 26,
                    Label = LocalizationProviderHelper.GetLocalizedValue <string>("Normal")
                };
            }

            if (string.IsNullOrEmpty(User.DefaultSubtitleColor))
            {
                User.DefaultSubtitleColor = "#FFFFFF";
            }
        }
示例#28
0
        /// <summary>
        /// Load movie's trailer asynchronously
        /// </summary>
        /// <param name="show">The show</param>
        /// <param name="ct">Cancellation token</param>
        public async Task LoadTrailerAsync(ShowJson show, CancellationToken ct)
        {
            try
            {
                var trailer = await ShowService.GetShowTrailerAsync(show, ct);

                if (!ct.IsCancellationRequested && string.IsNullOrEmpty(trailer))
                {
                    Logger.Error(
                        $"Failed loading show's trailer: {show.Title}");
                    Messenger.Default.Send(
                        new ManageExceptionMessage(
                            new PopcornException(
                                LocalizationProviderHelper.GetLocalizedValue <string>("TrailerNotAvailable"))));
                    Messenger.Default.Send(new StopPlayingTrailerMessage(Utils.MediaType.Show));
                    return;
                }

                if (!ct.IsCancellationRequested)
                {
                    Logger.Debug(
                        $"Show's trailer loaded: {show.Title}");
                    Messenger.Default.Send(new PlayTrailerMessage(trailer, show.Title, () =>
                    {
                        Messenger.Default.Send(new StopPlayingTrailerMessage(Utils.MediaType.Show));
                    },
                                                                  () =>
                    {
                        Messenger.Default.Send(new StopPlayingTrailerMessage(Utils.MediaType.Show));
                    }, Utils.MediaType.Show));
                }
            }
            catch (Exception exception) when(exception is TaskCanceledException)
            {
                Logger.Debug(
                    "LoadTrailerAsync cancelled.");
                Messenger.Default.Send(new StopPlayingTrailerMessage(Utils.MediaType.Show));
            }
            catch (Exception exception)
            {
                Logger.Error(
                    $"LoadTrailerAsync: {exception.Message}");
                Messenger.Default.Send(
                    new ManageExceptionMessage(
                        new PopcornException(
                            LocalizationProviderHelper.GetLocalizedValue <string>(
                                "TrailerNotAvailable"))));
                Messenger.Default.Send(new StopPlayingTrailerMessage(Utils.MediaType.Show));
            }
        }
 /// <summary>
 /// Display download progress
 /// </summary>
 private void DisplayDownloadProgress()
 {
     if (DownloadProgress >= 2.0)
     {
         DisplayText.Text =
             $"{LocalizationProviderHelper.GetLocalizedValue<string>("CurrentlyPlayingLabel")} : {MovieTitle}";
     }
     else
     {
         DisplayText.Text = DownloadRate >= 1000.0
             ? $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(DownloadProgress*50.0, 0)} % ({DownloadRate/1000.0} MB/s)"
             : $"{LocalizationProviderHelper.GetLocalizedValue<string>("BufferingLabel")} : {Math.Round(DownloadProgress*50.0, 0)} % ({DownloadRate} kB/s)";
     }
 }
示例#30
0
        /// <summary>
        /// Register commands
        /// </summary>
        /// <returns></returns>
        private void RegisterCommands()
        {
            SetFavoriteMovieCommand =
                new RelayCommand <MovieShort>(async movie =>
            {
                await MovieHistoryService.SetFavoriteMovieAsync(movie);
                Messenger.Default.Send(new ChangeFavoriteMovieMessage());
            });

            ChangeMovieGenreCommand =
                new RelayCommand <MovieGenre>(genre => Genre = genre.TmdbGenre.Name ==
                                                               LocalizationProviderHelper.GetLocalizedValue <string>(
                                                  "AllLabel")
                    ? null
                    : genre);
        }