|
@@ -2,18 +2,14 @@ package com.yingyang.login.ui.login
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.content.Intent
|
|
|
-import android.graphics.Typeface
|
|
|
import android.os.Build
|
|
|
-import android.text.InputType
|
|
|
import android.text.SpannableString
|
|
|
import android.text.Spanned
|
|
|
import android.text.style.ForegroundColorSpan
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
-import android.widget.TextView
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
-import com.google.android.material.tabs.TabLayout
|
|
|
import com.yingyang.login.R
|
|
|
import com.yingyang.login.databinding.ActivityLoginBinding
|
|
|
import com.yingyang.login.service.InitService
|
|
@@ -30,36 +26,15 @@ import com.yingyangfly.baselib.utils.User
|
|
|
*/
|
|
|
@Route(path = RouterUrlCommon.login)
|
|
|
class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
- View.OnTouchListener, TabLayout.OnTabSelectedListener {
|
|
|
+ View.OnTouchListener {
|
|
|
|
|
|
- private var tabTitles = mutableListOf("账号登录", "手机号登录")
|
|
|
+ private var tabTitles = mutableListOf("手机号登录")
|
|
|
private var loginType = 0
|
|
|
private lateinit var rxTimer: RxTimer
|
|
|
|
|
|
override fun initViews() {
|
|
|
rxTimer = RxTimer()
|
|
|
- initTabLayout()
|
|
|
- }
|
|
|
|
|
|
- @SuppressLint("InflateParams")
|
|
|
- private fun initTabLayout() {
|
|
|
- for (position in tabTitles.indices) {
|
|
|
- val doc = tabTitles[position]
|
|
|
- val view = layoutInflater.inflate(R.layout.layout_tab_view, null)
|
|
|
- val tab = binding.tabTitle.newTab()
|
|
|
- view as TextView
|
|
|
- if (position == 0) {
|
|
|
- view.text = doc
|
|
|
- } else {
|
|
|
- view.text = doc
|
|
|
- }
|
|
|
- if (position == 0) {
|
|
|
- view.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
|
|
|
- }
|
|
|
- tab.customView = view
|
|
|
- hideToolTipText(tab)
|
|
|
- binding.tabTitle.addTab(tab)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
@@ -67,26 +42,9 @@ class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
binding {
|
|
|
login.setOnTouchListener(this@LoginActivity)
|
|
|
tvCode.setOnTouchListener(this@LoginActivity)
|
|
|
- tabTitle.addOnTabSelectedListener(this@LoginActivity)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 非空验证
|
|
|
- */
|
|
|
- private fun judgeByAccount(): Boolean {
|
|
|
- if (binding.username.text.toString().trim().isEmpty()) {
|
|
|
- "请输入用户名".toast()
|
|
|
- return false
|
|
|
- }
|
|
|
- if (binding.username.text.toString().trim().isEmpty()) {
|
|
|
- "请输入密码".toast()
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 非空验证
|
|
|
*/
|
|
@@ -137,34 +95,11 @@ class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 用户登录
|
|
|
- */
|
|
|
- private fun loginByAccount() {
|
|
|
- viewModel.login(
|
|
|
- binding.username.text.toString().trim(),
|
|
|
- binding.password.text.toString().trim(),
|
|
|
- fail = {
|
|
|
- it.toast()
|
|
|
- },
|
|
|
- success = {
|
|
|
- if (it != null) {
|
|
|
- User.savePhone(binding.username.text.toString().trim())
|
|
|
- User.savePassword(binding.password.text.toString().trim())
|
|
|
- User.saveToken(it)
|
|
|
- getUserInfo()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
if (User.getPhone().isEmpty().not()) {
|
|
|
binding.username.setText(User.getPhone())
|
|
|
}
|
|
|
- if (User.getPassword().isEmpty().not()) {
|
|
|
- binding.password.setText(User.getPassword())
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -212,14 +147,8 @@ class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
if (v.id == R.id.login) {
|
|
|
- if (loginType == 0) {
|
|
|
- if (judgeByAccount()) {
|
|
|
- loginByAccount()
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (judgeByCode()) {
|
|
|
- loginMsg()
|
|
|
- }
|
|
|
+ if (judgeByCode()) {
|
|
|
+ loginMsg()
|
|
|
}
|
|
|
} else if (v.id == R.id.tvCode) {
|
|
|
if (judgeFormCode()) {
|
|
@@ -260,7 +189,7 @@ class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
rxTimer.cancel()
|
|
|
binding.tvCode.text = "重新发送"
|
|
|
binding.tvCode.isClickable = true
|
|
|
- } else{
|
|
|
+ } else {
|
|
|
binding.tvCode.text = setTvSendColor("重新发送(${time - 1 - it}s)")
|
|
|
}
|
|
|
}
|
|
@@ -278,69 +207,6 @@ class LoginActivity : BaseMVVMActivity<ActivityLoginBinding, LoginViewModel>(),
|
|
|
return spannableString
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 隐藏长按显示文本
|
|
|
- */
|
|
|
- private fun hideToolTipText(tab: TabLayout.Tab) {
|
|
|
- // 取消长按事件
|
|
|
- tab.view.isLongClickable = false
|
|
|
- // api 26 以上 设置空text
|
|
|
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
|
|
- tab.view.tooltipText = ""
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint("CutPasteId")
|
|
|
- override fun onTabSelected(tab: TabLayout.Tab?) {
|
|
|
- tab?.customView?.findViewById<TextView>(R.id.tv_tab)?.isSelected = true
|
|
|
- val tv: TextView? = tab?.customView?.findViewById(R.id.tv_tab)
|
|
|
- tv?.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
|
|
|
- tv?.invalidate()
|
|
|
- val index = tab?.position ?: 0
|
|
|
- loginType = index
|
|
|
- if (index == 0) {
|
|
|
- binding {
|
|
|
- password.post {
|
|
|
- username.hint = "请输入用户名"
|
|
|
- password.hint = "请输入密码"
|
|
|
- password.inputType =
|
|
|
- InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
|
|
- if (password.text.toString().trim().isNotEmpty()) {
|
|
|
- password.setSelection(password.text.toString().trim().length)
|
|
|
- }
|
|
|
- tvCode.clearAnimation()
|
|
|
- tvCode.visibility = View.GONE
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- binding {
|
|
|
- password.post {
|
|
|
- username.hint = "请输入手机号"
|
|
|
- password.hint = "请输入验证码"
|
|
|
- password.inputType =
|
|
|
- InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD or InputType.TYPE_CLASS_NUMBER
|
|
|
- if (password.text.toString().trim().isNotEmpty()) {
|
|
|
- password.setSelection(password.text.toString().trim().length)
|
|
|
- }
|
|
|
- tvCode.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- tab?.customView?.findViewById<TextView>(R.id.tv_tab)?.isSelected = false
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint("CutPasteId")
|
|
|
- override fun onTabUnselected(tab: TabLayout.Tab?) {
|
|
|
- tab?.customView?.findViewById<TextView>(R.id.tv_tab)?.isSelected = false
|
|
|
- val tv: TextView? = tab?.customView?.findViewById(R.id.tv_tab)
|
|
|
- tv?.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
|
|
|
- tv?.invalidate()
|
|
|
- }
|
|
|
-
|
|
|
- override fun onTabReselected(tab: TabLayout.Tab?) {
|
|
|
- }
|
|
|
-
|
|
|
override fun onDestroy() {
|
|
|
rxTimer.cancel()
|
|
|
super.onDestroy()
|