HDL Home App 第二版本 旧平台金堂用 正在使用
wjc
2022-12-01 351bdda734832d821a9764b0cde8be5d83c4ec50
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Shared.Common;
using Shared.Phone.SmartSound.Forms;
using Shared.Phone.UserCenter.Device;
using Shared.Phone.UserCenter.SmartSound.Util;
using Shared.Phone.UserCenter.SmartSound.Widget;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.SmartSound
{
    //智能音箱列表界面
    public class SmartSoundListForm : EditorCommonForm
    {
        public SmartSoundListForm()
        {
        }
 
        private SmartSoundInfo smartSoundInfo = null;
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListRefreshControl listView = null;
        /// <summary>
        /// 前一次显示出左滑菜单的RowLayout
        /// </summary>
        private RowLayoutControl oldShowRightMuneRow = null;
 
        private static string dataString = "";
        private MostRightIconControl btnAddDeviceIcon = null;
 
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
 
            this.ScrollEnabled = false;
 
            //设置标题信息
            base.SetTitleText("智能音箱");
            Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//楼层列表
 
            //右上添加按钮
            if (btnAddDeviceIcon == null)
            {
                btnAddDeviceIcon = new MostRightIconControl(69, 69);
                btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
                topFrameLayout.AddChidren(btnAddDeviceIcon);
                btnAddDeviceIcon.InitControl();
                btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
                {
                    var helpForm = new AddSmartSound();
                    helpForm.AddForm();
                };
            }
 
            //var helpBtn = new MyButton();
            //helpBtn.TextColor = UserCenterColor.Current.TextOrangeColor;
            //helpBtn.Text = "帮助";
            //helpBtn.Gravity = Gravity.CenterRight;
            //helpBtn.TextAlignment = TextAlignment.CenterRight;
            //topFrameLayout.AddChidren(helpBtn);
            //helpBtn.X -= Application.GetRealWidth(58);
 
            //初始化中部控件
            this.InitMiddleFrame();
 
            //helpBtn.MouseUpEventHandler += (sernder, e) =>
            //{
            //    var helpForm = new AddSmartSound();
            //    helpForm.AddForm();
            //    /*
            //    //生成一个弹窗画面
            //    var dialogForm = new TextDialog("绑定智能音箱到第三方 APP 进行操作", "跳转至小度APP");
            //    dialogForm.SetTitleText("帮助");
 
            //    //按下确认按钮
            //    dialogForm.ComfirmClickEvent += () =>
            //    {
            //        //画面关闭
            //        dialogForm.CloseDialog();
            //        OpenXiaoDuAPP();
            //    };*/
            //};
        }
 
        /// <summary>
        /// 初始化中部控件(外部可以调用)
        /// </summary>
        /// <param name="i_reGetDeviceOnlineStatu">重新获取设备的在线状态</param>
        public void InitMiddleFrame()
        {
            this.ClearBodyFrame();
           
            var frame = new FrameLayout();
            this.bodyFrameLayout.AddChidren(frame);
            frame.BackgroundColor = UserCenterColor.Current.White;
            frame.Y = 0;
            frame.Height = this.bodyFrameLayout.Height;
 
            // 初始化 lisetView
            listView = new VerticalListRefreshControl(29);
            listView.Y = 0;
            listView.Height = bodyFrameLayout.Height;
            frame.AddChidren(listView);
            listView.BeginHeaderRefreshingAction += () =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //隐藏下拉刷新特效
                        listView.EndHeaderRefreshing();
                        this.InitMiddleFrame();
                    });
                });
            };
 
            HdlThreadLogic.Current.RunThread(async () =>
            {
                this.ShowProgressBar();
                await getData();
 
                HdlThreadLogic.Current.RunMainInThread(() =>
                {
                    iniView();
 
                    if (smartSoundInfo == null || smartSoundInfo.ResponseData == null || smartSoundInfo.ResponseData.RowCount == 0)
                    {
                        // show出没有设备的图标文字提示
                        this.ShowNotDataImage(bodyFrameLayout, new string[] { "还没有音箱哦,", "绑定智能音箱请前往第三方 APP 进行操作" });
                    }
 
                    this.CloseProgressBar();
                });                
            });           
        }
       
        /// <summary>
        /// 获取音箱列表
        /// </summary>
        /// <returns></returns>
        private async Task getData()
        {
            string url = string.Format("https://developer.hdlcontrol.com/zigbeespeakerservice/Auth?Platform&PageSetting.PageSize=100&PageSetting.PageIndex=1&UserID={0}&HomeID={1}",
                Common.Config.Instance.Guid,Common.Config.Instance.Home.Id);
            
            dataString = await MyHttpWebResponse.GetWebRequest(url);            
            smartSoundInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<SmartSoundInfo>(dataString);            
        }
 
        /// <summary>
        /// 设置备注
        /// </summary>
        /// <param name="soundInfo"></param>
        /// <param name="new_remark"></param>
        /// <returns></returns>
        private async Task<string> setRemark(SmartSoundInfo.SoundInfo soundInfo, string new_remark)
        {            
            if (soundInfo == null)
                return "";
 
            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/Auth";
            string json = "{" +
                "\"AuthID\":" + "\"" + soundInfo.Id + "\"" + "," +
                "\"Remark\":" + "\"" + new_remark + "\"" + "," +
                "\"UserID\":" + "\"" + soundInfo.UserID + "\"" + "," +
                "\"HomeID\":" + "\"" + soundInfo.HomeID + "\"" + "}";
 
            string response_str = MyHttpWebResponse.PutWebRequest(url, json, Encoding.UTF8);
            JObject jObject = JObject.Parse(response_str);
            
            return jObject["StateCode"].ToString();
        }
 
        private void iniView()
        {
            //
            listView.RemoveAll();
 
            if (smartSoundInfo == null|| smartSoundInfo.ResponseData==null|| smartSoundInfo.ResponseData.Data==null)
                return;
 
            for (int i = 0; i < smartSoundInfo.ResponseData.Data.Count; i++)
            {
                try
                {
                    //
                    var smartSound = smartSoundInfo.ResponseData.Data[i];
                    var row = new SoundRowLayout();
                    listView.AddChidren(row);
 
                    if (smartSound.PlatfromName == "Baidu")
                    {
                        string remark = "小度";
                        if (smartSound.Remark != null && smartSound.Remark.Trim() != "")
                            remark += "(" + smartSound.Remark + ")";
 
                        row.ImagePath = "SmartSound/Xiaodu.png";
                        row.Remark = remark;
                    }else if (smartSound.PlatfromName == "AISpeech")
                    {
                        string remark = "思必驰";
                        if (smartSound.Remark != null && smartSound.Remark.Trim() != "")
                            remark += "(" + smartSound.Remark + ")";
 
                        row.ImagePath = "SmartSound/Sibici.png";
                        row.Remark = remark;
                    }
 
                    row.InitControl();
                    row.btnDelect.AddTag("index", i);
                    row.btnRename.AddTag("index", i);
                    row.frameTable.AddTag("index", i);
 
                    //重命名
                    row.btnRename.ButtonClickEvent += (sender, e) =>
                    {
                        int index = (int)((NormalViewControl)sender).GetTagByKey("index");
                        var smartSound1 = smartSoundInfo.ResponseData.Data[index];
                        ShowRenameDialog(row, smartSound1);
                    };
 
                    // 解除绑定
                    row.btnDelect.ButtonClickEvent += (sender, e) =>
                    {
                        int index = (int)(((NormalViewControl)sender).GetTagByKey("index"));
                        var smartSound1 = smartSoundInfo.ResponseData.Data[index];
                        ShowDelectDialog(smartSound1);
                    };
 
                    //跳转到控制内容界面  FrameRowControl
                    row.frameTable.ButtonClickEvent += (sender, e) =>
                    {
                        int index = (int)row.frameTable.GetTagByKey("index");
                        if (SmartSound.getInstantiate().LayerList != null)
                            SmartSound.getInstantiate().LayerList.Clear();
 
                        var smartSoundControlForm = new SmartSoundControlForm(smartSoundInfo.ResponseData.Data[index]);
                        smartSoundControlForm.AddForm();
                    };
                }
                catch (Exception e)
                {
                    this.ShowMassage(ShowMsgType.Tip, e.Message);
                }
            }
        }
 
        private void OpenXiaoDuAPP()
        {
            bool bol = false;
            try
            {
#if Android
                bol = HDLUtils.OpenAppWithPackageName("com.baidu.duer.superapp");
#else                
                bol=HDLUtils.OpenApp("xiaoduapp://");
#endif
 
                if (!bol)
                {
#if Android
                    HDLUtils.OpenUrl("market://details?id=com.baidu.duer.superapp");
#else
                HDLUtils.OpenUrl("https://apps.apple.com/cn/app/%E5%B0%8F%E5%BA%A6/id1437733193");
#endif
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
                bol = false;
            }
        }
 
        /// <summary>
        /// 思必驰
        /// </summary>
        private void OpenSBCAPP()
        {
            bool bol = false;
            try
            {
#if Android
                bol = HDLUtils.OpenAppWithPackageName("com.aispeech.companionapp");
#else                
                bol=HDLUtils.OpenApp("AispeechMobile://");
#endif
 
                if (!bol)
                {
#if Android
                    HDLUtils.OpenUrl("market://details?id=com.aispeech.companionapp");
#else
                HDLUtils.OpenUrl("https://apps.apple.com/cn/app/id1460767442");
#endif
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
                bol = false;
            }
        }
 
        /// <summary>
        /// 解除绑定弹窗
        /// </summary>
        private void ShowDelectDialog(SmartSoundInfo.SoundInfo smartSound)
        {
            //生成一个弹窗画面
            var dialogForm = new TextDialog("解除绑定需要到第三方 APP 进行操作", "跳转至第三方APP");
            dialogForm.SetTitleText("解除绑定");
 
            //按下确认按钮
            dialogForm.ComfirmClickEvent += () =>
            {
                if (smartSound.PlatfromName == "Baidu")
                {
                    OpenXiaoDuAPP();
                }
                else if (smartSound.PlatfromName == "AISpeech") {
                    OpenSBCAPP();
                }                
            };
        }
        /// <summary>
        /// 重命名弹窗
        /// </summary>
        /// <returns></returns>
        private void ShowRenameDialog(SoundRowLayout soundRowLayout, SmartSoundInfo.SoundInfo smartSound)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            //添加备份
            dialogForm.SetTitleText("重命名");
            //请输入备份名称
            dialogForm.SetTipText("请输入名称");
            dialogForm.Text = smartSound.Remark;
 
            //按下确认按钮
            dialogForm.ComfirmClickEvent += (async (textValue) =>
            {
                //画面关闭
                dialogForm.CloseDialog();
 
                string remark = textValue;
                string str = await setRemark(smartSound, remark); //上传备份
                if (str == "SUCCESS")
                {
                    smartSound.Remark = remark;
                    if (smartSound.PlatfromName == "Baidu")
                    {
                        soundRowLayout.btnRemark.Text = "小度" + "(" + textValue + ")";
                    }
                    else if (smartSound.PlatfromName == "AISpeech")
                    {
                        soundRowLayout.btnRemark.Text = "思必驰" + "(" + textValue + ")";
                    }
                    else 
                    {
                        soundRowLayout.btnRemark.Text =  textValue;
                    }
                    
                }
                else
                {
                    //错误弹窗提示
                    ShowMassage(ShowMsgType.Tip, "修改备注不成功!", null, "确认");
                }
            });
        }
 
        #endregion
 
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="soundInfo"></param>
        /// <returns></returns>
        private string DelectSmartSound(SmartSoundInfo.SoundInfo soundInfo)
        {
            if (soundInfo == null)
                return "";
 
            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/Auth";
            string json = "{" +
                "\"AuthID\":" + "\"" + soundInfo.Id + "\"" + "," +
                "\"UserID\":" + "\"" + soundInfo.UserID + "\"" + "," +
                "\"HomeID\":" + "\"" + soundInfo.HomeID + "\"" + "}";
 
            string response_str = MyHttpWebResponse.DeleteWebRequest(url, json, Encoding.UTF8);
            JObject jObject = JObject.Parse(response_str);
 
            return jObject["StateCode"].ToString();
        }
 
#region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            return 1;
        }
 
#endregion
 
#region ■ 关闭界面___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
        }
 
#endregion
                
    }
}