using System;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
public class DeviceSet : FrameLayout
{
public DeviceSet()
{
Tag = "PirView";
}
public void Show(Action action)
{
#region 界面布局
this.BackgroundColor = CSS.CSS_Color.viewMiddle;
PirDevice.View.TopView topView = new View.TopView();
topView.topNameBtn.TextID = StringId.shebeigaunli;
topView.topIconBtn.Visible = true;
this.AddChidren(topView.FLayoutView());
topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
{
action();
this.RemoveFromParent();
};
VerticalRefreshLayout vv = new VerticalRefreshLayout();
vv.Height = Application.GetRealHeight(667 - 64);
vv.Y = Application.GetRealHeight(64);
this.AddChidren(vv);
vv.BeginHeaderRefreshingAction += () =>
{
//关闭刷新View;
vv.EndHeaderRefreshing();
//获取列表
Method.GetPirDeviceList(this, () =>
{
Application.RunOnMainThread(() =>
{
//刷新界面
UIView(vv);
});
});
};
#endregion
UIView(vv);
}
///
/// 加载UI界面
///
/// 上下滑控件
void UIView(VerticalRefreshLayout vv)
{
vv.RemoveAll();
for (int i = 0; i < Pir.pirDeviceList.Count; i++)
{
var pirDevice = Pir.pirDeviceList[i];
#region 红外宝图标 版本号 名称 状态
FrameLayout fLayout = new FrameLayout
{
Width = Application.GetRealWidth(375),
Height = Application.GetRealHeight(12 + 92 + (50 * pirDevice.FunctioList.Count)),
};
vv.AddChidren(fLayout);
View.PirView pirView = new View.PirView();
//红外宝名称
pirView.deviceNameBtn.Text = pirDevice.name;
//红外宝当前有多少个遥控器
pirView.geBtn.Text = pirDevice.FunctioList.Count.ToString();
//红外宝是否在线-离线
if (pirDevice.online)
{
pirView.stateIconBtn.IsSelected = true;
pirView.stateTextBtn.IsSelected = true;
}
else
{
pirView.stateIconBtn.IsSelected = false;
pirView.stateTextBtn.IsSelected = false;
}
//标记红外宝
pirView.clickBtn.Tag = pirDevice;
//红外宝点击事件
pirView.clickBtn.MouseUpEventHandler += (sender, e) =>
{
var pirclick = (pirView.clickBtn.Tag as Pir);
NewSwitchView(pirclick, vv);
};
//加载界面
pirView.Show(pirDevice.FunctioList.Count, fLayout);
if (Pir.pirDeviceList.Count - 1 == i)
{
//最后一个后面增加间隔背景
vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(20) });
}
#endregion
for (int j = 0; j < pirDevice.FunctioList.Count; j++)
{
var control = pirDevice.FunctioList[j];
View.ControlView controlView = new View.ControlView();
controlView.Show(pirView.devfLayout, j);
//遥控器名称
controlView.nameBtn.Text = control.name;
//遥控器存放区域
controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(control);
//标记遥控器
controlView.delBtn.Tag = control;
//删除点击事件
controlView.delBtn.MouseUpEventHandler += (sender, e) =>
{
var Function = controlView.delBtn.Tag as Entity.Function;
string text = Language.StringByID(StringId.shanchushebei) + Function.name + "?";
TipPopView tipPopView = new TipPopView();
tipPopView.TipBox(StringId.tip, text, (dialog) =>
{
Thread(dialog, (responsePackNew) =>
{
dialog.Close();
var function = pirDevice.FunctioList.Find((c) => c.sid == Function.sid);
if (function != null)
{
pirDevice.FunctioList.Remove(Function);
if (Pir.currPir != null && pirDevice.sid == Pir.currPir.sid)
{
Pir.currPir.FunctioList = pirDevice.FunctioList;
}
}
UIView(vv);
}, "删除", Function.deviceId, "");
}, () => { }, false);
};
//view点击事件
controlView.clickBtn.MouseUpEventHandler += (sender, e) =>
{
EditControl editControl = new EditControl();
MainPage.BasePageView.AddChidren(editControl);
editControl.Show(control, pirDevice, (device) =>
{
//回调更新名字/区域
controlView.nameBtn.Text = device.name;
controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(device);
});
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
if (j == pirDevice.FunctioList.Count - 1)
{
//最后改变一个线的颜色
controlView.line1Btn.BackgroundColor = CSS.CSS_Color.viewTranslucence;
controlView.funControlRow.LineColor = CSS.CSS_Color.viewTranslucence;
}
}
}
}
///
/// 加载弹框
///
///
///
void NewSwitchView(Pir pirclick, VerticalRefreshLayout vv)
{
FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence };
this.AddChidren(frame);
SwitchView switchView = new SwitchView();
switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
switchView.FLayoutView(frame, StringId.shanchushebei, StringId.xiugaimingzi, "", (intValue) =>
{
if (StringId.xiugaimingzi == intValue)
{
List list = new List();
for (int b = 0; b < PirDevice.Pir.pirDeviceList.Count; b++)
{
list.Add(PirDevice.Pir.pirDeviceList[b].name);
}
Method methodView = new Method();
methodView.EditControlName(StringId.xiugaimingzi, list, pirclick.name, (name, view) =>
{
Thread(view, (responsePackNew) =>
{
pirclick.name = name;
view.Close();
UIView(vv);
}, "修改名称", pirclick.deviceId, pirclick.name);
}, () =>
{
NewSwitchView(pirclick, vv);
}, false);
}
else
{
string text = Language.StringByID(StringId.shanchushebei) + pirclick.name + "?";
TipPopView tipPopView = new TipPopView();
tipPopView.TipBox(StringId.tip, text, (dialog) =>
{
Thread(dialog, (responsePackNew) =>
{
var pir = Pir.pirDeviceList.Find((c) => c.deviceId == pirclick.deviceId);
if (pir != null)
{
Pir.pirDeviceList.Remove(pirclick);
}
dialog.Close();
UIView(vv);
}, "删除", pirclick.deviceId, "");
}, () =>
{
NewSwitchView(pirclick, vv);
}, false);
}
});
}
///
/// 发送线程
///
///
///
///
///
///
void Thread(Dialog dialog, Action action, string str, string deviceId, string obj)
{
//加载log
Loading loading = new Loading();
dialog.AddChidren(loading);
HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
loading.Start();
new System.Threading.Thread(() =>
{
try
{
if (str == "删除")
{
responsePackNew = PirSend.DeleteDevice(deviceId);
}
else if (str == "修改名称")
{
responsePackNew = PirSend.DeviceRename(deviceId, obj);
}
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
loading.Hide();
if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
{
action(responsePackNew);
}
else
{
Method method = new Method();
method.ErrorShow(responsePackNew,"");
}
});
}
})
{ IsBackground = true }.Start();
}
}
}