private async void listViewItem_Clicked(object sender, SelectedItemChangedEventArgs e) { AnimatePanel(); /* * //This is only necessary if we want to make the items unselectable (so they don't remain highlighted) * if (e.SelectedItem == null) * { * return; //ItemSelected is called on deselection, which results in SelectedItem being set to null * } * ((ListView)sender).SelectedItem = null; */ Job jobSelected = (Job)((ListView)sender).SelectedItem; var productSelection = App.ProductsDb.SelectProducts(jobSelected); ProductViewModel productViewModel = new ProductViewModel(); foreach (ProductMatrix productMatrix in productSelection) { ProductDescription productDescription = App.ProductsDb.GetProductInfo(productMatrix); productViewModel.Products.Add(new ProductResult() { Job = jobSelected, Description = productDescription }); if (productViewModel.Products.Count > 0) { productViewModel.SelectedProduct = productViewModel.Products[0]; } } //Note: This is an ugly workaround to a problem within ProductPage.xaml.cs // • ProductPage.InitializeCarouselView() // That method gets the IndustryOption from App.xaml.cs which is set when the user goes through the // accordion page. Obviously, it does not work when we try to jump straight to the ProductPage. if (jobSelected.JobType == 0) { App.IndustryOption = IndustryOptions.Civil; ((NavigationPage)App.Current.MainPage).BarBackgroundColor = Color.FromHex("#18b750"); } else if (jobSelected.JobType == 1) { App.IndustryOption = IndustryOptions.Mining; ((NavigationPage)App.Current.MainPage).BarBackgroundColor = Color.FromHex("#079ece"); } await Navigation.PushAsync(new ProductPage(productViewModel)); }
public AccordionViewModel(INavigation navigation) { trafficPane = null; calendarPane = null; weatherPane = null; locationAreaPane = null; this.Calculate = new Command(async(nothing) => { if (!calculateTapped) { calculateTapped = true; // double check the inputs (length, width, location) if (!validateInputs()) { // terminate the process calculateTapped = false; return; } Job newJob = new Job() { Area = area, AreaTypeID = (int)App.TrafficOption, CreationDate = DateTime.Now, WillRain = (App.WeatherOption == WeatherOptions.RainExpected), JobType = (int)App.IndustryOption, DurationMaxDays = (int)App.DurationOption, Location = Location }; //quick and nasty fix for calc issue. page is still buggy. //job area will be saved as sq metre if (areaUnit == Units.Kilometre) { newJob.Area = newJob.Area * 1000000; } if (Settings.EnableAnalytics) { //Starts Analytics up AnalyticsClass.SetDetails(); //Send all needed data AnalyticsClass.SendAnalytics(App.IndustryOption.ToString(), "Traffic", App.TrafficOption.ToString(), "Calendar", App.DurationOption.ToString(), "Rain", App.WeatherOption.ToString(), "Location", Location); } App.JobsDb.DbConnection.Insert(newJob); ProductViewModel productViewModel = new ProductViewModel(); DbConnectionManager productsDB = App.ProductsDb; IEnumerable <ProductMatrix> productSelection = productsDB.SelectProducts((int)App.DurationOption, (int)App.TrafficOption, (App.WeatherOption == WeatherOptions.RainExpected)); foreach (ProductMatrix productMatrix in productSelection) { ProductDescription productDescription = productsDB.GetProductInfo(productMatrix); productViewModel.Products.Add(new ProductResult() { Job = newJob, Description = productDescription }); if (productViewModel.Products.Count > 0) { productViewModel.SelectedProduct = productViewModel.Products[0]; } } await navigation.PushAsync(new ProductPage(productViewModel)); calculateTapped = false; } }); this.ChangeLengthUnit = new Command((nothing) => { if (LengthUnit == Units.Metre) { LengthUnit = Units.Kilometre; } else { LengthUnit = Units.Metre; } setArea(); }); this.ChangeWidthUnit = new Command((nothing) => { if (WidthUnit == Units.Metre) { WidthUnit = Units.Kilometre; } else { WidthUnit = Units.Metre; } setArea(); }); this.ChangeAreaUnit = new Command((nothing) => { if (AreaUnit == Units.Metre) { AreaUnit = Units.Kilometre; } else { AreaUnit = Units.Metre; } if (areaUntouched == area) { setArea(); } }); }