using Shared.Common;
using System;
namespace Shared.Phone.UserCenter.UserMain
{
///
/// 个人信息画面
///
public class UserInformationForm : EditorCommonForm
{
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//因为别的画面会调用这个函数,然后刷新画面
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 = 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.ImagePath = UserCenterResourse.UserInfo.UserIconFile;
specialTopFrame.AddChidren(btnUserIcon);
btnUserIcon.MouseUpEventHandler += (sender, e) =>
{
//显示获取图片来源菜单
this.ShowUserIconMenu(btnUserIcon);
};
}
#endregion
#region ■ 初始化中段控件_____________________
///
/// 初始化中部的信息
///
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);
var listMidFrame = new FrameListControl(12);
listMidFrame.Y = Application.GetRealHeight(11);
listMidFrame.Height = Application.GetRealHeight(1008 - 11);
frameBack.AddChidren(listMidFrame);
var rowName = new FrameRowControl(listMidFrame.rowSpace / 2);
//关闭点击状态
rowName.UseClickStatu = false;
listMidFrame.AddChidren(rowName);
//底线
rowName.AddBottomLine();
//名称View
rowName.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uName), 350);
//名称输入
var txtName = new TextInputExControl(700, 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 += (() =>
{
if (txtName.Text.Trim() == string.Empty)
{
//把名称还原回去
txtName.Text = UserCenterResourse.UserInfo.UserName;
return;
}
//更新用户名
this.SaveUserName(txtName.Text.Trim());
});
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
{
btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + UserCenterResourse.UserInfo.Phone;
}
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
rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 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();
//去修改
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();
//密码、手势、指纹
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 async void SaveUserName(string userName)
{
if (UserCenterResourse.UserInfo.UserName == userName)
{
return;
}
//打开进度条
this.ShowProgressBar();
var pra = new SaveUserNamePra();
pra.UserName = userName;
bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateUserName", false, pra);
//关闭进度条
this.CloseProgressBar();
if (result == false)
{
return;
}
//用户名称修改成功!
string msg = Language.StringByID(R.MyInternationalizationString.uUserNameSaveSuccess);
this.ShowMassage(ShowMsgType.Tip, msg);
UserCenterResourse.UserInfo.UserName = 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 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.ImagePath = 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.ShowForm();
return 1;
}
#endregion
}
}