using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
///
/// 联系人设置
///
public class CoerceContactSettionForm : UserCenterCommonForm
{
///
/// 列表控件
///
private VerticalScrolViewLayout listView = null;
///
/// 列表控件最多只能显示多少行控件,如果超过时,高度不再变化
///
private int listViewCount = 7;
///
/// 桌布控件
///
private FrameLayout frameTableLayout = null;
///
/// 【添加联系人】的行
///
private StatuRowLayout addPersonRow = null;
///
/// 电话列表
///
private List listPhoneData = null;
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 已经存在的联系方式
public void ShowForm(List listData)
{
this.listPhoneData = listData;
//计算理论值
int maxHeight = Application.GetRealHeight(180) * 7;
this.listViewCount = maxHeight / ControlCommonResourse.ListViewRowHeight;
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uContactSettion));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//胁迫状态下,被通知人的联系方式
var btnTitle = new TitleViewControl();
btnTitle.TextColor = UserCenterColor.Current.TextGrayColor;
btnTitle.Y = Application.GetRealHeight(40);
btnTitle.TextID = R.MyInternationalizationString.uContactInCoerceStatu;
bodyFrameLayout.AddChidren(btnTitle);
this.frameTableLayout = new FrameLayout();
frameTableLayout.Y = btnTitle.Bottom;
bodyFrameLayout.AddChidren(this.frameTableLayout);
//设置中间部分信息
this.SetMiddleInfo();
}
///
/// 设置中间部分信息
///
private void SetMiddleInfo()
{
this.listView = new VerticalScrolViewLayout();
this.listView.Height = 0;
frameTableLayout.AddChidren(this.listView);
new System.Threading.Thread(() =>
{
Application.RunOnMainThread(() =>
{
//添加联系人的明细行
this.AddPhoneNumList();
//添加【添加联系人】的行
this.AddAddContactPersionRow();
});
})
{ IsBackground = true }.Start();
}
///
/// 添加联系人的明细行
///
private void AddPhoneNumList()
{
int heightCount = listPhoneData.Count;
if (heightCount > listViewCount)
{
heightCount = listViewCount;
}
foreach (var data in listPhoneData)
{
//添加联系人行
this.AddPhoneNumRowLayout(data);
}
}
///
/// 添加联系人行
///
///
public void AddPhoneNumRowLayout(Safeguard.PushTargetInfo data)
{
var row = new RowLayout();
row.Height = ControlCommonResourse.ListViewRowHeight;
this.listView.AddChidren(row);
//图标
var btnIcon = new RowLeftIconView();
btnIcon.UnSelectedImagePath = "Account/ProfilePhotoMember.png";
row.AddChidren(btnIcon);
//电话号码
var btnPhone = new RowCenterView();
btnPhone.Text = "+" + data.PushNumber.Replace("-", " ");
row.AddChidren(btnPhone);
//删除
var btnDelete = new RowDeleteButton();
row.AddRightView(btnDelete);
btnDelete.MouseUpEventHandler += (sender, e) =>
{
string[] Arry = data.PushNumber.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
string PNumber = string.Empty;
string areaCode = string.Empty;
if (Arry.Length == 1)
{
PNumber = Arry[0];
}
else
{
areaCode= Arry[0];
PNumber = Arry[1];
}
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
this.ShowConfirmMsg(msg, "DeleteCoercePhoneNumber", areaCode, PNumber, row);
};
//新添加的时候,自动调整界面高度
this.AutoAdjustListViewHeight();
}
///
/// 添加【添加联系人】的行
///
private void AddAddContactPersionRow()
{
this.addPersonRow = new StatuRowLayout();
addPersonRow.Y = this.listView.Bottom;
frameTableLayout.AddChidren(addPersonRow);
//添加联系人
var txtAddPer = new RowCenterView(false);
txtAddPer.TextID = R.MyInternationalizationString.uAddContactPersion; ;
addPersonRow.AddChidren(txtAddPer);
//加号图标
var btnAdd = new MostRightEmptyView();
btnAdd.UnSelectedImagePath = "Item/Add.png";
btnAdd.SelectedImagePath = "Item/AddSelected.png";
addPersonRow.AddChidren(btnAdd);
addPersonRow.MouseUpEvent += (sender, e) =>
{
var form = new AddCoerceContactForm();
this.AddForm(form, this.listPhoneData);
};
}
///
/// 删除联系人方式
///
///
///
///
public async void DeleteCoercePhoneNumber(string areaCode, string phone,RowLayout row)
{
bool result = await Common.LocalSafeguard.Current.DeleteCoercePhoneNumber(areaCode, phone);
if (result == true)
{
Application.RunOnMainThread(() =>
{
row.RemoveFromParent();
//自动调整列表控件的高度
this.AutoAdjustListViewHeight();
this.LoadFormMethodByName("CoercePasswordMainForm", "InitMiddleFrame");
});
}
}
///
/// 自动调整列表控件的高度
///
private void AutoAdjustListViewHeight()
{
if (this.listView.ChildrenCount > this.listViewCount)
{
//不再扩大
return;
}
this.listView.Height = this.listView.ChildrenCount * ControlCommonResourse.ListViewRowHeight;
if (this.addPersonRow != null)
{
//有可能是画面正在初始化的时候
this.addPersonRow.Y = this.listView.Bottom;
}
}
}
}