Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = $"Set Up {ViewModel.DeviceTypeAsString}";

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

            var padding = Constants.Padding;

            var circleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 6,
            };

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

            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...",
            };

            View.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;
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = $"Set Up {ViewModel.DeviceTypeAsString}";

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

            var padding = Constants.Padding;

            var circleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 5,
            };

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

            var enterPasswordLabel = 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  = $"Enter the password for {selectedWifiNetwork.SSID}",
            };

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

            bottomLayoutGuide = new UILayoutGuide();

            View.AddLayoutGuide(bottomLayoutGuide);

            bottomLayoutGuide.TopAnchor.ConstraintEqualTo(enterPasswordLabel.BottomAnchor).Active = true;
            bottomLayoutConstraint        = bottomLayoutGuide.BottomAnchor.ConstraintEqualTo(View.BottomAnchor);
            bottomLayoutConstraint.Active = true;

            passwordTextFieldView = new TextFieldView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                SecureTextEntry = true,
                LabelText       = "Password",
                ReturnKeyType   = UIReturnKeyType.Go,
            };

            View.AddSubview(passwordTextFieldView);

            passwordTextFieldView.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
            passwordTextFieldView.CenterYAnchor.ConstraintEqualTo(bottomLayoutGuide.CenterYAnchor).Active = true;
            passwordTextFieldView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            passwordTextFieldView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;

            showPasswordButton = new UIButton {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            showPasswordButton.SetTitle("Show Password", UIControlState.Normal);
            showPasswordButton.TitleLabel.Font = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Fourteen);
            showPasswordButton.SetTitleColor(Constants.Color.DarkBlue, UIControlState.Normal);

            View.AddSubview(showPasswordButton);

            showPasswordButton.TopAnchor.ConstraintEqualTo(passwordTextFieldView.BottomAnchor, constant: padding / 2).Active = true;
            showPasswordButton.RightAnchor.ConstraintEqualTo(passwordTextFieldView.RightAnchor, constant: -padding).Active   = true;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = $"Find Your {ViewModel.DeviceTypeAsString}'s Network";

            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),
            };

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Constants.Assets.CloseX, UIBarButtonItemStyle.Plain, (sender, e) =>
            {
                DismissViewController(true, null);
            });

            var circleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 3,
            };

            View.AddSubview(circleNumberView);

            circleNumberView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, constant: Constants.Padding).Active = true;
            circleNumberView.WidthAnchor.ConstraintEqualTo(Constants.CircleNumberSize).Active    = true;
            circleNumberView.HeightAnchor.ConstraintEqualTo(circleNumberView.WidthAnchor).Active = true;

            var findLabel = 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  = $"The {ViewModel.DeviceTypeAsString} should be emitting a WiFi network of the format \"EDISON_XXXX.\"",
            };

            View.AddSubview(findLabel);

            findLabel.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor, constant: Constants.Padding).Active = true;
            findLabel.LeftAnchor.ConstraintEqualTo(circleNumberView.RightAnchor, constant: Constants.Padding).Active      = true;
            findLabel.CenterYAnchor.ConstraintEqualTo(circleNumberView.CenterYAnchor).Active = true;
            findLabel.RightAnchor.ConstraintEqualTo(View.RightAnchor, constant: -Constants.Padding).Active = true;

            networksTableViewSource = new NetworksTableViewSource();
            networksTableView       = new UITableView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AlwaysBounceVertical = true,
                BackgroundColor      = Constants.Color.White,
                TableHeaderView      = new UIView(),
                Source         = networksTableViewSource,
                SeparatorStyle = UITableViewCellSeparatorStyle.None,
            };

            var type = typeof(WifiNetworkTableViewCell);

            networksTableView.RegisterClassForCellReuse(type, type.Name);

            View.AddSubview(networksTableView);

            networksTableView.TopAnchor.ConstraintEqualTo(findLabel.BottomAnchor, constant: Constants.Padding).Active = true;
            networksTableView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active     = true;
            networksTableView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active   = true;
            networksTableView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor).Active = true;

            var tableViewBackgroundShadowView = new UIView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = Constants.Color.White,
            };

            tableViewBackgroundShadowView.Layer.ShadowColor   = Constants.Color.DarkGray.CGColor;
            tableViewBackgroundShadowView.Layer.ShadowRadius  = 3;
            tableViewBackgroundShadowView.Layer.ShadowOffset  = new CGSize(1, 1);
            tableViewBackgroundShadowView.Layer.ShadowOpacity = 0.4f;
            tableViewBackgroundShadowView.Layer.MasksToBounds = false;

            View.InsertSubviewBelow(tableViewBackgroundShadowView, networksTableView);

            tableViewBackgroundShadowView.LeftAnchor.ConstraintEqualTo(networksTableView.LeftAnchor).Active     = true;
            tableViewBackgroundShadowView.RightAnchor.ConstraintEqualTo(networksTableView.RightAnchor).Active   = true;
            tableViewBackgroundShadowView.TopAnchor.ConstraintEqualTo(networksTableView.TopAnchor).Active       = true;
            tableViewBackgroundShadowView.BottomAnchor.ConstraintEqualTo(networksTableView.BottomAnchor).Active = true;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

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

            NavigationController.InteractivePopGestureRecognizer.Delegate = null;

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = $"Set Up {ViewModel.DeviceTypeAsString}";

            cameraView = new CameraView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            View.AddSubview(cameraView);

            cameraView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
            cameraView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            cameraView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            cameraView.HeightAnchor.ConstraintEqualTo(View.HeightAnchor, multiplier: 0.55f).Active = true;

            var padding    = Constants.Padding;
            var circleSize = Constants.CircleNumberSize;

            var circleView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 3,
            };

            View.AddSubview(circleView);

            circleView.TopAnchor.ConstraintEqualTo(cameraView.BottomAnchor, constant: padding).Active = true;
            circleView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, constant: padding).Active        = true;
            circleView.WidthAnchor.ConstraintEqualTo(circleSize).Active = true;
            circleView.HeightAnchor.ConstraintEqualTo(circleView.WidthAnchor).Active = true;

            var scanLabel = 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  = $"Scan the QR Code on the {ViewModel.DeviceTypeAsString.ToLower()} to connect it to this phone.",
            };

            View.AddSubview(scanLabel);

            scanLabel.LeftAnchor.ConstraintEqualTo(circleView.RightAnchor, constant: padding).Active = true;
            scanLabel.CenterYAnchor.ConstraintEqualTo(circleView.CenterYAnchor).Active           = true;
            scanLabel.RightAnchor.ConstraintEqualTo(View.RightAnchor, constant: -padding).Active = true;

            var bottomLayoutGuide = new UILayoutGuide();

            View.AddLayoutGuide(bottomLayoutGuide);

            bottomLayoutGuide.TopAnchor.ConstraintEqualTo(scanLabel.BottomAnchor).Active = true;
            bottomLayoutGuide.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor).Active = true;

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

            noQRCodeButton.SetAttributedTitle(new NSAttributedString("NO QR CODE?", new UIStringAttributes
            {
                Font            = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
                ForegroundColor = Constants.Color.White,
            }), UIControlState.Normal);

            noQRCodeButton.AddStandardShadow();

            View.AddSubview(noQRCodeButton);

            noQRCodeButton.WidthAnchor.ConstraintEqualTo(View.WidthAnchor, multiplier: 0.5f).Active = true;
            noQRCodeButton.HeightAnchor.ConstraintEqualTo(44).Active = true;
            noQRCodeButton.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
            noQRCodeButton.CenterYAnchor.ConstraintEqualTo(bottomLayoutGuide.CenterYAnchor).Active = true;
        }
Ejemplo n.º 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = $"Set Up {ViewModel.DeviceTypeAsString}";

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

            var padding = Constants.Padding;

            var circleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 4,
            };

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

            var deviceTypeLabel = 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  = $"Select a Wifi network the {ViewModel.DeviceTypeAsString} should use.",
            };

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

            var availableNetworksLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = Constants.Color.MidGray,
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Twelve),
                AdjustsFontSizeToFitWidth = true,
                MinimumScaleFactor        = 0.1f,
                LineBreakMode             = UILineBreakMode.WordWrap,
                Lines = 0,
                Text  = "Available Networks",
            };

            View.AddSubview(availableNetworksLabel);
            availableNetworksLabel.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, constant: padding).Active = true;
            availableNetworksLabel.TopAnchor.ConstraintEqualTo(circleNumberView.BottomAnchor, constant: padding * 2).Active = true;

            tableViewSource = new NetworksTableViewSource();

            tableView = new UITableView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AlwaysBounceVertical = true,
                TableFooterView      = new UIView(),
                Source         = tableViewSource,
                SeparatorStyle = UITableViewCellSeparatorStyle.None,
            };

            var cellType = typeof(WifiNetworkTableViewCell);

            tableView.RegisterClassForCellReuse(cellType, cellType.Name);

            View.AddSubview(tableView);

            tableView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            tableView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            tableView.TopAnchor.ConstraintEqualTo(availableNetworksLabel.BottomAnchor, constant: padding).Active = true;
            tableView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor).Active = true;

            var tableViewBackgroundShadowView = new UIView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = Constants.Color.White,
            };

            tableViewBackgroundShadowView.Layer.ShadowColor   = Constants.Color.DarkGray.CGColor;
            tableViewBackgroundShadowView.Layer.ShadowRadius  = 3;
            tableViewBackgroundShadowView.Layer.ShadowOffset  = new CGSize(1, 1);
            tableViewBackgroundShadowView.Layer.ShadowOpacity = 0.4f;
            tableViewBackgroundShadowView.Layer.MasksToBounds = false;

            View.InsertSubviewBelow(tableViewBackgroundShadowView, tableView);

            tableViewBackgroundShadowView.LeftAnchor.ConstraintEqualTo(tableView.LeftAnchor).Active     = true;
            tableViewBackgroundShadowView.RightAnchor.ConstraintEqualTo(tableView.RightAnchor).Active   = true;
            tableViewBackgroundShadowView.TopAnchor.ConstraintEqualTo(tableView.TopAnchor).Active       = true;
            tableViewBackgroundShadowView.BottomAnchor.ConstraintEqualTo(tableView.BottomAnchor).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);
        }
Ejemplo n.º 7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = Constants.Color.BackgroundLightGray;

            Title = "Set Up New Device";

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

            NavigationController.InteractivePopGestureRecognizer.Delegate = null;

            var topHalfLayoutGuide = new UILayoutGuide();

            View.AddLayoutGuide(topHalfLayoutGuide);
            topHalfLayoutGuide.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
            topHalfLayoutGuide.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            topHalfLayoutGuide.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            topHalfLayoutGuide.HeightAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.HeightAnchor, multiplier: 0.5f).Active = true;

            var bottomHalfLayoutGuide = new UILayoutGuide();

            View.AddLayoutGuide(bottomHalfLayoutGuide);
            bottomHalfLayoutGuide.TopAnchor.ConstraintEqualTo(topHalfLayoutGuide.BottomAnchor).Active = true;
            bottomHalfLayoutGuide.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active   = true;
            bottomHalfLayoutGuide.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
            bottomHalfLayoutGuide.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor).Active = true;

            var padding    = Constants.Padding;
            var circleSize = Constants.CircleNumberSize;

            var oneCircleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 1,
            };

            View.AddSubview(oneCircleNumberView);
            oneCircleNumberView.TopAnchor.ConstraintEqualTo(topHalfLayoutGuide.TopAnchor, constant: padding).Active   = true;
            oneCircleNumberView.LeftAnchor.ConstraintEqualTo(topHalfLayoutGuide.LeftAnchor, constant: padding).Active = true;
            oneCircleNumberView.WidthAnchor.ConstraintEqualTo(circleSize).Active = true;
            oneCircleNumberView.HeightAnchor.ConstraintEqualTo(oneCircleNumberView.WidthAnchor).Active = true;

            var deviceTypeLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = Constants.Color.MidGray,
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
                AdjustsFontSizeToFitWidth = true,
                MinimumScaleFactor        = 0.1f,
                LineBreakMode             = UILineBreakMode.Clip,
                Lines = 0,
                Text  = "What type of device?",
            };

            View.AddSubview(deviceTypeLabel);
            deviceTypeLabel.LeftAnchor.ConstraintEqualTo(oneCircleNumberView.RightAnchor, constant: padding).Active = true;
            deviceTypeLabel.CenterYAnchor.ConstraintEqualTo(oneCircleNumberView.CenterYAnchor).Active = true;
            deviceTypeLabel.RightAnchor.ConstraintEqualTo(topHalfLayoutGuide.RightAnchor).Active      = true;

            buttonCheckboxView = new CheckBoxItemView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor         = Constants.Color.DarkGray,
                SelectedTextColor = Constants.Color.DarkBlue,
                Text = "Button",
            };

            buttonCheckboxView.OnTap += HandleCheckboxTap;

            View.AddSubview(buttonCheckboxView);

            buttonCheckboxView.LeftAnchor.ConstraintEqualTo(deviceTypeLabel.LeftAnchor, constant: -Constants.Padding).Active = true;
            buttonCheckboxView.TopAnchor.ConstraintEqualTo(deviceTypeLabel.BottomAnchor, constant: padding).Active           = true;
            buttonCheckboxView.RightAnchor.ConstraintEqualTo(topHalfLayoutGuide.RightAnchor, constant: -padding).Active      = true;
            buttonCheckboxView.HeightAnchor.ConstraintEqualTo(topHalfLayoutGuide.HeightAnchor, multiplier: 0.25f).Active     = true;

            soundSensorCheckboxView = new CheckBoxItemView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor         = Constants.Color.DarkGray,
                SelectedTextColor = Constants.Color.DarkBlue,
                Text = "Sound Sensor",
            };

            soundSensorCheckboxView.OnTap += HandleCheckboxTap;

            View.AddSubview(soundSensorCheckboxView);

            soundSensorCheckboxView.LeftAnchor.ConstraintEqualTo(deviceTypeLabel.LeftAnchor, constant: -Constants.Padding).Active = true;
            soundSensorCheckboxView.TopAnchor.ConstraintEqualTo(buttonCheckboxView.BottomAnchor, constant: padding).Active        = true;
            soundSensorCheckboxView.RightAnchor.ConstraintEqualTo(topHalfLayoutGuide.RightAnchor, constant: -padding).Active      = true;
            soundSensorCheckboxView.HeightAnchor.ConstraintEqualTo(topHalfLayoutGuide.HeightAnchor, multiplier: 0.25f).Active     = true;

            lightCheckboxView = new CheckBoxItemView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor         = Constants.Color.DarkGray,
                SelectedTextColor = Constants.Color.DarkBlue,
                Text = "Light",
            };

            lightCheckboxView.OnTap += HandleCheckboxTap;

            View.AddSubview(lightCheckboxView);

            lightCheckboxView.LeftAnchor.ConstraintEqualTo(deviceTypeLabel.LeftAnchor, constant: -Constants.Padding).Active = true;
            lightCheckboxView.TopAnchor.ConstraintEqualTo(soundSensorCheckboxView.BottomAnchor, constant: padding).Active   = true;
            lightCheckboxView.RightAnchor.ConstraintEqualTo(topHalfLayoutGuide.RightAnchor, constant: -padding).Active      = true;
            lightCheckboxView.HeightAnchor.ConstraintEqualTo(topHalfLayoutGuide.HeightAnchor, multiplier: 0.25f).Active     = true;

            var twoCircleNumberView = new CircleNumberView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Number = 2,
            };

            View.AddSubview(twoCircleNumberView);
            twoCircleNumberView.TopAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.TopAnchor, constant: padding).Active   = true;
            twoCircleNumberView.LeftAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.LeftAnchor, constant: padding).Active = true;
            twoCircleNumberView.WidthAnchor.ConstraintEqualTo(circleSize).Active = true;
            twoCircleNumberView.HeightAnchor.ConstraintEqualTo(twoCircleNumberView.WidthAnchor).Active = true;

            var powerLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = Constants.Color.MidGray,
                Font      = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Eighteen),
                AdjustsFontSizeToFitWidth = true,
                MinimumScaleFactor        = 0.1f,
                LineBreakMode             = UILineBreakMode.Clip,
                Lines = 0,
                Text  = "Turn on the device power.",
            };

            View.AddSubview(powerLabel);
            powerLabel.LeftAnchor.ConstraintEqualTo(twoCircleNumberView.RightAnchor, constant: padding).Active = true;
            powerLabel.CenterYAnchor.ConstraintEqualTo(twoCircleNumberView.CenterYAnchor).Active = true;
            powerLabel.RightAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.RightAnchor).Active   = true;

            nextButton = new UIButton
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = Constants.Color.DarkBlue,
                Enabled         = false,
                Alpha           = 0.4f,
            };

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

            var buttonCenterLayoutGuide = new UILayoutGuide();

            View.AddLayoutGuide(buttonCenterLayoutGuide);
            buttonCenterLayoutGuide.TopAnchor.ConstraintEqualTo(powerLabel.BottomAnchor).Active = true;
            buttonCenterLayoutGuide.BottomAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.BottomAnchor).Active = true;

            View.AddSubview(nextButton);
            nextButton.WidthAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.WidthAnchor, multiplier: 0.5f).Active = true;
            nextButton.HeightAnchor.ConstraintEqualTo(44).Active = true;
            nextButton.CenterYAnchor.ConstraintEqualTo(buttonCenterLayoutGuide.CenterYAnchor).Active = true;
            nextButton.CenterXAnchor.ConstraintEqualTo(bottomHalfLayoutGuide.CenterXAnchor).Active   = true;

            nextButton.AddStandardShadow();
        }