Ejemplo n.º 1
0
        private UIButton NavigationButton(UITextField nameField, ApiSearchResponse <MovieInfo> response, ImageDownloader downloader, UIActivityIndicatorView activitySpinner)
        {
            var navigateButton = UIButton.FromType(UIButtonType.RoundedRect);

            navigateButton.Frame = new CoreGraphics.CGRect(margin, spaceBetween * 3, this.View.Bounds.Width - (margin * 2), 50);
            navigateButton.SetTitle("See Movie list", UIControlState.Normal);

            navigateButton.TouchUpInside += async(sender, args) =>
            {
                activitySpinner.StartAnimating();
                nameField.ResignFirstResponder();
                response = await _movieApi.SearchByTitleAsync(nameField.Text); //Nær í allar upplýsingar tengdum myndunu

                MovieCredit[] credits = new MovieCredit[response.Results.Count];
                for (int i = 0; i < response.Results.Count; i++)
                {
                    var credit = await _movieApi.GetCreditsAsync(response.Results[i].Id, "en");

                    credits[i] = credit.Item;
                }

                var task = downloader.DownloadImagesFromResponces(response); //Download'ar öllum pósterum

                await task;

                activitySpinner.StopAnimating();
                this.NavigationController.PushViewController(new MovieListController(response, downloader, _movieApi, credits), true);
            };
            return(navigateButton);
        }
        public override async void ViewDidLoad()
        {
            StorageClient imageStorage = new StorageClient();

            downloader = new ImageDownloader(imageStorage);



            base.ViewDidLoad();
            this.Title = "Top Rated";

            UIActivityIndicatorView activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray);

            activitySpinner.Frame            = new CoreGraphics.CGRect(this.View.Bounds.Width / 2, 0, 24, 24);
            activitySpinner.HidesWhenStopped = true;
            this.View.AddSubview(activitySpinner);

            activitySpinner.StartAnimating();
            response = await _movieApi.GetTopRatedAsync();

            credits = new MovieCredit[response.Results.Count];
            for (int i = 0; i < response.Results.Count; i++)
            {
                var credit = await _movieApi.GetCreditsAsync(response.Results[i].Id, "en");

                credits[i] = credit.Item;
            }


            var task = downloader.DownloadImagesFromResponces(response); //Download'ar öllum pósterum

            await task;

            activitySpinner.StopAnimating();
            this.TableView.ReloadData();

            this.TableView.Source = new MovieListDataSource(response, _onSelectedMovie, downloader, _movieApi, credits);
        }