using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.DeviceShard
|
{
|
/// <summary>
|
/// 编辑分享设备的信息
|
/// </summary>
|
public class ShardDeviceMacInfoEditorForm : UserCenterCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 画面正常关闭的回调函数
|
/// </summary>
|
public Action<string> ActionFormClose = null;
|
/// <summary>
|
/// 设备对象
|
/// </summary>
|
private List<CommonDevice> listNewDevice = null;
|
/// <summary>
|
/// 获取得到了镜像信息
|
/// </summary>
|
private bool receiveImageInfo = false;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="listdevices">设备列表</param>
|
public void ShowForm(List<CommonDevice> listdevices)
|
{
|
this.listNewDevice = listdevices;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo));
|
|
//初始化删除设备的界面(右上)
|
//this.InitDeleteDeviceForm();
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
//设备图片
|
var btnpictrue = new PicViewControl(510, 320);
|
btnpictrue.Gravity = Gravity.CenterHorizontal;
|
btnpictrue.Y = Application.GetRealHeight(100);
|
Common.LocalDevice.Current.SetRealDeviceIconToControl(btnpictrue, listNewDevice);
|
bodyFrameLayout.AddChidren(btnpictrue);
|
|
var listview = new VerticalScrolViewLayout();
|
listview.Y = btnpictrue.Bottom + Application.GetRealHeight(100);
|
listview.Height = bodyFrameLayout.Height - btnpictrue.Bottom - Application.GetRealHeight(100);
|
bodyFrameLayout.AddChidren(listview);
|
|
//生产商名称
|
var row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnManuView = new RowTopGrayView(false);
|
btnManuView.TextID = R.MyInternationalizationString.uManufacturerName;
|
row.AddChidren(btnManuView);
|
var btnManu = new RowBottomBlackView(false);
|
btnManu.Text = listNewDevice[0].ManufacturerName;
|
if (string.IsNullOrEmpty(btnManu.Text) == true)
|
{
|
if (listNewDevice[0].DriveCode > 0)
|
{
|
//虚拟设备固定使用HDL
|
btnManu.Text = "HDL";
|
}
|
}
|
row.AddChidren(btnManu);
|
|
//设备型号
|
row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnModelIdView = new RowTopGrayView(false);
|
btnModelIdView.TextID = R.MyInternationalizationString.uModelIdentifier;
|
row.AddChidren(btnModelIdView);
|
var btnModelId = new RowBottomBlackView(false);
|
btnModelId.Text = listNewDevice[0].ModelIdentifier;
|
row.AddChidren(btnModelId);
|
|
//序列号
|
row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnSerialView = new RowTopGrayView(false);
|
btnSerialView.TextID = R.MyInternationalizationString.uSerialNumber;
|
row.AddChidren(btnSerialView);
|
var btnSerial = new RowBottomBlackView(false);
|
btnSerial.Text = listNewDevice[0].SerialNumber;
|
if (string.IsNullOrEmpty(btnSerial.Text) == true)
|
{
|
btnSerial.Text = listNewDevice[0].DeviceAddr;
|
}
|
row.AddChidren(btnSerial);
|
|
//产品名称
|
string caption = Language.StringByID(R.MyInternationalizationString.uProductName);
|
string nameValue = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
|
var btnDeviceView = new EditorNameValueRow(caption, nameValue);
|
listview.AddChidren(btnDeviceView);
|
btnDeviceView.InitControl();
|
//请输入产品名称
|
btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uProductNameMastInput));
|
//编辑产品名称
|
btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorProductName));
|
btnDeviceView.ActionNameChangedEvent += (deviceName) =>
|
{
|
//设备重命名然后打开新的画面
|
this.DeviceReName(deviceName);
|
};
|
|
//只有是河东的设备的时候
|
if (Common.LocalDevice.Current.IsHdlDevice(listNewDevice[0]) == true)
|
{
|
//添加【固件信息】行
|
this.AddFirmwareVersionRow(listview);
|
}
|
}
|
|
#endregion
|
|
#region ■ 固件信息___________________________
|
|
/// <summary>
|
/// 添加【固件信息】行
|
/// </summary>
|
/// <param name="listview"></param>
|
private void AddFirmwareVersionRow(VerticalScrolViewLayout listview)
|
{
|
//拥有200端口这个东西的时候,才会显示这一行
|
var oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr);
|
if (oTADevice == null || oTADevice.ImgVersion == -1)
|
{
|
return;
|
}
|
|
var statuRow = new StatuRowLayout(listview);
|
//固件信息
|
var btnUpview = new RowCenterView(false);
|
btnUpview.TextID = R.MyInternationalizationString.uFirmwareInformation;
|
statuRow.AddChidren(btnUpview);
|
|
statuRow.AddRightIconControl();
|
|
statuRow.MouseUpEvent += (sender, e) =>
|
{
|
var form = new Device.DeviceFirmwareInfoForm();
|
this.AddForm(form, listNewDevice);
|
};
|
|
//设置设备的版本信息
|
this.SetDeviceVersionInfo(oTADevice);
|
}
|
|
/// <summary>
|
/// 设置设备的版本信息
|
/// </summary>
|
/// <param name="oTADevice">ota设备</param>
|
private void SetDeviceVersionInfo(OTADevice oTADevice)
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
|
new System.Threading.Thread(async () =>
|
{
|
//设置设备全部的镜像信息
|
HdlDeviceImageInfoLogic.Current.SetAllImageInfoToOtaDevice(oTADevice, this.OtaImageInfoActionBack);
|
int count = 5;
|
while (this.receiveImageInfo == false && count > 0)
|
{
|
//等待设备镜像的反馈
|
await System.Threading.Tasks.Task.Delay(300);
|
count--;
|
}
|
//变量还原
|
this.receiveImageInfo = false;
|
//移除事件
|
HdlDeviceImageInfoLogic.Current.RemoveDeviceFirmwareVersionThread(oTADevice);
|
|
//关闭进度条
|
this.CloseProgressBar();
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 获取到了OTA镜像信息回调(100%特定回调)
|
/// </summary>
|
/// <param name="device"></param>
|
/// <param name="reportData"></param>
|
private void OtaImageInfoActionBack(CommonDevice device, CommonDevice.DeviceStatusReportData reportData)
|
{
|
this.receiveImageInfo = true;
|
}
|
|
#endregion
|
|
#region ■ 修改名字___________________________
|
|
/// <summary>
|
/// 设备重命名
|
/// </summary>
|
/// <param name="i_deviceName">deviceName.</param>
|
private async void DeviceReName(string i_deviceName)
|
{
|
//修改MAC名
|
string deviceName = i_deviceName.Trim();
|
var result = await Common.LocalDevice.Current.ReMacName(this.listNewDevice, deviceName);
|
if (result == false)
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
this.ActionFormClose?.Invoke(deviceName);
|
});
|
}
|
|
#endregion
|
|
#region ■ 关闭界面___________________________
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
public override void CloseForm()
|
{
|
this.ActionFormClose = null;
|
base.CloseForm();
|
}
|
|
#endregion
|
|
#region ■ 删除界面___________________________
|
|
/// <summary>
|
/// 初始化删除设备的界面
|
/// </summary>
|
private void InitDeleteDeviceForm()
|
{
|
var btnIcon = new TopLayoutMostRightView();
|
btnIcon.UnSelectedImagePath = "Item/More.png";
|
btnIcon.SelectedImagePath = "Item/MoreSelected.png";
|
topFrameLayout.AddChidren(btnIcon);
|
btnIcon.MouseUpEventHandler += ((sender, e) =>
|
{
|
//显示删除设备的弹窗界面
|
this.ShowDeleteDeviceDialogForm();
|
});
|
}
|
|
/// <summary>
|
/// 显示删除设备的弹窗界面
|
/// </summary>
|
private void ShowDeleteDeviceDialogForm()
|
{
|
var frame = new TopRightMenuControl(this, 1);
|
//删除设备
|
string deviceMenu = Language.StringByID(R.MyInternationalizationString.uDeleteDevice);
|
frame.AddRowMenu(deviceMenu, (obj) =>
|
{
|
//确认要删除该设备?{0}(删除设备后,绑定目标将消失)
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteDeviceMsg);
|
if (msg.Contains("{0}") == true)
|
{
|
msg = string.Format(msg, "\r\n");
|
}
|
this.ShowConfirmMsg(msg, "DoDeleteDevice");
|
});
|
}
|
|
/// <summary>
|
/// 删除指定设备
|
/// </summary>
|
public async void DoDeleteDevice()
|
{
|
//开启进度条
|
this.ShowProgressBar();
|
//删除设备
|
bool result = await Common.LocalDevice.Current.DeleteDevice(listNewDevice);
|
|
this.CloseProgressBar();
|
|
if (result == false)
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
//关闭界面
|
this.CloseForm();
|
//移除设备列表界面指定的设备
|
//this.LoadFormMethodByName("DeviceManagementMainForm", "RemoveDeviceFromMemory", listNewDevice);
|
});
|
}
|
#endregion
|
}
|
}
|