优化:修改消费码输入框为密��模式,添加显示/隐藏密码切换功能
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.sw.dualscreen.activity.fragment.pay
|
||||
|
||||
import android.text.InputType
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
import com.sw.dualscreen.databinding.FragmentNumberPayBinding
|
||||
@@ -13,6 +15,8 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
private lateinit var payActivity: PayActivity
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
// 密码是否显示的标志
|
||||
private var isPasswordVisible = false
|
||||
override fun inflateViewBinding(): FragmentNumberPayBinding {
|
||||
return FragmentNumberPayBinding.inflate(layoutInflater)
|
||||
}
|
||||
@@ -27,6 +31,12 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
foodName = it.foodName
|
||||
payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum
|
||||
}
|
||||
|
||||
// 密码显示/隐藏切换
|
||||
binding.ivTogglePassword.setOnClickListener {
|
||||
togglePasswordVisibility()
|
||||
}
|
||||
|
||||
binding.btnConfirm.setOnClickListener { v ->
|
||||
val phone = binding.etInputPhone.text.toString().trim()
|
||||
val key = binding.etInputNumber.text.toString().trim()
|
||||
@@ -127,6 +137,30 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
// 切换密码显示/隐藏
|
||||
private fun togglePasswordVisibility() {
|
||||
val editText = binding.etInputNumber
|
||||
val imageView = binding.ivTogglePassword
|
||||
|
||||
// 保存当前光标位置
|
||||
val cursorPosition = editText.selectionStart
|
||||
|
||||
if (isPasswordVisible) {
|
||||
// 当前显示,改为隐藏
|
||||
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
imageView.setImageResource(R.drawable.ic_eye_close)
|
||||
isPasswordVisible = false
|
||||
} else {
|
||||
// 当前隐藏,改为显示
|
||||
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||
imageView.setImageResource(R.drawable.ic_eye_open)
|
||||
isPasswordVisible = true
|
||||
}
|
||||
|
||||
// 恢复光标位置
|
||||
editText.setSelection(cursorPosition)
|
||||
}
|
||||
|
||||
// private fun bindOrder(userId: String, block: () -> Unit) {
|
||||
// payActivity.bindOrder(userId) { bindResult ->
|
||||
// if (bindResult.not()) {
|
||||
|
||||
Reference in New Issue
Block a user