public ChooseSizePage(SizesSet sizes, string source, Type caffeineType, double coeff) { BackgroundImageSource = CueConstants.BackgroundImage; beverageMappings = new Dictionary <string, Beverage>(); Title = "Choose Size"; Content = new StackLayout(); StackLayout stackContent = (StackLayout)Content; HashSet <Button> sizeButtons = new HashSet <Button>(); FieldInfo sizeInfo = caffeineType.GetField(source); Dictionary <string, Beverage> sizePairs = (Dictionary <string, Beverage>)sizeInfo.GetValue(sizes); Beverage firstBev = sizePairs.ElementAt(0).Value; perOz = firstBev.CaffeinePerOz; foreach (KeyValuePair <string, Beverage> sizePair in sizePairs) { string btnText = $"{sizePair.Key}: {sizePair.Value.Oz} ({sizePair.Value.Caffeine} mg)"; btnText = btnText.Replace('_', ' '); sizeButtons.Add(new Button { Text = btnText }); beverageMappings.Add(btnText, sizePair.Value); } foreach (Button button in sizeButtons) { button.BackgroundColor = Color.FloralWhite; button.TextColor = Color.SaddleBrown; button.Clicked += async(sender, e) => { double caffeineAmount = Convert.ToDouble(beverageMappings[button.Text].Caffeine); await Navigation.PushAsync(new QuantityPage(coeff, caffeineAmount)); }; stackContent.Children.Add(button); } Button customButton = new Button() { Text = "Custom Size", BackgroundColor = Color.FloralWhite, TextColor = Color.SaddleBrown }; customButton.Clicked += async(sender, e) => { await Navigation.PushAsync(new OuncePage(coeff, perOz)); }; stackContent.Children.Add(customButton); }
public ChooseTypePage(SizesSet sizesSet, double coeff) { BackgroundImageSource = CueConstants.BackgroundImage; Title = "Choose Type"; Content = new ScrollView(); ScrollView scrollView = (ScrollView)Content; StackLayout stackContent = new StackLayout(); if (sizesSet.QuantOnly.ContainsKey(CueConstants.EspressoShot)) { Button espressoButton = new Button { BackgroundColor = Color.FloralWhite, TextColor = Color.SaddleBrown, Text = "Espresso Shot" }; espressoButton.Clicked += async(sender, e) => { await Navigation.PushAsync(new QuantityPage(coeff, sizesSet.QuantOnly[CueConstants.EspressoShot])); }; stackContent.Children.Add(espressoButton); } HashSet <Button> buttonHash = new HashSet <Button>(); foreach (string source in sizesSet.Sources) { buttonHash.Add(new Button { Text = source.Replace('_', ' ') }); } foreach (Button button in buttonHash) { if (button.Text.Contains("Tea") || button.Text.Contains("Energy")) { button.TextColor = Color.ForestGreen; } else { button.TextColor = Color.SaddleBrown; } button.BackgroundColor = Color.FloralWhite; button.Clicked += async(sender, e) => { await Navigation.PushAsync(new ChooseSizePage(sizesSet, button.Text.Replace(' ', '_'), sizesSet.GetType(), coeff)); }; stackContent.Children.Add(button); } scrollView.Content = stackContent; }