using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Device
|
{
|
/// <summary>
|
/// 设备固件升级界面
|
/// </summary>
|
public class DeviceFirmwareUpdateForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
private string deviceMac = null;
|
/// <summary>
|
/// 固件信息
|
/// </summary>
|
private FirmwareVersionInfo deviceFirmware = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_deviceMac">设备mac地址</param>
|
public void ShowForm(string i_deviceMac)
|
{
|
if (deviceMac != null && deviceMac != i_deviceMac)
|
{
|
//不是同一个东西
|
return;
|
}
|
this.deviceMac = i_deviceMac;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFirmwareUpdate));
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
|
//历史版本
|
this.InitTopRightMenu();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac);
|
//获取设备最新版本
|
this.deviceFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A设备,
|
oTADevice.HwVersion.ToString(),
|
oTADevice.ImgTypeId.ToString(),
|
oTADevice.ImgVersion);
|
|
//如果当前住宅是虚拟住宅,或者是展示模板,则没有新版本的说法
|
if (Common.Config.Instance.Home.IsVirtually == true
|
|| Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
this.deviceFirmware = null;
|
}
|
|
if (deviceFirmware != null && deviceFirmware.FirmwareVersion > oTADevice.ImgVersion)
|
{
|
//拥有新版本
|
this.InitControlByNewVersion();
|
}
|
else
|
{
|
//没有新版本
|
this.InitControlByNotNewVersion();
|
}
|
}
|
|
#endregion
|
|
#region ■ 右上角菜单_________________________
|
|
/// <summary>
|
/// 初始化右上角菜单
|
/// </summary>
|
private void InitTopRightMenu()
|
{
|
if (HdlUserCenterResourse.HideOption.DeviceHistory != 1)
|
{
|
return;
|
}
|
var btnIcon = new MostRightIconControl(69, 69);
|
btnIcon.UnSelectedImagePath = "Item/More.png";
|
topFrameLayout.AddChidren(btnIcon);
|
btnIcon.InitControl();
|
btnIcon.ButtonClickEvent += ((sender, e) =>
|
{
|
//显示右上角菜单界面
|
this.ShowTopRightMenu();
|
});
|
}
|
|
/// <summary>
|
/// 显示右上角菜单界面
|
/// </summary>
|
private void ShowTopRightMenu()
|
{
|
var frame = new TopRightMenuControl(1, 2);
|
//历史版本
|
var deviceMenu = Language.StringByID(R.MyInternationalizationString.uHistoryVersion);
|
frame.AddRowMenu(deviceMenu, "", "", () =>
|
{
|
var form = new DeviceHistoryFirmwareVersionForm();
|
form.AddForm(deviceMac);
|
form.SelectFirmwareInfoEvent += (info) =>
|
{
|
this.deviceFirmware = info;
|
//拥有新版本
|
this.InitControlByNewVersion();
|
};
|
});
|
}
|
|
#endregion
|
|
#region ■ 拥有新版本_________________________
|
|
/// <summary>
|
/// 拥有新版本
|
/// </summary>
|
private void InitControlByNewVersion()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac);
|
|
//升级
|
var btnUpdate = new BottomClickButton();
|
btnUpdate.TextID = R.MyInternationalizationString.uLevelUp;
|
bodyFrameLayout.AddChidren(btnUpdate);
|
btnUpdate.ButtonClickEvent += (sender, e) =>
|
{
|
//设备升级
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
this.DoDeviceUpdate(oTADevice);
|
});
|
};
|
|
var frameWhiteBack = new FrameLayout();
|
frameWhiteBack.Height = Application.GetRealHeight(286);
|
frameWhiteBack.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(frameWhiteBack);
|
|
//当前固件版本
|
var frameNow = new FrameRowControl();
|
frameNow.UseClickStatu = false;
|
frameNow.Y = Application.GetRealHeight(20);
|
frameWhiteBack.AddChidren(frameNow);
|
frameNow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowFirmwareVersion), 500);
|
frameNow.AddMostRightView(HdlDeviceCommonLogic.Current.AppendVersion(oTADevice.ImgVersion), 500);
|
frameNow.AddBottomLine();
|
|
//最新固件版本
|
var frameNew = new FrameRowControl();
|
frameNew.UseClickStatu = false;
|
frameNew.Y = frameNow.Bottom + Application.GetRealHeight(12);
|
frameWhiteBack.AddChidren(frameNew);
|
frameNew.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNewFirmwareVersion), 500);
|
frameNew.AddMostRightView(HdlDeviceCommonLogic.Current.AppendVersion(deviceFirmware.FirmwareVersion), 500);
|
frameNew.AddBottomLine();
|
|
//添加固件介绍行
|
int maxHeight = btnUpdate.Y - HdlControlResourse.BottomButtonAndListViewSpace - frameNew.Bottom;
|
this.AddUpdateContent(deviceFirmware, maxHeight, frameNew.Bottom);
|
}
|
|
#endregion
|
|
#region ■ 没有新版本_________________________
|
|
/// <summary>
|
/// 没有新版本
|
/// </summary>
|
private void InitControlByNotNewVersion()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
var oTADevice = HdlDeviceCommonLogic.Current.GetOTADevice(deviceMac);
|
|
var frameWhiteBack = new FrameLayout();
|
frameWhiteBack.Height = Application.GetRealHeight(308);
|
frameWhiteBack.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(frameWhiteBack);
|
|
//当前固件版本
|
var frameNow = new FrameRowControl();
|
frameNow.UseClickStatu = false;
|
frameNow.Y = Application.GetRealHeight(20);
|
frameWhiteBack.AddChidren(frameNow);
|
frameNow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowFirmwareVersion), 500);
|
frameNow.AddMostRightView(HdlDeviceCommonLogic.Current.AppendVersion(oTADevice.ImgVersion), 500);
|
frameNow.AddBottomLine();
|
|
//最新固件版本
|
var frameNew = new FrameRowControl();
|
frameNew.UseClickStatu = false;
|
frameNew.Y = frameNow.Bottom + Application.GetRealHeight(12);
|
frameWhiteBack.AddChidren(frameNew);
|
frameNew.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNewFirmwareVersion), 500);
|
frameNew.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uNothing), 500);
|
}
|
|
#endregion
|
|
#region ■ 添加固件介绍行_____________________
|
|
/// <summary>
|
/// 添加固件介绍行
|
/// </summary>
|
/// <param name="versionInfo">固件对象</param>
|
/// <param name="Maxheight">最大高度</param>
|
/// <param name="YY"></param>
|
private void AddUpdateContent(FirmwareVersionInfo versionInfo, int Maxheight,int YY)
|
{
|
FrameListControl listFrame = null;
|
VerticalListControl listView = null;
|
|
var realHeight = Application.GetRealHeight(40 + 12) * versionInfo.UpdateContent.Count;
|
realHeight += Application.GetRealHeight(17 + 12 + 49 + 8 + 63);
|
|
//行间距
|
int rowSpace = 0;
|
if (realHeight > Maxheight)
|
{
|
realHeight = Maxheight;
|
listView = new VerticalListControl(12);
|
listView.Height = realHeight;
|
listView.Y = YY;
|
listView.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(listView);
|
rowSpace = listView.rowSpace / 2;
|
}
|
else
|
{
|
listFrame = new FrameListControl(12);
|
listFrame.Height = realHeight;
|
listFrame.Y = YY;
|
listFrame.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(listFrame);
|
rowSpace = listFrame.rowSpace / 2;
|
}
|
|
//添加头部空白间隙
|
var frameSpace1 = new FrameLayout();
|
frameSpace1.Height = Application.GetRealHeight(17);
|
listView?.AddChidren(frameSpace1);
|
listFrame?.AddChidren(frameSpace1);
|
|
//修改内容
|
var btnContentRow = new FrameRowControl(rowSpace);
|
btnContentRow.UseClickStatu = false;
|
btnContentRow.Height = Application.GetRealHeight(49);
|
listView?.AddChidren(btnContentRow);
|
listFrame?.AddChidren(btnContentRow);
|
var btnContent = btnContentRow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uEditorContent), 500);
|
btnContent.TextSize = 12;
|
|
//稍微再添加空白间隙
|
var frameSpace2 = new FrameLayout();
|
frameSpace2.Height = Application.GetRealHeight(8);
|
listView?.AddChidren(frameSpace2);
|
listFrame?.AddChidren(frameSpace2);
|
|
foreach (var msg in versionInfo.UpdateContent)
|
{
|
var btnRow = new FrameRowControl(rowSpace);
|
btnRow.UseClickStatu = false;
|
btnRow.Height = Application.GetRealHeight(40);
|
listView?.AddChidren(btnRow);
|
listFrame?.AddChidren(btnRow);
|
|
var btnMsg = btnRow.AddLeftCaption(msg, 965);
|
btnMsg.TextSize = 10;
|
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
|
}
|
|
//添加底部空白间隙
|
var frameSpace3 = new FrameLayout();
|
frameSpace3.Height = Application.GetRealHeight(63);
|
listView?.AddChidren(frameSpace3);
|
listFrame?.AddChidren(frameSpace3);
|
}
|
|
#endregion
|
|
#region ■ 设备升级___________________________
|
|
/// <summary>
|
/// 设备升级
|
/// </summary>
|
private void DoDeviceUpdate(OTADevice oTADevice)
|
{
|
//打开进度条
|
ProgressFormBar.Current.Start();
|
//设备升级
|
var updateLogic = new HdlDeviceUpdateLogic(oTADevice, deviceFirmware);
|
//更新状态变化的事件
|
updateLogic.UpdateStatuChangedEvent += (div, msg) =>
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
if (div == -1)
|
{
|
//异常
|
this.ShowMassage(ShowMsgType.Tip, msg);
|
ProgressFormBar.Current.Close();
|
}
|
else if (div == 0)
|
{
|
//一般信息
|
ProgressFormBar.Current.SetMsg(msg);
|
}
|
else if (div == 1)
|
{
|
//升级完成
|
ProgressFormBar.Current.Close();
|
this.ShowMassage(ShowMsgType.Tip, msg);
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//初始化中部控件
|
this.InitMiddleFrame();
|
});
|
}
|
else if (div == 2)
|
{
|
//主动终止升级
|
ProgressFormBar.Current.Close();
|
}
|
});
|
};
|
//进度值改变事件
|
updateLogic.ProgressEvent += (value) =>
|
{
|
ProgressFormBar.Current.SetValue(value, 100);
|
};
|
//设备升级开始
|
updateLogic.StartUpdateReady();
|
//终止升级
|
ProgressFormBar.Current.MsgClickEvent += () =>
|
{
|
//再次调用,内部条件达成时,可以选择终止升级
|
updateLogic.StartUpdateReady();
|
};
|
//关闭事件
|
ProgressFormBar.Current.CloseEvent += () =>
|
{
|
//升级对象
|
if (HdlFirmwareUpdateResourse.dicUpdateList.ContainsKey(deviceMac) == true
|
&& HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].IsFinishUpdate == true)
|
{
|
//如果设备已经升级完成,界面关闭时,则移除内存
|
HdlFirmwareUpdateResourse.dicUpdateList[deviceMac].Dispose();
|
HdlFirmwareUpdateResourse.dicUpdateList.Remove(deviceMac);
|
}
|
};
|
}
|
|
#endregion
|
}
|
}
|