public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            viewModel = new ImageSearchViewModel();

            CollectionViewImages.WeakDataSource = this;

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

                await viewModel.SearchForImagesAsync(TextFieldQuery.Text);

                CollectionViewImages.ReloadData();

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


            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Camera, async delegate
            {
                await viewModel.TakePhotoAndAnalyzeAsync(false);
            });
        }
        void SetupCamera()
        {
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(
                UIBarButtonSystemItem.Camera, async delegate
            {
                ButtonSearch.Enabled = false;
                ActivityIsLoading.StartAnimating();

                await viewModel.TakePhotoAndAnalyzeAsync(false);

                ButtonSearch.Enabled = true;
                ActivityIsLoading.StopAnimating();
            });
        }
Example #3
0
        void SetupCamera()
        {
            adapter.ItemClick += async(sender, args) =>
            {
                var image = viewModel.Images[args.Position].ThumbnailLink;
                await viewModel.AnalyzeImageAsync(image);
            };

            var fab = FindViewById <FloatingActionButton>(Resource.Id.fab_photo);

            fab.Visibility = ViewStates.Visible;

            fab.Click += async(sender, args) =>
            {
                fab.Enabled = false;
                await viewModel.TakePhotoAndAnalyzeAsync();

                fab.Enabled = true;
            };
        }
Example #4
0
        void SetupCamera()
        {
            adapter.ItemClick += async(sender, args) =>
            {
                var image = viewModel.Images[args.Position].ThumbnailLink;
                //var percentage = await viewModel.AnalyzeImageAsync(image);
                await viewModel.ShowImageMessage(ImageType, Percentage);
            };

            var fab = FindViewById <FloatingActionButton>(Resource.Id.fab_photo);

            fab.Visibility = ViewStates.Visible;

            fab.Click += async(sender, args) =>
            {
                //Get references to elements
                var progress           = FindViewById <ProgressBar>(Resource.Id.my_progress);
                var happinessLevelText = FindViewById <TextView>(Resource.Id.happiness_level_text);
                var helpCardText       = FindViewById <TextView>(Resource.Id.help_card_text);
                var helpCard           = FindViewById <CardView>(Resource.Id.help_card);

                //Hide startup and results elements
                fab.Enabled                   = false;
                fab.Visibility                = ViewStates.Gone;
                recyclerView.Visibility       = ViewStates.Gone;
                happinessLevelText.Visibility = ViewStates.Gone;

                //Show progress elements
                progress.Visibility     = ViewStates.Visible;
                helpCardText.Text       = "Analysing your happiness...";
                helpCardText.Visibility = ViewStates.Visible;
                helpCard.Visibility     = ViewStates.Visible;

                //Go to photo app then analyse over emotion api
                Percentage = await viewModel.TakePhotoAndAnalyzeAsync();

                //Change analysing text to results text
                var text = string.Format("You are {0}% happy! \nCute coming right up...", Percentage);
                helpCardText.Text = text;

                //Set the images to get
                SetImageType();

                //Search for the images
                await viewModel.SearchForImagesAsync(string.Format("cute {0}", ImageType.Trim()));

                //Set happiness level text
                happinessLevelText.Text = string.Format("You are {0}% happy as {1}", Percentage, ImageType);

                //Hide progress elements
                progress.Visibility     = ViewStates.Gone;
                helpCardText.Visibility = ViewStates.Gone;
                helpCard.Visibility     = ViewStates.Gone;

                //Show results and restart elements
                fab.Visibility = ViewStates.Visible;
                happinessLevelText.Visibility = ViewStates.Visible;
                recyclerView.Visibility       = ViewStates.Visible;
                fab.Enabled = true;
            };
        }
        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);


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

                await viewModel.SearchForImagesAsync(query.Text);

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

            var photo = FindViewById <Button>(Resource.Id.button1);

            photo.Click += async(sender, args) =>
            {
                await viewModel.TakePhotoAndAnalyzeAsync();
            };


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

                await viewModel.AnalyzeImageAsync(viewModel.Images[args.Position].ThumbnailLink);

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



            UserDialogs.Init(this);
            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }