public MovieByTitlePage()
        {
            InitializeComponent();
            if (viewModel == null)
            {
                viewModel        = new OMBdByTitleViewModel();
                viewModel.Title  = "Search something...";
                ImgPoster.Source = "iconMI.png";
            }

            if (viewModel.Ratings != null)
            {
                LsvOMDb.HeightRequest = (viewModel.Ratings.Count * 45);
            }

            waitLayout.IsVisible  = false;
            waitLayout2.IsVisible = false;
            this.BindingContext   = viewModel;
            WebYoutube.Source     = "";
        }
        private async Task GetMovieList()
        {
            try
            {
                var movie = await OMBdService.GetMovieByTitle(edtMovieTitle.Text);

                if (movie != null)
                {
                    viewModel           = movie;
                    this.BindingContext = viewModel;
                    if (viewModel.Poster == null)
                    {
                        ImgPoster.Source = "iconMI.png";
                    }
                    else
                    {
                        ImgPoster.Source = viewModel.Poster;
                    }
                    if (viewModel.Ratings != null)
                    {
                        LsvOMDb.HeightRequest = (viewModel.Ratings.Count * 45);
                    }
                }
                else
                {
                    viewModel           = new OMBdByTitleViewModel();
                    viewModel.Title     = "No results...";
                    this.BindingContext = viewModel;
                    ImgPoster.Source    = "iconMI.png";
                }
            }
            catch (Exception)
            {
                viewModel           = new OMBdByTitleViewModel();
                viewModel.Title     = "Check your internet connection...";
                this.BindingContext = viewModel;
                ImgPoster.Source    = "iconMI.png";
            }
            waitLayout.IsVisible = false;
        }
Example #3
0
        public static async Task <OMBdByTitleViewModel> GetMovieByTitle(string title)
        {
            if (title == null)
            {
                return(null);
            }

            var url = ENDPOINT_URL + "?t=" + title + API_KEY;

            try
            {
                using (var webClient = new WebClient())
                {
                    var result = await Task.Run(() => webClient.DownloadString(new Uri(url)));

                    if (result == null)
                    {
                        return(null);
                    }
                    OMBdModel OMBdmovie = JsonConvert.DeserializeObject <OMBdModel>(result);

                    if (OMBdmovie.Type == "movie")
                    {
                        OMBdByTitleViewModel viewModel = new OMBdByTitleViewModel(OMBdmovie);
                        return(viewModel);
                    }
                    else
                    {
                        return(MovieNotFound());
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }