Пример #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            viewModel = new ImageSearchViewModel();

            //Setup RecyclerView
            adapter      = new ImageAdapter(this, viewModel);
            recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            recyclerView.SetAdapter(adapter);
            layoutManager = new GridLayoutManager(this, 2);
            recyclerView.SetLayoutManager(layoutManager);

            progressBar            = FindViewById <ProgressBar>(Resource.Id.my_progress);
            progressBar.Visibility = ViewStates.Gone;

            var query = FindViewById <EditText>(Resource.Id.my_query);

            var clickButton = FindViewById <Button>(Resource.Id.my_button);

            clickButton.Click += async(sender, e) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;
                await viewModel.SearchForImagesAsync(query.Text.Trim());

                clickButton.Enabled    = true;
                progressBar.Visibility = ViewStates.Gone;
            };

//DEMO: 2b - Image Analysis
            //Button Click event to get images
            adapter.ItemClick += async(object sender, ImageAdapterClickEventArgs e) =>
            {
                clickButton.Enabled    = false;
                progressBar.Visibility = ViewStates.Visible;

                var result = await viewModel.GetImageDescription(viewModel.Images[e.Position].ImageLink);

                new AlertDialog.Builder(this)
                .SetTitle("Image Analysis")
                .SetMessage(result)
                .SetNeutralButton("OK", delegate { })
                .Show();

                progressBar.Visibility = ViewStates.Gone;
                clickButton.Enabled    = true;
            };

            UserDialogs.Init(this);

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
        public async void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            ActivityIsLoading.StartAnimating();

            string description = await viewModel.GetImageDescription(viewModel.Images[indexPath.Row].ImageLink);

            var resultAlert = UIAlertController.Create("Image Analysis", description, UIAlertControllerStyle.Alert);

            resultAlert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

            PresentViewController(resultAlert, true, null);

            ActivityIsLoading.StopAnimating();
        }