wxr
2024-01-03 300a5d5370d10d97eb5dfdfa43bb0156c15d23e3
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
using System;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI.UI2.Classification
{
    /// <summary>
    /// 跑马灯页面
    /// 序列页面
    /// </summary>
    public class SeriesFunctionListPage : FrameLayout
    {
        FrameLayout bodyView;
        public SeriesFunctionListPage()
        {
            bodyView = this;
        }
 
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.HorseRaceLamp)).LoadTopView();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
 
            var functionListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(603 - 12),
            };
            bodyView.AddChidren(functionListView);
 
            var waitPage = new Loading();
            bodyView.AddChidren(waitPage);
            waitPage.Hide();
 
            Dictionary<string, List<Button>> dicGroupButtons = new Dictionary<string, List<Button>>();
 
            List<string> oidList = new List<string>();
           
            foreach(var rgb in FunctionList.List.GetLightList())
            {
                //if(rgb.spk == SPK.LightRGB)
                {
                    var oid = rgb.sid.Substring(0, 16);
                    if (oidList.Contains(oid))
                    {
                        continue;
                    }
                    var seriesList = FunctionList.List.GetSeries().FindAll((obj) => obj.sid.StartsWith(oid));
                    if (seriesList.Count == 0)
                    {
                        continue;
                    }
                    oidList.Add(oid);
                    var list = new List<Function>();
                    List<Button> groupButtons = new List<Button>();
                    list.AddRange(seriesList);
                    var groupView = new VerticalScrolViewLayout()
                    {
                        Height = Application.GetRealHeight(44 + 51 * list.Count),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                        ScrollEnabled = false,
                    };
                    functionListView.AddChidren(groupView);
 
                    #region title
                    var titleView = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(44),
                    };
                    groupView.AddChidren(titleView);
 
                    var btnTitle = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.MainColor,
                        Text =Language.StringByID( StringId.HorseRaceLampGroup )+ " "+ oidList.Count.ToString(),
                    };
                    titleView.AddChidren(btnTitle);
 
                    #endregion
 
                    foreach (var series in list)
                    {
                        groupView.AddChidren(new Button
                        {
                            Height = 1,
                            BackgroundColor = CSS_Color.DividingLineColor,
                        });
 
                        var rgbColorfulView = new FrameLayout()
                        {
                            Height = Application.GetRealHeight(50),
                        };
                        groupView.AddChidren(rgbColorfulView);
 
                        var btnRgbColorfulTitle = new Button()
                        {
                            X = Application.GetRealWidth(16),
                            TextAlignment = TextAlignment.CenterLeft,
                            TextSize = CSS_FontSize.TextFontSize,
                            TextColor = CSS_Color.FirstLevelTitleColor,
                            Text = series.name == rgb.name ? Language.StringByID(StringId.AutomaticColoring) : series.name,
                        };
                        rgbColorfulView.AddChidren(btnRgbColorfulTitle);
 
                        var btnColorfulSwitch = new Button()
                        {
                            X = Application.GetRealWidth(320),
                            Gravity = Gravity.CenterVertical,
                            Width = Application.GetMinRealAverage(48),
                            Height = Application.GetMinRealAverage(36),
                            UnSelectedImagePath = "Public/Switch.png",
                            SelectedImagePath = "Public/SwitchOn.png",
                            Tag = series.sid,
                        };
                        rgbColorfulView.AddChidren(btnColorfulSwitch);
 
                        groupButtons.Add(btnColorfulSwitch);
 
                        btnColorfulSwitch.MouseUpEventHandler = (sener, e) => {
                            btnColorfulSwitch.IsSelected = !btnColorfulSwitch.IsSelected;
                            var state = btnColorfulSwitch.IsSelected ? "on" : "off";
                            waitPage.Start("");
                            new System.Threading.Thread(() =>
                            {
                                try
                                {
                                    var d = new Dictionary<string, string>();
                                    d.Add("on_off", state);
                                    DriverLayer.Control.Ins.SendWriteCommand(series, d);
                                    if (state == "on")
                                    {
                                        Application.RunOnMainThread(() =>
                                        {
                                            List<Button> updataList = new List<Button>();
                                            dicGroupButtons.TryGetValue(((Button)sener).Tag.ToString().Substring(0, 16), out updataList);
                                            foreach (var updataTemp in updataList)
                                            {
                                                updataTemp.IsSelected = false;
                                            }
                                            btnColorfulSwitch.IsSelected = true;
                                        });
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MainPage.Log($"序列控制异常:{ex.Message}");
                                }
                                finally
                                {
                                    Application.RunOnMainThread(() => {
                                        waitPage.Hide();
                                    });
                                }
                            })
                            { IsBackground = true }.Start();
                        };
 
 
                    }
                    Console.WriteLine("oid: " + oid);
                    dicGroupButtons.TryAdd(oid, groupButtons);
 
                    functionListView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(8),
                        BackgroundColor = CSS_Color.DividingLineColor,
                    });
 
                }
            }
 
        }
 
 
    }
}