using System;
|
using Shared.Common;
|
|
namespace Shared.Phone.UserCenter.DeviceBind
|
{
|
/// <summary>
|
/// 空气质量传感器的绑定多个时间设置
|
/// </summary>
|
public class AirQualitySensorLedBindTime : BindCommonLayout
|
{
|
/// 构造函数
|
/// </summary>
|
/// <param name="doorLock"></param>
|
public AirQualitySensorLedBindTime(ZigBee.Device.TemperatureSensor sensor)
|
{
|
this.sensor = sensor;
|
}
|
|
#region 变量申明
|
/// <summary>
|
/// 当前空气质量传感器对象
|
/// </summary>
|
ZigBee.Device.TemperatureSensor sensor;
|
/// <summary>
|
/// 显示被绑定设备或场景的view
|
/// </summary>
|
VerticalFrameRefreshControl midVerticalRefreshLayout;
|
/// <summary>
|
/// 空数据显示布局
|
/// </summary>
|
FrameLayout blankFrameLayout;
|
/// <summary>
|
/// 列表数据是否为空
|
/// </summary>
|
bool isEmpty = true;
|
|
#endregion
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
void InitListInfo()
|
{
|
System.Threading.Tasks.Task.Run(async () =>
|
{
|
try
|
{
|
bool isLost = false;
|
for (int i = 0; i < 5; i++)
|
{
|
if (isLost)
|
{
|
continue;//只要有一条获取失败,剩下的就停止获取,防止循环后等待透传时间太长
|
}
|
var result = await sensor.ReadAirQualitySensorLedTime(i);
|
if (result != null)
|
{
|
if (result.enable == 1)
|
{
|
if (sensor.AirQualitySensorLedTimeList.ContainsKey(result.serialNum))
|
{
|
sensor.AirQualitySensorLedTimeList[result.serialNum] = result;
|
}
|
else
|
{
|
sensor.AirQualitySensorLedTimeList.Add(result.serialNum, result);
|
}
|
}
|
else
|
{
|
if (sensor.AirQualitySensorLedTimeList.ContainsKey(result.serialNum))
|
{
|
sensor.AirQualitySensorLedTimeList.Remove(result.serialNum);
|
}
|
}
|
}
|
else
|
{
|
isLost = true;
|
}
|
}
|
if (isLost)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GetLedTimeLost), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance);
|
|
});
|
}
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
RefreshList();
|
midVerticalRefreshLayout.EndHeaderRefreshing();
|
CommonPage.Loading.Hide();
|
});
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示
|
/// </summary>
|
public void Show()
|
{
|
TopFrameLayout();
|
MiddleFrameLayout();
|
CommonPage.Loading.Start("");
|
InitListInfo();
|
}
|
|
/// <summary>
|
/// Top布局
|
/// </summary>
|
void TopFrameLayout()
|
{
|
this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.SetAirQualitySensorLight));
|
EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
this.btnBack.MouseUpEventHandler += eHandlerBack;
|
this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
|
|
var btnAddFrameLayout = new FrameLayout()
|
{
|
X = Application.GetRealWidth(772 - 58),
|
Width = Application.GetRealWidth(192),
|
};
|
this.titleFrameLayout.AddChidren(btnAddFrameLayout);
|
|
var btnBindAdd = new Button
|
{
|
X = Application.GetRealWidth(62),
|
Height = Application.GetMinReal(72),
|
Width = Application.GetMinReal(72),
|
UnSelectedImagePath = "BindPic/BindAdd.png",
|
};
|
btnAddFrameLayout.AddChidren(btnBindAdd);
|
|
#region eHandlerAdd
|
EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) =>
|
{
|
if (sensor.AirQualitySensorLedTimeList.Count == 5)
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.LedBindFull), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance);
|
return;
|
}
|
var airQualitySensorLogic = new Shared.Phone.UserCenter.DeviceBind.AirQualitySensorLogic(sensor);
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(airQualitySensorLogic);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
airQualitySensorLogic.Show();
|
airQualitySensorLogic.refreshAction = () =>
|
{
|
RefreshList();
|
};
|
};
|
btnBindAdd.MouseDownEventHandler += eHandlerAdd;
|
btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd;
|
#endregion
|
}
|
|
/// <summary>
|
/// Middle布局
|
/// </summary>
|
void MiddleFrameLayout()
|
{
|
this.MidFrameLayout(this);
|
VerticalFrameLayout();
|
BlankFrameLayout();
|
}
|
|
/// <summary>
|
/// VerticalFrameLayout布局
|
/// </summary>
|
void VerticalFrameLayout()
|
{
|
midVerticalRefreshLayout = new VerticalFrameRefreshControl(29)
|
{
|
Height = this.midFrameLayout.Height + 1,
|
};
|
this.midFrameLayout.AddChidren(midVerticalRefreshLayout);
|
|
midVerticalRefreshLayout.BeginHeaderRefreshingAction += () =>
|
{
|
midVerticalRefreshLayout.BeginHeaderRefreshing();
|
InitListInfo();
|
};
|
}
|
|
/// <summary>
|
/// BlankFrameLayout布局
|
/// </summary>
|
void BlankFrameLayout()
|
{
|
blankFrameLayout = new FrameLayout
|
{
|
Height = this.midFrameLayout.Height,
|
};
|
this.midFrameLayout.AddChidren(blankFrameLayout);
|
|
var entryStatusPic = new Button
|
{
|
X = Application.GetRealWidth(213),
|
Y = Application.GetRealHeight(418),
|
Height = Application.GetRealHeight(556),
|
Width = Application.GetRealWidth(654),
|
UnSelectedImagePath = "BindPic/BindEmptyPic.png",
|
};
|
blankFrameLayout.AddChidren(entryStatusPic);
|
|
var btnPicTip = new Button
|
{
|
Y = Application.GetRealHeight(1020),
|
Text = Language.StringByID(R.MyInternationalizationString.NoControlTargets),
|
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
|
Gravity = Gravity.CenterHorizontal,
|
TextSize = 12,
|
Height = Application.GetRealHeight(49),
|
};
|
blankFrameLayout.AddChidren(btnPicTip);
|
}
|
|
/// <summary>
|
/// 按键绑定表显示
|
/// </summary>
|
async void RefreshList()
|
{
|
if (sensor.AirQualitySensorLedTimeList.Count == 0)
|
{
|
isEmpty = true;
|
}
|
else
|
{
|
isEmpty = false;
|
}
|
|
if (isEmpty)
|
{
|
midVerticalRefreshLayout.Height = 0;
|
blankFrameLayout.Height = this.midFrameLayout.Height;
|
return;
|
}
|
else
|
{
|
blankFrameLayout.Height = 0;
|
midVerticalRefreshLayout.Height = this.midFrameLayout.Height;
|
midVerticalRefreshLayout.RemoveAll();
|
|
}
|
#region 数据处理
|
int currentIndex = 0;
|
foreach (var key in sensor.AirQualitySensorLedTimeList.Keys)
|
{
|
var ledTimeData = sensor.AirQualitySensorLedTimeList[key];
|
var rowLayout = new RowLayoutControl(midVerticalRefreshLayout.rowSpace / 2);
|
rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
|
midVerticalRefreshLayout.AddChidren2(rowLayout);
|
rowLayout.frameTable.UseClickStatu = false;
|
|
var devicePic = rowLayout.frameTable.AddLeftIcon();
|
devicePic.Y = Application.GetRealHeight(49);
|
devicePic.UnSelectedImagePath = "AirQualitySensor/LED84.png";
|
|
#region 绑定数据处理
|
var btnBindNameText = ledTimeData.remark;
|
string sm = ledTimeData.startMin.ToString();
|
string em = ledTimeData.endMin.ToString();
|
if (ledTimeData.startMin < 10)
|
{
|
sm = "0" + ledTimeData.startMin;
|
}
|
if (ledTimeData.endMin < 10)
|
{
|
em = "0" + ledTimeData.endMin;
|
}
|
var btnTimeText = ledTimeData.startHour + ":" + sm + "-" + ledTimeData.endHour + ":" + em;
|
var btnTipText = Language.StringByID(R.MyInternationalizationString.LedClose);
|
if (currentIndex == sensor.AirQualitySensorLedTimeList.Count - 1)
|
{
|
rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite;
|
}
|
|
rowLayout.frameTable.AddTopView(btnBindNameText, 410);
|
rowLayout.frameTable.AddBottomView(btnTimeText, 410);
|
rowLayout.frameTable.AddMostRightView(btnTipText, 410);
|
rowLayout.frameTable.AddBottomLine();
|
|
var btnEditor = rowLayout.AddEditorControl();
|
btnEditor.ButtonClickEvent += (sender, e) =>
|
{
|
var airQualitySensorLogic = new Shared.Phone.UserCenter.DeviceBind.AirQualitySensorLogic(sensor, ledTimeData);
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(airQualitySensorLogic);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
airQualitySensorLogic.Show();
|
airQualitySensorLogic.refreshAction = () =>
|
{
|
RefreshList();
|
};
|
};
|
|
var btnDel = rowLayout.AddDeleteControl();
|
btnDel.ButtonClickEvent += async (sender, e) =>
|
{
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Start("");
|
});
|
|
ledTimeData.enable = 0;
|
var result = await sensor.SetAirQualitySensorLedTime(ledTimeData);
|
if (result != null && result.responseData != null)
|
{
|
if (result.responseData.status == 0)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
sensor.AirQualitySensorLedTimeList.Remove(ledTimeData.serialNum);
|
RefreshList();
|
});
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
|
});
|
}
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
|
});
|
}
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
});
|
}
|
};
|
#endregion
|
currentIndex++;
|
}
|
midVerticalRefreshLayout.AdjustTableHeight(Application.GetRealHeight(23));
|
|
#endregion
|
}
|
|
/// <summary>
|
/// 重写移除方法
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
}
|
}
|