using System;
using Shared;
namespace HDL_ON.Entity
{
public class CommonMethod
{
private Loading loading;
private static CommonMethod commonMethod = null;
///
/// 获取对象
///
public static CommonMethod Current
{
get
{
if (commonMethod == null)
{
commonMethod = new CommonMethod();
}
return commonMethod;
}
}
///
/// 获取Loading对象
///
///
public Loading Loading
{
get
{
this.MainThread(() =>
{
if (loading == null)//|| MainPage.BasePageView.ChildrenCount < 1)
{
loading = new Loading();
}
Application.MainPage.AddChidren(loading);
});
return loading;
}
}
#region ---------自定义线程(子线程,主线程)--------
///
/// 子线程
///
/// 是否要提示错误信息(默认显示)
///
public void SunThread(Action action, TipType tipType = TipType.confirmation)
{
new System.Threading.Thread(() =>
{
try
{
action?.Invoke();
}
catch (Exception e)
{
this.ShowAlert(e, tipType);
}
})
{ IsBackground = true }.Start();
}
///
/// 主线程(UI更新)
///
/// 是否要提示错误信息(默认显示)
///
public void MainThread(Action action, TipType tipType = TipType.confirmation)
{
Application.RunOnMainThread(() =>
{
try
{
action?.Invoke();
}
catch (Exception e)
{
this.ShowAlert(e, tipType);
}
});
}
#endregion
#region --------- 提示框,确认框 --------
///
/// 对话框(只要程序报错的时候才用到)
///
/// 异常对象
/// 是否要提示错误信息(默认显示)
private void ShowAlert(Exception e, TipType tipType)
{
}
public void ShowTip(string msg,int time = 2)
{
new UI.PublicAssmebly().TipMsgAutoClose(msg, false, time);
}
#endregion
}
///
/// 弹框类型
///
public enum TipType
{
none,//无提示
flicker,//闪烁框
confirmation//确认框
}
///
/// 表示来自那个界面
///
public enum Comerom
{
function,//功能
collect,//收藏
room,//房间
push,//推送
sanfan,//添加第三方设备
}
}