黄学彪
2019-12-09 163777d8a2cb7cfa469f54a7042528870ebc10a3
ZigbeeApp/Shared/Phone/UserCenter/UserMain/UserInformationForm.cs
@@ -8,6 +8,11 @@
    /// </summary>
    public class UserInformationForm : EditorCommonForm
    {
        /// <summary>
        /// 中部桌布控件
        /// </summary>
        private FrameLayout frameMiddleBack = null;
        #region ■ 初始化_____________________________
        /// <summary>
@@ -46,11 +51,19 @@
            bodyFrameLayout.AddChidren(specialTopFrame);
            //用户图标
            var btnUserIcon = new IconViewControl(251);
            var btnUserIcon = new ImageView();
            btnUserIcon.Height = Application.GetMinRealAverage(251);
            btnUserIcon.Width = Application.GetMinRealAverage(251);
            btnUserIcon.Radius = (uint)Application.GetMinRealAverage(251) / 2;
            btnUserIcon.Y = Application.GetRealHeight(46);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            btnUserIcon.UnSelectedImagePath = UserCenterResourse.UserInfo.UserIconFile;
            btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(UserCenterResourse.UserInfo.UserIconFile);
            specialTopFrame.AddChidren(btnUserIcon);
            btnUserIcon.MouseUpEventHandler += (sender, e) =>
            {
                //显示获取图片来源菜单
                this.ShowUserIconMenu(btnUserIcon);
            };
        }
        #endregion
@@ -62,16 +75,23 @@
        /// </summary>
        private void InitMiddleBodyFrame()
        {
            var frameBack = new FrameLayout();
            frameBack.Y = Application.GetRealHeight(363);
            frameBack.Height = Application.GetRealHeight(1008);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
            if (this.frameMiddleBack == null)
            {
                frameMiddleBack = new FrameLayout();
                frameMiddleBack.Y = Application.GetRealHeight(363);
                frameMiddleBack.Height = Application.GetRealHeight(1008);
                frameMiddleBack.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frameMiddleBack);
            }
            else
            {
                frameMiddleBack.RemoveAll();
            }
            var listMidFrame = new FrameListControl(12);
            listMidFrame.Y = Application.GetRealHeight(11);
            listMidFrame.Height = Application.GetRealHeight(1008 - 11);
            frameBack.AddChidren(listMidFrame);
            frameMiddleBack.AddChidren(listMidFrame);
            var rowName = new FrameRowControl(listMidFrame.rowSpace / 2);
            //关闭点击状态
@@ -126,6 +146,7 @@
            rowEmail.AddRightArrow();
            //邮箱
            var btnEmail = rowEmail.AddMostRightView(UserCenterResourse.UserInfo.Email, 500);
            btnEmail.IsBold = true;
            if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
            {
                //未设置,请绑定
@@ -155,6 +176,7 @@
            rowPhone.AddRightArrow();
            //手机号
            var btnPhone = rowPhone.AddMostRightView(UserCenterResourse.UserInfo.Phone, 500);
            btnPhone.IsBold = true;
            if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true)
            {
                //未设置,请绑定
@@ -188,7 +210,8 @@
            //添加向右图标
            rowOther.AddRightArrow();
            //微信、QQ
            rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 500);
            var btnQQ = rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 500);
            btnQQ.IsBold = true;
            rowOther.ButtonClickEvent += (sender, e) =>
            {
                var form = new OtherParty.OtherPartyAccountMenuForm();
@@ -204,7 +227,8 @@
            //添加向右图标
            rowSysPsw.AddRightArrow();
            //去修改
            rowSysPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoEditor), 350);
            var btnPsw = rowSysPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoEditor), 350);
            btnPsw.IsBold = true;
            rowSysPsw.ButtonClickEvent += (sender, e) =>
            {
                var form = new Password.EditorAccountPasswordForm();
@@ -218,7 +242,8 @@
            //添加向右图标
            rowSecond.AddRightArrow();
            //密码、手势、指纹
            rowSecond.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uPasswordGestureFingerPrint), 400);
            var btnSecand = rowSecond.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uPasswordGestureFingerPrint), 400);
            btnSecand.IsBold = true;
            rowSecond.ButtonClickEvent += (sender, e) =>
            {
                var form = new SecondAuthenticationForm();
@@ -242,6 +267,7 @@
            //退出登陆
            var btnLogout = new NormalClickButton(specialFrame.Width, specialFrame.Height);
            btnLogout.clickStatuColor = 0xfffbfbfb;
            btnLogout.TextID = R.MyInternationalizationString.uLogoutAccount;
            btnLogout.TextColor = 0xff666666;
            btnLogout.BackgroundColor = UserCenterColor.Current.White;
@@ -296,15 +322,109 @@
        #endregion
        #region ■ 显示获取图片来源菜单_______________
        /// <summary>
        /// 显示获取图片来源菜单
        /// </summary>
        /// <param name="btnUser"></param>
        private void ShowUserIconMenu(ImageView btnUser)
        {
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(2);
            //拍照
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uTakePictrue), () =>
            {
                //通过相机拍照裁剪
                CropImage.TakePicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == false)
                    {
                        //移动用户头像文件
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                        }
                    }
                }, "HdlPicture");
            });
            //从相册中选择
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uGetPictrueFromAlbum), () =>
            {
                //从相册选择图片裁剪
                CropImage.SelectPicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == false)
                    {
                        //移动用户头像文件
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                        }
                    }
                }, "HdlPicture");
            });
        }
        /// <summary>
        /// 上传用户头像文件
        /// </summary>
        /// <param name="btnUser"></param>
        /// <param name="imagePath"></param>
        private async void UpLoadUserIconFile(ImageView btnUser, string imagePath)
        {
            var pra = new { HeadImage = Shared.IO.FileUtils.ReadFile(imagePath) };
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateHeadImage", false, pra);
            if (result == true)
            {
                UserCenterResourse.UserInfo.UserIconFileChanged = true;
                btnUser.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
            }
        }
        /// <summary>
        /// 移动用户头像文件
        /// </summary>
        /// <param name="imagePath"></param>
        /// <returns></returns>
        private bool MoveUserIconFile(string imagePath)
        {
            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);
                return true;
            }
            catch (Exception ex)
            {
                //出现未知错误
                var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                alert.Show();
                //Log
                HdlLogLogic.Current.WriteLog(ex);
                return false;
            }
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.ShowForm();
            //初始化中部的信息
            this.InitMiddleBodyFrame();
            return 1;
        }
        #endregion