黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
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
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 设备功能卡片的底层界面
    /// </summary>
    public class DeviceFunctionCardCommonForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 当前回路对象
        /// </summary>
        public Function device = null;
        /// <summary>
        /// 右上角配置结束的事件
        /// </summary>
        public Action SettionFinishEvent = null;
        /// <summary>
        /// 左右整个翻页的控件
        /// </summary>
        private PageLayout pageLayout = null;
        /// <summary>
        /// 设备名字控件(刷新用到)
        /// </summary>
        public NormalViewControl btnDeviceName = null;
        /// <summary>
        /// 房间名字控件(刷新用到)
        /// </summary>
        public NormalViewControl btnRoomName = null;
        /// <summary>
        /// 底部快捷按钮1
        /// </summary>
        private NormalViewControl btnBottomOne = null;
        /// <summary>
        /// 底部快捷按钮2
        /// </summary>
        private NormalViewControl btnBottomTwo = null;
        /// <summary>
        /// 第一索引的白色区域的桌布控件
        /// </summary>
        public NormalFrameLayout FrameWhiteCentet1 = null;
        /// <summary>
        /// 第二索引的白色区域的桌布控件(请先调用AddSecondPage函数完成添加)
        /// </summary>
        public NormalFrameLayout FrameWhiteCentet2 = null;
 
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_device">设备对象</param>
        /// <param name="btnHigherCollection">上一级界面的收藏控件(原来on的框架太坑)</param>
        /// <param name="btnHigherDeviceName">上一级界面的设备名字控件(原来on的框架太坑)</param>
        /// <param name="btnHigherRoom">上一级界面的房间名字控件(原来on的框架太坑)</param>
        public void ShowForm(Function i_device, Button btnHigherCollection, Button btnHigherDeviceName, Button btnHigherRoom)
        {
            this.device = i_device;
 
            //添加头部【设置】图标
            this.AddTopSettingIcon(btnHigherDeviceName, btnHigherRoom);
 
            //初始化中部信息
            this.InitMiddleFrame(btnHigherCollection);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        /// <param name="btnHigherCollection">上一级界面的收藏控件</param>
        private void InitMiddleFrame(Button btnHigherCollection)
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //左右整个翻页的控件
            this.pageLayout = new PageLayout();
            pageLayout.IsShowPoint = false;
            pageLayout.ScrollEnabled = false;
            bodyFrameLayout.AddChidren(pageLayout);
            pageLayout.PageChange += (sender, index) =>
            {
                //设置底部两个按钮的状态
                this.SetBottomTwoButtonStatu();
            };
 
            //初始化第一个索引的桌布
            this.InitFrameWhiteContent1(btnHigherCollection);
            //初始化白色内容(需要自主实现)
            this.InitFrameWhiteContent();
        }
 
        /// <summary>
        /// 初始化第一个索引的桌布
        /// </summary>
        /// <param name="btnHigherCollection">上一级界面的收藏控件</param>
        private void InitFrameWhiteContent1(Button btnHigherCollection)
        {
            //第一个索引桌布是必定存在的
            var frameTable1 = new FrameLayout();
            frameTable1.Width = pageLayout.Width;
            frameTable1.Height = pageLayout.Height;
            pageLayout.AddChidren(frameTable1);
            //第一个索引的白色桌布
            this.FrameWhiteCentet1 = new NormalFrameLayout();
            FrameWhiteCentet1.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.Y = Application.GetRealHeight(22);
            FrameWhiteCentet1.Width = Application.GetRealWidth(327);
            FrameWhiteCentet1.Height = Application.GetRealHeight(526);
            FrameWhiteCentet1.BackgroundImagePath = "Public/Fragmentbg.png";
            frameTable1.AddChidren(FrameWhiteCentet1);
            //设备名字
            this.btnDeviceName = new NormalViewControl(270, 37, true);
            btnDeviceName.X = Application.GetRealWidth(16);
            btnDeviceName.Y = Application.GetRealHeight(18);
            btnDeviceName.TextColor = CSS_Color.FirstLevelTitleColor;
            btnDeviceName.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel;
            btnDeviceName.Text = device.name;
            btnDeviceName.Width = btnDeviceName.GetRealWidthByText();
            FrameWhiteCentet1.AddChidren(btnDeviceName);
            //房间名字
            this.btnRoomName = new NormalViewControl(270, 21, true);
            btnRoomName.X = Application.GetRealWidth(16);
            btnRoomName.Y = btnDeviceName.Bottom;
            btnRoomName.TextColor = CSS_Color.PromptingColor1;
            btnRoomName.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnRoomName.Text = device.GetRoomListName();
            btnRoomName.Width = btnRoomName.GetRealWidthByText();
            FrameWhiteCentet1.AddChidren(btnRoomName);
            //成员没有收藏功能
            if (DB_ResidenceData.Instance.CurrentRegion.IsOthreShare == false)
            {
                var btnCollection = new IconViewControl(40);
                btnCollection.X = Application.GetRealWidth(273);
                btnCollection.Y = Application.GetRealHeight(16);
                btnCollection.SelectedImagePath = "Collection/CollectionIcon.png";
                btnCollection.UnSelectedImagePath = "Collection/CollectionGrayIcon.png";
                btnCollection.IsSelected = device.collect;
                FrameWhiteCentet1.AddChidren(btnCollection);
                btnCollection.ButtonClickEvent += (sender, e) =>
                {
                    btnCollection.IsSelected = !btnCollection.IsSelected;
                    device.collect = btnCollection.IsSelected;
                    btnHigherCollection.IsSelected = device.collect;
 
                    device.CollectFunction();
                };
            }
        }
 
        /// <summary>
        /// 初始化第二个索引的桌布
        /// </summary>
        private void InitFrameWhiteContent2()
        {
            this.pageLayout.ScrollEnabled = true;
            //第一个索引桌布是必定存在的
            var frameTable2 = new FrameLayout();
            frameTable2.Width = pageLayout.Width;
            frameTable2.Height = pageLayout.Height;
            pageLayout.AddChidren(frameTable2);
            //第一个索引的白色桌布
            this.FrameWhiteCentet2 = new NormalFrameLayout();
            FrameWhiteCentet2.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet2.Y = Application.GetRealHeight(22);
            FrameWhiteCentet2.Width = Application.GetRealWidth(327);
            FrameWhiteCentet2.Height = Application.GetRealHeight(526);
            FrameWhiteCentet2.BackgroundImagePath = "Public/Fragmentbg.png";
            frameTable2.AddChidren(FrameWhiteCentet2);
        }
 
        /// <summary>
        /// 初始化白色内容(需要自主实现)
        /// </summary>
        public virtual void InitFrameWhiteContent()
        {
        }
 
        #endregion
 
        #region ■ 添加第二索引页_____________________
 
        /// <summary>
        /// 添加第二索引页
        /// </summary>
        public void AddSecondPage()
        {
            //初始化第二个索引的桌布
            this.InitFrameWhiteContent2();
 
            //底部添加两个按钮
            this.btnBottomOne = new NormalViewControl(14, 6, true);
            btnBottomOne.X = Application.GetRealWidth(170);
            btnBottomOne.Y = FrameWhiteCentet1.Bottom + Application.GetRealHeight(30);
            btnBottomOne.BackgroundColor = CSS_Color.MainColor;
            btnBottomOne.Radius = (uint)Application.GetRealHeight(6) / 2;
            bodyFrameLayout.AddChidren(btnBottomOne);
            btnBottomOne.ButtonClickEvent += (sender, e) =>
            {
                this.pageLayout.PageIndex = 0;
                //设置底部两个按钮的状态
                this.SetBottomTwoButtonStatu();
            };
            this.btnBottomTwo = new NormalViewControl(14, 6, true);
            btnBottomTwo.X = btnBottomOne.Right + Application.GetRealWidth(8);
            btnBottomTwo.Y = btnBottomOne.Y;
            btnBottomTwo.BackgroundColor = 0xffadc7f7;
            btnBottomTwo.Radius = (uint)Application.GetRealHeight(6) / 2;
            bodyFrameLayout.AddChidren(btnBottomTwo);
            btnBottomTwo.ButtonClickEvent += (sender, e) =>
            {
                this.pageLayout.PageIndex = 1;
                //设置底部两个按钮的状态
                this.SetBottomTwoButtonStatu();
            };
        }
 
        /// <summary>
        /// 设置底部两个按钮的状态
        /// </summary>
        private void SetBottomTwoButtonStatu()
        {
            if (this.btnBottomTwo == null) { return; }
 
            if (this.pageLayout.PageIndex == 1)
            {
                this.btnBottomOne.BackgroundColor = 0xffadc7f7;
                this.btnBottomTwo.BackgroundColor = CSS_Color.MainColor;
            }
            else
            {
                this.btnBottomOne.BackgroundColor = CSS_Color.MainColor;
                this.btnBottomTwo.BackgroundColor = 0xffadc7f7;
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 添加头部【设置】的图标
        /// </summary>
        /// <param name="btnHigherCollection">上一级界面的收藏控件(原来on的框架太坑)</param>
        /// <param name="btnHigherDeviceName">上一级界面的设备名字控件(原来on的框架太坑)</param>
        private void AddTopSettingIcon(Button btnHigherDeviceName, Button btnHigherRoom)
        {
            //如果是成员没有功能
            if (DB_ResidenceData.Instance.CurrentRegion.IsOthreShare == true)
            {
                return;
            }
            //设置图标
            var btnSetting = new PicViewControl(28, 28);
            btnSetting.X = Application.GetRealWidth(337);
            btnSetting.Y = Application.GetRealHeight(9);
            btnSetting.UnSelectedImagePath = "Public/FuncInfoSetIcon.png";
            topFrameLayout.AddChidren(btnSetting);
 
            btnSetting.ButtonClickEvent += (sender, e) =>
            {
                var infoView = new UI.FunctionBaseInfoSetPage(this.device, () =>
                {
                    //刷新显示
                    btnHigherDeviceName.Text = this.device.name;
                    btnHigherRoom.Text = this.device.GetRoomListName();
 
                    //从新计算宽度
                    this.btnDeviceName.Text = btnHigherDeviceName.Text;
                    this.btnDeviceName.Width = this.btnDeviceName.GetRealWidthByText();
 
                    this.btnRoomName.Text = btnHigherRoom.Text;
                    this.btnRoomName.Width = this.btnRoomName.GetRealWidthByText();
 
                    //回调事件
                    this.SettionFinishEvent?.Invoke();
                });
                MainPage.BasePageView.AddChidren(infoView);
                infoView.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
        }
 
        #endregion
    }
}