Esempio n. 1
0
        private void InitializeEstimateContainer()
        {
            EstimateSelectedVehicleType = new VehicleTypeView(new CGRect(0f, 0f, 50f, this.Frame.Height));

            EstimatedFareLabel = new UILabel
            {
                AdjustsFontSizeToFitWidth = true,
                BackgroundColor           = UIColor.Clear,
                Lines         = 1,
                Font          = UIFont.FromName(FontName.HelveticaNeueLight, 32 / 2),
                TextAlignment = UITextAlignment.Natural,
                TextColor     = Theme.LabelTextColor,
                ShadowColor   = UIColor.Clear
            };
            EstimatedFareLabel.TranslatesAutoresizingMaskIntoConstraints = false;

            EtaLabel = new UILabel
            {
                AdjustsFontSizeToFitWidth = true,
                BackgroundColor           = UIColor.Clear,
                Lines         = 1,
                Font          = UIFont.FromName(FontName.HelveticaNeueLight, 24 / 2),
                TextAlignment = UITextAlignment.Natural,
                TextColor     = Theme.LabelTextColor,
                ShadowColor   = UIColor.Clear,
            };
            EtaLabel.TranslatesAutoresizingMaskIntoConstraints = false;

            EstimateContainer.AddSubviews(EstimateSelectedVehicleType, EstimatedFareLabel, EtaLabel);

            // initialize constraint values
            _estimatedFareLabelHeightValueWithEta    = NSLayoutConstraint.Create(EstimatedFareLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Height, 0.5f, 0f);
            _estimatedFareLabelHeightValueWithoutEta = NSLayoutConstraint.Create(EstimatedFareLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Height, 1f, 0f);
            _constraintEstimatedFareLabelTop         = NSLayoutConstraint.Create(EstimatedFareLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Top, 1f, EstimatedFareLabelTopValueWithoutEta);

            // Constraints for EstimateSelectedVehicleType
            _constraintEstimateVehicleWidth = NSLayoutConstraint.Create(EstimateSelectedVehicleType, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, 40f);
            EstimateContainer.AddConstraints(new []
            {
                _constraintEstimateVehicleWidth,
                NSLayoutConstraint.Create(EstimateSelectedVehicleType, NSLayoutAttribute.Height, NSLayoutRelation.Equal, EstimateSelectedVehicleType.Superview, NSLayoutAttribute.Height, 1f, 0f),
                NSLayoutConstraint.Create(EstimateSelectedVehicleType, NSLayoutAttribute.Top, NSLayoutRelation.Equal, EstimateSelectedVehicleType.Superview, NSLayoutAttribute.Top, 1f, 0f),
                NSLayoutConstraint.Create(EstimateSelectedVehicleType, NSLayoutAttribute.Left, NSLayoutRelation.Equal, EstimateSelectedVehicleType.Superview, NSLayoutAttribute.Left, 1f, 0f)
            });

            // Constraints for EstimatedFareLabel
            _constraintEstimatedFareLabelHeight = _estimatedFareLabelHeightValueWithoutEta;
            EstimateContainer.AddConstraints(new []
            {
                NSLayoutConstraint.Create(EstimatedFareLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, EstimateSelectedVehicleType, NSLayoutAttribute.Right, 1f, LabelPadding),
                NSLayoutConstraint.Create(EstimatedFareLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Right, 1f, -LabelPadding),
                _constraintEstimatedFareLabelHeight,
                _constraintEstimatedFareLabelTop
            });

            // Constraints for EstimatedFareLabel
            EstimateContainer.AddConstraints(new []
            {
                NSLayoutConstraint.Create(EtaLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, EstimateSelectedVehicleType, NSLayoutAttribute.Right, 1f, LabelPadding),
                NSLayoutConstraint.Create(EtaLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Right, 1f, -LabelPadding),
                NSLayoutConstraint.Create(EtaLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Height, 0.5f, 0f),
                NSLayoutConstraint.Create(EtaLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, EstimatedFareLabel.Superview, NSLayoutAttribute.Bottom, 1f, -2f)
            });
        }
Esempio n. 2
0
        private void Redraw()
        {
            if (ShowEstimate)
            {
                BackgroundColor = Theme.CompanyColor;
                HorizontalDividerTop.BackgroundColor = Theme.LabelTextColor;
                EstimateContainer.Hidden             = false;
                VehicleSelectionContainer.Hidden     = true;

                if (Eta.HasValue() && ShowEta)
                {
                    EstimateContainer.RemoveConstraint(_constraintEstimatedFareLabelHeight);
                    _constraintEstimatedFareLabelHeight = _estimatedFareLabelHeightValueWithEta;
                    EstimateContainer.AddConstraint(_constraintEstimatedFareLabelHeight);
                    _constraintEstimatedFareLabelTop.Constant = EstimatedFareLabelTopValueWithEta;
                }
                else
                {
                    EstimateContainer.RemoveConstraint(_constraintEstimatedFareLabelHeight);
                    _constraintEstimatedFareLabelHeight = _estimatedFareLabelHeightValueWithoutEta;
                    EstimateContainer.AddConstraint(_constraintEstimatedFareLabelHeight);
                    _constraintEstimatedFareLabelTop.Constant = EstimatedFareLabelTopValueWithoutEta;
                }
            }
            else
            {
                BackgroundColor = UIColor.Clear;
                HorizontalDividerTop.BackgroundColor = UIColor.FromRGB(177, 177, 177);
                EstimateContainer.Hidden             = true;
                VehicleSelectionContainer.Hidden     = false;

                VehicleSelectionContainer.Subviews.ForEach(x => x.RemoveFromSuperview());

                if (Vehicles.None())
                {
                    return;
                }

                var i = 0;
                foreach (var vehicle in Vehicles)
                {
                    var vehicleView = new VehicleTypeView(new CGRect(), vehicle, SelectedVehicle != null ? vehicle.Id == SelectedVehicle.Id : false);
                    vehicleView.TouchUpInside += (sender, e) => {
                        if (!IsReadOnly && VehicleSelected != null)
                        {
                            VehicleSelected(vehicle);
                        }
                    };

                    VehicleSelectionContainer.Add(vehicleView);

                    VehicleSelectionContainer.AddConstraints(new []
                    {
                        NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Top, 1f, 0f),
                        NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Height, 1f, 0f)
                    });

                    if (i == 0)
                    {
                        // first vehicle
                        VehicleSelectionContainer.AddConstraint(NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Left, 1f, VehicleSelectionPadding));
                    }
                    else
                    {
                        // add constraint relative to previous vehicle
                        VehicleSelectionContainer.AddConstraints(new []
                        {
                            NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, VehicleSelectionContainer.Subviews[i - 1], NSLayoutAttribute.Right, 1f, 0f),
                            NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, VehicleSelectionContainer.Subviews[i - 1], NSLayoutAttribute.Width, 1f, 0f)
                        });
                    }

                    if (i == (Vehicles.Count() - 1))
                    {
                        // last vehicle
                        VehicleSelectionContainer.AddConstraint(NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, VehicleSelectionContainer, NSLayoutAttribute.Right, 1f, -VehicleSelectionPadding));
                    }

                    i++;
                }
            }

            _constraintEstimateVehicleWidth.Constant = EstimateSelectedVehicleType.WidthToFitLabel();
        }