HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/UserCenter/UserMain/UserInformationForm.cs
@@ -11,7 +11,7 @@
        /// <summary>
        /// 中部桌布控件
        /// </summary>
        private FrameLayout frameMiddleBack = null;
        private NormalFrameLayout frameMiddleBack = null;
        #region ■ 初始化_____________________________
@@ -20,6 +20,9 @@
        /// </summary>
        public void ShowForm()
        {
            //记住它原来的昵称
            HdlUserCenterResourse.UserInfo.OldUserName = HdlUserCenterResourse.UserInfo.NickName;
            //因为别的画面会调用这个函数,然后刷新画面
            this.ClearBodyFrame();
@@ -52,12 +55,12 @@
            //用户图标
            var btnUserIcon = new ImageView();
            btnUserIcon.Height = Application.GetMinRealAverage(251);
            btnUserIcon.Width = Application.GetMinRealAverage(251);
            btnUserIcon.Radius = (uint)Application.GetMinRealAverage(251) / 2;
            btnUserIcon.Height = this.GetPictrueRealSize(251);
            btnUserIcon.Width = this.GetPictrueRealSize(251);
            btnUserIcon.Radius = (uint)this.GetPictrueRealSize(251) / 2;
            btnUserIcon.Y = Application.GetRealHeight(46);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(UserCenterResourse.UserInfo.UserIconFile);
            btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(HdlFileNameResourse.UserHeadIconFile);
            specialTopFrame.AddChidren(btnUserIcon);
            btnUserIcon.MouseUpEventHandler += (sender, e) =>
            {
@@ -77,9 +80,9 @@
        {
            if (this.frameMiddleBack == null)
            {
                frameMiddleBack = new FrameLayout();
                frameMiddleBack = new NormalFrameLayout();
                frameMiddleBack.Y = Application.GetRealHeight(363);
                frameMiddleBack.Height = Application.GetRealHeight(1008);
                frameMiddleBack.Height = Application.GetRealHeight(1008) - HdlControlResourse.ListViewRowHeight - Application.GetRealHeight(12);
                frameMiddleBack.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frameMiddleBack);
            }
@@ -102,25 +105,39 @@
            //名称View
            rowName.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uName), 350);
            //名称输入
            var txtName = new TextInputExControl(700, true);
            txtName.X = bodyFrameLayout.Width - Application.GetRealWidth(700) - ControlCommonResourse.XXLeft;
            var txtName = new TextInputControl(700, true);
            txtName.MaxByte = 36;//限制36个字节
            txtName.UseFocusColor = true;
            txtName.X = bodyFrameLayout.Width - Application.GetRealWidth(700) - HdlControlResourse.XXLeft;
            txtName.Gravity = Gravity.CenterVertical;
            txtName.TextAlignment = TextAlignment.CenterRight;
            txtName.Text = UserCenterResourse.UserInfo.UserName;
            txtName.Text = HdlUserCenterResourse.UserInfo.NickName;
            rowName.AddChidren(txtName, ChidrenBindMode.NotBind);
            txtName.Y += listMidFrame.rowSpace / 2;
            //输入结束事件
            txtName.FinishInputEvent += (() =>
            {
                if (txtName.Text.Trim() == string.Empty)
                {
                    //把名称还原回去
                    txtName.Text = UserCenterResourse.UserInfo.UserName;
                    return;
                }
                //更新用户名
                this.SaveUserName(txtName.Text.Trim());
                this.SaveUserName(txtName, true);
            });
            //输入值改变事件(2020.04.05:以前都定死说按回车键才更新,现在又说名字没有同步
            //所以才出此下策,添加这个事件)
            txtName.TextChangedEvent += (value) =>
            {
                HdlUserCenterResourse.UserInfo.NickName = value;
            };
            //光标改变事件(2020.04.05:以前都定死说按回车键才更新,现在又说名字没有同步
            //所以才出此下策,添加这个事件)
            txtName.FoucsChanged += (sender, focusEvent) =>
            {
                //光标离开时,执行名字修改
                if (focusEvent.Focus == false)
                {
                    //更新用户名
                    this.SaveUserName(txtName, false);
                }
            };
            //联动线的状态
            txtName.btnLine = btnNameLine;
@@ -147,15 +164,15 @@
            //添加向右图标
            rowEmail.AddRightArrow();
            //邮箱
            var btnEmail = rowEmail.AddMostRightView(UserCenterResourse.UserInfo.Email, 500);
            if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
            var btnEmail = rowEmail.AddMostRightView(HdlUserCenterResourse.UserInfo.UserEmail, 500);
            if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserEmail) == true)
            {
                //未设置,请绑定
                btnEmail.TextID = R.MyInternationalizationString.uNotSettionAndPleaseBind;
            }
            rowEmail.ButtonClickEvent += (sender, e) =>
            {
                if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
                if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserEmail) == true)
                {
                    var form = new Password.CheckNewEmailForm();
                    form.AddForm();
@@ -176,19 +193,29 @@
            //添加向右图标
            rowPhone.AddRightArrow();
            //手机号
            var btnPhone = rowPhone.AddMostRightView(UserCenterResourse.UserInfo.Phone, 500);
            if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true)
            var btnPhone = rowPhone.AddMostRightView(HdlUserCenterResourse.UserInfo.UserPhone, 500);
            if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserPhone) == true)
            {
                //未设置,请绑定
                btnPhone.TextID = R.MyInternationalizationString.uNotSettionAndPleaseBind;
            }
            else
            {
                btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + UserCenterResourse.UserInfo.Phone;
                string phoneNum = HdlUserCenterResourse.UserInfo.UserPhone;
                if (phoneNum.Length >= 11)
                {
                    phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 7, '*') + phoneNum.Substring(phoneNum.Length - 4, 4);
                }
                else if (phoneNum.Length >= 5)
                {
                    //或许这是国外的手机吧
                    phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 5, '*') + phoneNum.Substring(phoneNum.Length - 2, 2);
                }
                btnPhone.Text = "+" + HdlUserCenterResourse.UserInfo.PhoneAreaCode + " " + phoneNum;
            }
            rowPhone.ButtonClickEvent += (sender, e) =>
            {
                if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true)
                if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserPhone) == true)
                {
                    var form = new Password.CheckNewPhoneForm();
                    form.AddForm();
@@ -202,7 +229,7 @@
          
            var rowOther = new FrameRowControl(listMidFrame.rowSpace / 2);
            listMidFrame.AddChidren(rowOther);
            //listMidFrame.AddChidren(rowOther);
            //第三方账号
            rowOther.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAuthenticatedOtherPartyAccount), 400);
            //底线
@@ -258,8 +285,8 @@
        private void InitLogoutFrameLayout()
        {
            var specialFrame = new FrameLayout();
            specialFrame.Height = ControlCommonResourse.ListViewRowHeight;
            specialFrame.Y = Application.GetRealHeight(1394);
            specialFrame.Height = HdlControlResourse.ListViewRowHeight;
            specialFrame.Y = Application.GetRealHeight(1394) - HdlControlResourse.ListViewRowHeight - Application.GetRealHeight(12);
            specialFrame.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(specialFrame);
@@ -278,7 +305,7 @@
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //退出账号
                    UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
                    HdlAccountLogic.Current.ReLoginAgain(Common.Config.Instance.Account);
                });
            };
        }
@@ -290,32 +317,36 @@
        /// <summary>
        /// 更新用户名
        /// </summary>
        /// <param name="userName">昵称</param>
        private async void SaveUserName(string userName)
        /// <param name="txtName"></param>
        private void SaveUserName(TextInputControl txtName, bool showMsg)
        {
            if (UserCenterResourse.UserInfo.UserName == userName)
            if (HdlUserCenterResourse.UserInfo.NickName == string.Empty)
            {
                //把名称还原回去
                txtName.Text = HdlUserCenterResourse.UserInfo.OldUserName;
                HdlUserCenterResourse.UserInfo.NickName = HdlUserCenterResourse.UserInfo.OldUserName;
                return;
            }
            //打开进度条
            this.ShowProgressBar();
            if (HdlUserCenterResourse.UserInfo.OldUserName == HdlUserCenterResourse.UserInfo.NickName)
            {
                //无需修改
                return;
            }
            var pra = new SaveUserNamePra();
            pra.UserName = userName;
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateUserName", false, pra);
            //关闭进度条
            this.CloseProgressBar();
            bool result = HdlAccountLogic.Current.EditorUserNikeName(HdlUserCenterResourse.UserInfo.NickName, showMsg == true ? ShowNetCodeMode.YES : ShowNetCodeMode.No);
            if (result == false)
            {
                return;
            }
            //用户名称修改成功!
            string msg = Language.StringByID(R.MyInternationalizationString.uUserNameSaveSuccess);
            this.ShowMassage(ShowMsgType.Tip, msg);
            if (showMsg == true)
            {
                //用户名称修改成功!
                string msg = Language.StringByID(R.MyInternationalizationString.uUserNameSaveSuccess);
                this.ShowMassage(ShowMsgType.Tip, msg);
            }
            UserCenterResourse.UserInfo.UserName = userName;
            HdlUserCenterResourse.UserInfo.OldUserName = HdlUserCenterResourse.UserInfo.NickName;
        }
        #endregion
@@ -342,7 +373,7 @@
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                            this.UpLoadUserIconFile(btnUser, HdlFileNameResourse.UserHeadIconFile);
                        }
                    }
                }, "HdlPicture");
@@ -359,7 +390,7 @@
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                            this.UpLoadUserIconFile(btnUser, HdlFileNameResourse.UserHeadIconFile);
                        }
                    }
                }, "HdlPicture");
@@ -371,14 +402,18 @@
        /// </summary>
        /// <param name="btnUser"></param>
        /// <param name="imagePath"></param>
        private async void UpLoadUserIconFile(ImageView btnUser, string imagePath)
        private void UpLoadUserIconFile(ImageView btnUser, string imagePath)
        {
            var pra = new { HeadImage = Shared.IO.FileUtils.ReadFile(imagePath) };
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateHeadImage", false, pra);
            var headImage = Shared.IO.FileUtils.ReadFile(imagePath);
            if (headImage == null)
            {
                return;
            }
            var result = HdlAccountLogic.Current.UpLoadUserIconImage(headImage);
            if (result == true)
            {
                UserCenterResourse.UserInfo.UserIconFileChanged = true;
                btnUser.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                HdlUserCenterResourse.UserInfo.UserIconFileChanged = true;
                btnUser.ImageBytes = headImage;
            }
        }
@@ -391,12 +426,7 @@
        {
            try
            {
                if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
                {
                    System.IO.File.Delete(UserCenterResourse.UserInfo.UserIconFile);
                }
                //移动文件
                System.IO.File.Move(imagePath, UserCenterResourse.UserInfo.UserIconFile);
                HdlFileLogic.Current.MoveFile(imagePath, HdlFileNameResourse.UserHeadIconFile);
                return true;
            }
            catch (Exception ex)