예제 #1
0
 /// <summary>
 /// Creates the db.
 /// </summary>
 void CreateDB()
 {
     try
     {
         App.AppSQLiteConnection.CreateTable <Dates>(SQLite.CreateFlags.None);
         App.AppSQLiteConnection.CreateTable <Results>(SQLite.CreateFlags.None);
         App.AppSQLiteConnection.CreateTable <Images>(SQLite.CreateFlags.None);
         App.AppSQLiteConnection.CreateTable <Genres>(SQLite.CreateFlags.None);
     }
     catch
     {
         mobileCeterCrashesService.AskBeforeSendCrashReport();
         uiFunctionsService.ShowToast(Constants.CreateDatabaseErrorMessage, ToastType.Error, 8000);
     }
 }
        /// <summary>
        /// Does the search movie.
        /// </summary>
        /// <returns>The search movie.</returns>
        /// <param name="letter">Letter.</param>
        async Task DoSearchMovie(string letter)
        {
            if (string.IsNullOrEmpty(letter))
            {
                GetLocalMovieList();
                return;
            }

            var sorted = resultsService.GetAll().Where(x => x.OriginalTitle.ToLowerInvariant().Contains(letter.ToLowerInvariant()))
                         .ToList();

            try
            {
                if (sorted == null || !sorted.Any())
                {
                    sorted = await resultsService
                             .GetAllRemoteData(APIOperations.SearchMovieURLAddres, ConfigureParameters(APIOperations.SearchMovieURLAddres, 1, letter));

                    sorted = AddImageLinkAndRemoveRepeated(sorted);
                }

                Movies = new ObservableCollection <Results>(sorted);
            }
            catch (ConnectionException)
            {
                uiFunctionsService.HideLoading();
                uiFunctionsService.ShowToast(Constants.OfflineMessage, ToastType.Info, 8000);
            }
            catch (FetchRemoteDataException)
            {
                uiFunctionsService.ShowToast(Constants.GetOnlineDataErrorMessage, ToastType.Error, 8000);
                GetLocalMovieList();
            }
            catch
            {
                mobileCenterCrashesService.AskBeforeSendCrashReport();
                uiFunctionsService.ShowToast(Constants.GeneralErrorMessage, ToastType.Warning, 8000);
                GetLocalMovieList();
            }
            finally
            {
                analyticsFunctionsService.TrackEvent(AnalitycsEventsName.SearchMovie,
                                                     new Dictionary <string, string> {
                    { letter, sorted.Count.ToString() }
                });
            }
        }
        /// <summary>
        /// Associates the genres with movies.
        /// </summary>
        /// <param name="movies">Movies.</param>
        public List <Results> AssociateGenresWithMovies(List <Results> movies)
        {
            try
            {
                for (int i = 0; i < movies.Count; i++)
                {
                    if (movies[i].Genres == null || movies[i].Genres.Count == 0)
                    {
                        movies[i].Genres = new List <Genres>();
                    }

                    for (int j = 0; j < movies[i].GenresIds.Count; j++)
                    {
                        if (movies[i].GenresIds[j] <= 0)
                        {
                            continue;
                        }

                        var genre = App.AppSQLiteConnection.Get <Genres>(movies[i].GenresIds[j]);

                        if (genre == null)
                        {
                            movies[i].Genres.Add(new Genres {
                                Id = 999, Name = "Undefined"
                            });
                        }
                        else
                        {
                            movies[i].Genres.Add(genre as Genres);
                        }
                    }
                }

                return(movies);
            }
            catch
            {
                mobileCeterCrashesService.AskBeforeSendCrashReport();
                uiFunctionsService.ShowToast(Constants.AssocieateGenreAndMovieErrorMessage, ToastType.Warning, 3000);
                return(new List <Results>());
            }
        }
        public void OnNavigatingTo(NavigationParameters parameters)
        {
            uiFunctionsService.ShowLoading("MessageLoadingMovieDetails");

            try
            {
                if (parameters.ContainsKey("MOVIE"))
                {
                    Movie = parameters["MOVIE"] as Results;
                }
            }
            catch
            {
                mobileCenterCrashesService.AskBeforeSendCrashReport();
                uiFunctionsService.ShowToast(Constants.LoadingMovieDetailsErrorMessage, ToastType.Warning, 8000);
                _navigationService.GoBackAsync();
            }

            uiFunctionsService.HideLoading();
        }