using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Safety
|
{
|
/// <summary>
|
/// 联系人设置
|
/// </summary>
|
public class CoerceContactSettionForm : UserCenterCommonForm
|
{
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalScrolViewLayout listView = null;
|
/// <summary>
|
/// 列表控件最多只能显示多少行控件,如果超过时,高度不再变化
|
/// </summary>
|
private int listViewCount = 7;
|
/// <summary>
|
/// 桌布控件
|
/// </summary>
|
private FrameLayout frameTableLayout = null;
|
/// <summary>
|
/// 【添加联系人】的行
|
/// </summary>
|
private StatuRowLayout addPersonRow = null;
|
/// <summary>
|
/// 电话列表
|
/// </summary>
|
private List<Safeguard.PushTargetInfo> listPhoneData = null;
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="listData">已经存在的联系方式</param>
|
public void ShowForm(List<Safeguard.PushTargetInfo> listData)
|
{
|
this.listPhoneData = listData;
|
|
//计算理论值
|
int maxHeight = Application.GetRealHeight(180) * 7;
|
this.listViewCount = maxHeight / ControlCommonResourse.ListViewRowHeight;
|
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uContactSettion));
|
|
//初始化中部信息
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
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();
|
}
|
|
/// <summary>
|
/// 设置中间部分信息
|
/// </summary>
|
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();
|
}
|
|
/// <summary>
|
/// 添加联系人的明细行
|
/// </summary>
|
private void AddPhoneNumList()
|
{
|
int heightCount = listPhoneData.Count;
|
if (heightCount > listViewCount)
|
{
|
heightCount = listViewCount;
|
}
|
|
foreach (var data in listPhoneData)
|
{
|
//添加联系人行
|
this.AddPhoneNumRowLayout(data);
|
}
|
}
|
|
/// <summary>
|
/// 添加联系人行
|
/// </summary>
|
/// <param name="data"></param>
|
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();
|
}
|
|
|
/// <summary>
|
/// 添加【添加联系人】的行
|
/// </summary>
|
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);
|
};
|
}
|
|
/// <summary>
|
/// 删除联系人方式
|
/// </summary>
|
/// <param name="areaCode"></param>
|
/// <param name="phone"></param>
|
/// <param name="row"></param>
|
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");
|
});
|
}
|
}
|
|
/// <summary>
|
/// 自动调整列表控件的高度
|
/// </summary>
|
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;
|
}
|
}
|
}
|
}
|