using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter.UserMain
|
{
|
/// <summary>
|
/// 消息中心
|
/// </summary>
|
public class MessageManagementForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalFrameControl listView = null;
|
/// <summary>
|
/// 全部的行
|
/// </summary>
|
private Dictionary<string, RowLayoutControl> dicAllRow = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uMessageCenter));
|
|
listView = new VerticalFrameControl(35);
|
listView.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listView);
|
|
//初始化右上角菜单
|
this.InitTopRightMenu();
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//初始化中部信息
|
this.InitMiddleData();
|
});
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private async void InitMiddleData()
|
{
|
this.dicAllRow = new Dictionary<string, RowLayoutControl>();
|
|
//打开进度条
|
this.ShowProgressBar();
|
var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetPushMessageRecord", false, "");
|
if (result == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MessageRecordInfo>>(result);
|
//合并数据
|
var dicData = this.MergeMessageRecordData(dataInfo);
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMainInThread(() =>
|
{
|
//初始化中部控件
|
this.InitMiddleFrame(dicData);
|
});
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
/// <param name="dicData"></param>
|
private void InitMiddleFrame(Dictionary<string, List<MessageRecordInfo>> dicData)
|
{
|
int index = 0;
|
foreach (var keys in dicData.Keys)
|
{
|
var listData = dicData[keys];
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
index++;
|
//容器
|
var framBack = new FrameListControl(23);
|
framBack.Name = index.ToString();
|
framBack.Height = Application.GetRealHeight(100);
|
framBack.BackgroundColor = UserCenterColor.Current.White;
|
listView.AddChidrenFrame(framBack);
|
|
//日期
|
string strMonth = Language.StringByID(R.MyInternationalizationString.Month);
|
string strDate = Language.StringByID(R.MyInternationalizationString.Day);
|
var frameDate = new FrameLayout();
|
frameDate.Height = Application.GetRealHeight(118);
|
framBack.AddChidren(frameDate);
|
var btnDate = new NormalViewControl(500, 60, true);
|
btnDate.TextSize = 15;
|
btnDate.X = ControlCommonResourse.XXLeft;
|
btnDate.Y = Application.GetRealHeight(35);
|
btnDate.Text = Convert.ToDateTime(listData[0].MsgTime).ToString("MM" + strMonth + "dd" + strDate);
|
frameDate.AddChidren(btnDate);
|
|
for (int i = 0; i < listData.Count; i++)
|
{
|
//添加信息行
|
this.AddMsgRowControl(framBack, listData[i], i != listData.Count - 1);
|
}
|
//调整高度
|
listView.AdjustChidrenFrameHeight(framBack, Application.GetRealHeight(23));
|
if (index == dicData.Count)
|
{
|
listView.AdjustTableHeight();
|
}
|
});
|
}
|
}
|
|
#endregion
|
|
#region ■ 右上角菜单_________________________
|
|
/// <summary>
|
/// 初始化右上角菜单
|
/// </summary>
|
private void InitTopRightMenu()
|
{
|
var btnIcon = new MostRightIconControl(69, 69);
|
btnIcon.UnSelectedImagePath = "Item/More.png";
|
topFrameLayout.AddChidren(btnIcon);
|
btnIcon.InitControl();
|
btnIcon.ButtonClickEvent += ((sender, e) =>
|
{
|
//显示底部菜单界面
|
this.ShowBottomMenu();
|
});
|
}
|
|
/// <summary>
|
/// 显示底部菜单界面
|
/// </summary>
|
private void ShowBottomMenu()
|
{
|
var menuContr = new BottomMenuSelectForm();
|
menuContr.AddForm(2);
|
//全部已读
|
menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllRead), () =>
|
{
|
//设置全部为已读
|
this.SetAllTickIsRead();
|
});
|
//全部删除
|
menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllDelete), () =>
|
{
|
//删除全部的消息
|
this.DeleteAllMsg();
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加信息行_________________________
|
|
/// <summary>
|
/// 添加信息行
|
/// </summary>
|
/// <param name="frameList"></param>
|
/// <param name="recordInfo"></param>
|
/// <param name="addLine"></param>
|
private void AddMsgRowControl(FrameListControl frameList, MessageRecordInfo recordInfo, bool addLine)
|
{
|
var rowControl = new RowLayoutControl(frameList.rowSpace / 2);
|
frameList.AddChidren(rowControl);
|
rowControl.Name = frameList.ChildrenCount.ToString();
|
rowControl.MainKeys = recordInfo.RegId;
|
this.dicAllRow[frameList.Name + "-" + rowControl.Name] = rowControl;
|
|
//图标(现在测试)
|
var btnIcon = rowControl.frameTable.AddLeftIcon(81);
|
btnIcon.UnSelectedImagePath = "Item/Safety.png";
|
|
//消息类型
|
var btnMsgObject = rowControl.frameTable.AddLeftCaption("测试:消息类型", 600);
|
PicViewControl btnNewTip = null;
|
if (recordInfo.IsRead == 0)
|
{
|
btnNewTip = new PicViewControl(78, 55);
|
btnNewTip.UnSelectedImagePath = "Item/NewVersion.png";
|
btnNewTip.Y = Application.GetRealHeight(9) + rowControl.frameTable.chidrenYaxis;
|
btnNewTip.X = btnMsgObject.X + btnMsgObject.GetRealWidthByText(14);
|
rowControl.frameTable.AddChidren(btnNewTip, ChidrenBindMode.BindEventOnly);
|
}
|
|
//消息
|
var btnMsg = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 600, 60);
|
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnMsg.Y = Application.GetRealHeight(5) + rowControl.frameTable.chidrenYaxis;
|
rowControl.frameTable.AddChidren(btnMsg, ChidrenBindMode.BindEventOnly);
|
//时间
|
var btnTime = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 200, 50);
|
btnTime.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnTime.Y = btnMsg.Bottom + Application.GetRealHeight(12);
|
btnTime.Text = Convert.ToDateTime(recordInfo.MsgTime).ToString("HH:mm");
|
rowControl.frameTable.AddChidren(btnTime, ChidrenBindMode.BindEventOnly);
|
//底线
|
if (addLine == true)
|
{
|
rowControl.frameTable.AddBottomLine();
|
}
|
//已读
|
if (recordInfo.IsRead == 1)
|
{
|
rowControl.frameTable.UseClickStatu = false;
|
//消息类型
|
btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
|
//消息
|
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
|
}
|
//删除
|
var btnDelete = rowControl.AddDeleteControl();
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
//确认删除消息?
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteMessageMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
|
{
|
await this.DeleteMsg(recordInfo.RegId, frameList, rowControl);
|
});
|
};
|
|
//点击
|
rowControl.frameTable.ButtonClickEvent += async (sender, e) =>
|
{
|
if (recordInfo.IsRead == 1)
|
{
|
return;
|
}
|
recordInfo.IsRead = 1;
|
rowControl.frameTable.UseClickStatu = false;
|
//消息类型
|
btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
|
//消息
|
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnNewTip.RemoveFromParent();
|
if (sender != null)
|
{
|
//标记已读(不管它成功不成功)
|
await this.SetTickIsRead(recordInfo.RegId);
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 标记已读___________________________
|
|
/// <summary>
|
/// 标记已读
|
/// </summary>
|
/// <param name="strId"></param>
|
private async System.Threading.Tasks.Task<bool> SetTickIsRead(string strId)
|
{
|
var pra = new { Id = strId };
|
await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/TickIsRead", true, pra);
|
return true;
|
}
|
|
/// <summary>
|
/// 设置全部为已读
|
/// </summary>
|
private void SetAllTickIsRead()
|
{
|
if (dicAllRow.Count == 0)
|
{
|
return;
|
}
|
//确认标记全部消息为已读?
|
this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uUnTipAllMessageMsg), () =>
|
{
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
foreach (var contr in this.dicAllRow.Values)
|
{
|
//标识全部为已读
|
var result = await this.SetTickIsRead(contr.MainKeys);
|
if (result == false)
|
{
|
//关闭进度条
|
this.CloseProgressBar();
|
return;
|
}
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//设置全部状态
|
foreach (var contr in this.dicAllRow.Values)
|
{
|
contr.frameTable.ButtonClickEvent?.Invoke(null, null);
|
}
|
});
|
});
|
});
|
}
|
|
#endregion
|
|
#region ■ 删除信息___________________________
|
|
/// <summary>
|
/// 删除信息
|
/// </summary>
|
/// <param name="strId"></param>
|
/// <param name="frameList"></param>
|
/// <param name="rowContr"></param>
|
private async System.Threading.Tasks.Task<bool> DeleteMsg(string strId, FrameListControl frameList, RowLayoutControl rowContr)
|
{
|
var pra = new { Id = strId };
|
var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/DeletePushMessage", true, pra);
|
if (result == true && frameList != null)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//移除缓存
|
this.dicAllRow.Remove(frameList.Name + "-" + rowContr.Name);
|
//调整控件位置
|
this.AdjustControlLocation(frameList, rowContr);
|
});
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 删除全部的消息
|
/// </summary>
|
private void DeleteAllMsg()
|
{
|
if (dicAllRow.Count == 0)
|
{
|
return;
|
}
|
//确认删除全部消息?
|
this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteAllMessageMsg), () =>
|
{
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
foreach (var contr in this.dicAllRow.Values)
|
{
|
//删除全部消息
|
var result = await this.DeleteMsg(contr.MainKeys, null, null);
|
if (result == false)
|
{
|
//关闭进度条
|
this.CloseProgressBar();
|
return;
|
}
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
bodyFrameLayout.RemoveAll();
|
listView = new VerticalFrameControl(35);
|
listView.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listView);
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//初始化中部信息
|
this.InitMiddleData();
|
});
|
});
|
});
|
});
|
}
|
|
#endregion
|
|
#region ■ 调整控件位置_______________________
|
|
/// <summary>
|
/// 调整控件位置
|
/// </summary>
|
/// <param name="frameList"></param>
|
private void AdjustControlLocation(FrameListControl frameList, RowLayoutControl removeRow)
|
{
|
int changedHeight = frameList.GetChildren(frameList.ChildrenCount - 1).Height;
|
if (frameList.ChildrenCount <= 2)
|
{
|
//已经删完了,只剩下标题日期了
|
changedHeight = frameList.Height;
|
}
|
//先调整各自容器的Y轴坐标
|
bool canChangedLoaction = false;
|
for (int i = 0; i < this.listView.frameTable.ChildrenCount; i++)
|
{
|
var myView = this.listView.frameTable.GetChildren(i);
|
if (myView.Name == frameList.Name)
|
{
|
//它之后的控件全部往上移动
|
canChangedLoaction = true;
|
continue;
|
}
|
if (canChangedLoaction == true)
|
{
|
myView.Y -= changedHeight;
|
}
|
}
|
//调整父容器大小
|
this.listView.AdjustTableHeight();
|
|
|
if (frameList.ChildrenCount <= 2)
|
{
|
//已经删完了,只剩下标题日期了
|
frameList.RemoveFromParent();
|
}
|
else
|
{
|
//这个容器里面被移除的行的下面的全部行,往上移动
|
bool changedFlage = false;
|
for (int i = 0; i < frameList.ChildrenCount; i++)
|
{
|
var myView = frameList.GetChildren(i);
|
if (myView.Name == removeRow.Name)
|
{
|
//它之后的控件全部往上移动
|
changedFlage = true;
|
continue;
|
}
|
if (changedFlage == true)
|
{
|
myView.Y -= changedHeight;
|
}
|
}
|
//移除指定的行
|
removeRow.RemoveFromParent();
|
//容器大小减少
|
frameList.Height -= changedHeight;
|
}
|
}
|
|
#endregion
|
|
#region ■ 合并数据___________________________
|
|
/// <summary>
|
/// 合并数据
|
/// </summary>
|
/// <param name="dataInfo"></param>
|
/// <returns></returns>
|
private Dictionary<string, List<MessageRecordInfo>> MergeMessageRecordData(List<MessageRecordInfo> dataInfo)
|
{
|
var dicData = new Dictionary<string, List<MessageRecordInfo>>();
|
|
//首先先排序一下,时间大的放在前面
|
var dicTemp = new Dictionary<string, List<MessageRecordInfo>>();
|
var listSortKeys = new List<string>();
|
foreach (var data in dataInfo)
|
{
|
if (dicTemp.ContainsKey(data.MsgTime) == false)
|
{
|
dicTemp[data.MsgTime] = new List<MessageRecordInfo>();
|
listSortKeys.Add(data.MsgTime);
|
}
|
dicTemp[data.MsgTime].Add(data);
|
}
|
listSortKeys.Sort();
|
for (int i = listSortKeys.Count - 1; i >= 0; i--)
|
{
|
var listData = dicTemp[listSortKeys[i]];
|
foreach (var data2 in listData)
|
{
|
string[] myArry = data2.MsgTime.Split(new string[] { "T" }, StringSplitOptions.RemoveEmptyEntries);
|
if (myArry.Length != 2)
|
{
|
continue;
|
}
|
if (dicData.ContainsKey(myArry[0]) == false)
|
{
|
dicData[myArry[0]] = new List<MessageRecordInfo>();
|
}
|
dicData[myArry[0]].Add(data2);
|
}
|
}
|
return dicData;
|
}
|
|
#endregion
|
|
#region ■ 结构体_____________________________
|
|
/// <summary>
|
/// 信息结果
|
/// </summary>
|
private class MessageRecordInfo
|
{
|
/// <summary>
|
/// 主键
|
/// </summary>
|
public string RegId = string.Empty;
|
/// <summary>
|
/// 消息内容
|
/// </summary>
|
public string MsgContent = string.Empty;
|
/// <summary>
|
/// MsgType
|
/// </summary>
|
public string MsgType = string.Empty;
|
/// <summary>
|
/// 是否已读
|
/// </summary>
|
public int IsRead = 0;
|
/// <summary>
|
/// 时间 2019-09-10 13:11:55
|
/// </summary>
|
public string MsgTime = string.Empty;
|
}
|
|
#endregion
|
}
|
}
|