using Shared.Common;
using System;
namespace Shared.Phone.UserCenter.UserMain
{
///
/// 个人信息画面
///
public class UserInformationForm : EditorCommonForm
{
///
/// 中部桌布控件
///
private NormalFrameLayout frameMiddleBack = null;
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//记住它原来的昵称
UserCenterResourse.UserInfo.OldUserName = UserCenterResourse.UserInfo.UserName;
//因为别的画面会调用这个函数,然后刷新画面
this.ClearBodyFrame();
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uPersonalInfo));
//初始化上部的信息
this.InitTopBodyFrame();
//初始化中部的信息
this.InitMiddleBodyFrame();
//初始化退出账号的FrameLayout
this.InitLogoutFrameLayout();
}
#endregion
#region ■ 初始化上段控件_____________________
///
/// 初始化上部的信息
///
private void InitTopBodyFrame()
{
var specialTopFrame = new FrameLayout();
specialTopFrame.Height = Application.GetRealHeight(340);
specialTopFrame.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(specialTopFrame);
//用户图标
var btnUserIcon = new ImageView();
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);
specialTopFrame.AddChidren(btnUserIcon);
btnUserIcon.MouseUpEventHandler += (sender, e) =>
{
//显示获取图片来源菜单
this.ShowUserIconMenu(btnUserIcon);
};
}
#endregion
#region ■ 初始化中段控件_____________________
///
/// 初始化中部的信息
///
private void InitMiddleBodyFrame()
{
if (this.frameMiddleBack == null)
{
frameMiddleBack = new NormalFrameLayout();
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);
frameMiddleBack.AddChidren(listMidFrame);
var rowName = new FrameRowControl(listMidFrame.rowSpace / 2);
//关闭点击状态
rowName.UseClickStatu = false;
listMidFrame.AddChidren(rowName);
//底线
var btnNameLine = rowName.AddBottomLine();
//名称View
rowName.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uName), 350);
//名称输入
var txtName = new TextInputControl(700, true);
txtName.UseFocusColor = true;
txtName.X = bodyFrameLayout.Width - Application.GetRealWidth(700) - ControlCommonResourse.XXLeft;
txtName.Gravity = Gravity.CenterVertical;
txtName.TextAlignment = TextAlignment.CenterRight;
txtName.Text = UserCenterResourse.UserInfo.UserName;
rowName.AddChidren(txtName, ChidrenBindMode.NotBind);
txtName.Y += listMidFrame.rowSpace / 2;
//输入结束事件
txtName.FinishInputEvent += (() =>
{
//更新用户名
this.SaveUserName(txtName, true);
});
//输入值改变事件(2020.04.05:以前都定死说按回车键才更新,现在又说名字没有同步
//所以才出此下策,添加这个事件)
txtName.TextChangeEventHandler += (sender, value) =>
{
UserCenterResourse.UserInfo.UserName = value;
};
//光标改变事件(2020.04.05:以前都定死说按回车键才更新,现在又说名字没有同步
//所以才出此下策,添加这个事件)
txtName.FoucsChanged += (sender, focusEvent) =>
{
//光标离开时,执行名字修改
if (focusEvent.Focus == false)
{
//更新用户名
this.SaveUserName(txtName, false);
}
};
//联动线的状态
txtName.btnLine = btnNameLine;
var rowQrCode = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowQrCode);
//底线
rowQrCode.AddBottomLine();
//二维码
rowQrCode.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uQRCode), 350);
var btnQrCode = rowQrCode.AddMostRightEmptyIcon(92, 92);
btnQrCode.UnSelectedImagePath = "Item/QRCode.png";
rowQrCode.ButtonClickEvent += (sender, e) =>
{
var form = new QRCodeForm();
form.AddForm();
};
var rowEmail = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowEmail);
//底线
rowEmail.AddBottomLine();
//邮箱View
rowEmail.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uEmail), 350);
//添加向右图标
rowEmail.AddRightArrow();
//邮箱
var btnEmail = rowEmail.AddMostRightView(UserCenterResourse.UserInfo.Email, 500);
if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
{
//未设置,请绑定
btnEmail.TextID = R.MyInternationalizationString.uNotSettionAndPleaseBind;
}
rowEmail.ButtonClickEvent += (sender, e) =>
{
if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
{
var form = new Password.CheckNewEmailForm();
form.AddForm();
}
else
{
var form = new Password.CheckOldEmailForm();
form.AddForm();
}
};
var rowPhone = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowPhone);
//底线
rowPhone.AddBottomLine();
//手机号View
rowPhone.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uPhone), 350);
//添加向右图标
rowPhone.AddRightArrow();
//手机号
var btnPhone = rowPhone.AddMostRightView(UserCenterResourse.UserInfo.Phone, 500);
if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true)
{
//未设置,请绑定
btnPhone.TextID = R.MyInternationalizationString.uNotSettionAndPleaseBind;
}
else
{
string phoneNum = UserCenterResourse.UserInfo.Phone;
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 = "+" + UserCenterResourse.UserInfo.AreaCode + " " + phoneNum;
}
rowPhone.ButtonClickEvent += (sender, e) =>
{
if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true)
{
var form = new Password.CheckNewPhoneForm();
form.AddForm();
}
else
{
var form = new Password.CheckOldPhoneForm();
form.AddForm();
}
};
var rowOther = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowOther);
//第三方账号
rowOther.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAuthenticatedOtherPartyAccount), 400);
//底线
rowOther.AddBottomLine();
//添加向右图标
rowOther.AddRightArrow();
//微信、QQ
//var btnQQ = rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 500);
var btnQQ = rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChat), 500);
rowOther.ButtonClickEvent += (sender, e) =>
{
var form = new OtherParty.OtherPartyAccountMenuForm();
form.AddForm();
};
var rowSysPsw = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowSysPsw);
//添加底线
rowSysPsw.AddBottomLine();
//系统密码
rowSysPsw.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSystemPassword), 350);
//添加向右图标
rowSysPsw.AddRightArrow();
//去修改
var btnPsw = rowSysPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoEditor), 350);
rowSysPsw.ButtonClickEvent += (sender, e) =>
{
var form = new Password.EditorAccountPasswordForm();
form.AddForm();
};
var rowSecond = new FrameRowControl(listMidFrame.rowSpace / 2);
listMidFrame.AddChidren(rowSecond);
//二次安全验证
rowSecond.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSecondAuthentication), 350);
//添加向右图标
rowSecond.AddRightArrow();
//密码、手势、指纹
var btnSecand = rowSecond.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uPasswordGestureFingerPrint), 400);
rowSecond.ButtonClickEvent += (sender, e) =>
{
var form = new SecondAuthenticationForm();
form.AddForm();
};
}
#endregion
#region ■ 初始化下段控件_____________________
///
/// 初始化退出账号的FrameLayout
///
private void InitLogoutFrameLayout()
{
var specialFrame = new FrameLayout();
specialFrame.Height = ControlCommonResourse.ListViewRowHeight;
specialFrame.Y = Application.GetRealHeight(1394);
specialFrame.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(specialFrame);
//退出登陆
var btnLogout = new NormalClickButton(specialFrame.Width, specialFrame.Height);
btnLogout.clickStatuColor = 0xfffbfbfb;
btnLogout.TextID = R.MyInternationalizationString.uLogoutAccount;
btnLogout.TextColor = 0xff666666;
btnLogout.BackgroundColor = UserCenterColor.Current.White;
specialFrame.AddChidren(btnLogout);
btnLogout.ButtonClickEvent += (sender, e) =>
{
//确定退出当前账号?
string msg = Language.StringByID(R.MyInternationalizationString.uLogoutAccountMsg);
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
{
//退出账号
UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
});
};
}
#endregion
#region ■ 更新用户名_________________________
///
/// 更新用户名
///
///
private void SaveUserName(TextInputControl txtName, bool showMsg)
{
if (UserCenterResourse.UserInfo.UserName == string.Empty)
{
//把名称还原回去
txtName.Text = UserCenterResourse.UserInfo.OldUserName;
UserCenterResourse.UserInfo.UserName = UserCenterResourse.UserInfo.OldUserName;
return;
}
if (UserCenterResourse.UserInfo.OldUserName == UserCenterResourse.UserInfo.UserName)
{
//无需修改
return;
}
var pra = new SaveUserNamePra();
pra.UserName = UserCenterResourse.UserInfo.UserName;
bool result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateUserName", false, pra);
if (result == false)
{
return;
}
if (showMsg == true)
{
//用户名称修改成功!
string msg = Language.StringByID(R.MyInternationalizationString.uUserNameSaveSuccess);
this.ShowMassage(ShowMsgType.Tip, msg);
}
UserCenterResourse.UserInfo.OldUserName = UserCenterResourse.UserInfo.UserName;
}
#endregion
#region ■ 显示获取图片来源菜单_______________
///
/// 显示获取图片来源菜单
///
///
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");
});
}
///
/// 上传用户头像文件
///
///
///
private void UpLoadUserIconFile(ImageView btnUser, string imagePath)
{
var pra = new { HeadImage = Shared.IO.FileUtils.ReadFile(imagePath) };
var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateHeadImage", false, pra);
if (result == true)
{
UserCenterResourse.UserInfo.UserIconFileChanged = true;
btnUser.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
}
}
///
/// 移动用户头像文件
///
///
///
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 ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
///
public override int FormActionAgainEvent()
{
//初始化中部的信息
this.InitMiddleBodyFrame();
return 1;
}
#endregion
}
}