Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            UsernameTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Username",
                ReturnKeyType = UIReturnKeyType.Next
            };

            UsernameTextField.ShouldReturn = _ => PasswordTextField.BecomeFirstResponder();

            PasswordTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder     = "Password",
                SecureTextEntry = true,
                ReturnKeyType   = UIReturnKeyType.Done
            };

            PasswordTextField.ShouldReturn = _ => PasswordTextField.ResignFirstResponder();

            View.AddSubviews(UsernameTextField, PasswordTextField);

            View.AddConstraints(new NSLayoutConstraint[]
            {
                UsernameTextField.TopAnchor.ConstraintEqualTo(View.TopAnchor, 128),
                UsernameTextField.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor, 16),
                UsernameTextField.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -16),
                UsernameTextField.HeightAnchor.ConstraintEqualTo(48),
                PasswordTextField.TopAnchor.ConstraintEqualTo(UsernameTextField.BottomAnchor, 16),
                PasswordTextField.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor, 16),
                PasswordTextField.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -16),
                PasswordTextField.HeightAnchor.ConstraintEqualTo(48)
            });
        }
        private void InitElements()
        {
            // Enable back navigation using swipe.
            NavigationController.InteractivePopGestureRecognizer.Delegate = null;

            new AppDelegate().disableAllOrientation = true;
            var deviceModel = Xamarin.iOS.DeviceHardware.Model;

            if (deviceModel.Contains("X"))
            {
                headerView.Frame  = new Rectangle(0, 0, Convert.ToInt32(View.Frame.Width), (Convert.ToInt32(View.Frame.Height) / 10) + 8);
                backBn.Frame      = new Rectangle(0, (Convert.ToInt32(View.Frame.Width) / 20) + 20, Convert.ToInt32(View.Frame.Width) / 8, Convert.ToInt32(View.Frame.Width) / 8);
                headerLabel.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 5, (Convert.ToInt32(View.Frame.Width) / 12) + 20, (Convert.ToInt32(View.Frame.Width) / 5) * 3, Convert.ToInt32(View.Frame.Width) / 18);
                removeBn.Frame    = new Rectangle(Convert.ToInt32(View.Frame.Width - View.Frame.Width / 4), Convert.ToInt32(View.Frame.Width) / 12 + 20, Convert.ToInt32(View.Frame.Width) / 4, Convert.ToInt32(View.Frame.Width) / 19);
            }
            else
            {
                headerView.Frame  = new Rectangle(0, 0, Convert.ToInt32(View.Frame.Width), (Convert.ToInt32(View.Frame.Height) / 10));
                backBn.Frame      = new Rectangle(0, Convert.ToInt32(View.Frame.Width) / 20, Convert.ToInt32(View.Frame.Width) / 8, Convert.ToInt32(View.Frame.Width) / 8);
                headerLabel.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 5, Convert.ToInt32(View.Frame.Width) / 12, (Convert.ToInt32(View.Frame.Width) / 5) * 3, Convert.ToInt32(View.Frame.Width) / 18);
                removeBn.Frame    = new Rectangle(Convert.ToInt32(View.Frame.Width - View.Frame.Width / 4), Convert.ToInt32(View.Frame.Width) / 12, Convert.ToInt32(View.Frame.Width) / 4, Convert.ToInt32(View.Frame.Width) / 19);
            }
            View.BackgroundColor       = UIColor.FromRGB(36, 43, 52);
            headerView.BackgroundColor = UIColor.FromRGB(36, 43, 52);
            headerLabel.Text           = headerValue;
            removeBn.SetTitle("Удалить", UIControlState.Normal);

            acceptBn.BackgroundColor = UIColor.FromRGB(255, 99, 62);
            backBn.ImageEdgeInsets   = new UIEdgeInsets(backBn.Frame.Height / 3.5F, backBn.Frame.Width / 2.35F, backBn.Frame.Height / 3.5F, backBn.Frame.Width / 3);
            activityIndicator.Color  = UIColor.FromRGB(255, 99, 62);
            activityIndicator.Frame  = new Rectangle((int)(View.Frame.Width / 2 - View.Frame.Width / 20), (int)(View.Frame.Height / 2 - View.Frame.Width / 20), (int)(View.Frame.Width / 10), (int)(View.Frame.Width / 10));

            var hintLabel = new UILabel();

            hintLabel.TextColor = UIColor.White;
            hintLabel.Text      = "Укажите свой аккаунт в социальной сети (id) или вставьте ссылку на свой профиль";

            hintLabel.Frame = new CoreGraphics.CGRect(20, headerView.Frame.Height + 10, headerView.Frame.Width - 40, headerView.Frame.Height / 1.65);
            hintLabel.Lines = 2;
            View.AddSubview(hintLabel);
            hintLabel.Font      = UIFont.FromName(Constants.fira_sans, 14f);
            hintLabel.TextColor = UIColor.FromRGB(146, 150, 155);
            //hintLabel.TextAlignment = UITextAlignment.;
            //hintLabel.BackgroundColor = UIColor.Red;

            webView = new WKWebView(View.Frame, new WKWebViewConfiguration());
            //webView = new UIWebView();
            webView.NavigationDelegate = this;
            View.AddSubview(webView);
            //webView.Hidden = true;
            UpdateWebView();
            acceptBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                           (Convert.ToInt32(View.Frame.Height) / 10) * 9,
                                           Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                           Convert.ToInt32(View.Frame.Height) / 12);
            acceptBn.SetTitle("СОХРАНИТЬ", UIControlState.Normal);
            acceptBn.Font = acceptBn.Font.WithSize(15f);
            var val = View.Frame.Height - acceptBn.Frame.Y - acceptBn.Frame.Height;

            webView.Frame = new Rectangle(0,
                                          (int)headerView.Frame.Height * 2 + 51,
                                          (int)View.Frame.Width,
                                          (int)(acceptBn.Frame.Y - headerView.Frame.Height * 3 - val));
            acceptBn.Font = UIFont.FromName(Constants.fira_sans, 15f);
            removeBn.Font = UIFont.FromName(Constants.fira_sans, 17f);

            UrlTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder            = "Ссылка на ваш профиль",
                TextColor              = UIColor.White,
                ReturnKeyType          = UIReturnKeyType.Done,
                AutocapitalizationType = UITextAutocapitalizationType.None
            };
            UrlTextField.ShouldReturn = _ => View.EndEditing(true);

            UrlTextField.EditingChanged += (s, e) =>
            {
                urlString = UrlTextField.Text;
                UpdateWebView();
                webView.Hidden = true;
                // Second condition means that we do not need facebook and linkedin previews.
                if (!String.IsNullOrEmpty(UrlTextField.Text) && urlRoot != SocialNetworkData.SampleData()[2].ContactUrl && urlRoot != SocialNetworkData.SampleData()[0].ContactUrl)
                {
                    showBn.Hidden = false;
                }
                else
                {
                    showBn.Hidden = true;
                }

                //if (!UrlTextField.Text.ToLower().Contains("http"))
                //JoinIdAndLink();
            };
            View.AddSubview(UrlTextField);
            View.AddConstraints(new NSLayoutConstraint[]
            {
                UrlTextField.TopAnchor.ConstraintEqualTo(View.TopAnchor, hintLabel.Frame.Y + hintLabel.Frame.Height + 10),
                UrlTextField.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor, 16),
                UrlTextField.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -16),
                UrlTextField.HeightAnchor.ConstraintEqualTo(48)
            });

            showBn      = new UIButton();
            showBn.Font = UIFont.FromName(Constants.fira_sans, 15f);
            View.AddSubview(showBn);
            showBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                         Convert.ToInt32(webView.Frame.Y),
                                         Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                         Convert.ToInt32(View.Frame.Height) / 12);
            showBn.SetTitle("ПРОСМОТР", UIControlState.Normal);
            showBn.BackgroundColor = UIColor.FromRGB(255, 99, 62);
            showBn.TouchUpInside  += (s, e) =>
            {
                // Check if the user entered id of his profile.
                if (!UrlTextField.Text.ToLower().Contains("http"))
                {
                    JoinIdAndLink();
                }
                webView.Hidden = false;
                showBn.Hidden  = true;
            };
        }
        private void InitElements()
        {
            // Enable back navigation using swipe.
            NavigationController.InteractivePopGestureRecognizer.Delegate = null;

            new AppDelegate().disableAllOrientation = true;
            keyboard_height = (float)(View.Frame.Height / 2);
            // Fires when keyboard shows.
            //keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, (notification) =>
            //{
            //    NSValue nsKeyboardBounds = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey);
            //    keyboardBounds = nsKeyboardBounds.RectangleFValue;
            //    keyboard_height = keyboardBounds.Height;
            //    //if (needToScroll)
            //    //{
            //    //if ((View.Frame.Height - keyboardBounds.Height - 50) < 360)
            //    //{
            //    //scrollView.ContentOffset = new CoreGraphics.CGPoint(0, keyboardBounds.Height - 100);
            //    //}
            //    //}

            //});
            //// Fires when keyboard hides.
            //keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, (notification) =>
            //{
            //    //centering scroll
            //    //scrollView.ContentOffset = new CoreGraphics.CGPoint(0, 0);
            //});

            var deviceModel = Xamarin.iOS.DeviceHardware.Model;

            //image_bgIV.Frame = new Rectangle(0, 0, Convert.ToInt32(View.Frame.Width), Convert.ToInt32(View.Frame.Height));
            if (deviceModel.Contains("X"))
            {
                headerView.Frame  = new Rectangle(0, 0, Convert.ToInt32(View.Frame.Width), (Convert.ToInt32(View.Frame.Height) / 10) + 8);
                backBn.Frame      = new Rectangle(0, (Convert.ToInt32(View.Frame.Width) / 20) + 20, Convert.ToInt32(View.Frame.Width) / 8, Convert.ToInt32(View.Frame.Width) / 8);
                headerLabel.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 5, (Convert.ToInt32(View.Frame.Width) / 12) + 20, (Convert.ToInt32(View.Frame.Width) / 5) * 3, Convert.ToInt32(View.Frame.Width) / 18);
                resetBn.Frame     = new Rectangle(Convert.ToInt32(View.Frame.Width - View.Frame.Width / 4), Convert.ToInt32(View.Frame.Width) / 12 + 20, Convert.ToInt32(View.Frame.Width) / 4, Convert.ToInt32(View.Frame.Width) / 19);
            }
            else
            {
                headerView.Frame  = new Rectangle(0, 0, Convert.ToInt32(View.Frame.Width), (Convert.ToInt32(View.Frame.Height) / 10));
                backBn.Frame      = new Rectangle(0, Convert.ToInt32(View.Frame.Width) / 20, Convert.ToInt32(View.Frame.Width) / 8, Convert.ToInt32(View.Frame.Width) / 8);
                headerLabel.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 5, Convert.ToInt32(View.Frame.Width) / 12, (Convert.ToInt32(View.Frame.Width) / 5) * 3, Convert.ToInt32(View.Frame.Width) / 18);
                resetBn.Frame     = new Rectangle(Convert.ToInt32(View.Frame.Width - View.Frame.Width / 4), Convert.ToInt32(View.Frame.Width) / 12, Convert.ToInt32(View.Frame.Width) / 4, Convert.ToInt32(View.Frame.Width) / 19);
            }
            View.BackgroundColor       = UIColor.FromRGB(36, 43, 52);
            headerView.BackgroundColor = UIColor.FromRGB(36, 43, 52);
            headerLabel.Text           = "Адрес компании";
            activityIndicator.Color    = UIColor.FromRGB(255, 99, 62);
            activityIndicator.Frame    = new Rectangle((int)(View.Frame.Width / 2 - View.Frame.Width / 20), (int)(headerView.Frame.Height * 2), (int)(View.Frame.Width / 10), (int)(View.Frame.Width / 10));

            applyAddressBn.BackgroundColor = UIColor.FromRGB(255, 99, 62);

            backBn.ImageEdgeInsets = new UIEdgeInsets(backBn.Frame.Height / 3.5F, backBn.Frame.Width / 2.35F, backBn.Frame.Height / 3.5F, backBn.Frame.Width / 3);
            scrollView.Frame       = new Rectangle(0, Convert.ToInt32(headerView.Frame.Y + headerView.Frame.Height), Convert.ToInt32(View.Frame.Width), (Convert.ToInt32(View.Frame.Height - headerView.Frame.Height)));

            scrollView.Hidden = true;

            view_in_scroll.Frame = new Rectangle(0, 0 /*Convert.ToInt32(headerView.Frame.Y + headerView.Frame.Height*1.2)*/, Convert.ToInt32(View.Frame.Width), Convert.ToInt32(scrollView.Frame.Height /* - headerView.Frame.Height * 1.2*/));

            scrollView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.Interactive;


            CountryTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Страна",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Next
            };
            CountryTextField.ShouldReturn = _ => RegionTextField.BecomeFirstResponder();
            RegionTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Регион",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Next
            };
            RegionTextField.ShouldReturn = _ => CityTextField.BecomeFirstResponder();
            CityTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Город",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Next
            };
            CityTextField.ShouldReturn = _ => DetailAddressTextField.BecomeFirstResponder();

            DetailAddressTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Улица, Дом, Корпус, Офис",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Next
            };
            DetailAddressTextField.ShouldReturn = _ => IndexTextField.BecomeFirstResponder();

            IndexTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Индекс",
                KeyboardType  = UIKeyboardType.NumberPad,
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Next
            };
            IndexTextField.ShouldReturn = _ => NotationTextField.BecomeFirstResponder();

            NotationTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Примечание",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Done
            };
            NotationTextField.ShouldReturn = _ => View.EndEditing(true);

            CoordsTextField = new FloatingTextField
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Placeholder   = "Координаты",
                TextColor     = UIColor.White,
                ReturnKeyType = UIReturnKeyType.Done
            };
            CoordsTextField.ShouldReturn = _ => View.EndEditing(true);

            CoordsRemoveBn = new UIButton
            {
                BackgroundColor = UIColor.Clear
            };
            CoordsRemoveBn.Frame = new CoreGraphics.CGRect(0, 430, View.Frame.Width, 60);
            //ApartmentTextField = new FloatingTextField
            //         {
            //             TranslatesAutoresizingMaskIntoConstraints = false,
            //             Placeholder = "Квартира",
            //             TextColor = UIColor.White,
            //  ReturnKeyType = UIReturnKeyType.Done
            //         };
            //ApartmentTextField.ShouldReturn = _ => View.EndEditing(true);

            //CountryTextField.EditingDidBegin += SetInsets;
            //RegionTextField.EditingDidBegin += SetInsets;
            //CityTextField.EditingDidBegin += SetInsets;
            //DetailAddressTextField.EditingDidBegin += SetInsets;
            //IndexTextField.EditingDidBegin += SetInsets;
            //NotationTextField.EditingDidBegin += SetInsets;


            view_in_scroll.AddSubviews(CountryTextField, RegionTextField, CityTextField, DetailAddressTextField, IndexTextField, NotationTextField, CoordsTextField, CoordsRemoveBn);
            view_in_scroll.AddConstraints(new NSLayoutConstraint[]
            {
                CountryTextField.TopAnchor.ConstraintEqualTo(view_in_scroll.TopAnchor, 12),
                CountryTextField.LeadingAnchor.ConstraintEqualTo(view_in_scroll.LeadingAnchor, 16),
                CountryTextField.TrailingAnchor.ConstraintEqualTo(view_in_scroll.TrailingAnchor, -16),
                CountryTextField.HeightAnchor.ConstraintEqualTo(48),
                RegionTextField.TopAnchor.ConstraintEqualTo(CountryTextField.TopAnchor, 70),
                RegionTextField.LeadingAnchor.ConstraintEqualTo(CountryTextField.LeadingAnchor, 0),
                RegionTextField.TrailingAnchor.ConstraintEqualTo(CountryTextField.TrailingAnchor, 0),
                RegionTextField.HeightAnchor.ConstraintEqualTo(48),
                CityTextField.TopAnchor.ConstraintEqualTo(RegionTextField.TopAnchor, 70),
                CityTextField.LeadingAnchor.ConstraintEqualTo(RegionTextField.LeadingAnchor, 0),
                CityTextField.TrailingAnchor.ConstraintEqualTo(RegionTextField.TrailingAnchor, 0),
                CityTextField.HeightAnchor.ConstraintEqualTo(48),
                DetailAddressTextField.TopAnchor.ConstraintEqualTo(CityTextField.TopAnchor, 70),
                DetailAddressTextField.LeadingAnchor.ConstraintEqualTo(CityTextField.LeadingAnchor, 0),
                DetailAddressTextField.TrailingAnchor.ConstraintEqualTo(CityTextField.TrailingAnchor, 0),
                DetailAddressTextField.HeightAnchor.ConstraintEqualTo(48),
                IndexTextField.TopAnchor.ConstraintEqualTo(DetailAddressTextField.TopAnchor, 70),
                IndexTextField.LeadingAnchor.ConstraintEqualTo(DetailAddressTextField.LeadingAnchor, 0),
                IndexTextField.TrailingAnchor.ConstraintEqualTo(DetailAddressTextField.TrailingAnchor, 0),
                IndexTextField.HeightAnchor.ConstraintEqualTo(48),
                NotationTextField.TopAnchor.ConstraintEqualTo(IndexTextField.TopAnchor, 70),
                NotationTextField.LeadingAnchor.ConstraintEqualTo(IndexTextField.LeadingAnchor, 0),
                NotationTextField.TrailingAnchor.ConstraintEqualTo(IndexTextField.TrailingAnchor, 0),
                NotationTextField.HeightAnchor.ConstraintEqualTo(48),
                CoordsTextField.TopAnchor.ConstraintEqualTo(NotationTextField.TopAnchor, 70),
                CoordsTextField.LeadingAnchor.ConstraintEqualTo(NotationTextField.LeadingAnchor, 0),
                CoordsTextField.TrailingAnchor.ConstraintEqualTo(NotationTextField.TrailingAnchor, 0),
                CoordsTextField.HeightAnchor.ConstraintEqualTo(48),
                CoordsRemoveBn.TopAnchor.ConstraintEqualTo(NotationTextField.TopAnchor, 70),
                CoordsRemoveBn.LeadingAnchor.ConstraintEqualTo(NotationTextField.LeadingAnchor, 0),
                CoordsRemoveBn.TrailingAnchor.ConstraintEqualTo(NotationTextField.TrailingAnchor, 0),
                CoordsRemoveBn.HeightAnchor.ConstraintEqualTo(48),
            });

            resetBn.SetTitle("Сбросить", UIControlState.Normal);
            applyAddressBn.SetTitle("ПОДТВЕРДИТЬ АДРЕС", UIControlState.Normal);
            mapAddressBn.Layer.BorderColor = UIColor.FromRGB(255, 99, 62).CGColor;
            mapAddressBn.Layer.BorderWidth = 1f;
            mapAddressBn.SetTitle("ВЫБРАТЬ НА КАРТЕ", UIControlState.Normal);
            applyAddressBn.Font = UIFont.FromName(Constants.fira_sans, 15f);
            mapAddressBn.Font   = UIFont.FromName(Constants.fira_sans, 15f);
            resetBn.Font        = UIFont.FromName(Constants.fira_sans, 15f);
            if (!deviceModel.Contains("e 5") && !deviceModel.Contains("e 4") && !deviceModel.ToLower().Contains("e se"))
            {
                applyAddressBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                                     600,
                                                     Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                                     Convert.ToInt32(View.Frame.Height) / 12);
                mapAddressBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                                   Convert.ToInt32(applyAddressBn.Frame.Y - (int)(applyAddressBn.Frame.Height + 10)),
                                                   Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                                   Convert.ToInt32(View.Frame.Height) / 12);
            }
            else
            {
                applyAddressBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                                     Convert.ToInt32(view_in_scroll.Frame.Height + 60 - headerView.Frame.Height / 3),
                                                     Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                                     Convert.ToInt32(View.Frame.Height) / 12);
                mapAddressBn.Frame = new Rectangle(Convert.ToInt32(View.Frame.Width) / 15,
                                                   Convert.ToInt32(applyAddressBn.Frame.Y - (int)(applyAddressBn.Frame.Height + 10)),
                                                   Convert.ToInt32(View.Frame.Width) - ((Convert.ToInt32(View.Frame.Width) / 15) * 2),
                                                   Convert.ToInt32(View.Frame.Height) / 12);
                var diff = view_in_scroll.Frame.Height - (applyAddressBn.Frame.Y + applyAddressBn.Frame.Height);
                if (diff < 0)
                {
                    view_in_scroll.Frame = new Rectangle(0, 0 /*Convert.ToInt32(headerView.Frame.Y + headerView.Frame.Height*1.2)*/, Convert.ToInt32(View.Frame.Width), Convert.ToInt32(applyAddressBn.Frame.Y + applyAddressBn.Frame.Height));
                }
            }

            SetScrollViewContentSize();
        }