using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone
{
///
/// 底部弹窗项目选择界面
///
public class BottomItemSelectForm : DialogCommonForm
{
#region ■ 变量声明___________________________
///
/// 完成选择的事件(参数为选择的是列表的第几行,从0开始)
/// 当CancelCallEvent=true时,点击确认按钮时,参数为:-1
///
public Action FinishSelectEvent = null;
///
/// 前回选择的控件
///
private NormalSelectControl oldSelectContr = null;
///
/// 选择取消(不是左下角),并且按下确定键时,是否调用回调函数(调用时传递的参数是 -1,默认不回调)
///
public bool CancelCallEvent = false;
///
/// 选择的行能否取消(默认可以取消)
///
public bool SelectRowCanCancel = true;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 头部标题
/// 需要显示的列表信息
/// 需要显示的列表信息(底部),如果只是单行显示,则此值设置为null(如果不为null,但是索引所指向的值为null,则该行强制单行显示)
/// 设置哪个文本为默认选择(不设置填-1)
public void ShowForm(string i_topText, List i_listText, List i_listBottomText, int i_selectNo)
{
//初始化中部信息
this.InitMiddleFrame(i_topText, i_listText, i_listBottomText, i_selectNo);
}
///
/// 初始化中部信息
///
/// 头部标题
/// 需要显示的列表信息
/// 需要显示的列表信息(底部)
/// 默认选择
private void InitMiddleFrame(string i_topText, List i_listText, List i_listBottomtext, int i_selectNo)
{
//不能够滑动的东西
FrameListControl listDetailView1 = null;
//能够滑动的东西
VerticalListControl listDetailView2 = null;
//★★从下往上添加控件★★
//明细高度(初始最多只显示9行)
int detailHeight = HdlControlResourse.ListViewRowHeight + Application.GetRealHeight(12);
if (i_listText.Count > 9)
{
//63:上部间距 58:下部间距
detailHeight = detailHeight * 9 + Application.GetRealHeight(63 + 58);
listDetailView2 = new VerticalListControl(12);
listDetailView2.Height = detailHeight;
listDetailView2.Gravity = Gravity.BottomCenter;
listDetailView2.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(listDetailView2);
}
else
{
//63:上部间距 58:下部间距
detailHeight = detailHeight * i_listText.Count + Application.GetRealHeight(63 + 58);
listDetailView1 = new FrameListControl(12);
listDetailView1.Height = detailHeight;
listDetailView1.Gravity = Gravity.BottomCenter;
listDetailView1.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(listDetailView1);
}
//线
int lineYY = listDetailView1 != null ? listDetailView1.Y : listDetailView2.Y;
var btnLine = new NormalViewControl(bodyFrameLayout.Width, HdlControlResourse.BottomLineHeight, false);
btnLine.Y = lineYY - HdlControlResourse.BottomLineHeight;
btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
bodyFrameLayout.AddChidren(btnLine);
//头部白色背景
var topBackFame = new FrameLayout();
topBackFame.Y = btnLine.Y - Application.GetRealHeight(138);
topBackFame.BackgroundColor = UserCenterColor.Current.White;
topBackFame.Height = Application.GetRealHeight(138);
topBackFame.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
bodyFrameLayout.AddChidren(topBackFame);
//头部信息
var btnTitle = new NormalViewControl(topBackFame.Width, Application.GetRealHeight(65), false);
btnTitle.Y = Application.GetRealHeight(34);
btnTitle.Text = i_topText;
btnTitle.TextColor = UserCenterColor.Current.TextColor4;
btnTitle.TextSize = 16;
btnTitle.TextAlignment = TextAlignment.Center;
topBackFame.AddChidren(btnTitle);
//取消
var btnCancel = new NormalViewControl(Application.GetRealWidth(200), topBackFame.Height, false);
btnCancel.X = Application.GetRealWidth(81);
btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
btnCancel.TextID = R.MyInternationalizationString.uCancel;
topBackFame.AddChidren(btnCancel);
btnCancel.ButtonClickEvent += (sender, e) =>
{
this.CloseForm();
};
//完成
var btnFinish = new NormalViewControl(Application.GetRealWidth(200), topBackFame.Height, false);
btnFinish.X = topBackFame.Width - btnCancel.X - Application.GetRealWidth(200);
btnFinish.TextAlignment = TextAlignment.CenterRight;
btnFinish.TextColor = 0xfffb744a;
btnFinish.TextID = R.MyInternationalizationString.uFinish;
topBackFame.AddChidren(btnFinish);
btnFinish.ButtonClickEvent += (sender, e) =>
{
if (FinishSelectEvent != null && oldSelectContr != null)
{
//回调函数
FinishSelectEvent.Invoke(Convert.ToInt32(oldSelectContr.MainKeys));
}
else if (FinishSelectEvent != null && this.CancelCallEvent == true)
{
//回调函数
FinishSelectEvent.Invoke(-1);
}
this.CloseForm();
};
//添加一个白色的间距
var frameSpace = new FrameLayout();
frameSpace.Height = Application.GetRealHeight(63);
listDetailView1?.AddChidren(frameSpace);
listDetailView2?.AddChidren(frameSpace);
//明细列表控件
int rowSpace = listDetailView1 != null ? listDetailView1.rowSpace : listDetailView2.rowSpace;
for (int i = 0; i < i_listText.Count; i++)
{
NormalSelectControl btnRow = null;
if (i_listBottomtext == null || i_listBottomtext[i] == null)
{
//只显示一行
btnRow = new NormalSelectControl(i_listText[i], rowSpace / 2);
}
else
{
//显示上下两行
btnRow = new NormalSelectControl(i_listText[i], i_listBottomtext[i], rowSpace / 2);
}
btnRow.LeftOffset = Application.GetRealWidth(81) - HdlControlResourse.XXLeft;//向右偏移
btnRow.RightOffset = HdlControlResourse.XXLeft - Application.GetRealWidth(81);//向左偏移
listDetailView1?.AddChidren(btnRow);
listDetailView2?.AddChidren(btnRow);
btnRow.InitControl();
btnRow.MainKeys = i.ToString();
btnRow.ButtonClickEvent += (sender, e) =>
{
//取消选择
if (btnRow.IsSelected == true)
{
//允许取消的时候,才能取消
if (this.SelectRowCanCancel == true)
{
btnRow.IsSelected = false;
oldSelectContr = null;
}
return;
}
if (oldSelectContr != null)
{
oldSelectContr.IsSelected = false;
}
btnRow.IsSelected = true;
oldSelectContr = btnRow;
};
//默认选择
if (i == i_selectNo)
{
btnRow.IsSelected = true;
oldSelectContr = btnRow;
}
if (i != i_listText.Count - 1)
{
//底线
btnRow.AddBottomLine();
}
}
//如果是滑动控件,则添加底部间距
if (listDetailView2 != null)
{
var frameSpace2 = new FrameLayout();
frameSpace2.Height = Application.GetRealHeight(58);
listDetailView2?.AddChidren(frameSpace2);
}
}
#endregion
}
}