JLChen
2020-06-05 f86c8b5dcf5c84386745b009fc4115fa9db3b76d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Net;
using Shared.SimpleControl;
 
namespace Shared
{
    [System.Serializable]
    public class RemoteInfo
    {
        static RemoteInfo ()
        {
            Current = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoteInfo> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile ("RemoteInfoMsgList")));
            if (Current == null)
                Current = new RemoteInfo ();
        }
 
 
        /// <summary>
        /// 从服务器读取相应数目的数据
        /// </summary>
        public void ReadMsgList (bool needTip)
        {
            if (MainPage.LoginUser == null)
                return;
#if HDL
            new System.Threading.Thread (() => {
                try {
 
                    string jsonString = "{" +
                                      "\"RegID\":" + "\"" + UserConfig.Instance.tokenID + "\"" + "," +
                                           "}";
                    var revertObj = MainPage.RequestHttps (@"GetMsgList", jsonString, true);
 
                    if (revertObj.StateCode == "SUCCESS") {
                        var msgList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RemoteInfoMsg>> (revertObj.ResponseData.ToString ());
                        ////清楚角标 2020-06-05 高胜说云端已自动清空,不需要调用
                        //new WebClient().DownloadData ($"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/CornerClear");
 
                        if (msgList == null || msgList.Count == 0)
                            return;
                        if (msgList.Count == Current.RemoteInfoList.Count && msgList [msgList.Count - 1].MsgTime == Current.RemoteInfoList [Current.RemoteInfoList.Count - 1].MsgTime)
                            return;
                        Current.RemoteInfoList.Clear ();
                        foreach (var msg in msgList) {
                            Current.RemoteInfoList.Add (new RemoteInfoMsg () { Msg = msg.Msg, MsgID = msg.MsgID, MsgTime = msg.MsgTime, MsgType = msg.MsgType });
                        }
                        Current.Save ();
                        if (msgList.Count > 0) {
                            Application.RunOnMainThread (() => {
                                string tipMsg = Language.StringByID (SimpleControl.R.MyInternationalizationString.NewMessageReceived);
 
                                if (needTip) {
                                    Alert alert = new Alert (Language.StringByID (SimpleControl.R.MyInternationalizationString.Tip),
                                                             tipMsg,
                                                             Language.StringByID (SimpleControl.R.MyInternationalizationString.Close),
                                                             Language.StringByID (SimpleControl.R.MyInternationalizationString.Read));
                                    alert.Show ();
                                    alert.ResultEventHandler += (sender, e) => {
                                        if (e) {
                                            if (Shared.Application.IsPad) {
                                                //SimpleControl.Pad.WarningList.ShowWarningListPage ();
                                            } else {
                                                SimpleControl.Phone.UserMiddle.ShowSettingView ();
                                                var msgView = new SimpleControl.Phone.WarningList ();
                                                SimpleControl.Phone.UserMiddle.SettingPageView.AddChidren (msgView);
                                                msgView.ShowWarningListPage ();
                                                SimpleControl.Phone.UserMiddle.SettingPageView.PageIndex = 1;
                                            }
                                        }
                                    };
                                } else {
                                    if (Shared.Application.IsPad) {
                                        //SimpleControl.Pad.WarningList.ShowWarningListPage ();
                                    } else {
                                        SimpleControl.Phone.UserMiddle.ShowSettingView ();
                                        var msgView = new SimpleControl.Phone.WarningList ();
                                        SimpleControl.Phone.UserMiddle.SettingPageView.AddChidren (msgView);
                                        msgView.ShowWarningListPage ();
                                        SimpleControl.Phone.UserMiddle.SettingPageView.PageIndex = 1;
                                    }
                                }
                            });
                        }
                    }
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                    if (MainPage.LoginUser.AccountString == "750183166@qq.com") {
                        Application.RunOnMainThread (() => {
                            var ss = new Alert ("", ex.Message, "Close");
                            ss.Show ();
                        });
                    }
                } finally {
                    //Application.RunOnMainThread (() => {
                    //    MainPage.Loading.Hide ();
                    //});
                }
            }) { IsBackground = true}.Start();
#endif
        }
 
        public static RemoteInfo Current {
            get;
            private set;
        }
 
        public List<RemoteInfoMsg> RemoteInfoList = new List<RemoteInfoMsg> ();
 
 
        public void Del (RemoteInfoMsg msg)
        {
            RemoteInfoList.Remove (msg);
            Save ();
        }
 
        public void CleanAll ()
        {
            Current.RemoteInfoList.Clear ();
            Save ();
        }
 
        public void Save ()
        {
            var saveBytes = CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (Current));
            IO.FileUtils.WriteFileByBytes ("RemoteInfoMsgList", saveBytes);
        }
    }
 
    [System.Serializable]
    public class RemoteInfoMsg
    {
        public long MsgID;
 
        public string Msg;
 
        public string MsgType;
 
        public DateTime MsgTime;
 
    }
}