Пример #1
0
        public ImageAdapter(Activity activity, ImageSearchViewModel viewModel)
        {
            this.viewModel = viewModel;
            this.activity = activity;

            this.viewModel.Images.CollectionChanged += (sender, args) =>
            {
                this.activity.RunOnUiThread(NotifyDataSetChanged);
            };
        }
Пример #2
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);

            // Get our button from the layout resource,
            // and attach an event to it
            var clickButton = FindViewById<Button>(Resource.Id.my_button);

            //Button Click event to get images

            clickButton.Click += async (sender, args) =>
            {
                clickButton.Enabled = false;
                progressBar.Visibility = ViewStates.Visible;

                await viewModel.SearchForImagesAsync(query.Text.Trim());

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

            UserDialogs.Init(this);
            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
Пример #3
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
            viewModel = new ImageSearchViewModel();

            CollectionViewImages.WeakDataSource = this;

            //Button Click event to get images

            ButtonSearch.TouchUpInside += async (sender, args) =>
            {
                ButtonSearch.Enabled = false;
                ActivityIsLoading.StartAnimating();

                await viewModel.SearchForImagesAsync(TextFieldQuery.Text);
                CollectionViewImages.ReloadData();

                ButtonSearch.Enabled = true;
                ActivityIsLoading.StopAnimating();
            };

        }