New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | |
| | | namespace Shared.Phone |
| | | { |
| | | /// <summary> |
| | | /// 界面相关的逻辑 |
| | | /// </summary> |
| | | public class HdlFormLogic |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 界面相关的逻辑 |
| | | /// </summary> |
| | | private static HdlFormLogic m_Current; |
| | | /// <summary> |
| | | /// 界面相关的逻辑 |
| | | /// </summary> |
| | | public static HdlFormLogic Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new HdlFormLogic(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// <para>当前已经打开了的画面(继承于UserCenterCommonForm才能使用)。</para> |
| | | /// <para>画面打开时,会自动追击,画面关闭时,自动移除。</para> |
| | | /// <para>新添加的界面会放在前面</para> |
| | | /// </summary> |
| | | private List<CommonFormBase> ListActionForm = new List<CommonFormBase>(); |
| | | /// <summary> |
| | | /// 当前正在操作的画面ID(没人会懂它为何要存在) |
| | | /// </summary> |
| | | public string NowActionFormID |
| | | { |
| | | get |
| | | { |
| | | return ListActionForm.Count > 0 ? ListActionForm[0].FormID : string.Empty; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加界面相关_______________________ |
| | | |
| | | /// <summary> |
| | | /// 检测能否添加画面 |
| | | /// </summary> |
| | | /// <returns>true:可以追加 false:不可追加</returns> |
| | | /// <param name="form">Form</param> |
| | | public bool CheckCanAddForm(CommonFormBase form) |
| | | { |
| | | //获取画面英文名字 |
| | | string formId = GetFormID(form); |
| | | |
| | | //暂时这样弄看看,如果重复,则关闭掉原来的界面 |
| | | var formTemp = this.GetFormByName(formId); |
| | | formTemp?.CloseForm(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 把打开的画面添加到内存中 |
| | | /// </summary> |
| | | /// <param name="form">Form.</param> |
| | | public void AddActionForm(CommonFormBase form) |
| | | { |
| | | //获取画面英文名字 |
| | | string formId = GetFormID(form); |
| | | |
| | | //内存添加 |
| | | form.FormID = formId; |
| | | this.ListActionForm.Insert(0, form); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从列表中移除画面 |
| | | /// </summary> |
| | | /// <param name="i_closeForm">关闭的界面</param> |
| | | public void RemoveActionForm(CommonFormBase i_closeForm) |
| | | { |
| | | //获取画面ID |
| | | string formId = GetFormID(i_closeForm); |
| | | var removeForm = this.GetFormByName(formId); |
| | | if (removeForm == null) |
| | | { |
| | | return; |
| | | } |
| | | //移除画面 |
| | | this.ListActionForm.Remove(removeForm); |
| | | |
| | | var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1); |
| | | if (actionForm == null) |
| | | { |
| | | return; |
| | | } |
| | | //如果关闭的界面是DialogCommonForm类型,则不需要触发激活函数 |
| | | if (i_closeForm is DialogCommonForm) |
| | | { |
| | | return; |
| | | } |
| | | //关闭的界面为EditorCommonForm的时候 |
| | | else if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm)) |
| | | { |
| | | //接下来激活的界面 |
| | | try |
| | | { |
| | | var Myform = actionForm as EditorCommonForm; |
| | | //重置左滑使能 |
| | | Myform.ScrollEnabled = Myform.ScrollEnabled; |
| | | //触发界面再次激活的事件 |
| | | int value = Myform.FormActionAgainEvent(); |
| | | if (value == 1) |
| | | { |
| | | //Log出力 |
| | | HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //Log出力 |
| | | HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + this.NowActionFormID); |
| | | } |
| | | } |
| | | else if (actionForm is UserView.UserPage) |
| | | { |
| | | //这里它已经退到主页了 |
| | | var nowForm = UserView.UserPage.Instance.GetNowActionForm(); |
| | | nowForm?.FormActionAgainEvent(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取画面ID |
| | | /// </summary> |
| | | /// <returns>The form name.</returns> |
| | | /// <param name="form">Form.</param> |
| | | private string GetFormID(CommonFormBase form) |
| | | { |
| | | if (form.FormID != string.Empty) |
| | | { |
| | | return form.FormID; |
| | | } |
| | | //将命名空间去掉 |
| | | string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); |
| | | string formName = Arry[Arry.Length - 1].Trim(); |
| | | return formName; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 关闭界面相关_______________________ |
| | | |
| | | /// <summary> |
| | | /// 关闭所有打开了的界面 |
| | | /// </summary> |
| | | /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param> |
| | | /// <param name="refreshMainPage">当关闭的界面达到主页时,是否刷新主页</param> |
| | | public void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true) |
| | | { |
| | | while (UserView.HomePage.Instance.ChildrenCount > 0) |
| | | { |
| | | var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1); |
| | | //(因底层控件修改了, 父控件移除时, 不触发子控件的移除事件) |
| | | if (view is ViewGroup) |
| | | { |
| | | //关闭加载在ViewGroup里面的自定义界面Form |
| | | CloseViewGroupChildren((ViewGroup)view); |
| | | } |
| | | |
| | | if (view is CommonFormBase) |
| | | { |
| | | if (((CommonFormBase)view).FormID == tagetFrom) |
| | | { |
| | | //只关闭到指定目标界面 |
| | | return; |
| | | } |
| | | ((CommonFormBase)view).CloseForm(); |
| | | } |
| | | else if (view is UserView.UserPage) |
| | | { |
| | | //刷新主页 |
| | | if (refreshMainPage == true) |
| | | { |
| | | UserView.UserPage.Instance.ReFreshControl(); |
| | | } |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | view.RemoveFromParent(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭加载在ViewGroup里面的自定义界面Form(因底层控件修改了,父控件移除时,不触发子控件的移除事件) |
| | | /// </summary> |
| | | /// <param name="group"></param> |
| | | private void CloseViewGroupChildren(ViewGroup group) |
| | | { |
| | | for (int i = 0; i < group.ChildrenCount; i++) |
| | | { |
| | | var view = group.GetChildren(i); |
| | | if (view is CommonFormBase) |
| | | { |
| | | ((CommonFormBase)view).CloseForm(); |
| | | i--; |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ■ 一般方法___________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取当前正在激活的界面 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public CommonFormBase GetNowActionForm() |
| | | { |
| | | return this.ListActionForm.Count > 0 ? this.ListActionForm[0] : null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据名字获取指定已经打开了的界面 |
| | | /// </summary> |
| | | /// <param name="i_formName"></param> |
| | | /// <returns></returns> |
| | | public CommonFormBase GetFormByName(string i_formName) |
| | | { |
| | | for (int i = 0; i < this.ListActionForm.Count; i++) |
| | | { |
| | | if (this.ListActionForm[i].FormID == i_formName) |
| | | { |
| | | return this.ListActionForm[i]; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭指定的画面 |
| | | /// </summary> |
| | | /// <param name="formName">指定要关闭的画面英文名字</param> |
| | | public void CloseFormByFormName(string formName) |
| | | { |
| | | var form = this.GetFormByName(formName); |
| | | //关闭指定画面 |
| | | form?.CloseForm(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断指定的界面是否打开 |
| | | /// </summary> |
| | | /// <param name="formId"></param> |
| | | /// <returns></returns> |
| | | public bool IsFormOpen(string formId) |
| | | { |
| | | var form = this.GetNowActionForm(); |
| | | |
| | | return form != null ? form.FormID == formId : false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取全部已经打开了的界面 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<CommonFormBase> GetAllOpenForm() |
| | | { |
| | | var list = new List<CommonFormBase>(); |
| | | try |
| | | { |
| | | for (int i = 0; i < this.ListActionForm.Count; i++) |
| | | { |
| | | list.Add(this.ListActionForm[i]); |
| | | } |
| | | return list; |
| | | } |
| | | catch { return list; } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 引导界面___________________________ |
| | | |
| | | /// <summary> |
| | | /// 显示引导界面 |
| | | /// </summary> |
| | | /// <param name="result">同步结果 -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据</param> |
| | | public void ShowGuideForm(int result) |
| | | { |
| | | var checkFile = HdlFileNameResourse.GuideFile; |
| | | if (System.IO.File.Exists(checkFile) == true) |
| | | { |
| | | //不需要显示 |
| | | return; |
| | | } |
| | | if (result == 2 && Common.Config.Instance.Home.IsOtherShare == false) |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | var form = new UserCenter.Guide.GuideHouseForm(); |
| | | form.ShowFrom(); |
| | | }); |
| | | } |
| | | |
| | | //创建一个空文件(标识已经完成引导) |
| | | var file = System.IO.File.Create(checkFile); |
| | | file.Close(); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |