wxr
2022-08-02 66c72ee19b9e3543537621b8dd25685c9b5c03c4
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
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class Iot_BrandFunctionListPage :FrameLayout
    {
        FrameLayout bodyView;
 
        FrameLayout contentView;
 
 
 
        IntegratedBrand_Iot brand_Iot;
        /// <summary>
        /// 解绑回调
        /// </summary>
        public Action unboundAction;
 
        public Iot_BrandFunctionListPage(IntegratedBrand_Iot brand_Iot)
        {
            bodyView = this;
            this.brand_Iot = brand_Iot;
        }
 
        public void LoadPage()
        {
            Action action = () => {
                var page = new iot_BindTipPage();
                MainPage.BasePageView.AddChidren(page);
                page.unboundAction = () => {
                    this.RemoveFromParent();
                    unboundAction?.Invoke();
                };
                page.LoadPage(brand_Iot);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            }; 
            new TopViewDiv(bodyView, brand_Iot.brandName).LoadTopView_3tyIot(action);
 
            bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
 
 
            bodyView.AddChidren(new Button
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
 
            Button btnTipText = new Button()
            {
                Y = Application.GetRealHeight(80),
                Width = Application.GetRealWidth(347),
                Height = Application.GetRealHeight(65),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealWidth(5),
                BackgroundColor = 0x194484F4,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Padding = new Padding(12,  Application.GetRealWidth(16), 12, Application.GetRealWidth(16)),
                TextSize = CSS_FontSize.TextFontSize,
                Text = "默认将第三方品牌的设备全部关联到On Pro上,您也可以通过下方的开关按键,进行选择性关联。",
                IsMoreLines = true,
                TextAlignment = TextAlignment.CenterLeft,
            };
            bodyView.AddChidren(btnTipText);
 
            contentView = new FrameLayout()
            {
                Y = Application.GetRealHeight(150),
                Height = Application.GetRealHeight(573),
            };
            bodyView.AddChidren(contentView);
 
 
            var waitPage = new Loading();
            contentView.AddChidren(waitPage);
            waitPage.Start("");
            new System.Threading.Thread(() =>
            {
                try
                {
                    var pack = http.Get3tyIotDeviceFunctionList(brand_Iot.companyId);
                    if (pack != null)
                    {
                        if (pack.Code == StateCode.SUCCESS)
                        {
                            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>>(pack.Data.ToString());
                            Application.RunOnMainThread(() =>
                            {
                                LoadDeviceFunctionControlZone(list);
                            });
                        }
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() => {
                        waitPage.Hide();
                        waitPage.RemoveFromParent();
                    });
                }
            }) { IsBackground = true }.Start();
 
        }
 
 
        /// <summary>
        /// 加载设备功能显示区域
        /// </summary>
        void LoadDeviceFunctionControlZone(List<Function> list)
        {
            contentView.RemoveAll();
 
            if (list.Count == 0)
            {
                NotListTipView();
                return;
            }
 
            VerticalScrolViewLayout deviceFunctionView = new VerticalScrolViewLayout();
            contentView.AddChidren(deviceFunctionView);
 
            #region ContextView
            var rowView = new FrameLayout();
            try
            {
                int index = 0;
              
                foreach (var function in list)
                {
                    if(function.homeId != DB_ResidenceData.Instance.CurrentRegion.id && function.homeId != "0")
                    {
                        continue;
                    }
 
                    if (index % 2 == 0)
                    {
                        rowView = new FrameLayout()
                        {
                            Height = Application.GetRealWidth(140),
                        };
                        deviceFunctionView.AddChidren(rowView);
                    }
                    var functionView_X = Application.GetRealWidth((182 + 7) * (index % 2));
                    if (index % 2 == 0)
                    {
                        functionView_X += Application.GetRealWidth(7);
                    }
                    var functionView = new FrameLayout()
                    {
                        X = functionView_X,
                        Width = Application.GetRealWidth(182),
                        Height = Application.GetRealWidth(140),
                        Radius = (uint)Application.GetRealWidth(12),
                        Tag = function.sid
                    };
                    rowView.AddChidren(functionView);
 
                    var btnbg = new Button()
                    {
                        UnSelectedImagePath = "Collection/Functionbg.png",
                        SelectedImagePath = "Collection/FunctionOnbg.png",
                        Tag = function.sid
                    };
                    functionView.AddChidren(btnbg);
                    LoadDeviceFunctionDiv(functionView, function,btnbg);
                    index++;
 
                
                }
 
                if (index == 0)
                {
                    var view = new FrameLayout();
                    deviceFunctionView.AddChidren(view);
 
                    var btnNoCollectionTip = new Button()
                    {
                        Height = Application.GetRealHeight(42),
                        Y = Application.GetRealHeight(100),
                        TextAlignment = TextAlignment.Center,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                        Text = "没有任何设备"
                    };
                    view.AddChidren(btnNoCollectionTip);
                }
            }
            catch (Exception ex)
            {
            }
            deviceFunctionView.AddChidren(new Button { Height = Application.GetRealHeight(30) });
            #endregion
 
        }
 
 
        /// <summary>
        /// 加载功能控制卡片
        /// </summary>
        void LoadDeviceFunctionDiv(FrameLayout view, Function function,Button btnBg)
        {
            try
            {
                Button btnIcon;
                btnIcon = new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(24),
                    Width = Application.GetMinRealAverage(54),
                    Height = Application.GetMinRealAverage(54),
                };
                view.AddChidren(btnIcon);
 
                btnIcon.UnSelectedImagePath = $"FunctionIcon/Icon/HomeIcon/{function.IconName}_blue.png";
                btnIcon.SelectedImagePath = $"FunctionIcon/Icon/HomeIcon/{function.IconName}_white.png";
 
                Button btnName;
                btnName = new Button()
                {
                    Y = btnIcon.Bottom,
                    Text = function.name,
                    IsBold = true,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    SelectedTextColor = CSS_Color.MainBackgroundColor,
                    TextSize = CSS_FontSize.TextFontSize,
                    Height = Application.GetRealWidth(24),
                    TextAlignment = TextAlignment.Center,
                };
                view.AddChidren(btnName);
 
 
                Button btnClick = new Button();
                view.AddChidren(btnClick);
                btnClick.MouseUpEventHandler = (sender, e) => {
                    function.collect = !function.collect;
                    if (function.collect)
                    {
                        var pack = http.Set3tyIotFunctionToHouse(function.deviceId, DB_ResidenceData.Instance.CurrentRegion.id,brand_Iot.companyId);
                        if (pack != null)
                        {
                            if(pack.Code == StateCode.SUCCESS)
                            {
                                btnName.IsSelected = btnIcon.IsSelected = btnBg.IsSelected = true;
                            }
                        }
                    }
                    else
                    {
                        btnName.IsSelected = btnIcon.IsSelected = btnBg.IsSelected = false;
                        var pack = http.Set3tyIotFunctionToHouse(function.deviceId, "0", brand_Iot.companyId);
                        if (pack != null)
                        {
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                btnName.IsSelected = btnIcon.IsSelected = btnBg.IsSelected = false;
                            }
                        }
                    }
 
                };
 
            }
            catch (Exception ex)
            {
                MainPage.Log("homepage LoadControlView error : " + ex.Message);
            }
        }
 
 
        void NotListTipView()
        {
            contentView.RemoveAll();
            var btnTip = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(88),
                Width = Application.GetRealWidth(180),
                Height = Application.GetRealWidth(180),
                UnSelectedImagePath = "TipNot.png",
            };
            contentView.AddChidren(btnTip);
 
            var btnTipText = new Button()
            {
                Y = Application.GetRealHeight(252),
                Height = Application.GetRealHeight(52),
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextAlignment = TextAlignment.Center,
                TextID = StringId.TipNotThirdPartyDevice,
            };
            contentView.AddChidren(btnTipText);
 
            var btnAdd = new Button()
            {
                Y = Application.GetRealHeight(400),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                BackgroundColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                IsBold = true,
                Radius = (uint)Application.GetRealWidth(22),
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Text = "查看设备支持范围"
            };
            contentView.AddChidren(btnAdd);
            btnAdd.MouseUpEventHandler = (sender, e) =>
            {
                //var page = new AddThirdPartyBrandListpage(brandList);
                //MainPage.BasePageView.AddChidren(page);
                //page.LoadPage();
                //MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
 
 
 
        }
 
 
        HttpServerRequest http = new HttpServerRequest();
 
 
    }
}