优化:修改消费码输入框为密��模式,添加显示/隐藏密码切换功能
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()) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<!-- 斜线 -->
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
android:pathData="M1,4.27L3.28,6.55L3.02,7.04C1.71,8.97 1,11.25 1,12s0.73,4.02 2.02,5.96l0.26,0.44C2.98,20.88 7.45,24 12,24c1.38,0 2.74,-0.35 3.97,-0.98l0.36,0.36l2.27,2.27l1.41,-1.41L2.41,2.86 1,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01zM23,12c0,0.75 -0.73,4.02 -2.02,5.96l-0.26,0.44C21.02,20.88 16.55,24 12,24c-1.38,0 -2.74,-0.35 -3.97,-0.98l-0.36,-0.36 -2.27,-2.27 -1.41,1.41 19.59,19.59 1.41,-1.41L23,12zM12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.63,-2.82 3.12,-4.75h-5.15c-0.03,-0.02 -0.06,-0.02 -0.09,-0.02s-0.06,0 -0.09,0.02h-5.15c0.49,1.93 1.61,3.49 3.12,4.75l2.92,-2.92C13.26,13.26 13.13,12.65 13.13,12 13.13,9.24 15.37,7 18.13,7z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<!-- 眼睛轮廓 -->
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
|
||||
<!-- 眼睛瞳孔 -->
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
android:pathData="M12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z" />
|
||||
</vector>
|
||||
@@ -34,24 +34,41 @@
|
||||
android:textStyle="bold"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputNumber"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginHorizontal="64dp"
|
||||
android:inputType="textVisiblePassword"
|
||||
android:background="@drawable/setting_border_gray3"
|
||||
android:hint="输入消费码"
|
||||
android:textColorHint="#ffc4cfda"
|
||||
android:textColor="#ff0a1428"
|
||||
android:layout_marginTop="32dp"
|
||||
android:textSize="36sp"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:text=""
|
||||
android:paddingHorizontal="50dp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
|
||||
android:layout_marginTop="32dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputNumber"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textPassword"
|
||||
android:background="@drawable/setting_border_gray3"
|
||||
android:hint="输入消费码"
|
||||
android:textColorHint="#ffc4cfda"
|
||||
android:textColor="#ff0a1428"
|
||||
android:textSize="36sp"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:text=""
|
||||
android:paddingHorizontal="50dp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivTogglePassword"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:paddingEnd="16dp"
|
||||
android:contentDescription="@string/app_name"
|
||||
android:src="@drawable/ic_eye_close"
|
||||
android:scaleType="centerInside"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnConfirm"
|
||||
|
||||
Reference in New Issue
Block a user