HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-11-13 8b9ce384b26c414db32f98e94e088f5334869c2d
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.UserCenter.Device;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    /// <summary>
    /// 门锁管理
    /// </summary>
    public class UserManagement : DoorLockCommonLayout, ZigBee.Common.IStatus
    {
        /// <summary>
        /// 按键模式接收
        /// </summary>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
            Shared.Application.RunOnMainThread(() =>
            {
            });
        }
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public UserManagement(ZigBee.Device.DoorLock doorLock)
        {
            this.doorLock = doorLock;
        }
 
        #region ◆ 变量申明__________________________
        ZigBee.Device.DoorLock doorLock;
        VerticalScrolViewLayout midVerticalScrolViewLayout;
        #endregion
 
        void ReadAccountList()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
                try
                {
                    var localAccountListTemp = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.LocalAccountList();
                    if (localAccountListTemp != null)
                    {
                        doorLock.localAllAccountList.Clear();
                        doorLock.localAllAccountList = localAccountListTemp;
                        foreach (var sub in localAccountListTemp)
                        {
                            //初始化权限信息
                            if (doorLock.IsFreezeAccount.ContainsKey(sub.SubAccountDistributedMark) == false)
                            {
                                doorLock.IsFreezeAccount.Add(sub.SubAccountDistributedMark, false);
                            }
                            if (doorLock.HasRemoteUnlockAccess.ContainsKey(sub.SubAccountDistributedMark) == false)
                            {
                                doorLock.HasRemoteUnlockAccess.Add(sub.SubAccountDistributedMark, false);
                            }
                            if (doorLock.IsFailedToGetDoorLockInfo.ContainsKey(sub.SubAccountDistributedMark) == false)
                            {
                                doorLock.IsFailedToGetDoorLockInfo.Add(sub.SubAccountDistributedMark, false);
                            }
                        }
                        doorLock.ReSave();
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(this.btnTip);
                        });
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        MidFrameLayoutContent();
                        CommonPage.Loading.Hide();
                    });
                }
            });
        }
 
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.UserManagement));
 
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
 
            var btnAddFrameLayout = new FrameLayout
            {
                X = Application.GetRealWidth(829 - 116),
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(190),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
 
            var btnUndistributeIcon = new Button
            {
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(69),
                UnSelectedImagePath = "DoorLock/UndistributeIcon.png",
            };
            btnAddFrameLayout.AddChidren(btnUndistributeIcon);
 
            var btnUndistributeText = new Button
            {
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(121),
                TextID = R.MyInternationalizationString.Undistributed,
                TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                X = btnUndistributeIcon.Right,
                TextAlignment = TextAlignment.CenterLeft,
            };
            btnAddFrameLayout.AddChidren(btnUndistributeText);
            if (UserCenterResourse.UserInfo.AuthorityNo != 1)
            {
                btnUndistributeIcon.Width = 0;
                btnUndistributeText.Width = 0;
            }
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                var undistributeDoorlockUserPage = new Shared.Phone.UserCenter.DoorLock.UndistributeDoorlockUserPage(doorLock, doorLock.localAllAccountList);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(undistributeDoorlockUserPage);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                undistributeDoorlockUserPage.Show();
            };
            btnAddFrameLayout.MouseDownEventHandler += eHandler;
            btnUndistributeText.MouseDownEventHandler += eHandler;
            btnUndistributeIcon.MouseDownEventHandler += eHandler;
            midVerticalScrolViewLayout = new VerticalScrolViewLayout()
            {
            };
            this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
            ReadAccountList();
        }
 
        async void MidFrameLayoutContent()
        {
            midVerticalScrolViewLayout.RemoveAll();
            for (int i = 0; i < doorLock.localAllAccountList.Count; i++)
            {
                var currentAccount = doorLock.localAllAccountList[i];
                var RowView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(161),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMTopFrameLayout,
                };
                midVerticalScrolViewLayout.AddChidren(RowView);
 
                var btnText = new Button()
                {
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                    Gravity = Gravity.CenterVertical,
                    TextSize = 14,
                };
                RowView.AddChidren(btnText);
 
                var btnRightFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(110),
                    Width = Application.GetRealWidth(110),
                    X = Application.CurrentWidth - Application.GetRealWidth(150),
                    Y = Application.GetRealHeight(25),
                };
                RowView.AddChidren(btnRightFrameLayout);
 
                var btnRight = new Button()
                {
                    Height = Application.GetRealHeight(58),
                    Width = Application.GetRealWidth(58),
                    UnSelectedImagePath = "DoorLock/RightIcon.png",
                    Gravity = Gravity.Center,
                };
                btnRightFrameLayout.AddChidren(btnRight);
 
                var line2 = new Button()
                {
                    Y = RowView.Height - 1,
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(965),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                RowView.AddChidren(line2);
                int currentIndex = i;
                if (currentIndex == doorLock.localAllAccountList.Count - 1)
                {
                    line2.Visible = false;
                }
 
                if (currentAccount.UserName != null)
                {
                    btnText.Text = currentAccount.UserName;
                }
                else
                {
                    btnText.Text = currentAccount.Account;
                }
 
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    if (currentIndex == 0)
                    {
                        var masterManagementPage = new Shared.Phone.UserCenter.DoorLock.MasterManagementPage(doorLock, currentAccount);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(masterManagementPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        masterManagementPage.Show();
                    }
                    else
                    {
                        var memberFrozenPage = new Shared.Phone.UserCenter.DoorLock.MemberFrozenPage(doorLock, currentAccount);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(memberFrozenPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        memberFrozenPage.Show();
                    }
                };
                btnRight.MouseUpEventHandler += eHandler;
                RowView.MouseUpEventHandler += eHandler;
                btnText.MouseUpEventHandler += eHandler;
            }
        }
 
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
 
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
 
        public void ChangedISceneStatus(Scene scene)
        {
        }
    }
}