示例#1
0
        private async void SearchForBeers(object sender, EventArgs e)
        {
            UserDialogs.Instance.ShowLoading("Searching");
            var response = await indexClient.Documents.SearchAsync <BeerDrinkin.Models.IndexedBeer>(searchBar.Text);

            var beers = new List <BeerItem>();

            foreach (var result in response)
            {
                var beerResult = result.Document;
                if (beerResult != null)
                {
                    var beer = new BeerItem
                    {
                        ABV         = beerResult.Abv,
                        Name        = beerResult.Name,
                        Brewery     = beerResult.BreweryName,
                        Description = beerResult.Description,
                        BreweryDbId = beerResult.Id,
                        BreweryId   = beerResult.BreweryId,
                        Upc         = beerResult.Upc
                    };
                    try
                    {
                        if (beerResult.Images != null || beerResult.Images[0] != null)
                        {
                            beer.ImageLarge  = beerResult.Images[0];
                            beer.ImageMedium = beerResult.Images[1];
                            beer.ImageSmall  = beerResult.Images[2];
                        }
                    }
                    catch (Exception ex)
                    {
                        Insights.Report(ex);
                    }
                    beers.Add(beer);
                }
            }
            var source = new SearchDataSource(beers);

            source.DidSelectBeer += (beer) =>
            {
                selectedBeer = beer;
                PerformSegue("beerDescriptionSegue", this);
                searchResultsTableView.DeselectRow(placeHolderTableView.IndexPathForSelectedRow, true);
            };

            searchResultsTableView.Source = source;
            searchResultsTableView.ReloadData();
            View.BringSubviewToFront(searchResultsTableView);
            UserDialogs.Instance.HideLoading();
        }
示例#2
0
        private void DisplayBeers(List <BeerItem> beers)
        {
            DataSource = new SearchDataSource(beers);
            DataSource.DidSelectBeer += delegate
            {
                PerformSegue("beerDescriptionSegue", this);
                placeHolderTableView.DeselectRow(placeHolderTableView.IndexPathForSelectedRow, true);
            };

            placeHolderTableView.Source = DataSource;
            placeHolderTableView.ReloadData();

            View.BringSubviewToFront(placeHolderTableView);
            UserDialogs.Instance.HideLoading();
        }
        private void DisplayBeers(List<BeerItem> beers)
        {
            DataSource = new SearchDataSource(beers);
            DataSource.DidSelectBeer += delegate
            {
                PerformSegue("beerDescriptionSegue", this);
                    placeHolderTableView.DeselectRow(placeHolderTableView.IndexPathForSelectedRow, true);
            };

            placeHolderTableView.Source = DataSource;
            placeHolderTableView.ReloadData();

            View.BringSubviewToFront(placeHolderTableView);
            UserDialogs.Instance.HideLoading();
        }
 private async void SearchForBeers (object sender, EventArgs e)
 {
     UserDialogs.Instance.ShowLoading("Searching");
     var response = await indexClient.Documents.SearchAsync<BeerDrinkin.Models.IndexedBeer>(searchBar.Text);             
     var beers = new List<BeerItem>();
     foreach(var result in response)
     {
         var beerResult = result.Document; 
         if (beerResult != null)
         {
             var beer = new BeerItem
             {
                 ABV = beerResult.Abv,
                 Name = beerResult.Name,
                 Brewery = beerResult.BreweryName,
                 Description = beerResult.Description,
                 BreweryDbId = beerResult.Id,
                 BreweryId = beerResult.BreweryId,
                 Upc = beerResult.Upc
             };
             try
             {
                 if(beerResult.Images != null || beerResult.Images[0] != null)
                 {
                     beer.ImageLarge = beerResult.Images[0];
                     beer.ImageMedium = beerResult.Images[1];
                     beer.ImageSmall = beerResult.Images[2];
                 }
             }
             catch(Exception ex)
             {
                 Insights.Report(ex);
             }
             beers.Add(beer);
         }
     }
     var source = new SearchDataSource(beers);
     source.DidSelectBeer += (beer) => 
     {
         selectedBeer = beer;
         PerformSegue("beerDescriptionSegue", this);
         searchResultsTableView.DeselectRow(placeHolderTableView.IndexPathForSelectedRow, true);
     };
     
     searchResultsTableView.Source = source;
     searchResultsTableView.ReloadData();
     View.BringSubviewToFront(searchResultsTableView);
     UserDialogs.Instance.HideLoading();
 }       
        public void SetupEvents()
        {
            searchBar.TextChanged += SearchBarTextChanged;           

            searchBar.SearchButtonClicked += async delegate
            {
                UserDialogs.Instance.ShowLoading("Searching");
                await viewModel.SearchForBeersCommand(searchBar.Text);
            };

            viewModel.Beers.CollectionChanged += delegate
            {
                datasource = new SearchDataSource(viewModel.Beers.ToList());
                datasource.DidSelectBeer += delegate
                {
                    PerformSegue("beerDescriptionSegue", this);
                    tableView.DeselectRow(tableView.IndexPathForSelectedRow, true);
                };

                tableView.Source = datasource;
                tableView.ReloadData();

                datasource.CheckInBeer += async (beer, index) =>
                {
                    var result = await viewModel.QuickCheckIn(beer);
                    var cell = tableView.CellAt(index) as SearchBeerTableViewCell;
                    if (cell != null)
                        cell.isCheckedIn = result;
                };

                UserDialogs.Instance.HideLoading();

                View.BringSubviewToFront(tableView);
                searchBar.ResignFirstResponder();
            };
        }