Beispiel #1
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            NavigationController.NavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);
            NavigationController.NavigationBar.ShadowImage     = null;
            NavigationController.NavigationBar.Translucent     = true;
            NavigationController.NavigationBar.BackgroundColor = Constants.Color.DarkBlue;
            NavigationController.NavigationBar.BarTintColor    = Constants.Color.DarkBlue;
            NavigationController.NavigationBar.TintColor       = Constants.Color.White;

            NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes
            {
                ForegroundColor = Constants.Color.White,
                Font            = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
            };

            scrollView = new UIScrollView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AlwaysBounceVertical = true,
            };

            View.AddSubview(scrollView);

            scrollView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            scrollView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            scrollView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
            scrollViewBottomConstraint        = scrollView.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor);
            scrollViewBottomConstraint.Active = true;

            var deviceTypeImageView = new UIImageView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Image = ViewModel.DeviceModel?.Sensor ?? false ? Constants.Assets.Lines : Constants.Assets.Power,
            };

            scrollView.AddSubview(deviceTypeImageView);

            deviceTypeImageView.TopAnchor.ConstraintEqualTo(scrollView.TopAnchor, constant: Constants.Padding).Active   = true;
            deviceTypeImageView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: Constants.Padding).Active = true;
            deviceTypeImageView.WidthAnchor.ConstraintEqualTo(32).Active = true;
            deviceTypeImageView.HeightAnchor.ConstraintEqualTo(deviceTypeImageView.WidthAnchor).Active = true;

            var deviceLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text      = ViewModel.DeviceModel.Name,
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.TwentyFour),
                TextColor = Constants.Color.DarkGray,
            };

            scrollView.AddSubview(deviceLabel);

            deviceLabel.CenterYAnchor.ConstraintEqualTo(deviceTypeImageView.CenterYAnchor).Active = true;
            deviceLabel.LeftAnchor.ConstraintEqualTo(deviceTypeImageView.RightAnchor, constant: Constants.Padding).Active = true;
            deviceLabel.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor, constant: -Constants.Padding).Active        = true;

            var locationLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text      = "Device Location",
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Fourteen),
                TextColor = Constants.Color.DarkGray,
            };

            scrollView.AddSubview(locationLabel);

            locationLabel.TopAnchor.ConstraintEqualTo(deviceTypeImageView.BottomAnchor, constant: Constants.Padding).Active = true;
            locationLabel.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: Constants.Padding).Active           = true;

            mapView = new MKMapView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                CenterCoordinate = ViewModel.DeviceModel.Geolocation != null
                    ? new CLLocationCoordinate2D(ViewModel.DeviceModel.Geolocation.Latitude, ViewModel.DeviceModel.Geolocation.Longitude)
                    : new CLLocationCoordinate2D(),
            };

            scrollView.AddSubview(mapView);

            mapView.AddStandardShadow();

            mapView.TopAnchor.ConstraintEqualTo(locationLabel.BottomAnchor, constant: Constants.Padding).Active = true;
            mapView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active   = true;
            mapView.WidthAnchor.ConstraintEqualTo(scrollView.WidthAnchor).Active = true;
            mapView.HeightAnchor.ConstraintEqualTo(scrollView.HeightAnchor, multiplier: 0.25f).Active = true;

            pinView = new MKPinAnnotationView(CGRect.Empty)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            var pinHeight = 39;

            scrollView.AddSubview(pinView);

            pinView.CenterXAnchor.ConstraintEqualTo(mapView.CenterXAnchor, constant: pinView.CenterOffset.X).Active = true;
            pinView.CenterYAnchor.ConstraintEqualTo(mapView.CenterYAnchor, constant: pinView.CenterOffset.Y).Active = true;
            pinView.HeightAnchor.ConstraintEqualTo(pinHeight).Active = true;
            pinView.WidthAnchor.ConstraintEqualTo(pinHeight).Active  = true;

            var moveLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Lines         = 0,
                LineBreakMode = UILineBreakMode.WordWrap,
                TextColor     = Constants.Color.MidGray,
                Font          = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Twelve),
                Text          = "MOVE THE PIN AS NEEDED TO MAKE SURE ITS LOCATION ACCURATELY REPRESENTS A PRECISE SPOT WHERE THE DEVICE WILL BE.",
            };

            scrollView.AddSubview(moveLabel);

            moveLabel.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: Constants.Padding).Active = true;
            moveLabel.TopAnchor.ConstraintEqualTo(mapView.BottomAnchor, constant: Constants.Padding).Active   = true;
            moveLabel.WidthAnchor.ConstraintEqualTo(View.WidthAnchor, constant: -Constants.Padding).Active    = true;

            //buildingTextFieldView = new TextFieldView
            //{
            //    TranslatesAutoresizingMaskIntoConstraints = false,
            //    LabelText = "Building",
            //};

            //scrollView.AddSubview(buildingTextFieldView);

            //buildingTextFieldView.TopAnchor.ConstraintEqualTo(moveLabel.BottomAnchor, constant: Constants.Padding).Active = true;
            //buildingTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            //buildingTextFieldView.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor).Active = true;

            //floorTextFieldView = new TextFieldView
            //{
            //    TranslatesAutoresizingMaskIntoConstraints = false,
            //    LabelText = "Floor",
            //};

            //scrollView.AddSubview(floorTextFieldView);

            //floorTextFieldView.TopAnchor.ConstraintEqualTo(buildingTextFieldView.BottomAnchor, constant: Constants.Padding / 2).Active = true;
            //floorTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            //floorTextFieldView.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor).Active = true;

            //roomTextFieldView = new TextFieldView
            //{
            //    TranslatesAutoresizingMaskIntoConstraints = false,
            //    LabelText = "Room",
            //};

            //scrollView.AddSubview(roomTextFieldView);

            //roomTextFieldView.TopAnchor.ConstraintEqualTo(floorTextFieldView.BottomAnchor, constant: Constants.Padding / 2).Active = true;
            //roomTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            //roomTextFieldView.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor).Active = true;

            //wifiTextFieldView = new TextFieldView
            //{
            //    TranslatesAutoresizingMaskIntoConstraints = false,
            //    LabelText = "WiFi",
            //};

            //scrollView.AddSubview(wifiTextFieldView);

            //wifiTextFieldView.TopAnchor.ConstraintEqualTo(roomTextFieldView.BottomAnchor, constant: Constants.Padding * 2).Active = true;
            //wifiTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            //wifiTextFieldView.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor).Active = true;

            //var bottomAreaLayoutGuide = new UILayoutGuide();

            //scrollView.AddLayoutGuide(bottomAreaLayoutGuide);

            //bottomAreaLayoutGuide.TopAnchor.ConstraintEqualTo(wifiTextFieldView.BottomAnchor).Active = true;
            //bottomAreaLayoutGuide.BottomAnchor.ConstraintEqualTo(scrollView.SafeAreaLayoutGuide.BottomAnchor).Active = true;

            //doneButton = new UIButton
            //{
            //    TranslatesAutoresizingMaskIntoConstraints = false,
            //    BackgroundColor = Constants.Color.DarkBlue,
            //};

            //doneButton.SetAttributedTitle(new NSAttributedString("DONE", new UIStringAttributes
            //{
            //    Font = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
            //    ForegroundColor = Constants.Color.White,
            //}), UIControlState.Normal);

            //doneButton.AddStandardShadow();

            //scrollView.AddSubview(doneButton);

            //doneButton.WidthAnchor.ConstraintEqualTo(scrollView.WidthAnchor, multiplier: 0.5f).Active = true;
            //doneButton.HeightAnchor.ConstraintEqualTo(44).Active = true;
            //doneButton.CenterXAnchor.ConstraintEqualTo(scrollView.CenterXAnchor).Active = true;
            //doneButton.CenterYAnchor.ConstraintEqualTo(bottomAreaLayoutGuide.CenterYAnchor).Active = true;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = "Manage Device";

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Constants.Assets.ArrowLeft, UIBarButtonItemStyle.Plain, (sender, e) =>
            {
                NavigationController.PopViewController(true);
            });

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, async(object sender, EventArgs e) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = false;

                UpdateCurrentDeviceAttributes();

                await ViewModel.UpdateDevice();

                NavigationItem.RightBarButtonItem.Enabled = true;
            });

            NavigationController.InteractivePopGestureRecognizer.Delegate = null;


            NavigationController.NavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);
            NavigationController.NavigationBar.ShadowImage     = null;
            NavigationController.NavigationBar.Translucent     = true;
            NavigationController.NavigationBar.BackgroundColor = Constants.Color.DarkBlue;
            NavigationController.NavigationBar.BarTintColor    = Constants.Color.DarkBlue;
            NavigationController.NavigationBar.TintColor       = Constants.Color.White;

            NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes
            {
                ForegroundColor = Constants.Color.White,
                Font            = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
            };

            var padding       = Constants.Padding;
            var halfPadding   = padding / 2;
            var doublePadding = padding * 2;

            scrollView = new UIScrollView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AlwaysBounceVertical         = true,
                ShowsVerticalScrollIndicator = true,
            };

            View.AddSubview(scrollView);

            scrollView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            scrollView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            scrollView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
            scrollViewBottomConstraint        = scrollView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor);
            scrollViewBottomConstraint.Active = true;

            var deviceTypeImageView = new UIImageView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Image = ViewModel.CurrentDeviceModel?.Sensor ?? false ? Constants.Assets.Lines : Constants.Assets.Power,
            };

            var importantDetailsLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = Constants.Color.MidGray,
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
                AdjustsFontSizeToFitWidth = true,
                MinimumScaleFactor        = 0.1f,
                LineBreakMode             = UILineBreakMode.WordWrap,
                Lines = 0,
                Text  = "Let's give this device some important details...",
            };

            if (!ViewModel.IsOnboardingStepSix)
            {
                scrollView.AddSubview(deviceTypeImageView);

                deviceTypeImageView.TopAnchor.ConstraintEqualTo(scrollView.TopAnchor, constant: padding).Active   = true;
                deviceTypeImageView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: padding).Active = true;
                deviceTypeImageView.WidthAnchor.ConstraintEqualTo(32).Active = true;
                deviceTypeImageView.HeightAnchor.ConstraintEqualTo(deviceTypeImageView.WidthAnchor).Active = true;

                var deviceLabel = new UILabel
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = ViewModel.CurrentDeviceModel.Name,
                    Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.TwentyFour),
                    TextColor = Constants.Color.DarkGray,
                };

                scrollView.AddSubview(deviceLabel);

                deviceLabel.CenterYAnchor.ConstraintEqualTo(deviceTypeImageView.CenterYAnchor).Active = true;
                deviceLabel.LeftAnchor.ConstraintEqualTo(deviceTypeImageView.RightAnchor, constant: padding).Active = true;
                deviceLabel.RightAnchor.ConstraintEqualTo(scrollView.RightAnchor, constant: -padding).Active        = true;
            }
            else
            {
                var circleNumberView = new CircleNumberView
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Number = 6,
                };

                scrollView.AddSubview(circleNumberView);
                circleNumberView.TopAnchor.ConstraintEqualTo(scrollView.TopAnchor, constant: padding).Active   = true;
                circleNumberView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: padding).Active = true;
                circleNumberView.WidthAnchor.ConstraintEqualTo(Constants.CircleNumberSize).Active    = true;
                circleNumberView.HeightAnchor.ConstraintEqualTo(circleNumberView.WidthAnchor).Active = true;



                scrollView.AddSubview(importantDetailsLabel);
                importantDetailsLabel.LeftAnchor.ConstraintEqualTo(circleNumberView.RightAnchor, constant: padding).Active = true;
                importantDetailsLabel.CenterYAnchor.ConstraintEqualTo(circleNumberView.CenterYAnchor).Active     = true;
                importantDetailsLabel.RightAnchor.ConstraintEqualTo(View.RightAnchor, constant: -padding).Active = true;
            }

            var locationLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text      = "Device Location",
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Fourteen),
                TextColor = Constants.Color.DarkGray,
            };

            scrollView.AddSubview(locationLabel);

            locationLabel.TopAnchor.ConstraintEqualTo(!ViewModel.IsOnboardingStepSix ? deviceTypeImageView.BottomAnchor : importantDetailsLabel.BottomAnchor, constant: padding).Active = true;
            locationLabel.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: padding).Active = true;

            mapView = new MKMapView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                ShowsUserLocation = true,
                CenterCoordinate  = ViewModel.CurrentDeviceModel.Geolocation != null
                    ? new CLLocationCoordinate2D(ViewModel.CurrentDeviceModel.Geolocation.Latitude, ViewModel.CurrentDeviceModel.Geolocation.Longitude)
                    : new CLLocationCoordinate2D(),
                Delegate = this,
            };

            scrollView.AddSubview(mapView);

            mapView.AddStandardShadow();

            mapView.TopAnchor.ConstraintEqualTo(locationLabel.BottomAnchor, constant: padding).Active = true;
            mapView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active   = true;
            mapView.WidthAnchor.ConstraintEqualTo(scrollView.WidthAnchor).Active = true;
            mapView.HeightAnchor.ConstraintEqualTo(View.HeightAnchor, multiplier: 0.25f).Active = true;

            if (ViewModel.CurrentDeviceModel.Geolocation == null)
            {
                Task.Run(async() =>
                {
                    var edisonLocation = await ViewModel.GetLastKnownLocation();

                    if (edisonLocation == null)
                    {
                        return;
                    }

                    InvokeOnMainThread(() => mapView.CenterCoordinate = new CLLocationCoordinate2D
                    {
                        Latitude  = edisonLocation.Latitude,
                        Longitude = edisonLocation.Longitude,
                    });
                });
            }

            pinView = new MKPinAnnotationView(CGRect.Empty)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            var pinHeight = 39;

            scrollView.AddSubview(pinView);

            pinView.CenterXAnchor.ConstraintEqualTo(mapView.CenterXAnchor, constant: pinView.CenterOffset.X).Active = true;
            pinView.CenterYAnchor.ConstraintEqualTo(mapView.CenterYAnchor, constant: pinView.CenterOffset.Y).Active = true;
            pinView.HeightAnchor.ConstraintEqualTo(pinHeight).Active = true;
            pinView.WidthAnchor.ConstraintEqualTo(pinHeight).Active  = true;

            var moveLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Lines         = 0,
                LineBreakMode = UILineBreakMode.WordWrap,
                TextColor     = Constants.Color.MidGray,


                Font = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Twelve),
                Text = "MOVE THE PIN AS NEEDED TO MAKE SURE ITS LOCATION ACCURATELY REPRESENTS A PRECISE SPOT WHERE THE DEVICE WILL BE.",
            };

            scrollView.AddSubview(moveLabel);

            moveLabel.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor, constant: padding).Active = true;
            moveLabel.TopAnchor.ConstraintEqualTo(mapView.BottomAnchor, constant: padding).Active   = true;
            moveLabel.WidthAnchor.ConstraintEqualTo(View.WidthAnchor, constant: -padding).Active    = true;

            nameTextFieldView = new TextFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LabelText = "Name",
            };

            scrollView.AddSubview(nameTextFieldView);

            nameTextFieldView.TopAnchor.ConstraintEqualTo(moveLabel.BottomAnchor, constant: padding).Active = true;
            nameTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            nameTextFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;

            enabledSwitchFieldView = new SwitchFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LabelText = "Enabled",
            };

            scrollView.AddSubview(enabledSwitchFieldView);

            enabledSwitchFieldView.TopAnchor.ConstraintEqualTo(nameTextFieldView.BottomAnchor, constant: padding).Active = true;
            enabledSwitchFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            enabledSwitchFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;

            buildingTextFieldView = new TextFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LabelText = "Building",
            };

            scrollView.AddSubview(buildingTextFieldView);

            buildingTextFieldView.TopAnchor.ConstraintEqualTo(enabledSwitchFieldView.BottomAnchor, constant: padding).Active = true;
            buildingTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            buildingTextFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;

            floorTextFieldView = new TextFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LabelText = "Floor",
            };

            scrollView.AddSubview(floorTextFieldView);

            floorTextFieldView.TopAnchor.ConstraintEqualTo(buildingTextFieldView.BottomAnchor, constant: halfPadding).Active = true;
            floorTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            floorTextFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;

            roomTextFieldView = new TextFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LabelText = "Room",
            };

            scrollView.AddSubview(roomTextFieldView);

            roomTextFieldView.TopAnchor.ConstraintEqualTo(floorTextFieldView.BottomAnchor, constant: halfPadding).Active = true;
            roomTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
            roomTextFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;

            if (ViewModel.IsOnboardingStepSix)
            {
                roomTextFieldView.BottomAnchor.ConstraintEqualTo(scrollView.BottomAnchor, constant: -halfPadding).Active = true;
            }
            else
            {
                wifiTextFieldView = new TextFieldView
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    LabelText = "WiFi",
                };

                scrollView.AddSubview(wifiTextFieldView);

                wifiTextFieldView.TopAnchor.ConstraintEqualTo(roomTextFieldView.BottomAnchor, constant: padding).Active = true;
                wifiTextFieldView.LeftAnchor.ConstraintEqualTo(scrollView.LeftAnchor).Active = true;
                wifiTextFieldView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active     = true;
                wifiTextFieldView.BottomAnchor.ConstraintEqualTo(scrollView.BottomAnchor, constant: -halfPadding).Active = true;
            }

            textFieldViews = new List <TextFieldView>
            {
                nameTextFieldView,
                buildingTextFieldView,
                floorTextFieldView,
                roomTextFieldView,
            };

            textFieldViews.ForEach(t => t.ReturnKeyType = UIReturnKeyType.Done);
        }