From b621c50182f42a095b75fc08584240905e22d944 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 24 三月 2021 15:24:20 +0800
Subject: [PATCH] 2021-03-24 1.修改时间选择控件不调用系统的时间选择器,实现自定义时间选择器。   2.优化注册和忘记密码页面,增加倒计时和重发按钮功能

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountRegistration.cs |   85 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountRegistration.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountRegistration.cs
index 27137d9..c6686a3 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountRegistration.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountRegistration.cs
@@ -1,5 +1,6 @@
 锘縰sing System;
 using System.Text.RegularExpressions;
+using System.Threading;
 
 namespace Shared.SimpleControl.Phone
 {
@@ -157,7 +158,9 @@
         /// </summary>
         /// <param name="account">璐﹀彿 閭鎴栬�呮墜鏈哄彿</param>
         /// <param name="isPhone">鏄惁鏄墜鏈�</param>
-        void SendVerificationCode (string account, bool isPhone = true)
+        /// <param name="isResend"></param>
+        /// <param name="btnResend"></param>
+        void SendVerificationCode (string account, bool isPhone = true, bool isResend = false, Button btnResend = null)
         {
             MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load));
             System.Threading.Tasks.Task.Run (() => {
@@ -165,9 +168,14 @@
                     var requestRevertObj = HttpServerRequest.Current.VerificationCodeSend (VerifyType.REGISTER_USER, account);
                     if (requestRevertObj.Code == StateCode.SUCCESS) {
                         Application.RunOnMainThread (() => {
-                            // isPhone 鏄惁鏄墜鏈�
-                            InitSMSView (account, false);
-                            bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1;
+                            if (isResend) {
+                                //濡傛灉鏄噸鍙戠殑
+                                StartCountdown (btnResend);
+                            } else {
+                                // isPhone 鏄惁鏄墜鏈�
+                                InitSMSView (account, false);
+                                bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1;
+                            }
                         });
                     } else {
                         //鎻愮ず閿欒
@@ -328,9 +336,12 @@
             mobileChencView.AddChidren (btnTitle);
 
             EditText etCode = new EditText () {
-                Width = Application.GetRealWidth (500),
+                //Width = Application.GetRealWidth (500),
+                //Height = Application.GetRealWidth (85),
+                //Gravity = Gravity.CenterHorizontal,
+                Width = Application.GetRealWidth (390),
                 Height = Application.GetRealWidth (85),
-                Gravity = Gravity.CenterHorizontal,
+                X = Application.GetRealWidth (70),
                 Y = btnTitle.Bottom,
                 BorderWidth = 1,
                 Radius = 5,
@@ -339,6 +350,33 @@
                 TextColor = SkinStyle.Current.TextColor1
             };
             mobileChencView.AddChidren (etCode);
+
+            Button btnResend = new Button () {
+                Y = btnTitle.Bottom,
+                X = etCode.Right + Application.GetRealWidth (10),
+                Width = Application.GetRealWidth (100),
+                Height = Application.GetRealWidth (85),
+                BackgroundColor = SkinStyle.Current.MainColor,
+                SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
+                //TextID = R.MyInternationalizationString.Resend,
+                Text = "Resend",
+                TextColor = SkinStyle.Current.TextColor1,
+                Radius = 5,
+                BorderColor = SkinStyle.Current.Transparent,
+                BorderWidth = 0,
+                TextSize = 15,
+                TextAlignment = TextAlignment.Center,
+            };
+            mobileChencView.AddChidren (btnResend);
+            btnResend.MouseDownEventHandler += (sender, e) => {
+                btnResend.IsSelected = true;
+            };
+            btnResend.MouseUpEventHandler += (sender, e) => {
+                btnResend.IsSelected = false;
+                Resend (mAccount, btnResend);
+            };
+            StartCountdown (btnResend);
+
 
             Button btnConfirem = new Button () {
                 Gravity = Gravity.CenterHorizontal,
@@ -442,6 +480,41 @@
 
         }
 
+        /// <summary>
+        /// 閲嶅彂
+        /// </summary>
+        void Resend (string account, Button btnResend)
+        {
+            SendVerificationCode (account, false, true, btnResend);
+        }
 
+        /// <summary>
+        /// 寮�濮嬭鏃�
+        /// </summary>
+        /// <param name="btnResend"></param>
+        void StartCountdown (Button btnResend)
+        {
+            if (btnResend == null) return;
+
+            btnResend.Enable = false;
+            int time = 60;
+
+            //2.1鑾峰彇楠岃瘉鐮佸�掕鏃�
+            new Thread (() => {
+                while (time > 0) {
+                    time--;
+                    Application.RunOnMainThread (() => {
+                        btnResend.Text = time.ToString () + "s";
+                    });
+                    Thread.Sleep (1000);
+                }
+                Application.RunOnMainThread (() => {
+                    //鍥炲鑾峰彇鐭俊鎸夐挳浜嬩欢
+                    btnResend.Enable = true;
+                    btnResend.TextID = R.MyInternationalizationString.Resend;
+                });
+            }) { IsBackground = true }.Start ();
+        }
     }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0