黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.Suggestion
{
    /// <summary>
    /// 意见反馈的界面
    /// </summary>
    public class FeedbackForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 1:BUG、2:优化(OPTIMIZE)、3:新需求(REQUIRE)
        /// </summary>
        private string typeMode = string.Empty;
        /// <summary>
        /// 意见反馈剩余次数
        /// </summary>
        private int suggestionCount = 3;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.Suggestions));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //提交
            var btnSubmit = new BottomClickButton();
 
            var frameInput = new FrameLayout();
            frameInput.Height = Application.GetRealHeight(576);
            frameInput.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameInput);
 
            //字数
            var btnFild = new NormalViewControl(150, 60, true);
            btnFild.X = frameInput.Width - HdlControlResourse.XXLeft - Application.GetRealWidth(150);
            btnFild.Y = Application.GetRealHeight(503);
            btnFild.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnFild.TextSize = 12;
            btnFild.Text = "500";
            btnFild.TextAlignment = TextAlignment.CenterRight;
            frameInput.AddChidren(btnFild);
 
            //您的反馈和意见会让我们变得更好
            var txtInput = new EditTextView();
            txtInput.Width = bodyFrameLayout.Width - HdlControlResourse.XXLeft * 2;
            txtInput.Height = Application.GetRealHeight(470);
            txtInput.Y = Application.GetRealHeight(32);
            txtInput.TextAlignment = TextAlignment.TopLeft;
            txtInput.Gravity = Gravity.CenterHorizontal;
            txtInput.TextColor = UserCenterColor.Current.TextColor1;
            txtInput.PlaceholderTextColor = UserCenterColor.Current.TextGrayColor1;
            txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uYouSuggestionMsg);
            frameInput.AddChidren(txtInput);
            txtInput.InitIosPlaceholderUILabelWithHeight(Application.GetRealHeight(60));
            //输入值改变事件
            Action<View, string> txtInputChangedEvent = (sender, txtValue) =>
            {
                if (this.suggestionCount <= 0)
                {
                    return;
                }
 
                var newValue = txtValue;
                //如果输入的值,已经大于指定的数,则截取
                if (newValue.Length > 500)
                {
                    //截取指定的byte字节
                    newValue = newValue.Substring(0, 500);
                    txtInput.Text = newValue;
                    //将光标至于最后
#if Android
                    txtInput.SetSelectionEnd();
#endif
                }
 
                int length = newValue.Length;
                if (length == 0)
                {
                    if (btnSubmit.CanClick == true) { btnSubmit.CanClick = false; }
                }
                else
                {
                    if (btnSubmit.CanClick == false)
                    {
                        //变灰色字体
                        btnFild.TextColor = UserCenterColor.Current.TextGrayColor1;
                        btnSubmit.CanClick = true;
                    }
                }
                btnFild.Text = (500 - length).ToString();
            };
            txtInput.TextChangeEventHandler += txtInputChangedEvent;
 
            var framType = new FrameLayout();
            framType.Height = Application.GetRealHeight(150);
            framType.Y = frameInput.Bottom + Application.GetRealHeight(23);
            framType.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(framType);
 
            IconViewControl btnBugIcon = null;
            IconViewControl btnOptimizationIcon = null;
            IconViewControl btnDemandIcon = null;
 
            //反馈类型
            var btnType = new NormalViewControl(220, 60, true);
            btnType.X = HdlControlResourse.XXLeft;
            btnType.Gravity = Gravity.CenterVertical;
            btnType.TextID = R.MyInternationalizationString.uSuggestionType;
            framType.AddChidren(btnType);
            //Bug
            var frameBug = new FrameLayoutStatuControl();
            frameBug.UseClickStatu = false;
            frameBug.Width = Application.GetRealWidth(200);
            frameBug.X = Application.GetRealWidth(314);
            framType.AddChidren(frameBug);
            btnBugIcon = new IconViewControl(58);
            btnBugIcon.UnSelectedImagePath = "Item/ItemUnSelected.png";
            btnBugIcon.SelectedImagePath = "Item/ItemSelected.png";
            btnBugIcon.Gravity = Gravity.CenterVertical;
            frameBug.AddChidren(btnBugIcon);
            btnBugIcon.IsSelected = true;
            var btnBug = new NormalViewControl(140, 60, true);
            btnBug.X = btnBugIcon.Right + Application.GetRealWidth(12);
            btnBug.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnBug.Gravity = Gravity.CenterVertical;
            btnBug.Text = "Bug";
            frameBug.AddChidren(btnBug);
            frameBug.ButtonClickEvent += (sender, e) =>
            {
                if (btnBugIcon.IsSelected == false)
                {
                    btnBugIcon.IsSelected = true;
                    btnOptimizationIcon.IsSelected = false;
                    btnDemandIcon.IsSelected = false;
                    this.typeMode = "BUG";
                }
            };
            //优化
            var frameOptimization = new FrameLayoutStatuControl();
            frameOptimization.UseClickStatu = false;
            frameOptimization.Width = Application.GetRealWidth(200);
            frameOptimization.X = Application.GetRealWidth(524);
            framType.AddChidren(frameOptimization);
            btnOptimizationIcon = new IconViewControl(58);
            btnOptimizationIcon.UnSelectedImagePath = "Item/ItemUnSelected.png";
            btnOptimizationIcon.SelectedImagePath = "Item/ItemSelected.png";
            btnOptimizationIcon.Gravity = Gravity.CenterVertical;
            frameOptimization.AddChidren(btnOptimizationIcon);
            var btnOptimization = new NormalViewControl(140, 60, true);
            btnOptimization.X = btnOptimizationIcon.Right + Application.GetRealWidth(12);
            btnOptimization.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnOptimization.Gravity = Gravity.CenterVertical;
            btnOptimization.TextID = R.MyInternationalizationString.uOptimization;
            frameOptimization.AddChidren(btnOptimization);
            frameOptimization.ButtonClickEvent += (sender, e) =>
            {
                if (btnOptimizationIcon.IsSelected == false)
                {
                    btnOptimizationIcon.IsSelected = true;
 
                    btnBugIcon.IsSelected = false;
                    btnDemandIcon.IsSelected = false;
                    this.typeMode = "OPTIMIZE";
                }
            };
            //新需求
            var frameDemand = new FrameLayoutStatuControl();
            frameDemand.UseClickStatu = false;
            frameDemand.Width = Application.GetRealWidth(200);
            frameDemand.X = Application.GetRealWidth(734);
            framType.AddChidren(frameDemand);
            btnDemandIcon = new IconViewControl(58);
            btnDemandIcon.UnSelectedImagePath = "Item/ItemUnSelected.png";
            btnDemandIcon.SelectedImagePath = "Item/ItemSelected.png";
            btnDemandIcon.Gravity = Gravity.CenterVertical;
            frameDemand.AddChidren(btnDemandIcon);
            var btnDemand = new NormalViewControl(140, 60, true);
            btnDemand.X = btnDemandIcon.Right + Application.GetRealWidth(12);
            btnDemand.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnDemand.Gravity = Gravity.CenterVertical;
            btnDemand.TextID = R.MyInternationalizationString.uNewDemand;
            frameDemand.AddChidren(btnDemand);
            frameDemand.ButtonClickEvent += (sender, e) =>
            {
                if (btnDemandIcon.IsSelected == false)
                {
                    btnDemandIcon.IsSelected = true;
 
                    btnBugIcon.IsSelected = false;
                    btnOptimizationIcon.IsSelected = false;
                    this.typeMode = "REQUIRE";
                }
            };
 
            var frameEmail = new FrameLayout();
            frameEmail.Height = Application.GetRealHeight(150);
            frameEmail.BackgroundColor = UserCenterColor.Current.White;
            frameEmail.Y = framType.Bottom + Application.GetRealHeight(23);
            bodyFrameLayout.AddChidren(frameEmail);
            //联系方式
            var btnContact = new NormalViewControl(220, 60, true);
            btnContact.X = HdlControlResourse.XXLeft;
            btnContact.Gravity = Gravity.CenterVertical;
            btnContact.TextID = R.MyInternationalizationString.uContactInformation;
            frameEmail.AddChidren(btnContact);
            var txtEmail = new TextInputControl(720, 60, true);
            txtEmail.X = Application.GetRealWidth(314);
            txtEmail.Gravity = Gravity.CenterVertical;
            txtEmail.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputYourContactInformation);
            frameEmail.AddChidren(txtEmail);
 
            //提交
            btnSubmit.oldBackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            btnSubmit.TextID = R.MyInternationalizationString.uSubmit;
            bodyFrameLayout.AddChidren(btnSubmit);
            btnSubmit.CanClick = false;
            btnSubmit.ButtonClickEvent += (sender, e) =>
            {
                //如果是虚拟住宅,则此功能无效
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    return;
                }
                //上传意见
                this.UploadSuggestion(txtInput.Text, txtEmail.Text);
            };
 
            var data = HdlFileLogic.Current.ReadFileTextContent(HdlFileNameResourse.SuggestionFile);
            if (data != null)
            {
                var strNowData = DateTime.Now.ToString("yyyyMMdd");
                if (strNowData != data.Substring(1))
                {
                    this.suggestionCount = 3;
                    return;
                }
                //剩余次数
                this.suggestionCount = Convert.ToInt32(data.Substring(0, 1));
                if (this.suggestionCount <= 1)
                {
                    btnSubmit.TextID = R.MyInternationalizationString.uSubmitCountIsOverMsg;
                }
            }
        }
 
        #endregion
 
        #region ■ 上传意见___________________________
 
        /// <summary>
        /// 上传意见
        /// </summary>
        /// <param name="strContent"></param>
        /// <param name="email"></param>
        private void UploadSuggestion(string strContent, string email)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                var pra = new { contactWay = email, content = strContent, feedbackType = this.typeMode };
                var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/feedback/add", RestSharp.Method.POST, pra);
                //检测状态码
                if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
                {
                    return;
                }
                //保存次数
                this.suggestionCount--;
                //写入内容
                HdlFileLogic.Current.SaveTextToFile(HdlFileNameResourse.SuggestionFile, this.suggestionCount + DateTime.Now.ToString("yyyyMMdd"));
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //显示成功的界面
                    this.ShowSuccessMsg();
                });
            });
        }
 
        /// <summary>
        /// 显示成功的界面
        /// </summary>
        private void ShowSuccessMsg()
        {
            var frameBack = new FrameLayout();
            frameBack.BackgroundColor = 0x80000000;
            this.AddChidren(frameBack);
 
            var frameMsg = new FrameLayout();
            frameMsg.BackgroundColor = UserCenterColor.Current.White;
            frameMsg.Width = Application.GetRealWidth(622);
            frameMsg.Height = Application.GetRealHeight(317);
            frameMsg.Radius = (uint)Application.GetRealHeight(17);
            frameMsg.Gravity = Gravity.CenterHorizontal;
            frameMsg.Y = Application.GetRealHeight(792);
            frameBack.AddChidren(frameMsg);
 
            //提示
            var btnTitle = new NormalViewControl(492, 65, true);
            btnTitle.Y = Application.GetRealHeight(68);
            btnTitle.Gravity = Gravity.CenterHorizontal;
            btnTitle.TextID = R.MyInternationalizationString.NormalTip;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.TextColor = 0xFF333443;
            frameMsg.AddChidren(btnTitle);
 
            //您的反馈已成功提交
            var btnSuccess = new NormalViewControl(frameMsg.Width, Application.GetRealHeight(60), false);
            btnSuccess.Y = Application.GetRealHeight(166);
            btnSuccess.TextAlignment = TextAlignment.Center;
            btnSuccess.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnSuccess.TextID = R.MyInternationalizationString.uSubmitSuccessMsg;
            frameMsg.AddChidren(btnSuccess);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(2000);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.CloseForm();
                });
            });
        }
 
        #endregion
    }
}