| 
					
				 | 
			
			
				@@ -1,15 +1,40 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.yingyangfly.baselib.dialog 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.content.Context 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.os.Bundle 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.text.SpannableString 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.text.Spanned 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.text.style.ForegroundColorSpan 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.view.LayoutInflater 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.view.View 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.view.ViewGroup 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import androidx.appcompat.widget.AppCompatButton 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import androidx.appcompat.widget.AppCompatEditText 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import androidx.fragment.app.DialogFragment 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gyf.immersionbar.BarHide 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gyf.immersionbar.ktx.immersionBar 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yingyangfly.baselib.R 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.ext.click 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.ext.toast 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.net.BaseObserver 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.net.BaselibServiceFactory 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.net.MyRxScheduler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.utils.RxTimer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yingyangfly.baselib.utils.ViewTool 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import io.reactivex.schedulers.Schedulers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 大屏测评绑定手机号弹窗 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class BindingPhoneDialog : DialogFragment() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var editPhone: AppCompatEditText? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var editCode: AppCompatEditText? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var btnCode: AppCompatButton? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var btnBinding: AppCompatButton? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private lateinit var rxTimer: RxTimer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var mContent: Context? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     override fun onCreate(savedInstanceState: Bundle?) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         super.onCreate(savedInstanceState) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         isCancelable = false 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -24,4 +49,146 @@ class BindingPhoneDialog : DialogFragment() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         dialog?.window?.setBackgroundDrawableResource(R.color.transparent) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    override fun onCreateView( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        inflater: LayoutInflater, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        container: ViewGroup?, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        savedInstanceState: Bundle? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ): View? { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        immersionBar { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            hideBar(BarHide.FLAG_HIDE_BAR) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            navigationBarColor(R.color.transparent) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val rootView = ViewTool.inflateFragmentPixels( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            activity, R.layout.dialog_binding_phone, container, 1194, 834 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mContent = activity 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        findId(rootView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        init() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        initListener() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return rootView 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun findId(rootView: View) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editPhone = rootView.findViewById(R.id.editPhone) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        editCode = rootView.findViewById(R.id.editCode) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnCode = rootView.findViewById(R.id.btnCode) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnBinding = rootView.findViewById(R.id.btnBinding) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun init() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rxTimer = RxTimer() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun initListener() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnCode?.click { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (mContent != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (editCode?.text.toString().trim().isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "请输入验证码".toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sendCode() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnBinding?.click { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (mContent != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (judgeByCode()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    login() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 非空验证 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun judgeByCode(): Boolean { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (editPhone?.text.toString().trim().isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "请输入手机号".toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (editCode?.text.toString().trim().isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "请输入验证码".toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 发送验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun sendCode() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BaselibServiceFactory.getService() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .sendCode(editPhone?.text.toString().trim()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .subscribeOn(Schedulers.io()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .compose(MyRxScheduler.ioMain(mContent!!, true)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .subscribe(object : BaseObserver<Any>() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                override fun onSuccess(t: Any?) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    timer() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                override fun onFail(msg: String) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    msg.toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 登录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun login() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BaselibServiceFactory.getService() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .loginMsg(editPhone?.text.toString().trim(), editCode?.text.toString().trim()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .subscribeOn(Schedulers.io()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .compose(MyRxScheduler.ioMain(mContent!!, true)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            .subscribe(object : BaseObserver<String>() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                override fun onSuccess(t: String?) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "登陆成功".toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    dismiss() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                override fun onFail(msg: String) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    msg.toast() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 开始倒计时 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun timer() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnCode?.isClickable = false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val time = 60.toLong() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val m: Long = 1000 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        btnCode?.text = setTvSendColor("重新发送(${time}s)") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rxTimer.interval(m) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (it == time - 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                rxTimer.cancel() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                btnCode?.text = "重新发送" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                btnCode?.isClickable = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                btnCode?.text = setTvSendColor("重新发送(${time - 1 - it}s)") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun setTvSendColor(str: String): SpannableString { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val startIndex = "重新发送(".length - 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val spannableString = SpannableString(str) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        spannableString.setSpan( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ForegroundColorSpan(resources.getColor(R.color.color_FF92ADFF)), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            startIndex, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Spanned.SPAN_INCLUSIVE_EXCLUSIVE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return spannableString 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    override fun dismiss() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rxTimer.cancel() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        super.dismiss() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |