public ComponentsModel(int id, ComponentListMode mode) { if (mode == ComponentListMode.Variation) { Variation variation = Database.GetVariation(id); foreach (Component component in variation.Components.Values) { ComponentModel newComponentModel = new ComponentModel(component); componentModels.Add(newComponentModel); } componentModels.Sort(); } else { Component component = Database.GetComponent(id); foreach (Component subComponent in component.Components.Values) { ComponentModel newComponentModel = new ComponentModel(subComponent); componentModels.Add(newComponentModel); } componentModels.Sort(); } }
private void DisplayComponents(int id, bool ignoreDefaults, ComponentListMode mode) { if (mode == ComponentListMode.Variation) { variationId = id; } else { componentId = id; } confirmButton.Visibility = ViewStates.Visible; variationsList.Adapter = null; componentsAdapter = new ComponentListViewAdapter(id, this.Context, mode, ignoreDefaults); componentsAdapter.ComponentChecked += ListAdapter_ComponentChecked; componentsAdapter.PortionClicked += ComponentsAdapter_PortionClicked; componentsAdapter.ArrowClicked += ComponentsAdapter_ArrowClicked; foreach (CheckBoxWithId checkBox in componentsAdapter.CheckBoxes) { if (checkBox.Checked && mode == ComponentListMode.Variation) { AddComponent(checkBox.ComponentId, componentsAdapter[checkBox.Position].Portions, componentsAdapter[checkBox.Position].Position); } else if (checkBox.Checked) { AddComponentComponent(checkBox.ComponentId); } } CheckBoxes(); SetPortions(); variationsList.Adapter = componentsAdapter; backButton.Visibility = ViewStates.Visible; forwardButton.Visibility = ViewStates.Invisible; }
public ComponentListViewAdapter(int id, Context context, ComponentListMode mode, bool ignoreDefaults = true) { model = new ComponentsModel(id, mode); int position = 0; foreach (ComponentModel cModel in model.ComponentModels) { CheckBoxWithId thisItem = new CheckBoxWithId(context); thisItem.Group = cModel.Group; thisItem.Position = position++; thisItem.ComponentId = cModel.Id; TextViewWithId portions = new TextViewWithId(context); portions.ComponentId = cModel.Id; portions.Text = " " + cModel.Portions.ToString(); portions.SetTextColor(Color.White); portions.SetBackgroundColor(Color.Black); portions.SetTextSize(Android.Util.ComplexUnitType.Sp, 25); portions.Click += Portions_Click; ImageViewWithId arrow = new ImageViewWithId(context); arrow.SetImageResource(Resource.Drawable.ViewComponents); arrow.SetPadding(5, 8, 0, 0); arrow.ComponentId = cModel.Id; arrow.Visibility = ViewStates.Invisible; arrow.Click += Arrow_Click; if (!ignoreDefaults && cModel.IsDefault) { thisItem.Checked = true; } checkBoxes.Add(thisItem); this.portions.Add(portions); arrows.Add(arrow); } }