Explorar o código

支付密码的弹窗

liukai %!s(int64=2) %!d(string=hai) anos
pai
achega
6e68c14988

+ 13 - 0
cpt_ewallet/src/main/java/com/hongyegroup/cpt_ewallet/mvvm/EWalletWithdrawViewModel.kt

@@ -1,8 +1,11 @@
 package com.hongyegroup.cpt_ewallet.mvvm
 
+import androidx.lifecycle.LiveData
 import androidx.lifecycle.SavedStateHandle
+import androidx.lifecycle.liveData
 import com.guadou.lib_baselib.base.vm.BaseViewModel
 import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.delay
 import kotlinx.coroutines.flow.MutableStateFlow
 import javax.inject.Inject
 
@@ -15,4 +18,14 @@ class EWalletWithdrawViewModel @Inject constructor(
     var mAllMoney = MutableStateFlow("")
     var mWithdrawMoney = MutableStateFlow("")
 
+
+    //验证支付密码
+    fun verifyPassword(code: String): LiveData<Boolean> {
+        return liveData {
+            loadStartProgress()
+            delay(1000)
+            loadHideProgress()
+            emit(true)
+        }
+    }
 }

+ 21 - 1
cpt_ewallet/src/main/java/com/hongyegroup/cpt_ewallet/ui/EWalletWithdrawActivity.kt

@@ -2,7 +2,9 @@ package com.hongyegroup.cpt_ewallet.ui
 
 import android.os.Bundle
 import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
+import com.guadou.cs_cptservices.popup.PaymentPasswordPopup
 import com.guadou.lib_baselib.bean.DataBindingConfig
+import com.guadou.lib_baselib.engine.toast
 import com.guadou.lib_baselib.ext.checkNumberPoint
 import com.guadou.lib_baselib.ext.commContext
 import com.guadou.lib_baselib.ext.gotoActivity
@@ -111,7 +113,7 @@ class EWalletWithdrawActivity : YYBaseVDBActivity<EWalletWithdrawViewModel, Acti
                 .dismissOnBackPressed(false)
                 .dismissOnTouchOutside(false)
                 .asCustom(WithdrawDisclaimersPopup(mActivity) {
-                    gotoBankWithdrawPage()
+                    verifyPaymentPassword()
                 })
                 .show()
         }
@@ -121,5 +123,23 @@ class EWalletWithdrawActivity : YYBaseVDBActivity<EWalletWithdrawViewModel, Acti
             BankWithdrawActivity.startInstance(mViewModel.mWithdrawMoney.value)
         }
 
+        //验证支付密码
+        private fun verifyPaymentPassword() {
+            XPopup.Builder(mActivity)
+                .moveUpToKeyboard(true)
+                .hasShadowBg(true)
+                .isRequestFocus(true)
+                .asCustom(PaymentPasswordPopup(mActivity) { code ->
+                    toast("输入的密码:$code")
+
+                    //调用接口验证支付密码
+                    mViewModel.verifyPassword(code).observe(this@EWalletWithdrawActivity) {
+                        gotoBankWithdrawPage()
+                    }
+
+                })
+                .show()
+        }
+
     }
 }

+ 1 - 1
cpt_ewallet/src/main/res/layout/activity_payment_psd.xml

@@ -90,9 +90,9 @@
                         android:inputType="number"
                         android:maxLength="1"
                         android:minEms="2"
-                        android:text="@{click.et1Code}"
                         android:textColor="@color/profile_red"
                         android:textSize="@dimen/d_23sp"
+                        android:text="@{click.et1Code}"
                         binding:onFocusGet="@{click.onCodeETFocusGet}"
                         binding:typefaceMedium="@{true}" />
 

+ 2 - 2
cs_baselib/src/main/java/com/guadou/lib_baselib/base/activity/AbsActivity.kt

@@ -1,6 +1,5 @@
 package com.guadou.lib_baselib.base.activity
 
-import android.app.Activity
 import android.content.Context
 import android.content.Intent
 import android.content.res.Configuration
@@ -8,6 +7,7 @@ import android.content.res.Resources
 import android.graphics.Color
 import android.os.Bundle
 import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.FragmentActivity
 import com.guadou.lib_baselib.receiver.ConnectivityReceiver
 import com.guadou.lib_baselib.utils.ActivityManage
 import com.guadou.lib_baselib.utils.StatusBarUtils
@@ -21,7 +21,7 @@ abstract class AbsActivity() : AppCompatActivity(), ConnectivityReceiver.Connect
     /**
      * 获取Context对象
      */
-    protected lateinit var mActivity: Activity
+    protected lateinit var mActivity: FragmentActivity
     protected lateinit var mContext: Context
 
     abstract fun setContentView()

+ 1 - 0
cs_baselib/src/main/res/values/dimens.xml

@@ -60,6 +60,7 @@
     <dimen name="d_30dp">30dp</dimen>
     <dimen name="d_32dp">32dp</dimen>
     <dimen name="d_35dp">35dp</dimen>
+    <dimen name="d_36dp">36dp</dimen>
     <dimen name="d_38dp">38dp</dimen>
     <dimen name="d_40dp">40dp</dimen>
     <dimen name="d_42dp">42dp</dimen>

+ 165 - 0
cs_cptServices/src/main/java/com/guadou/cs_cptservices/popup/PaymentPasswordPopup.kt

@@ -0,0 +1,165 @@
+package com.guadou.cs_cptservices.popup
+
+import android.annotation.SuppressLint
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.widget.TextView
+import androidx.databinding.DataBindingUtil
+import androidx.fragment.app.FragmentActivity
+import com.guadou.cs_cptservices.BR
+import com.guadou.cs_cptservices.R
+import com.guadou.cs_cptservices.databinding.PopupPaymentPasswordBinding
+import com.guadou.lib_baselib.utils.CommUtils
+import com.guadou.lib_baselib.utils.KeyboardUtils
+import com.guadou.lib_baselib.utils.log.YYLogUtils
+import com.lxj.xpopup.core.CenterPopupView
+import com.lxj.xpopup.util.XPopupUtils
+import kotlinx.coroutines.flow.MutableStateFlow
+
+/**
+ * 校验支付密码的弹窗
+ */
+@SuppressLint("ViewConstructor")
+class PaymentPasswordPopup(
+    private val activity: FragmentActivity,
+    private val onCodeEntered: (String) -> Unit
+) : CenterPopupView(activity) {
+
+    private lateinit var mBinding: PopupPaymentPasswordBinding
+    private val mClickProxy by lazy { ClickProxy() }
+
+    //我需要使用DataBinding,所以我没有使用getImplLayoutId,我直接使用addInnerContent添加布局的时候绑定DataBinding
+    override fun addInnerContent() {
+
+        mBinding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.popup_payment_password, centerPopupContainer, false)
+        mBinding.setVariable(BR.click, mClickProxy)
+        mBinding.lifecycleOwner = activity
+
+        contentView = mBinding.root
+        val params = contentView.layoutParams as LayoutParams
+        params.gravity = Gravity.CENTER
+        centerPopupContainer.addView(contentView, params)
+    }
+
+    override fun getMaxWidth(): Int {
+        return XPopupUtils.getWindowWidth(CommUtils.getContext())
+    }
+
+    override fun onCreate() {
+        super.onCreate()
+
+        setupTextWithStatus()
+    }
+
+    private fun setupTextWithStatus() {
+        //默认设置第一个选择的背景和对话框
+        mClickProxy.curSelectedIndex.value = 0
+
+        //需要输入密码的类似,是支付还是提现?
+    }
+
+    override fun onDismiss() {
+        KeyboardUtils.hideSoftInput(mBinding.editTextHidden)
+        super.onDismiss()
+    }
+
+    /**
+     * DataBinding事件处理
+     */
+    inner class ClickProxy {
+
+        var curSelectedIndex = MutableStateFlow(0)  //当前输入的框框索引
+        var et1Code = MutableStateFlow("")
+        var et2Code = MutableStateFlow("")
+        var et3Code = MutableStateFlow("")
+        var et4Code = MutableStateFlow("")
+        var et5Code = MutableStateFlow("")
+        var et6Code = MutableStateFlow("")
+
+        val onHidenChanged: (String) -> Unit = { hiden ->
+            YYLogUtils.w("当前的值:" + hiden)
+            when (hiden.length) {
+                0 -> {
+                    curSelectedIndex.value = 0
+                    et1Code.value = ""
+                    et2Code.value = ""
+                    et3Code.value = ""
+                    et4Code.value = ""
+                    et5Code.value = ""
+                    et6Code.value = ""
+                }
+                1 -> {
+                    curSelectedIndex.value = 1
+                    et1Code.value = hiden[0].toString()
+                }
+                2 -> {
+                    curSelectedIndex.value = 2
+                    et2Code.value = hiden[1].toString()
+                }
+                3 -> {
+                    curSelectedIndex.value = 3
+                    et3Code.value = hiden[2].toString()
+                }
+                4 -> {
+                    curSelectedIndex.value = 4
+                    et4Code.value = hiden[3].toString()
+                }
+                5 -> {
+                    curSelectedIndex.value = 5
+                    et5Code.value = hiden[4].toString()
+                }
+                6 -> {
+                    curSelectedIndex.value = 6
+                    et6Code.value = hiden[5].toString()
+
+                    KeyboardUtils.hideSoftInput(mBinding.editTextHidden)
+
+                    onCodeEntered(hiden)
+
+                    dismiss()
+                }
+            }
+
+        }
+
+        //上面6个输入框的焦点获取
+        val onCodeETFocusGet: TextView.() -> Unit = {
+            YYLogUtils.w("焦点获取")
+            setHidenFocus()
+            KeyboardUtils.showSoftInput(activity, mBinding.editTextHidden)
+        }
+
+        //当按键Del触发的事件
+        val onKeyDelEvent: () -> Unit = {
+            val curCode = mBinding.editTextHidden.text.toString()
+            when (curCode.length) {
+                6 -> et6Code.value = ""
+                5 -> et5Code.value = ""
+                4 -> et4Code.value = ""
+                3 -> et3Code.value = ""
+                2 -> et2Code.value = ""
+                1 -> et1Code.value = ""
+            }
+            if (curCode.isNotEmpty()) {
+                mBinding.editTextHidden.setText(curCode.subSequence(0, curCode.length - 1))
+                mBinding.editTextHidden.setSelection(mBinding.editTextHidden.text.length)
+            }
+
+        }
+
+        //设置隐藏的Code框焦点
+        private fun setHidenFocus() {
+            mBinding.editTextHidden.isFocusable = true
+            mBinding.editTextHidden.isFocusableInTouchMode = true
+            mBinding.editTextHidden.requestFocus()
+            mBinding.editTextHidden.setSelection(mBinding.editTextHidden.text.length)
+        }
+
+        //关闭弹窗
+        fun dismissPopup() {
+            dismiss()
+        }
+
+    }
+
+}

+ 304 - 0
cs_cptServices/src/main/res/layout/popup_payment_password.xml

@@ -0,0 +1,304 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:binding="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="RtlHardcoded">
+
+    <data>
+
+        <variable
+            name="click"
+            type="com.guadou.cs_cptservices.popup.PaymentPasswordPopup.ClickProxy" />
+
+    </data>
+
+    <LinearLayout
+        android:layout_width="293dp"
+        android:layout_height="320dp"
+        android:orientation="vertical">
+
+        <RelativeLayout
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/d_70dp"
+            android:background="@drawable/shape_blue_top_round10">
+
+            <ImageView
+                android:id="@+id/iv_delete"
+                android:layout_width="@dimen/d_35dp"
+                android:layout_height="@dimen/d_35dp"
+                android:layout_alignParentRight="true"
+                android:layout_marginTop="@dimen/d_5dp"
+                android:layout_marginRight="@dimen/d_5dp"
+                android:padding="@dimen/d_5dp"
+                binding:clicks="@{click.dismissPopup}"
+                android:src="@drawable/disclaimers_delete" />
+
+            <com.guadou.lib_baselib.font_text_view.TextViewBold
+                android:id="@+id/tv_dialog_title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_centerInParent="true"
+                android:text="支付密码"
+                android:textColor="@color/white"
+                android:textSize="@dimen/d_22sp" />
+
+        </RelativeLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/shape_white_bottom_round10"
+            android:orientation="vertical">
+
+
+            <com.guadou.lib_baselib.font_text_view.TextViewMedium
+                android:id="@+id/tv_payment_method"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_15dp"
+                android:layout_marginTop="@dimen/d_20dp"
+                android:layout_marginRight="@dimen/d_15dp"
+                android:gravity="center"
+                android:text="提现"
+                android:textColor="#000000"
+                android:textSize="@dimen/d_21sp" />
+
+
+            <androidx.constraintlayout.widget.ConstraintLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_15dp"
+                android:layout_marginTop="@dimen/d_15dp"
+                android:layout_marginRight="@dimen/d_15dp"
+                android:layout_marginBottom="@dimen/d_18dp"
+                android:background="#eee"
+                android:paddingTop="@dimen/d_8dp"
+                android:paddingBottom="@dimen/d_8dp">
+
+                <TextView
+                    android:id="@+id/tv_currency_sign"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="@dimen/d_10dp"
+                    android:layout_marginRight="@dimen/d_8dp"
+                    android:text="SGD"
+                    android:textColor="@color/black"
+                    android:textSize="@dimen/d_10dp"
+                    app:layout_constraintRight_toLeftOf="@+id/tv_money"
+                    app:layout_constraintTop_toTopOf="@+id/tv_money" />
+
+                <TextView
+                    android:id="@+id/tv_money"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:text="93,026"
+                    android:textColor="@color/app_blue"
+                    android:textSize="@dimen/d_28dp"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintLeft_toLeftOf="parent"
+                    app:layout_constraintRight_toRightOf="parent"
+                    app:layout_constraintTop_toTopOf="parent" />
+
+            </androidx.constraintlayout.widget.ConstraintLayout>
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/d_0.7dp"
+                android:background="@color/divider_color" />
+
+            <com.guadou.lib_baselib.font_text_view.TextViewMedium
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_22dp"
+                android:layout_marginTop="@dimen/d_10dp"
+                android:text="输入密码"
+                android:textColor="#000000"
+                android:textSize="@dimen/d_21sp" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="@dimen/d_20dp"
+                android:layout_marginTop="@dimen/d_16dp"
+                android:focusable="true"
+                android:focusableInTouchMode="true">
+
+
+                <FrameLayout
+                    android:id="@+id/frame_first_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:background="@{click.curSelectedIndex>=0?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_first_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et1Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_second_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:background="@{click.curSelectedIndex>=1?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_second_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et2Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_third_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:background="@{click.curSelectedIndex>=2?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_third_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et3Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_fourth_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:background="@{click.curSelectedIndex>=3?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_fourth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et4Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_fifth_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:background="@{click.curSelectedIndex>=4?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_fifth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et5Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+                <FrameLayout
+                    android:id="@+id/frame_sixth_code"
+                    android:layout_width="@dimen/d_36dp"
+                    android:layout_height="@dimen/d_36dp"
+                    android:layout_marginLeft="@dimen/d_6dp"
+                    android:background="@{click.curSelectedIndex>=5?@drawable/white_input_finish:@drawable/white_input_field}"
+                    tools:background="@drawable/white_input_field">
+
+                    <EditText
+                        android:id="@+id/edit_text_sixth_code"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:background="@android:color/transparent"
+                        android:cursorVisible="false"
+                        android:gravity="center"
+                        android:inputType="numberPassword"
+                        android:maxLength="1"
+                        android:minEms="2"
+                        android:text="@{click.et6Code}"
+                        android:textColor="@color/dark_gray_text"
+                        android:textSize="@dimen/d_20sp"
+                        binding:onFocusGet="@{click.onCodeETFocusGet}"
+                        binding:typefaceMedium="@{true}" />
+
+                </FrameLayout>
+
+            </LinearLayout>
+
+            <EditText
+                android:id="@+id/edit_text_hidden"
+                android:layout_width="@dimen/d_1dp"
+                android:layout_height="@dimen/d_1dp"
+                android:layout_gravity="center_horizontal"
+                android:background="@null"
+                android:cursorVisible="false"
+                android:gravity="center_horizontal"
+                android:inputType="numberPassword"
+                android:maxLength="6"
+                android:textColor="@color/transparent"
+                binding:onKeyDel="@{click.onKeyDelEvent}"
+                binding:onTextChanged="@{click.onHidenChanged}" />
+
+        </LinearLayout>
+
+    </LinearLayout>
+
+</layout>