using System;
|
using System.Collections.Generic;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON
|
{
|
/// <summary>
|
/// 楼层DiySelectPopupDialog
|
/// </summary>
|
public class DiySelectPopupDialog : Dialog
|
{
|
/// <summary>
|
/// ALLSELECT,标识
|
/// </summary>
|
public const string ALLSELECT = "ALLSELECT";
|
|
/// bodyView
|
/// </summary>
|
FrameLayout bodyView;
|
/// <summary>
|
/// 底部View
|
/// 自己根据需要调整X、Y坐标
|
/// </summary>
|
public FrameLayout BackView;
|
/// <summary>
|
/// 全部按钮
|
/// </summary>
|
Button leftAllButton;
|
/// <summary>
|
/// 一级滑动View
|
/// </summary>
|
VerticalScrolViewLayout leftScrolView;
|
/// <summary>
|
/// 二级滑动View
|
/// </summary>
|
VerticalScrolViewLayout rightScrolView;
|
/// <summary>
|
/// 选中回调事件
|
/// </summary>
|
Action<string> SelectAction;
|
/// <summary>
|
/// 一级List
|
/// </summary>
|
List<RoomCellInfo> mFirstList = new List<RoomCellInfo>();
|
/// <summary>
|
/// 二级联动List
|
/// </summary>
|
List<List<RoomCellInfo>> mSecondList = new List<List<RoomCellInfo>>();
|
/// <summary>
|
/// 二级所有List
|
/// </summary>
|
List<RoomCellInfo> mSecondAllList = new List<RoomCellInfo>();
|
|
/// <summary>
|
/// DiySelectPopupDialog
|
/// </summary>
|
public DiySelectPopupDialog()
|
{
|
bodyView = new FrameLayout();
|
|
}
|
|
/// <summary>
|
/// 显示View
|
/// mFirstList、mSecondList不合法都不会显示View
|
/// mSecondList 不传为默认一级
|
/// </summary>
|
/// <param name="mFirstList">一级数据集合</param>
|
/// <param name="mSecondList">二级数据集合</param>
|
/// <param name="SelectAction">选择回调事件</param>
|
/// <param name="selectTagId"></param>
|
public void ShowView(List<RoomCellInfo> mFirstList, List<List<RoomCellInfo>> mSecondList, Action<string> SelectAction, string selectTagId = ALLSELECT)
|
{
|
if (mFirstList == null)
|
{
|
Utlis.WriteLine("mFirstList null");
|
return;
|
}
|
//注册回调事件
|
this.SelectAction = SelectAction;
|
//二是否需要二级判断
|
if (mSecondList == null || mSecondList.Count == 0)
|
{
|
//一级
|
this.mFirstList = mFirstList;
|
//View显示
|
ShowOneBaseView();
|
//数据内容填充
|
RefreshOneBaseView(selectTagId);
|
}
|
else
|
{
|
if (mFirstList.Count != mSecondList.Count)
|
{
|
Utlis.WriteLine("数据 不联动异常");
|
return;
|
}
|
//二级联动
|
this.mFirstList = mFirstList;
|
this.mSecondList = mSecondList;
|
this.mSecondAllList.Clear();
|
foreach (var list in mSecondList)
|
{
|
foreach (var data in list)
|
{
|
this.mSecondAllList.Add(data);
|
}
|
}
|
|
//View显示
|
ShowDoubleBaseView();
|
//数据内容填充
|
RefreshDoubleBaseView();
|
//选中效果
|
SetSelectTagId(selectTagId);
|
|
}
|
this.Show();
|
}
|
|
|
/// <summary>
|
/// 刷新UI,选择全部
|
/// </summary>
|
void SelectAll()
|
{
|
RefreshSelectButton(leftScrolView, ALLSELECT);
|
var all = new RoomCellInfo()
|
{
|
TagId = ALLSELECT,
|
Title = "ALL",
|
};
|
LoadRightScrolView(all, this.mSecondAllList);
|
}
|
|
/// <summary>
|
/// 根据tagID选中
|
/// </summary>
|
void SetSelectTagId(string tagId)
|
{
|
if (string.IsNullOrEmpty(tagId) || tagId == ALLSELECT || mFirstList == null)
|
{
|
SelectAll();
|
}
|
else
|
{
|
//一级楼层匹配成功
|
var tagInfo = mFirstList.Find((m) => m.TagId == tagId);
|
if (tagInfo != null)
|
{
|
var index = mFirstList.IndexOf(tagInfo);
|
if (index < mSecondList.Count)
|
{
|
RefreshSelectButton(leftScrolView, tagId);
|
LoadRightScrolView(tagInfo, mSecondList[index]);
|
return;
|
}
|
else
|
{
|
SelectAll();
|
}
|
}
|
else
|
{
|
//SelectAll();
|
//一级的楼层匹配失败,尝试匹配二级
|
if (mSecondList == null || mFirstList.Count != mSecondList.Count)
|
{
|
SelectAll();
|
}
|
else
|
{
|
//是否匹配到房间
|
bool isFind = false;
|
//1.遍历二级房间数据
|
for (var i = 0; i < mSecondList.Count; i++)
|
{
|
foreach (var room in mSecondList[i])
|
{
|
if (tagId == room.TagId)
|
{
|
//匹配房间成功,选中对于的楼层
|
var tagFirstInfo = mFirstList[i];
|
isFind = true;
|
RefreshSelectButton(leftScrolView, tagFirstInfo.TagId);
|
LoadRightScrolView(tagFirstInfo, mSecondList[i]);
|
break;
|
}
|
}
|
}
|
|
//没有匹配到房间
|
if (!isFind)
|
{
|
SelectAll();
|
}
|
}
|
|
|
}
|
}
|
}
|
|
#region 二级联动选择效果
|
/// <summary>
|
/// 显示二级view
|
/// </summary>
|
void ShowDoubleBaseView()
|
{
|
bodyView.BackgroundColor = CSS_Color.DialogTransparentColor1;
|
this.AddChidren(bodyView);
|
bodyView.MouseUpEventHandler = (sender, e) =>
|
{
|
this.Close();
|
};
|
|
BackView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(10),
|
Y = Application.GetRealHeight(104),
|
Width = Application.GetRealWidth(283),
|
Height = Application.GetRealWidth(242),
|
};
|
bodyView.AddChidren(BackView);
|
|
var backImageView = new ImageView()
|
{
|
Width = BackView.Width,
|
Height = BackView.Height,
|
ImagePath = "Public/PopupDialog.png"
|
};
|
BackView.AddChidren(backImageView);
|
|
leftAllButton = new Button()
|
{
|
Y = Application.GetRealWidth(14),
|
X = Application.GetRealWidth(24),
|
Height = Application.GetRealWidth(44),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextID = StringId.All,
|
IsSelected = true,
|
//IsBold = true,
|
};
|
BackView.AddChidren(leftAllButton);
|
//分割线
|
var lineView1 = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(112),
|
Height = Application.GetRealHeight(1),
|
Y = leftAllButton.Bottom,
|
X = leftAllButton.X,
|
BackgroundColor = CSS_Color.DividingLineColor,
|
};
|
BackView.AddChidren(lineView1);
|
|
leftScrolView = new VerticalScrolViewLayout()
|
{
|
X = Application.GetRealWidth(8),
|
Y = leftAllButton.Bottom,
|
Height = Application.GetRealWidth(176),
|
Width = Application.GetRealWidth(128),
|
VerticalScrollBarEnabled = false,
|
};
|
BackView.AddChidren(leftScrolView);
|
|
rightScrolView = new VerticalScrolViewLayout()
|
{
|
X = leftScrolView.Right + Application.GetRealWidth(12),
|
Y = Application.GetRealWidth(58),
|
Height = Application.GetRealWidth(176),
|
Width = Application.GetRealWidth(128),
|
VerticalScrollBarEnabled = false,
|
};
|
BackView.AddChidren(rightScrolView);
|
|
leftAllButton.MouseUpEventHandler = (sender, e) =>
|
{
|
leftAllButton.IsSelected = true;
|
|
//加载全部
|
SelectAll();
|
};
|
}
|
|
/// <summary>
|
/// 刷新二级联动的VIEW
|
/// </summary>
|
void RefreshDoubleBaseView()
|
{
|
leftScrolView.RemoveAll();
|
for (var i = 0; i < mFirstList.Count; i++)
|
{
|
AddSelectButton(leftScrolView, mFirstList[i], mSecondList[i]);
|
}
|
}
|
|
/// <summary>
|
/// scrolView里面Button 选中效果互斥
|
/// </summary>
|
/// <param name="scrolView"></param>
|
/// <param name="selectBtnTag"></param>
|
void RefreshSelectButton(VerticalScrolViewLayout scrolView, string selectBtnTag)
|
{
|
try
|
{
|
if (leftAllButton != null)
|
{
|
leftAllButton.IsSelected = selectBtnTag == ALLSELECT;
|
}
|
|
if (scrolView != null)
|
{
|
for (int i = 0; i < scrolView.ChildrenCount; i++)
|
{
|
if (scrolView.GetChildren(i).GetType() == typeof(FrameLayout))
|
{
|
var cellView = (FrameLayout)scrolView.GetChildren(i);
|
for (int j = 0; j < cellView.ChildrenCount; j++)
|
{
|
if (cellView.GetChildren(j).GetType() == typeof(Button))
|
{
|
var titleButton = (Button)cellView.GetChildren(j);
|
var o = titleButton.GetTagByKey("BtnKey");
|
if (o != null && o.ToString() == selectBtnTag)
|
{
|
titleButton.IsSelected = true;
|
}
|
else
|
{
|
titleButton.IsSelected = false;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
catch
|
{
|
|
}
|
}
|
|
/// <summary>
|
/// 添加一级楼层选择CellView
|
/// </summary>
|
/// <param name="scrolView"></param>
|
/// <param name="firstData"></param>
|
/// <param name="rightList"></param>
|
void AddSelectButton(VerticalScrolViewLayout scrolView, RoomCellInfo firstData, List<RoomCellInfo> rightList)
|
{
|
var cellView = new FrameLayout()
|
{
|
Height = Application.GetRealWidth(44),
|
Tag = "cell"
|
};
|
scrolView.AddChidren(cellView);
|
|
var titleButton = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Height = Application.GetRealWidth(44),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = firstData.Title,
|
};
|
cellView.AddChidren(titleButton);
|
titleButton.AddTag("BtnKey", firstData.TagId);
|
|
//顶部分割线
|
var lineView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(16),
|
Height = Application.GetRealHeight(1),
|
Width = Application.GetRealWidth(112),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
Y = cellView.Height - Application.GetRealHeight(1),
|
};
|
cellView.AddChidren(lineView);
|
|
EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
|
{
|
//cellView.BackgroundColor = CSS_Color.viewTranslucence;
|
RefreshSelectButton(scrolView, firstData.TagId);
|
LoadRightScrolView(firstData, rightList);
|
};
|
|
titleButton.MouseUpEventHandler = eventHandler;
|
cellView.MouseUpEventHandler = eventHandler;
|
|
//EventHandler<MouseEventArgs> mousDownEventHandler = (sender, e) =>
|
//{
|
// cellView.BackgroundColor = CSS_Color.TopViewColor;
|
//};
|
|
//titleButton.MouseDownEventHandler = mousDownEventHandler;
|
//cellView.MouseDownEventHandler = mousDownEventHandler;
|
}
|
|
|
|
/// <summary>
|
/// 加载二级滑动View
|
/// </summary>
|
/// <param name="firstData"></param>
|
/// <param name="rightList"></param>
|
void LoadRightScrolView(RoomCellInfo firstData, List<RoomCellInfo> rightList)
|
{
|
rightScrolView.RemoveAll();
|
|
//添加顶部分割线
|
var lineView2 = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(112),
|
Height = Application.GetRealHeight(1),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
};
|
rightScrolView.AddChidren(lineView2);
|
//添加全部按钮
|
var allInfo = new RoomCellInfo()
|
{
|
Title = Language.StringByID(StringId.All),
|
TagId = firstData.TagId,//上一级楼层ID
|
};
|
AddRightSelectButton(rightScrolView, allInfo, true);
|
|
for (var i = 0; i < rightList.Count; i++)
|
{
|
AddRightSelectButton(rightScrolView, rightList[i]);
|
}
|
|
}
|
|
/// <summary>
|
/// 添加二级选择CellView
|
/// </summary>
|
/// <param name="scrolView"></param>
|
/// <param name="secondData"></param>
|
/// <param name="isSelected"></param>
|
void AddRightSelectButton(VerticalScrolViewLayout scrolView, RoomCellInfo secondData, bool isSelected = false)
|
{
|
var cellView = new FrameLayout()
|
{
|
Height = Application.GetRealWidth(44),
|
};
|
scrolView.AddChidren(cellView);
|
|
var titleButton = new Button()
|
{
|
//X = Application.GetRealWidth(16),
|
Height = Application.GetRealWidth(44),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = secondData.Title,
|
IsSelected = isSelected
|
};
|
cellView.AddChidren(titleButton);
|
|
var lineView = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(112),
|
Height = Application.GetRealHeight(1),
|
Y = cellView.Height - Application.GetRealHeight(1),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
};
|
cellView.AddChidren(lineView);
|
|
EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
|
{
|
this.Close();
|
//回调选中索引
|
SelectAction?.Invoke(secondData.TagId);
|
};
|
|
titleButton.MouseUpEventHandler = eventHandler;
|
cellView.MouseUpEventHandler = eventHandler;
|
|
|
}
|
|
#endregion
|
|
|
#region 只有一级的联动
|
/// <summary>
|
/// 都显示一级的
|
/// </summary>
|
void ShowOneBaseView()
|
{
|
bodyView.BackgroundColor = CSS_Color.DialogTransparentColor1;
|
this.AddChidren(bodyView);
|
bodyView.MouseUpEventHandler = (sender, e) =>
|
{
|
this.Close();
|
};
|
|
BackView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(10),
|
Y = Application.GetRealHeight(104),
|
Width = Application.GetRealWidth(160),
|
Height = Application.GetRealWidth(198),
|
};
|
bodyView.AddChidren(BackView);
|
|
var backImageView = new ImageView()
|
{
|
Width = BackView.Width,
|
Height = BackView.Height,
|
ImagePath = "PersonalCenter/HomeList3bg.png"
|
};
|
BackView.AddChidren(backImageView);
|
|
leftAllButton = new Button()
|
{
|
Y = Application.GetRealWidth(14),
|
X = Application.GetRealWidth(24),
|
Height = Application.GetRealWidth(44),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextID = StringId.All,
|
//IsBold = true,
|
};
|
BackView.AddChidren(leftAllButton);
|
//分割线
|
var lineView1 = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(112),
|
Height = Application.GetRealHeight(1),
|
Y = leftAllButton.Bottom,
|
X = leftAllButton.X,
|
BackgroundColor = CSS_Color.DividingLineColor,
|
};
|
BackView.AddChidren(lineView1);
|
|
leftScrolView = new VerticalScrolViewLayout()
|
{
|
X = Application.GetRealWidth(8),
|
Y = leftAllButton.Bottom,
|
Height = Application.GetRealWidth(132),
|
Width = Application.GetRealWidth(144),
|
VerticalScrollBarEnabled = false,
|
};
|
BackView.AddChidren(leftScrolView);
|
|
leftAllButton.MouseUpEventHandler = (sender, e) =>
|
{
|
this.Close();
|
SelectAction?.Invoke(ALLSELECT);
|
};
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="tagId"></param>
|
void RefreshOneBaseView(string tagId)
|
{
|
if (leftAllButton != null)
|
{
|
leftAllButton.IsSelected = tagId == ALLSELECT;
|
}
|
leftScrolView.RemoveAll();
|
for (var i = 0; i < mFirstList.Count; i++)
|
{
|
AddOneSelectButton(leftScrolView, mFirstList[i], tagId);
|
}
|
}
|
|
/// <summary>
|
/// 添加一级楼层选择CellView
|
/// </summary>
|
/// <param name="scrolView"></param>
|
/// <param name="firstIndex"></param>
|
/// <param name="firstText"></param>
|
void AddOneSelectButton(VerticalScrolViewLayout scrolView, RoomCellInfo firstData, string tagId)
|
{
|
var cellView = new FrameLayout()
|
{
|
Height = Application.GetRealWidth(44),
|
Tag = "cell"
|
};
|
scrolView.AddChidren(cellView);
|
|
var titleButton = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Height = Application.GetRealWidth(44),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = firstData.Title,
|
};
|
cellView.AddChidren(titleButton);
|
titleButton.IsSelected = firstData.TagId == tagId;
|
titleButton.AddTag("BtnKey", firstData.TagId);
|
|
//顶部分割线
|
var lineView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(16),
|
Height = Application.GetRealHeight(1),
|
Width = Application.GetRealWidth(112),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
Y = cellView.Height - Application.GetRealHeight(1),
|
};
|
cellView.AddChidren(lineView);
|
|
EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
|
{
|
this.Close();
|
//回调选中索引
|
SelectAction?.Invoke(firstData.TagId);
|
};
|
|
titleButton.MouseUpEventHandler = eventHandler;
|
cellView.MouseUpEventHandler = eventHandler;
|
|
//EventHandler<MouseEventArgs> mousDownEventHandler = (sender, e) =>
|
//{
|
// cellView.BackgroundColor = CSS_Color.TopViewColor;
|
//};
|
|
//titleButton.MouseDownEventHandler = mousDownEventHandler;
|
//cellView.MouseDownEventHandler = mousDownEventHandler;
|
}
|
|
|
|
#endregion
|
|
|
#region 选择楼层和房间专用
|
|
|
#endregion
|
|
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public class RoomCellInfo
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public string Title;
|
/// <summary>
|
///
|
/// </summary>
|
public string TagId;
|
}
|
}
|