using System;
using System.Collections.Generic;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON
{
///
/// 楼层DiySelectPopupDialog
///
public class DiySelectPopupDialog : Dialog
{
///
/// ALLSELECT,标识
///
public const string ALLSELECT = "ALLSELECT";
/// bodyView
///
FrameLayout bodyView;
///
/// 底部View
/// 自己根据需要调整X、Y坐标
///
public FrameLayout BackView;
///
/// 全部按钮
///
Button leftAllButton;
///
/// 一级滑动View
///
VerticalScrolViewLayout leftScrolView;
///
/// 二级滑动View
///
VerticalScrolViewLayout rightScrolView;
///
/// 选中回调事件
///
Action SelectAction;
///
/// 一级List
///
List mFirstList = new List();
///
/// 二级联动List
///
List> mSecondList = new List>();
///
/// 二级所有List
///
List mSecondAllList = new List();
///
/// DiySelectPopupDialog
///
public DiySelectPopupDialog()
{
bodyView = new FrameLayout();
}
///
/// 显示View
/// mFirstList、mSecondList不合法都不会显示View
/// mSecondList 不传为默认一级
///
/// 一级数据集合
/// 二级数据集合
/// 选择回调事件
///
public void ShowView(List mFirstList, List> mSecondList, Action SelectAction, string selectTagId = ALLSELECT, int offsetY = 0)
{
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(offsetY);
//数据内容填充
RefreshDoubleBaseView();
//选中效果
SetSelectTagId(selectTagId);
}
this.Show();
}
///
/// 刷新UI,选择全部
///
void SelectAll()
{
RefreshSelectButton(leftScrolView, ALLSELECT);
var all = new RoomCellInfo()
{
TagId = ALLSELECT,
Title = "ALL",
};
LoadRightScrolView(all, this.mSecondAllList);
}
///
/// 根据tagID选中
///
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 二级联动选择效果
///
/// 显示二级view
///
void ShowDoubleBaseView(int offsetY = 0)
{
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+ offsetY),
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();
};
}
///
/// 刷新二级联动的VIEW
///
void RefreshDoubleBaseView()
{
leftScrolView.RemoveAll();
for (var i = 0; i < mFirstList.Count; i++)
{
AddSelectButton(leftScrolView, mFirstList[i], mSecondList[i]);
}
}
///
/// scrolView里面Button 选中效果互斥
///
///
///
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
{
}
}
///
/// 添加一级楼层选择CellView
///
///
///
///
void AddSelectButton(VerticalScrolViewLayout scrolView, RoomCellInfo firstData, List 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 eventHandler = (sender, e) =>
{
//cellView.BackgroundColor = CSS_Color.viewTranslucence;
RefreshSelectButton(scrolView, firstData.TagId);
LoadRightScrolView(firstData, rightList);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
//EventHandler mousDownEventHandler = (sender, e) =>
//{
// cellView.BackgroundColor = CSS_Color.TopViewColor;
//};
//titleButton.MouseDownEventHandler = mousDownEventHandler;
//cellView.MouseDownEventHandler = mousDownEventHandler;
}
///
/// 加载二级滑动View
///
///
///
void LoadRightScrolView(RoomCellInfo firstData, List 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]);
}
}
///
/// 添加二级选择CellView
///
///
///
///
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 eventHandler = (sender, e) =>
{
this.Close();
//回调选中索引
SelectAction?.Invoke(secondData.TagId);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
}
#endregion
#region 只有一级的联动
///
/// 都显示一级的
///
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);
};
}
///
///
///
///
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);
}
}
///
/// 添加一级楼层选择CellView
///
///
///
///
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 eventHandler = (sender, e) =>
{
this.Close();
//回调选中索引
SelectAction?.Invoke(firstData.TagId);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
//EventHandler mousDownEventHandler = (sender, e) =>
//{
// cellView.BackgroundColor = CSS_Color.TopViewColor;
//};
//titleButton.MouseDownEventHandler = mousDownEventHandler;
//cellView.MouseDownEventHandler = mousDownEventHandler;
}
#endregion
#region 选择楼层和房间专用
#endregion
}
///
///
///
public class RoomCellInfo
{
///
///
///
public string Title;
///
///
///
public string TagId;
}
}