黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
using System;
using System.Collections.Generic;
using Shared.Common;
using System.Text;
using Shared.Phone.UserCenter;
 
namespace Shared.Phone.UserView
{
    /// <summary>
    /// User page.
    /// </summary>
    public class UserPage : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 当前选择的菜单
        /// </summary>
        private MenuSelectEnum nowSelectMenu = MenuSelectEnum.A未选择;
        /// <summary>
        /// 用户界面
        /// </summary>
        private static UserPage userMenuPage = null;
        /// <summary>
        /// 用户界面
        /// </summary>
        /// <value>The instance.</value>
        public static UserPage Instance
        {
            get
            {
                if (userMenuPage == null)
                {
                    userMenuPage = new UserPage { };
                }
                return userMenuPage;
            }
        }
 
        /// <summary>
        /// 用户主体界面(中间部分)
        /// </summary>
        private NormalFrameLayout bodyFrameView = null;
        /// <summary>
        /// 界面缓存(2020.05.07:切换时不移除界面,直接隐藏)
        /// </summary>
        private List<EditorCommonForm> listForm = new List<EditorCommonForm>() { null, null, null };
        /// <summary>
        /// 控件缓存(看不懂的话,不要动它)
        /// </summary>
        private List<ButtonBase> listButton = new List<ButtonBase>();
        /// <summary>
        /// 如果设置此变量为true,则在单击底部菜单时,强制无条件全部刷新
        /// </summary>
        public bool RefreshAllForm = false;
        /// <summary>
        /// 刷新主页
        /// </summary>
        public bool RefreshMainPageForm = false;
        /// <summary>
        /// 刷新分类
        /// </summary>
        public bool RefreshCategoryForm = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化
        /// </summary>
        public UserPage()
        {
            BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor;
            //添加App的经纬度上报事件
            HdlOtherFunctionLogic.Current.AddAppLatAndLonEvent();
        }
 
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitPage()
        {
            if (this.ChildrenCount > 0)
            {
                return;
            }
#if iOS
            if (Shared.Application.IsFullScreen == true)
            {
                //高版本的苹果机型,屏幕底部会有一个黑色的杠
                ControlCommonResourse.BottomFrameHeight = Application.GetRealHeight(180);
            }
#endif
            //用户主体界面(中间部分)
            this.bodyFrameView = new NormalFrameLayout();
            bodyFrameView.Height = this.Height - HdlControlResourse.BottomFrameHeight;
            bodyFrameView.BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor;
            this.AddChidren(bodyFrameView);
 
            //用户菜单界面(底部部分)
            var bottomMenuFrame = new FrameLayout();
            bottomMenuFrame.Gravity = Gravity.BottomCenter;
            bottomMenuFrame.Height = HdlControlResourse.BottomFrameHeight;
            bottomMenuFrame.BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBottomColor;
            this.AddChidren(bottomMenuFrame);
            //底部菜单的头部线
            var bottomLine = new NormalViewControl(bottomMenuFrame.Width, HdlControlResourse.BottomLineHeight, false);
            bottomLine.BackgroundColor = 0xffc8c8c9;
            bottomMenuFrame.AddChidren(bottomLine);
 
            //主页容器
            var frameHomePage = new FrameLayout();
            frameHomePage.Width = bottomMenuFrame.Width / 3;
            frameHomePage.Height = bottomMenuFrame.Height;
            bottomMenuFrame.AddChidren(frameHomePage);
            //主页图标
            var btnHomeIcon = new PicViewControl(138, 98);
            btnHomeIcon.Y = Application.GetRealHeight(3);
            btnHomeIcon.UnSelectedImagePath = "Navigation/Home.png";
            btnHomeIcon.SelectedImagePath = "Navigation/HomeSelected.png";
            btnHomeIcon.Gravity = Gravity.CenterHorizontal;
            frameHomePage.AddChidren(btnHomeIcon);
            this.listButton.Add(btnHomeIcon);
            btnHomeIcon.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A主页, true);
            };
            //主页
            var btnHomeName = new NormalViewControl(btnHomeIcon.Width, Application.GetRealHeight(40), false);
            btnHomeName.Y = btnHomeIcon.Bottom;
            btnHomeName.TextID = R.MyInternationalizationString.HomePage;
            btnHomeName.TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor;
            btnHomeName.SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2;
            btnHomeName.TextSize = 10;
            btnHomeName.Gravity = Gravity.CenterHorizontal;
            btnHomeName.TextAlignment = TextAlignment.Center;
            frameHomePage.AddChidren(btnHomeName);
            this.listButton.Add(btnHomeName);
            btnHomeName.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A主页, true);
            };
 
            //分类容器
            var frameCategory = new FrameLayout();
            frameCategory.X = frameHomePage.Right;
            frameCategory.Width = bottomMenuFrame.Width / 3;
            frameCategory.Height = bottomMenuFrame.Height;
            bottomMenuFrame.AddChidren(frameCategory);
            //分类图标
            var btnCategoryIcon = new PicViewControl(138, 98);
            btnCategoryIcon.Y = Application.GetRealHeight(3);
            btnCategoryIcon.UnSelectedImagePath = "Navigation/Category.png";
            btnCategoryIcon.SelectedImagePath = "Navigation/CategorySelected.png";
            btnCategoryIcon.Gravity = Gravity.CenterHorizontal;
            frameCategory.AddChidren(btnCategoryIcon);
            this.listButton.Add(btnCategoryIcon);
            btnCategoryIcon.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A分类, true);
            };
            //分类
            var btnCategoryName = new NormalViewControl(btnCategoryIcon.Width, Application.GetRealHeight(40), false);
            btnCategoryName.Y = btnCategoryIcon.Bottom;
            btnCategoryName.TextID = R.MyInternationalizationString.Category;
            btnCategoryName.TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor;
            btnCategoryName.SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2;
            btnCategoryName.TextSize = 10;
            btnCategoryName.Gravity = Gravity.CenterHorizontal;
            btnCategoryName.TextAlignment = TextAlignment.Center;
            frameCategory.AddChidren(btnCategoryName);
            this.listButton.Add(btnCategoryName);
            btnCategoryName.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A分类, true);
            };
 
 
            //我的容器
            var frameSetting = new FrameLayout();
            frameSetting.X = frameCategory.Right;
            frameSetting.Width = bottomMenuFrame.Width / 3;
            frameSetting.Height = bottomMenuFrame.Height;
            bottomMenuFrame.AddChidren(frameSetting);
            //我的图标
            var btnSettingIcon = new PicViewControl(138, 98);
            btnSettingIcon.Y = Application.GetRealHeight(3);
            btnSettingIcon.UnSelectedImagePath = "Navigation/Setting.png";
            btnSettingIcon.SelectedImagePath = "Navigation/SettingSelected.png";
            btnSettingIcon.Gravity = Gravity.CenterHorizontal;
            frameSetting.AddChidren(btnSettingIcon);
            this.listButton.Add(btnSettingIcon);
            btnSettingIcon.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A个人中心, true);
            };
            //我的
            var btnSettingName = new NormalViewControl(btnCategoryIcon.Width, Application.GetRealHeight(40), false);
            btnSettingName.Y = btnSettingIcon.Bottom;
            btnSettingName.TextID = R.MyInternationalizationString.Me;
            btnSettingName.TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor;
            btnSettingName.SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2;
            btnSettingName.TextSize = 10;
            btnSettingName.Gravity = Gravity.CenterHorizontal;
            btnSettingName.TextAlignment = TextAlignment.Center;
            frameSetting.AddChidren(btnSettingName);
            this.listButton.Add(btnSettingName);
            btnSettingName.ButtonClickEvent += (sender, e) =>
            {
                this.BottomMenuClickEvent(MenuSelectEnum.A个人中心, true);
            };
        }
 
        /// <summary>
        /// 刷新控件
        /// </summary>
        public void ReFreshControl()
        {
            //这里做全刷新处理
            this.listForm = new List<EditorCommonForm>() { null, null, null };
            this.bodyFrameView.RemoveAll();
 
            this.BottomMenuClickEvent(MenuSelectEnum.A主页, false);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 底部菜单的点击事件
        /// </summary>
        /// <param name="selectEnum">菜单选择枚举</param>
        /// <param name="handClick">是否是手动点击</param>
        private void BottomMenuClickEvent(MenuSelectEnum selectEnum, bool handClick)
        {
            if (this.RefreshAllForm == false && selectEnum == this.nowSelectMenu && handClick == true)
            {
                //手动点击同一个菜单,则不做处理
                return;
            }
 
            //如果强制指定刷新界面的话
            if (this.RefreshAllForm == true)
            {
                //全部刷新
                this.listForm = new List<EditorCommonForm>() { null, null, null };
                this.bodyFrameView.RemoveAll();
 
                this.RefreshAllForm = false;
            }
 
            this.nowSelectMenu = selectEnum;
 
            //主页
            if (selectEnum == MenuSelectEnum.A主页)
            {
                //左滑菜单可
                CommonPage.Instance.IsDrawerLockMode = false;
                if (this.RefreshMainPageForm == true)
                {
                    //刷新主页
                    listForm[0]?.CloseForm();
                    listForm[0] = null;
                    this.RefreshMainPageForm = false;
                }
                if (listForm[0] == null)
                {
                    var form = new MainPage.HomeMainPageForm();
                    this.bodyFrameView.AddChidren(form);
                    form.ShowForm();
                    //加缓存
                    listForm[0] = form;
                }
            }
            else if (selectEnum == MenuSelectEnum.A分类)
            {
                //左滑菜单不可
                CommonPage.Instance.IsDrawerLockMode = true;
                if (this.RefreshCategoryForm == true)
                {
                    //刷新分类
                    listForm[1]?.CloseForm();
                    listForm[1] = null;
                    this.RefreshCategoryForm = false;
                }
                if (listForm[1] == null)
                {
                    var form = new Category.CategoryMainForm();
                    this.bodyFrameView.AddChidren(form);
                    form.ShowForm();
                    //加缓存
                    listForm[1] = form;
                }
            }
            else if (selectEnum == MenuSelectEnum.A个人中心)
            {
                //左滑菜单不可
                CommonPage.Instance.IsDrawerLockMode = true;
                if (listForm[2] == null)
                {
                    var form = new UserCenter.UserMain.UserMainForm();
                    this.bodyFrameView.AddChidren(form);
                    form.ShowForm();
                    //加缓存
                    listForm[2] = form;
                }
            }
            //设置全部控件的各种状态状态
            this.SetAllControlStatu();
        }
 
        /// <summary>
        /// 设置全部控件的各种状态状态
        /// </summary>
        private void SetAllControlStatu()
        {
            int index = (int)this.nowSelectMenu - 1;
            for (int i = 0; i < listForm.Count; i++)
            {
                if (i == index)
                {
                    //当前选择的菜单的话,则全部可视
                    listForm[i].Visible = true;
                    //控件图片和颜色变更
                    this.listButton[i * 2].IsSelected = true;
                    this.listButton[i * 2 + 1].IsSelected = true;
                }
                else
                {
                    //不是当前选择的菜单的话,全部不可视
                    if (listForm[i] != null)
                    {
                        listForm[i].Visible = false;
                    }
                    //控件图片和颜色变更
                    this.listButton[i * 2].IsSelected = false;
                    this.listButton[i * 2 + 1].IsSelected = false;
                }
            }
        }
 
        /// <summary>
        /// 强制显示自动化列表界面
        /// </summary>
        public void ShowCategoryAutoListForm()
        {
            //关闭全部界面,直到主页为止
            HdlFormLogic.Current.CloseAllOpenForm(null, false);
            //强制显示自动化列表界面
            HdlUserCenterResourse.ResidenceOption.CategoryPageSwitchIndex = 2;
 
            this.nowSelectMenu = MenuSelectEnum.A分类;
 
            //左滑菜单不可
            CommonPage.Instance.IsDrawerLockMode = true;
            if (listForm[1] == null)
            {
                var form = new Category.CategoryMainForm();
                this.bodyFrameView.AddChidren(form);
                form.ShowForm();
                //加缓存
                listForm[1] = form;
            }
            else
            {
                ((Category.CategoryMainForm)listForm[1]).RefreshBodyView();
            }
            //设置全部控件的各种状态状态
            this.SetAllControlStatu();
        }
 
        /// <summary>
        /// 获取当前激活的界面
        /// </summary>
        /// <returns></returns>
        public EditorCommonForm GetNowActionForm()
        {
            int index = ((int)this.nowSelectMenu) - 1;
            if (index != -1)
            {
                //调用此界面的激活函数
                return this.listForm[index];
            }
            return null;
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 菜单选择的枚举
        /// </summary>
        private enum MenuSelectEnum
        {
            A未选择 = 0,
            A主页 = 1,
            A分类 = 2,
            A个人中心 = 3
        }
 
        #endregion
    }
}