using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public class OrderFunctionPage : FrameLayout
{
#region 控件列表
///
/// 当前窗体
///
static FrameLayout bodyView;
///
/// 功能列表集合显示区域
///
static VerticalScrolViewLayout functionListView;
///
/// 完成按钮
///
Button btnConfrim;
#endregion
///
/// 回调刷新
///
Action backActon;
List orderList = new List();
List orderNumber = new List();
public OrderFunctionPage()
{
bodyView = this;
}
public void LoadPage(List functions,Action action)
{
List orderNumberAlreay = new List();
for (int i=0;i< functions.Count; i++)
{
if (functions[i].FunctionOrderNumber != 9999)
{
orderNumberAlreay.Add(functions[i].FunctionOrderNumber);
}
}
for (int i = 1; i < functions.Count + 1; i++)
{
if (!orderNumberAlreay.Contains(i))
{
orderNumber.Add(i);
}
}
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
new TopViewDiv(bodyView, Language.StringByID(StringId.Sort)).LoadTopView();
functionListView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(84),
Height = Application.GetRealHeight(640 - 100),
};
bodyView.AddChidren(functionListView);
LoadRow(functions);
#region 底部view
var bottomView = new FrameLayout()
{
Y = Application.GetRealHeight(591),
Height = Application.GetRealHeight(100),
BackgroundColor = CSS_Color.MainBackgroundColor,
Radius = (uint)Application.GetRealWidth(12),
};
this.AddChidren(bottomView);
btnConfrim = new Button()
{
Y = Application.GetRealHeight(12),
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(220),
Height = Application.GetRealHeight(44),
Radius = (uint)Application.GetRealHeight(22),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.MainBackgroundColor,
BackgroundColor = CSS_Color.BackgroundColor,
TextID = StringId.Confirm,
TextSize = CSS_FontSize.SubheadingFontSize,
SelectedTextColor = CSS_Color.MainBackgroundColor,
SelectedBackgroundColor = CSS_Color.MainColor,
IsSelected = true
};
bottomView.AddChidren(btnConfrim);
btnConfrim.MouseUpEventHandler = (sender, e) => {
foreach(var function in functions)
{
function.SaveFunctionFile();
}
action?.Invoke();
this.RemoveFromParent();
};
#endregion
}
///
/// 显示的设备的总数
///
int showCount = 0;
///
/// 加载功能row
///
///
void LoadRow(List functions, bool isAppend = false)
{
var waitPage = new Loading();
bodyView.AddChidren(waitPage);
waitPage.Start("");
new System.Threading.Thread(() =>
{
try
{
Application.RunOnMainThread(() =>
{
if (!isAppend)
{
showCount = 0;
functionListView.RemoveAll();
}
for(var i =0;i<100;i++)
//foreach (var function in functions)
{
showCount++;
if (showCount >= functions.Count)
{
break;
}
var function = functions[showCount];
var functionDiv = new OrderFunctionRow()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealHeight(62),
Radius = (uint)Application.GetMinRealAverage(12),
BorderColor = 0x00FFFFFF,
BorderWidth = 1,
BackgroundColor = CSS_Color.MainBackgroundColor,
};
functionDiv.LoadDiv(function, orderNumber);
functionListView.AddChidren(functionDiv);
functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
}
if (functions.Count > showCount)
{
var btnAppend = new Button()
{
Height = Application.GetRealHeight(60),
TextAlignment = TextAlignment.Center,
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.FirstLevelTitleColor,
TextID = StringId.LoadMore,
};
functionListView.AddChidren(btnAppend);
btnAppend.MouseUpEventHandler = (sender, e) =>
{
btnAppend.RemoveFromParent();
LoadRow(functions, true);
};
}
});
}
catch (Exception ex)
{
MainPage.Log("ShowFunctionRowError : " + ex.Message);
}
finally
{
Application.RunOnMainThread(() =>
{
if (waitPage != null)
{
waitPage.RemoveFromParent();
waitPage = null;
}
});
}
})
{ IsBackground = true }.Start();
}
}
public class OrderFunctionRow : FrameLayout
{
#region 区域控件
static FrameLayout bodyDiv;
///
/// 功能/场景icon
///
Button btnIcon;
///
/// 功能名称/场景名称
///
Button btnName;
///
/// 楼层信息显示按钮
///
Button btnFromFloor;
///
/// 选中按钮
///
Button btnSelect;
#endregion
public OrderFunctionRow()
{
bodyDiv = this;
}
///
/// 加载控制卡片区域
///
public void LoadDiv(Function function, List orderNumber)
{
btnIcon = new Button()
{
X = Application.GetRealWidth(10),
Y = Application.GetRealHeight(15),
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png"
};
bodyDiv.AddChidren(btnIcon);
btnName = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Y = Application.GetRealHeight(10),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(24),
Text = function.name,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
};
bodyDiv.AddChidren(btnName);
btnFromFloor = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Y = Application.GetRealHeight(10 + 24),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(18),
Text = function.GetRoomListName(),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
};
bodyDiv.AddChidren(btnFromFloor);
btnSelect = new Button()
{
X = Application.GetRealWidth(303),
Gravity = Gravity.CenterVertical,
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
Text = function.FunctionOrderNumber == 9999 ? "" : function.FunctionOrderNumber.ToString(),
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.Center,
};
bodyDiv.AddChidren(btnSelect);
EventHandler eventHandler = (sender, e) => {
lock (orderNumber)
{
if (function.FunctionOrderNumber == 9999)
{
function.FunctionOrderNumber = orderNumber[0];
orderNumber.RemoveAt(0);
btnSelect.Text = function.FunctionOrderNumber.ToString();
}
else
{
if (!orderNumber.Contains(function.FunctionOrderNumber))
{
for (var i = 0; i < orderNumber.Count; i++)
{
if (orderNumber[i] > function.FunctionOrderNumber)
{
orderNumber.Insert(i, function.FunctionOrderNumber);
function.FunctionOrderNumber = 9999;
break;
}
}
}
if (function.FunctionOrderNumber != 9999)
{
orderNumber.Add(function.FunctionOrderNumber);
function.FunctionOrderNumber = 9999;
}
btnSelect.Text = "";
}
}
};
btnName.MouseUpEventHandler = eventHandler;
btnSelect.MouseUpEventHandler = eventHandler;
bodyDiv.MouseUpEventHandler = eventHandler;
}
}
}