|
@@ -3,16 +3,30 @@ package cn.yyxx.eyuangame.core.impl.center.fragment
|
|
|
import android.content.Context
|
|
|
import android.graphics.Color
|
|
|
import android.os.Bundle
|
|
|
+import android.os.Handler
|
|
|
+import android.os.Looper
|
|
|
+import android.os.Message
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import android.widget.*
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import androidx.fragment.app.Fragment
|
|
|
+import cn.yyxx.eyuangame.base.utils.Logger
|
|
|
import cn.yyxx.eyuangame.core.entity.ClickType
|
|
|
+import cn.yyxx.eyuangame.core.entity.ResultInfo
|
|
|
+import cn.yyxx.eyuangame.core.entity.SdkBackLoginInfo
|
|
|
import cn.yyxx.eyuangame.core.impl.center.MemberActivity
|
|
|
+import cn.yyxx.eyuangame.core.internal.IRequestCallback
|
|
|
+import cn.yyxx.eyuangame.core.network.SdkRequest
|
|
|
import cn.yyxx.eyuangame.core.ui.EventEditText
|
|
|
+import cn.yyxx.eyuangame.core.utils.EditTextUtils
|
|
|
+import cn.yyxx.eyuangame.core.utils.TimeDownUtils
|
|
|
import cn.yyxx.support.ResUtils
|
|
|
+import cn.yyxx.support.hawkeye.ToastUtils
|
|
|
+import org.json.JSONObject
|
|
|
|
|
|
/**
|
|
|
* @author #Suyghur.
|
|
@@ -23,14 +37,18 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
private lateinit var mView: View
|
|
|
private lateinit var memberImpl: MemberActivity
|
|
|
|
|
|
+ private lateinit var llGroup1: LinearLayout
|
|
|
+ private lateinit var llGroup2: LinearLayout
|
|
|
+ private lateinit var clTips: ConstraintLayout
|
|
|
+
|
|
|
private lateinit var ivReturn: ImageView
|
|
|
private lateinit var eetPhone: EventEditText
|
|
|
private lateinit var eetCaptcha: EventEditText
|
|
|
private lateinit var btnCaptCha: Button
|
|
|
private lateinit var btnConfirm: Button
|
|
|
-
|
|
|
private lateinit var tvArea: TextView
|
|
|
private lateinit var ivArrow: ImageView
|
|
|
+ private lateinit var tvBindTips: TextView
|
|
|
|
|
|
private lateinit var rlAreaList: RelativeLayout
|
|
|
private lateinit var llAreaList: LinearLayout
|
|
@@ -43,6 +61,14 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
|
|
|
private var code = ""
|
|
|
|
|
|
+ private val handler = object : Handler(Looper.getMainLooper()) {
|
|
|
+ override fun handleMessage(msg: Message) {
|
|
|
+ if (msg.what == 101) {
|
|
|
+ changeTimeView(msg.obj as Int)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
super.onCreateView(inflater, container, savedInstanceState)
|
|
|
memberImpl = requireActivity() as MemberActivity
|
|
@@ -62,6 +88,10 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
setOnClickListener(this@BindPhoneFragment)
|
|
|
}
|
|
|
|
|
|
+ llGroup1 = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_ll_group1", "id"))
|
|
|
+ llGroup2 = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_ll_group2", "id"))
|
|
|
+ clTips = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_cl_tips", "id"))
|
|
|
+
|
|
|
eetPhone = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_eet_phone", "id"))
|
|
|
eetPhone.editText.hint = ResUtils.getResString(requireActivity(), "yyxx_hint_forget_phone")
|
|
|
|
|
@@ -80,19 +110,22 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
setOnClickListener(this@BindPhoneFragment)
|
|
|
}
|
|
|
|
|
|
- rlAreaList = view.findViewById(ResUtils.getResId(context, "yyxx_rl_area_list", "id"))
|
|
|
+ rlAreaList = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_rl_area_list", "id"))
|
|
|
rlAreaList.visibility = View.GONE
|
|
|
- llAreaList = view.findViewById(ResUtils.getResId(context, "yyxx_ll_area_list", "id"))
|
|
|
- svAreaList = view.findViewById(ResUtils.getResId(context, "yyxx_sv_area_list", "id"))
|
|
|
+ llAreaList = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_ll_area_list", "id"))
|
|
|
+ svAreaList = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_sv_area_list", "id"))
|
|
|
|
|
|
|
|
|
- tvArea = view.findViewById(ResUtils.getResId(context, "yyxx_tv_area", "id"))
|
|
|
- ivArrow = view.findViewById(ResUtils.getResId(context, "yyxx_iv_arrow", "id"))
|
|
|
+ tvArea = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_tv_area", "id"))
|
|
|
+ ivArrow = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_iv_arrow", "id"))
|
|
|
ivArrow.setOnClickListener {
|
|
|
changeAreaList()
|
|
|
}
|
|
|
|
|
|
autoFillAreaList(requireActivity())
|
|
|
+
|
|
|
+ tvBindTips = view.findViewById(ResUtils.getResId(requireActivity(), "yyxx_tv_tips2", "id"))
|
|
|
+ tvBindTips.text = "${ResUtils.getResString(requireActivity(), "yyxx_iv_bind_phone_tips2")}135xxxx0963"
|
|
|
}
|
|
|
|
|
|
private fun autoFillAreaList(context: Context) {
|
|
@@ -148,7 +181,6 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
val tvAreaCode = findViewById<TextView>(ResUtils.getResId(context, "yyxx_tv_area", "id"))
|
|
|
tvAreaCode.gravity = Gravity.CENTER
|
|
|
tvAreaCode.text = areaCode
|
|
|
- code = areaCode
|
|
|
setOnClickListener(OnItemClick(areaCode))
|
|
|
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height)
|
|
|
llAreaList.addView(this, llAreaList.childCount)
|
|
@@ -169,6 +201,129 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun callGetCaptcha() {
|
|
|
+ val areaCode = code
|
|
|
+ Logger.d("$areaCode ...")
|
|
|
+ val phoneNum = eetPhone.editText.text.trim().toString()
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(areaCode)) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), ResUtils.getResString(requireActivity(), "yyxx_tips_area_code_format_error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!EditTextUtils.filterPwd(phoneNum)) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), ResUtils.getResString(requireActivity(), "yyxx_tips_phone_format_error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ with(JSONObject()) {
|
|
|
+ put("sms_type", "bind_phone")
|
|
|
+ put("area_code", areaCode)
|
|
|
+ put("phone_number", phoneNum)
|
|
|
+ SdkRequest.instance.getCaptcha(requireActivity(), this, object : IRequestCallback {
|
|
|
+ override fun onResponse(resultInfo: ResultInfo) {
|
|
|
+ if (resultInfo.code == 1) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), resultInfo.msg)
|
|
|
+ changeTimeNum()
|
|
|
+ } else {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), resultInfo.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun callBindPhone() {
|
|
|
+ val phoneNum = eetPhone.editText.text.trim().toString()
|
|
|
+ val captcha = eetCaptcha.editText.text.trim().toString()
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(captcha)) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), ResUtils.getResString(requireActivity(), "yyxx_tips_captcha_format_error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!EditTextUtils.filterPhone(phoneNum)) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), ResUtils.getResString(requireActivity(), "yyxx_tips_phone_format_error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ with(JSONObject()) {
|
|
|
+ put("uid", SdkBackLoginInfo.instance.userId)
|
|
|
+ put("phone_number", phoneNum)
|
|
|
+ put("sms_code", captcha)
|
|
|
+ SdkRequest.instance.bindPhone(requireActivity(), this, object : IRequestCallback {
|
|
|
+ override fun onResponse(resultInfo: ResultInfo) {
|
|
|
+ if (resultInfo.code == 1) {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), resultInfo.msg)
|
|
|
+ requireActivity().onBackPressed()
|
|
|
+ } else {
|
|
|
+ ToastUtils.toastInfo(requireActivity(), resultInfo.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun changeTimeView(time: Int) {
|
|
|
+ btnCaptCha.apply {
|
|
|
+ text = if (time <= 0) {
|
|
|
+ this.isEnabled = true
|
|
|
+ ResUtils.getResString(requireActivity(), "yyxx_tv_get_captcha")
|
|
|
+ } else {
|
|
|
+ this.isEnabled = false
|
|
|
+ "${time}s"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun changeTimeNum() {
|
|
|
+ if (!TimeDownUtils.isRunning()) {
|
|
|
+ TimeDownUtils.start(60, object : TimeDownUtils.TimeCallback {
|
|
|
+ override fun onTime(time: Int) {
|
|
|
+ val msg = Message.obtain()
|
|
|
+ msg.what = 101
|
|
|
+ msg.obj = time
|
|
|
+ handler.sendMessage(msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ TimeDownUtils.resetCallback(object : TimeDownUtils.TimeCallback {
|
|
|
+ override fun onTime(time: Int) {
|
|
|
+ val msg = Message.obtain()
|
|
|
+ msg.what = 101
|
|
|
+ msg.obj = time
|
|
|
+ handler.sendMessage(msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showOrHideTips() {
|
|
|
+ if (TextUtils.isEmpty(SdkBackLoginInfo.instance.phoneNum)) {
|
|
|
+ llGroup1.visibility = View.VISIBLE
|
|
|
+ llGroup2.visibility = View.VISIBLE
|
|
|
+ clTips.visibility = View.GONE
|
|
|
+ btnConfirm.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ llGroup1.visibility = View.GONE
|
|
|
+ llGroup2.visibility = View.GONE
|
|
|
+ clTips.visibility = View.VISIBLE
|
|
|
+ btnConfirm.visibility = View.GONE
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onResume() {
|
|
|
+ super.onResume()
|
|
|
+ showOrHideTips()
|
|
|
+ }
|
|
|
+
|
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
|
areaList.clear()
|
|
@@ -179,6 +334,8 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
v?.apply {
|
|
|
when (tag as Int) {
|
|
|
ClickType.ACTION_RETURN -> requireActivity().onBackPressed()
|
|
|
+ ClickType.ACTION_GET_CAPTCHA -> callGetCaptcha()
|
|
|
+ ClickType.ACTION_CONFIRM -> callBindPhone()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -191,6 +348,7 @@ class BindPhoneFragment : Fragment(), View.OnClickListener {
|
|
|
tvArea.apply {
|
|
|
changeAreaList()
|
|
|
tvArea.text = areaCode
|
|
|
+ this@BindPhoneFragment.code = areaCode
|
|
|
}
|
|
|
}
|
|
|
}
|