优化"账户与安全"模块代码
This commit is contained in:
@ -12,6 +12,8 @@ import android.text.style.URLSpan
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorRes
|
||||
@ -801,4 +803,15 @@ fun List<String>?.checkSameFromStringArray(check2: List<String>?): Boolean {
|
||||
if (!this.contains(tag)) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* EditText弹出软键盘
|
||||
*/
|
||||
fun EditText.showKeyBoard() {
|
||||
this.postDelayed({
|
||||
this.requestFocus()
|
||||
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
inputMethodManager.showSoftInput(this, 0)
|
||||
}, 300)
|
||||
}
|
||||
@ -17,7 +17,6 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
@ -25,6 +24,7 @@ import androidx.lifecycle.ViewModelProviders;
|
||||
import com.gh.base.fragment.WaitingDialogFragment;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.ExtensionsKt;
|
||||
import com.gh.common.util.LogUtils;
|
||||
import com.gh.common.util.LoginHelper;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
@ -91,7 +91,7 @@ public class LoginFragment extends NormalFragment implements LoginUtils.onCaptch
|
||||
mLoginCaptcha.setText(arg1 + "s");
|
||||
} else {
|
||||
mLoginCaptcha.setText("重新获取");
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_font));
|
||||
mLoginCaptcha.setTextColor(ExtensionsKt.toColor(R.color.theme_font));
|
||||
// mLoginCaptcha.setBackgroundResource(R.drawable.border_black_bg);
|
||||
mLoginCaptcha.setEnabled(true);
|
||||
}
|
||||
@ -171,6 +171,7 @@ public class LoginFragment extends NormalFragment implements LoginUtils.onCaptch
|
||||
final String phoneNum = mLoginPhoneEt.getText().toString().trim().replaceAll(" ", "");
|
||||
if (PatternUtils.isPhoneNum(phoneNum) && phoneNum.length() == 11) {
|
||||
mLoginCaptcha.setEnabled(false);
|
||||
ExtensionsKt.showKeyBoard(mLoginPassEt);
|
||||
LoginUtils.getPhoneCaptcha(getContext(), phoneNum, LoginFragment.this);
|
||||
} else {
|
||||
toast("请输入正确的手机号");
|
||||
@ -236,7 +237,7 @@ public class LoginFragment extends NormalFragment implements LoginUtils.onCaptch
|
||||
message.what = 0;
|
||||
message.arg1 = 60; // 倒数时间
|
||||
mBaseHandler.sendMessage(message);
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(getContext(), R.color.hint));
|
||||
mLoginCaptcha.setTextColor(ExtensionsKt.toColor(R.color.hint));
|
||||
// mLoginCaptcha.setBackgroundResource(R.drawable.border_captcha_bg);
|
||||
mLoginCaptcha.setEnabled(false);
|
||||
} else {
|
||||
|
||||
@ -7,9 +7,7 @@ import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import butterknife.OnClick
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.gh.common.util.DisplayUtils
|
||||
import com.gh.common.util.EntranceUtils
|
||||
import com.gh.common.util.ImageUtils
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.ConflictUserEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
@ -37,8 +35,8 @@ class BindPhoneConflictFragment : NormalFragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
mConflictPhone = requireArguments().getString(EntranceUtils.KEY_CONFLICT_PHONE)
|
||||
mConflictUser = requireArguments().getParcelable(EntranceUtils.KEY_CONFLICT_USER)
|
||||
mConflictPhone = requireArguments().getString(EntranceUtils.KEY_CONFLICT_PHONE)!!
|
||||
mConflictUser = requireArguments().getParcelable(EntranceUtils.KEY_CONFLICT_USER)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -49,12 +47,12 @@ class BindPhoneConflictFragment : NormalFragment() {
|
||||
mCurrentDesc.text = "注册方式:${getRegisterType(UserManager.getInstance().loginTokenEntity.loginType)}"
|
||||
val userInfo = UserManager.getInstance().userInfoEntity
|
||||
mCurrentName.text = userInfo.name
|
||||
ImageUtils.displayIcon(mCurrentIcon, userInfo.icon)
|
||||
ImageUtils.display(mCurrentIcon, userInfo.icon)
|
||||
|
||||
mConflictUser.run {
|
||||
mConflictName.text = user?.name
|
||||
mConflictDesc.text = "注册方式:${getRegisterType(registerType)}"
|
||||
ImageUtils.displayIcon(mConflictIcon, user?.icon)
|
||||
ImageUtils.display(mConflictIcon, user?.icon)
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,13 +84,13 @@ class BindPhoneConflictFragment : NormalFragment() {
|
||||
private fun showGuide(v: View) {
|
||||
if (!::mPopupWindow.isInitialized) {
|
||||
contentView = layoutInflater.inflate(R.layout.dialog_conflict_guide, null)
|
||||
mPopupWindow = PopupWindow(contentView, DisplayUtils.dip2px(330f), ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
mPopupWindow = PopupWindow(contentView, 330f.dip2px(), ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
mPopupWindow.run {
|
||||
contentView = contentView
|
||||
isOutsideTouchable = true
|
||||
isFocusable = true
|
||||
}
|
||||
}
|
||||
mPopupWindow.showAsDropDown(v, -DisplayUtils.dip2px(170f), 0)
|
||||
mPopupWindow.showAsDropDown(v, (-170f).dip2px(), 0)
|
||||
}
|
||||
}
|
||||
@ -2,14 +2,10 @@ package com.gh.gamecenter.security
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
import android.os.Message
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Observer
|
||||
import butterknife.OnClick
|
||||
import com.gh.common.util.*
|
||||
@ -19,9 +15,8 @@ import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.normal.NormalFragment
|
||||
import com.lightgame.utils.Utils
|
||||
import kotterknife.bindView
|
||||
import kotlin.math.floor
|
||||
|
||||
class BindPhoneFragment : NormalFragment(){
|
||||
class BindPhoneFragment : NormalFragment() {
|
||||
|
||||
private val mBindPhoneTitle by bindView<TextView>(R.id.bind_phone_title)
|
||||
private val mBindPhoneDesc by bindView<TextView>(R.id.bind_phone_desc)
|
||||
@ -37,7 +32,6 @@ class BindPhoneFragment : NormalFragment(){
|
||||
private var mChangePhone = false
|
||||
|
||||
private lateinit var mViewModel: BindPhoneViewModel
|
||||
private lateinit var mCountDownTimer: CountDownTimer
|
||||
|
||||
override fun handleMessage(msg: Message) {
|
||||
if (msg.what == 0) { // 验证码倒计时
|
||||
@ -52,7 +46,7 @@ class BindPhoneFragment : NormalFragment(){
|
||||
} else {
|
||||
mBindPhoneCaptcha.run {
|
||||
text = "重新获取"
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font))
|
||||
setTextColor(R.color.theme_font.toColor())
|
||||
isEnabled = true
|
||||
}
|
||||
}
|
||||
@ -69,20 +63,6 @@ class BindPhoneFragment : NormalFragment(){
|
||||
mChangePhone = requireArguments().getBoolean(EntranceUtils.KEY_CHANGE_PHONE)
|
||||
|
||||
mViewModel = viewModelProvider()
|
||||
|
||||
mCountDownTimer = object : CountDownTimer(60 * 1000, 1000) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
mBindPhoneCaptcha.text = floor((millisUntilFinished / 1000).toDouble()).toInt().toString()
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
mBindPhoneCaptcha.run {
|
||||
text = "重新获取"
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font))
|
||||
isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -97,13 +77,13 @@ class BindPhoneFragment : NormalFragment(){
|
||||
requireContext().resources.getString(R.string.bind_phone_desc)
|
||||
}
|
||||
|
||||
mBindPhoneEt.addTextChangedListener(BindPhoneTextWatcher(mBindPhoneEt))
|
||||
mBindPhonePassEt.addTextChangedListener(BindPhoneTextWatcher(mBindPhonePassEt))
|
||||
// 设置EditText文本输入监听
|
||||
setTextChangedListener()
|
||||
|
||||
mViewModel.nextLiveData.observe(viewLifecycleOwner, Observer {
|
||||
mBindPhoneEt.isEnabled = false
|
||||
mBindPhonePasswordContainer.visibility = View.VISIBLE
|
||||
mBindPhonePassEt.requestFocus()
|
||||
mBindPhonePassEt.showKeyBoard()
|
||||
mBindPhoneBtn.run {
|
||||
alpha = 0.6f
|
||||
isEnabled = false
|
||||
@ -117,7 +97,7 @@ class BindPhoneFragment : NormalFragment(){
|
||||
message.arg1 = 60 // 倒数时间
|
||||
|
||||
mBaseHandler.sendMessage(message)
|
||||
mBindPhoneCaptcha.setTextColor(ContextCompat.getColor(requireContext(), R.color.hint))
|
||||
mBindPhoneCaptcha.setTextColor(R.color.hint.toColor())
|
||||
mBindPhoneCaptcha.isEnabled = false
|
||||
})
|
||||
|
||||
@ -140,12 +120,58 @@ class BindPhoneFragment : NormalFragment(){
|
||||
mBindPhoneErrorTv.text = "验证码错误"
|
||||
}
|
||||
})
|
||||
|
||||
mBindPhoneEt.showKeyBoard()
|
||||
}
|
||||
|
||||
private fun setTextChangedListener() {
|
||||
mBindPhoneEt.setTextChangedListener { s, _, _, _ ->
|
||||
if (s.isNotEmpty()) {
|
||||
mBindPhoneBtn.isEnabled = true
|
||||
mBindPhoneBtn.alpha = 1f
|
||||
} else {
|
||||
mBindPhoneBtn.isEnabled = false
|
||||
mBindPhoneBtn.alpha = 0.6f
|
||||
}
|
||||
|
||||
// 输入手机号码加空格
|
||||
val stringBuilder = StringBuilder()
|
||||
for (i in s.indices) {
|
||||
if (i != 3 && i != 8 && s[i] == ' ') {
|
||||
continue
|
||||
} else {
|
||||
stringBuilder.append(s[i])
|
||||
if ((stringBuilder.length == 4 || stringBuilder.length == 9)
|
||||
&& stringBuilder[stringBuilder.length - 1] != ' ') {
|
||||
stringBuilder.insert(stringBuilder.length - 1, ' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stringBuilder.toString() != s.toString()) {
|
||||
mBindPhoneEt.setText(stringBuilder.toString())
|
||||
mBindPhoneEt.setSelection(mBindPhoneEt.text.toString().length)
|
||||
}
|
||||
}
|
||||
|
||||
mBindPhonePassEt.setTextChangedListener { s, _, _, _ ->
|
||||
if (s.length > 5) {
|
||||
mBindPhoneBtn.isEnabled = true
|
||||
mBindPhoneBtn.alpha = 1f
|
||||
} else {
|
||||
mBindPhoneBtn.isEnabled = false
|
||||
mBindPhoneBtn.alpha = 0.6f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == BindPhoneActivity.RESULT_FINISH_CODE) {
|
||||
// 回到"账户与安全"界面
|
||||
requireActivity().finish()
|
||||
} else {
|
||||
// 从手机号冲突界面回到本界面,再次弹出软键盘
|
||||
mBindPhoneEt.showKeyBoard()
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,49 +226,4 @@ class BindPhoneFragment : NormalFragment(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class BindPhoneTextWatcher(private var mEditText: EditText) : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
if (mEditText == mBindPhoneEt) {
|
||||
if (s.isNotEmpty()) {
|
||||
mBindPhoneBtn.isEnabled = true
|
||||
mBindPhoneBtn.alpha = 1f
|
||||
} else {
|
||||
mBindPhoneBtn.isEnabled = false
|
||||
mBindPhoneBtn.alpha = 0.6f
|
||||
}
|
||||
|
||||
val stringBuilder = StringBuilder()
|
||||
for (i in s.indices) {
|
||||
if (i != 3 && i != 8 && s[i] == ' ') {
|
||||
continue
|
||||
} else {
|
||||
stringBuilder.append(s[i])
|
||||
if ((stringBuilder.length == 4 || stringBuilder.length == 9)
|
||||
&& stringBuilder[stringBuilder.length - 1] != ' ') {
|
||||
stringBuilder.insert(stringBuilder.length - 1, ' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stringBuilder.toString() != s.toString()) {
|
||||
mBindPhoneEt.setText(stringBuilder.toString())
|
||||
mBindPhoneEt.setSelection(mBindPhoneEt.text.toString().length)
|
||||
}
|
||||
}
|
||||
|
||||
if (mEditText === mBindPhonePassEt) {
|
||||
if (s.length > 5) {
|
||||
mBindPhoneBtn.isEnabled = true
|
||||
mBindPhoneBtn.alpha = 1f
|
||||
} else {
|
||||
mBindPhoneBtn.isEnabled = false
|
||||
mBindPhoneBtn.alpha = 0.6f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user