using System;
|
using HDL_ON.Entity;
|
using System.Collections.Generic;
|
using Shared;
|
using HDL_ON.DAL.Server;
|
#if __IOS__
|
using Foundation;
|
#else
|
using Com.Videogo.Hdl;
|
#endif
|
|
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
|
{
|
/// <summary>
|
/// 萤石视频门锁公共方法类
|
/// </summary>
|
public class CommonMethod
|
{
|
|
private Loading loading;
|
/// <summary>
|
/// 记录当前界面索引值
|
/// </summary>
|
private int pageLayoutIndexValue;
|
|
private static CommonMethod commonMethod = null;
|
/// <summary>
|
/// 获取对象
|
/// </summary>
|
public static CommonMethod Current
|
{
|
get
|
{
|
if (commonMethod == null)
|
{
|
commonMethod = new CommonMethod();
|
}
|
|
return commonMethod;
|
|
}
|
|
}
|
|
#region --------- 跳转到Android,ios那边的方法(萤石视频门锁) --------
|
/// <summary>
|
/// android,ios源生添加设备到云端成功后回调方法
|
/// 再读取云端的上萤石设备列表
|
/// <paramref name="spk"/>spk</param>
|
public void SkipAddDeviceActivity(string spk)
|
{
|
|
this.InitializationAndroidData((isEzChildAccessToken) =>
|
{
|
this.SunThread(() =>
|
{
|
var list = this.GetVideoDoorLockLockModelsList("notAllowedConfigNetworkModels");
|
|
this.MainThread(() =>
|
{
|
#if __IOS__
|
//跳转添加萤石设备
|
ezsdkDelegate = new IosIHdlInterface();
|
ezsdkDelegate.mAction += (serials) =>
|
{
|
this.GetYingshiDeviceList(serials);
|
};
|
EZSDK.IOS.EZSDK.SharedInstance().Delegate = ezsdkDelegate;
|
NSObject[] nSObject = new NSObject[list.Count];
|
for (int i = 0; i < list.Count; i++)
|
{
|
string strValue = list[i];
|
nSObject[i] = new NSString(strValue);
|
}
|
EZSDK.IOS.EZSDK.SharedInstance().ConnectTipModels = nSObject;
|
EZSDK.IOS.EZSDK.SharedInstance().AddEzvizMonitorWithDeviceType(spk);
|
|
#else
|
HDLEzvizSdk.Instance.JumpToEZScanActivity(Application.Activity, spk,list);
|
HDLEzvizSdk.SetAddCallback(new AndroidIHdlInterface((isBool, serials) =>
|
{
|
if (isBool)
|
{
|
this.GetYingshiDeviceList(serials);
|
}
|
|
}));
|
#endif
|
|
});
|
|
|
});
|
});
|
|
|
|
|
|
}
|
/// <summary>
|
/// 读取云端的上萤石设备列表
|
/// <paramref name="serials"/>序列号</param>
|
private void GetYingshiDeviceList(string serials)
|
{
|
this.SunThread(() =>
|
{
|
var list = VideDoorLockSend.Current.GetVideoDoorLockDeviceList(SPK.VideoDoorLock);
|
this.MainThread(() =>
|
{
|
if (list.Count > 0)
|
{
|
var function = list.Find((o) => o.sid == serials);
|
if (function != null)
|
{
|
this.SaveFunctionFile(function);
|
}
|
}
|
});
|
});
|
|
}
|
/// <summary>
|
/// 打开实时视频画面
|
/// </summary>
|
/// <param name="deviceSerial">设备序列号</param>
|
/// <param name="deviceId">设备id(云端上deviceId)</param>
|
/// <param name="spk">设备spk(云雀上定义好的)</param>
|
/// <param name="isDialog">是否需要弹框</param>
|
public void SkipRTVActivity(string deviceSerial, string deviceId, string spk, bool isDialog)
|
{
|
this.Loading.Start();
|
this.InitializationAndroidData((isEzChildAccessToken) =>
|
{
|
this.MainThread(() =>
|
{
|
this.Loading.Hide();
|
if (isDialog)
|
{
|
Video.View.ShowDialog.Currnet.ClickBox(Language.StringByID(StringId.laizimenlinghujiao), (dialog) =>
|
{
|
dialog.Close();
|
this.SkipRTVActivity(deviceSerial, deviceId, spk);
|
}, (dialog) => { dialog.Close(); });
|
}
|
else
|
{
|
this.SkipRTVActivity(deviceSerial, deviceId, spk);
|
}
|
|
});
|
});
|
|
}
|
/// <summary>
|
/// 打开实时视频画面
|
/// </summary>
|
/// <param name="deviceSerial">设备序列号</param>
|
/// <param name="deviceId">设备id(云端上deviceId)</param>
|
/// <param name="spk">设备spk(云雀上定义好的)</param>
|
private void SkipRTVActivity(string deviceSerial, string deviceId, string spk)
|
{
|
|
#if __IOS__
|
//打开萤石视频界面
|
EZSDK.IOS.EZSDK.SharedInstance().PlayWithDeviceSerial(deviceSerial, deviceId, spk);
|
|
#else
|
HDLEzvizSdk.Instance.JumpToEZRealPlayActivity(Application.Activity,deviceId,deviceSerial,spk);
|
#endif
|
|
|
}
|
|
/// <summary>
|
/// 浏览历史记录
|
/// </summary>
|
public void SkipRecordActivity(string deviceId)
|
{
|
this.InitializationAndroidData((s) =>
|
{
|
this.MainThread(() =>
|
{
|
#if __IOS__
|
//打开萤石历史记录界面
|
EZSDK.IOS.EZSDK.SharedInstance().ToDeviceMsgListView(deviceId);
|
#else
|
HDLEzvizSdk.Instance.JumpLockHistoryActivity(Application.Activity, deviceId);
|
#endif
|
});
|
});
|
|
}
|
/// <summary>
|
/// 临时密码开门
|
/// <paramref name="deviceId"/>
|
/// </summary>
|
public void SkipPSWActivity(string deviceId)
|
{
|
this.InitializationAndroidData((isBools) =>
|
{
|
this.MainThread(() =>
|
{
|
#if __IOS__
|
//打开萤石临时密码界面
|
EZSDK.IOS.EZSDK.SharedInstance().ToTemPassView(deviceId);
|
#else
|
HDLEzvizSdk.Instance.JumpTempPasswordActivity(Application.Activity, deviceId);
|
#endif
|
});
|
});
|
}
|
|
/// <summary>
|
/// 初始化萤石SDK(实际就是传参数,多次调用也没有影响)
|
/// </summary>
|
public void InitializationAndroidData(Action<bool> action)
|
{
|
bool isBool = true;
|
//this.Loading.Start();
|
this.SunThread(() =>
|
{
|
try
|
{
|
//先获取萤石云子账号token
|
var ezChildAccessToken = VideDoorLockSend.Current.GetEZGetChildToken();
|
this.MainThread(() =>
|
{
|
if (string.IsNullOrEmpty(ezChildAccessToken))
|
{
|
//Token
|
isBool = false;
|
//this.ShowTip("获取萤石云子账号token失败。");
|
return;
|
}
|
|
string appKey = "1aa98a90489b4838b966b57018b4b04b";//正式服务器
|
//if (OnAppConfig.Instance.RequestHttpsHost == "https://test-gz.hdlcontrol.com")
|
//{
|
// appKey = "941b1b72b6294998acfd36c14931b675";//用在测试服务器推送的
|
//}
|
|
|
#if __IOS__
|
//iOS
|
//初始化萤石云SDK,中文国内key、英文海外key 开发者账号使用应用包名申请的APPKEY,不同包名应用需配置不同的APPKEY
|
EZSDK.IOS.EZSDK.SharedInstance().InitLibWithAppKey(appKey, appKey);
|
//1.设置所需河东的AccessToken和RefreshToken、域名地址
|
EZSDK.IOS.EZSDK.SharedInstance().SetHDlAccessToken(UserInfo.Current.LoginTokenString, UserInfo.Current.RefreshToken);
|
EZSDK.IOS.EZSDK.SharedInstance().SetRequestHttpsHostAndPlatform(OnAppConfig.Instance.RequestHttpsHost, 1, DB_ResidenceData.Instance.CurrentRegion.id);
|
//2.设置萤石子账号的AccessToken到SDK
|
EZSDK.IOS.EZSDK.SharedInstance().SetEZAccessToken(ezChildAccessToken);
|
//////3.打开摄像头设备列表页面
|
//EZSDK.IOS.EZSDK.SharedInstance().Go2EZvizMonitor();
|
//EZSDK.IOS.EZDeviceInfo info = new EZSDK.IOS.EZDeviceInfo();
|
//info.de
|
//EZSDK.IOS.EZSDK.Play(info);
|
#else
|
|
HDLEzvizSdk.Instance.Init(Application.Activity.Application, ezChildAccessToken, UserInfo.Current.LoginTokenString, UserInfo.Current.RefreshToken, OnAppConfig.Instance.RequestHttpsHost, appKey, 1, DB_ResidenceData.Instance.CurrentRegion.id);
|
|
#endif
|
|
|
});
|
|
}
|
catch (Exception e)
|
{
|
}
|
finally
|
{
|
this.MainThread(() =>
|
{
|
//this.Loading.Hide();
|
action?.Invoke(isBool);
|
});
|
}
|
});
|
}
|
|
/// <summary>
|
/// 更换住宅
|
/// </summary>
|
/// <param name="home">对象</param>
|
public void ChangeCurrHome(RegionInfoRes home)
|
{
|
|
if (DB_ResidenceData.Instance.CurrentRegion.id == home.id || string.IsNullOrEmpty(home.id)) return;
|
#if __IOS__
|
#else
|
HDLEzvizSdk.Instance.SetHomeId(home.id);
|
#endif
|
|
}
|
#endregion
|
|
/// <summary>
|
/// 获取【门锁型号】列表
|
/// </summary>
|
/// <returns>返回结果不会为null</returns>
|
public List<string> GetVideoDoorLockLockModelsList(string mode = "lockModels")
|
{
|
var lockModels = VideDoorLockSend.Current.GetVideoDoorLockLockModelsList();
|
if (mode == "lockModels")
|
{
|
return lockModels.lockModels;
|
}
|
else
|
{
|
return lockModels.notAllowedConfigNetworkModels;
|
}
|
}
|
/// <summary>
|
/// 门锁推送
|
/// </summary>
|
/// <param name="pushMessageType"></param>
|
/// <param name="jPushMessageInfo"></param>
|
public void DoorLockPush(JPushMessageInfo jpushMessageInfo)
|
{
|
this.MainThread(() =>
|
{
|
if (string.IsNullOrEmpty(jpushMessageInfo.expantContent)) return;
|
//{ "deviceSid":"J92513662","type":"opendoormsg","extDevId":"J92513662","deviceId":"1641010144999936001","spk":"security.door.ezviz"}
|
var expantContent = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpantContent>(jpushMessageInfo.expantContent);
|
if (expantContent == null)
|
{
|
return;
|
}
|
if (expantContent.spk != SPK.VideoDoorLock)
|
{
|
return;
|
}
|
if (jpushMessageInfo.messageType.Contains(PushMessageType.DOOR_BELL.ToString()))
|
{
|
///打开视频门锁
|
this.SkipRTVActivity(expantContent.devSerial, expantContent.deviceId, expantContent.spk, true);
|
}
|
else if (jpushMessageInfo.messageType.Contains(PushMessageType.Alarm.ToString()))
|
{
|
//低电量推送
|
this.UpdateDoorLockState(PushMessageType.Alarm);
|
}
|
else if (jpushMessageInfo.messageType.Contains(PushMessageType.Prompt.ToString()))
|
{
|
//开门推送
|
this.UpdateDoorLockState(PushMessageType.Prompt);
|
}
|
});
|
|
}
|
/// <summary>
|
/// 更新开锁图标和电池状态
|
/// </summary>
|
private void UpdateDoorLockState(PushMessageType pushMessageType)
|
{
|
int childrenCount = MainPage.BasePageView.ChildrenCount - 1;
|
for (int i = childrenCount; childrenCount > i; i--)
|
{
|
View view = MainPage.BasePageView.GetChildren(i);
|
if (view is VideoDoorLockPage)
|
{
|
VideoDoorLockPage videoDoorLockPage = (VideoDoorLockPage)view;
|
if (videoDoorLockPage != null)
|
{
|
videoDoorLockPage.UpdateState(pushMessageType);
|
}
|
|
}
|
}
|
|
}
|
/// <summary>
|
/// 获取萤石视频【门锁】列表
|
/// </summary>
|
/// <returns></returns>
|
public List<Function> GetVideoDoorLockList()
|
{
|
var list = FunctionList.List.GetVideoDoorLockList();
|
#if DEBUG
|
//list.Add(new Function { name = "视频门锁一", sid = "23456789", spk = SPK.VideoDoorLock });
|
//list.Add(new Function { name = "视频门锁二", sid = "2345678922", spk = SPK.VideoDoorLock });
|
#endif
|
return list;
|
}
|
#region --------- 功能文件保存,删除 --------
|
/// <summary>
|
/// 保存本地文件
|
/// </summary>
|
/// <param name="function">当前设备</param>
|
public void SaveFunctionFile(Function function)
|
{
|
if (function == null) return;
|
function.AssembleStatus();
|
function.SaveFunctionFile();
|
FunctionList.List.IniFunctionList(function.savePath, true);
|
MainPage.Log($"文件保存->{function.name}-->{function.spk}");
|
}
|
|
/// <summary>
|
/// 删除本地文件
|
/// </summary>
|
/// <param name="function">当前设备</param>
|
public void DeleteFunction(Function function)
|
{
|
if (function == null) return;
|
FunctionList.List.DeleteFunction(function);
|
MainPage.Log($"文件删除->{function.name}-->{function.spk}");
|
}
|
#endregion
|
/// <summary>
|
/// 萤石视频门锁的图标
|
/// <param name="comerom">来自那里</param>
|
/// </summary>
|
public string GetVideoDoorLockIcon(Comerom comerom)
|
{
|
|
if (comerom == Comerom.collect)
|
{
|
return "FunctionIcon/DoorLock/VideoDoorLockOpen1.png";
|
}
|
else
|
{
|
return "FunctionIcon/DoorLock/VideoDoorlockClose1.png";
|
}
|
|
}
|
|
/// <summary>
|
/// 获取Loading对象
|
/// </summary>
|
/// <returns></returns>
|
public Loading Loading
|
{
|
get
|
{
|
this.MainThread(() =>
|
{
|
//if (loading != null && this.pageLayoutIndexValue == MainPage.BasePageView.ChildrenCount - 1)
|
//{
|
// //防止二重添加对象
|
// return;
|
//}
|
if (loading == null)//|| MainPage.BasePageView.ChildrenCount < 1)
|
{
|
loading = new Loading();
|
}
|
//loading.BringToFront();
|
Application.MainPage.AddChidren(loading);
|
//View view = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1);
|
//if (view is ViewGroup)
|
//{
|
// pageLayoutIndexValue = MainPage.BasePageView.ChildrenCount - 1;
|
// ((ViewGroup)view).AddChidren(loading);
|
//}
|
});
|
return loading;
|
}
|
|
}
|
|
|
#region ---------自定义线程(子线程,主线程)--------
|
/// <summary>
|
/// 子线程
|
/// </summary>
|
/// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref>
|
/// <param name="action"></param>
|
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();
|
|
}
|
/// <summary>
|
/// 主线程(UI更新)
|
/// </summary>
|
/// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref>
|
/// <param name="action"></param>
|
public void MainThread(Action action, TipType tipType = TipType.confirmation)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
try
|
{
|
action?.Invoke();
|
}
|
catch (Exception e)
|
{
|
this.ShowAlert(e, tipType);
|
}
|
});
|
|
}
|
#endregion
|
#region --------- 提示框,确认框 --------
|
/// <summary>
|
/// 对话框(只要程序报错的时候才用到)
|
/// </summary>
|
/// <paramref name="e"/>异常对象<paramref>
|
/// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref>
|
private void ShowAlert(Exception e, TipType tipType)
|
{
|
|
if (tipType != TipType.confirmation)
|
{
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
string msg = e.Message + "\r\n" + e.StackTrace;
|
Alert alert = new Alert("抱歉程序出错了.", "按\"确定\"能获取更详细的错误信息.", "取消", "确定");
|
alert.Show();
|
alert.ResultEventHandler += (alerts, isBool) =>
|
{
|
alert.Dismiss();
|
if (isBool)
|
{
|
StackTraceLog stackTraceLog = new StackTraceLog(msg);
|
stackTraceLog.Show();
|
}
|
};
|
});
|
}
|
/// <summary>
|
/// 信息提示窗口,自动关闭
|
/// </summary>
|
/// <param name="msg">提示错误文本</param>
|
public void ShowTip(string msg, int time = 2)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new PublicAssmebly().TipMsgAutoClose(msg, false, time * 1000);
|
});
|
}
|
|
|
#endregion
|
/// <summary>
|
/// 弹框类型
|
/// </summary>
|
public enum TipType
|
{
|
none,//无提示
|
flicker,//闪烁框
|
confirmation//确认框
|
}
|
/// <summary>
|
/// 表示来自那个界面
|
/// </summary>
|
public enum Comerom
|
{
|
function,//功能
|
collect,//收藏
|
room,//房间
|
push,//推送
|
sanfan,//添加第三方设备
|
}
|
|
#if __IOS__
|
IosIHdlInterface ezsdkDelegate;
|
/// <summary>
|
/// 专门定义给Ios回调用,没有特殊含义
|
/// </summary>
|
public class IosIHdlInterface : EZSDK.IOS.EZSDKDelegate
|
{
|
public Action<string> mAction;
|
public IosIHdlInterface()
|
{
|
|
}
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="p0">true是入网成功(源生回调返回)</param>
|
/// <param name="p1">设备的序列化(源生回调返回)</param>
|
public override void AddDeviceSuccessed(string deviceSerial)
|
{
|
mAction?.Invoke(deviceSerial);
|
}
|
}
|
#else
|
/// <summary>
|
/// 专门定义给安卓回调用,没有特殊含义
|
/// </summary>
|
public class AndroidIHdlInterface : Java.Lang.Object, IHdlInterface
|
{
|
|
Action<bool,string> mAction;
|
public AndroidIHdlInterface(Action<bool,string> action)
|
{
|
mAction = action;
|
}
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="p0">true是入网成功(源生回调返回)</param>
|
/// <param name="p1">设备的序列化(源生回调返回)</param>
|
public void AddCallback(bool p0, string p1)
|
{
|
mAction?.Invoke(p0,p1);
|
}
|
|
|
}
|
#endif
|
|
|
}
|
|
|
}
|