Esempio n. 1
0
        private void Bind()
        {
            overview.Text      = viewModel.Overview;
            originalTitle.Text = viewModel.OriginalTitle;
            releaseDate.Text   = viewModel.ReleaseDate;
            rating.Rating      = viewModel.Rating;
            votes.Text         = viewModel.Votes;
            favorite.Text      = viewModel.FavoriteButtonText;
            similarManager     = new LinearLayoutManager(Activity, LinearLayoutManager.Horizontal, false);
            similar.SetLayoutManager(similarManager);
            similarAdapter = new ItemAdapter(viewModel.GetCachedItems());
            similar.SetAdapter(similarAdapter);
            var similarScrollListener = new ItemAdapterScollListener(similarManager);

            similarScrollListener.LoadMore += async delegate()
            {
                if (!viewModel.CanLoadMoreSimilar())
                {
                    return;
                }
                await viewModel.GetSimilar().ConfigureAwait(false);
            };
            similar.AddOnScrollListener(similarScrollListener);

            favorite.Click += delegate
            {
                //quick and dirty, need to use canexecute on command
                if (uiBusy)
                {
                    return;
                }
                uiBusy = true;
                viewModel.ToggleFavorite();
                uiBusy = false;
            };

            play.Click += delegate
            {
                if (uiBusy)
                {
                    return;
                }
                uiBusy = true;
                viewModel.PlayVideo();
                uiBusy = false;
            };

            Task.Run(async() =>
            {
                var url    = await Locator.Get <IApiService>().GetImageUrl(viewModel.PosterPath).ConfigureAwait(false);
                var bitmap = Locator.Get <IImageService>().LoadImage(url);
                Locator.Get <IUIDispatcher>().RunOnUiThread(() =>
                {
                    poster.SetImageBitmap(bitmap);
                    bitmap.Dispose();
                    bitmap = null;
                });
            });
        }