using System;
using HDL_ON.Entity;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
{
///
/// 萤石视频门锁公共方法类
///
public class CommonMethod
{
private Loading loading;
private static CommonMethod commonMethod = null;
public static CommonMethod Current
{
get
{
if (commonMethod == null)
{
commonMethod = new CommonMethod();
}
return commonMethod;
}
}
#region --------- 跳转到Android那边的方法(萤石视频门锁) --------
///
/// 添加设备到云端
/// 设备序列号
///
public void SkipAddDeviceActivity(string devSerial)
{
if (string.IsNullOrEmpty(devSerial)) return;
new System.Threading.Thread(() =>
{
var list = VideDoorLockSend.Current.GetVideoDoorLockDeviceList(SPK.VideoDoorLock);
if (list.Count > 0)
{
var function = list.Find((o) => o.sid == devSerial);
if (function != null)
{
this.SaveFunctionFile(function);
}
}
})
{ IsBackground = true }.Start();
//未实现
#if __IOS__
#else
#endif
}
///
/// 打开实时视频画面
///
/// 设备序列号
/// 设备id(云端上deviceId)
/// 设备spk(云雀上定义好的)
public void SkipRTVActivity(string deviceSerial, string deviceId, string spk)
{
Video.View.ShowDialog.Currnet.ClickBox(Language.StringByID(StringId.laizimenlinghujiao), (dialog) =>
{
dialog.Close();
}, (dialog) =>
{
dialog.Close();
});
#if __IOS__
#else
#endif
//jumpToEZRealPlayActivity(Shared.Application.Activity, deviceId, deviceSerial, spk)
}
///
/// 浏览历史记录
///
public void SkipRecordActivity()
{
//未实现
//this.InitializationAndroidData();
//
}
///
/// 临时密码开门
///
public void SkipPSWActivity()
{
//jumpTempPasswordActivity(Application.Activity, deviceId);
}
///
/// 初始化萤石SDK(实际就是传参数,多次调用也没有影响)
///
public void InitializationAndroidData(Action action)
{
bool isBool = true;
this.SunThread(() =>
{
try
{
//先获取萤石云子账号token
var ezChildAccessToken = VideDoorLockSend.Current.GetEZGetChildToken();
this.MainThread(() =>
{
if (string.IsNullOrEmpty(ezChildAccessToken))
{
//Token
isBool = false;
return;
}
Application.RunOnMainThread(() =>
{
#if __IOS__
//iOS
//初始化萤石云SDK,中文国内key、英文海外key 开发者账号使用应用包名申请的APPKEY,不同包名应用需配置不同的APPKEY
EZSDK.IOS.EZSDK.SharedInstance().InitLibWithAppKey("1aa98a90489b4838b966b57018b4b04b", "1aa98a90489b4838b966b57018b4b04b");
//1.设置所需河东的AccessToken和RefreshToken、域名地址
EZSDK.IOS.EZSDK.SharedInstance().SetHDlAccessToken(UserVideoDoorLockInfo.Current.LoginTokenString, UserVideoDoorLockInfo.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
//Android
//1.设置所需河东的token、域名地址
//2.设置萤石子账号的token
//3.打开摄像头设备列表页面
((BaseActivity)Shared.Application.Activity).SetCamera(b =>
{
if (b)
{
((BaseActivity)Shared.Application.Activity).SetPermission(result =>
{
if (result)
{
Android.Content.Intent intent = new Android.Content.Intent();
var bundle = new Android.OS.Bundle();
//传递name参数为tinyphp
bundle.PutString("EzChildAccessToken", ezChildAccessToken);
bundle.PutString("HdlToken", UserInfo.Current.LoginTokenString);
bundle.PutString("HdlrefreshToken", UserInfo.Current.RefreshToken);
bundle.PutString("Url", OnAppConfig.Instance.RequestHttpsHost);
bundle.PutString("EzvizAppKey", "1aa98a90489b4838b966b57018b4b04b");
bundle.PutInt("Platform", 1);
bundle.PutString("HomeId", DB_ResidenceData.Instance.CurrentRegion.id);
intent.PutExtras(bundle);
//intent.SetComponent(new Android.Content.ComponentName(Shared.Application.Activity, "com.videogo.MainActivity"));
//Shared.Application.Activity.StartActivity(intent);
}
}, "android.permission.RECORD_AUDIO");
}
});
#endif
});
});
}
catch (Exception e)
{
}
finally
{
this.MainThread(() =>
{
action?.Invoke(isBool);
});
}
});
}
///
/// 更换住宅
///
/// 对象
public void ChangeCurrHome(RegionInfoRes home)
{
if (DB_ResidenceData.Instance.CurrentRegion.id == home.id || string.IsNullOrEmpty(home.id)) return;
}
#endregion
///
/// 萤石视频门锁的图标
/// 来自那里
///
public string GetVideoDoorLockIcon(Comerom comerom)
{
if (comerom == Comerom.collect)
{
return "FunctionIcon/DoorLock/VideoDoorLockOpen.png";
}
else
{
return "FunctionIcon/DoorLock/VideoDoorlockClose.png";
}
}
#region --------- 功能文件保存,删除 --------
///
/// 保存本地文件
///
/// 当前设备
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}");
}
///
/// 删除本地文件
///
/// 当前设备
public void DeleteFunction(Function function)
{
if (function == null) return;
FunctionList.List.DeleteFunction(function);
MainPage.Log($"文件删除->{function.name}-->{function.spk}");
}
#endregion
///
/// 获取Loading对象
///
///
public Loading Loading
{
get
{
if (loading == null)
{
loading = new Loading();
}
if (MainPage.BasePageView.ChildrenCount < 1)
{
return loading;
}
View view = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1);
if (view is FrameLayout)
{
((FrameLayout)view).AddChidren(loading);
}
else if (view is PageLayout)
{
((PageLayout)view).AddChidren(loading);
}
return loading;
}
}
///
/// 获取萤石视频门锁列表
///
///
public List 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 ---------自定义线程(子线程,主线程)--------
///
/// 子线程
///
/// 是否要提示错误信息(默认显示)
///
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)
{
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();
}
};
});
}
///
/// 信息提示窗口,自动关闭
///
/// 提示错误文本
public void ShowTip(string msg, int time = 2)
{
Application.RunOnMainThread(() =>
{
new PublicAssmebly().TipMsgAutoClose(msg, false, time * 1000);
});
}
#endregion
///
/// 弹框类型
///
public enum TipType
{
none,//无提示
flicker,//闪烁框
confirmation//确认框
}
///
/// 表示来自那个界面
///
public enum Comerom
{
function,//功能
collect,//收藏
room,//房间
push,//推送
}
}
}