Commit fed32d8a authored by zhaopengxiang's avatar zhaopengxiang

密码校验弹窗ui调整,校验以及跳转逻辑添加

parent 03eb164d
...@@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.Gravity import android.view.Gravity
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.R import com.miya.fastcashier.R
...@@ -12,6 +13,7 @@ import com.miya.fastcashier.databinding.ActivityLoginBinding ...@@ -12,6 +13,7 @@ import com.miya.fastcashier.databinding.ActivityLoginBinding
import com.miya.fastcashier.databinding.ActivityMainBinding import com.miya.fastcashier.databinding.ActivityMainBinding
import com.miya.fastcashier.service.AccountService import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService import com.miya.fastcashier.service.PrintService
import com.miya.fastcashier.ui.dialog.AuthorizePasswordInputDialog
import com.miya.fastcashier.ui.dialog.CommonDialog import com.miya.fastcashier.ui.dialog.CommonDialog
import com.miya.fastcashier.ui.dialog.MessageDialog import com.miya.fastcashier.ui.dialog.MessageDialog
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
...@@ -102,12 +104,13 @@ class MainActivity : BaseActivity() { ...@@ -102,12 +104,13 @@ class MainActivity : BaseActivity() {
} }
private fun toRefund() { private fun toRefund() {
AccountPasswordManageKit.getInstance() val FRAGMENT_TAG = "Authorize_Password"
.loadAccountPassword(this, AccountPasswordManageKit.AccountPasswordManageCallback { val fm: FragmentManager = getSupportFragmentManager()
if ("121212".equals(it)) RefundActivity.start(this@MainActivity) val oldFrag = fm.findFragmentByTag(FRAGMENT_TAG)
else CenterToasty.error(this@MainActivity, "密码错误").show() if (oldFrag != null) {
}) fm.beginTransaction().remove(oldFrag).commitAllowingStateLoss()
}
AuthorizePasswordInputDialog.newInstance().show(fm, FRAGMENT_TAG)
} }
private fun checkAccountPassword() { private fun checkAccountPassword() {
......
package com.miya.fastcashier.ui.dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.*
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.DialogFragment
import com.blankj.utilcode.util.ScreenUtils
import com.miya.fastcashier.databinding.DialogAuthorizePasswordInputBinding
import com.miya.fastcashier.ui.BaseActivity
import com.miya.fastcashier.ui.RefundActivity
import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.dp2px
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
class AuthorizePasswordInputDialog() : DialogFragment(), View.OnClickListener {
private lateinit var viewBinding: DialogAuthorizePasswordInputBinding
companion object {
fun newInstance(): AuthorizePasswordInputDialog {
return AuthorizePasswordInputDialog()
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
viewBinding = DialogAuthorizePasswordInputBinding.inflate(inflater)
viewBinding.ivClose.setOnClickListener(this)
viewBinding.tvConfirm.setOnClickListener(this)
viewBinding.etPassword.apply {
afterTextChanged {
viewBinding.tvError.visibility = View.GONE
}
}
return viewBinding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val window = dialog!!.window!!
window.setDimAmount(0.0f)
super.onViewCreated(view, savedInstanceState)
window.setBackgroundDrawable(ColorDrawable(0x191919))
window.setGravity(Gravity.BOTTOM)
window.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
context?.let { dp2px(it,637f) }!!
)
showView()
}
fun showView() {
dialog!!.window!!.setDimAmount(0.7f)
viewBinding.container.visibility = View.VISIBLE
}
override fun onClick(view: View?) {
when (view) {
viewBinding.ivClose -> dismissAllowingStateLoss()
viewBinding.tvConfirm -> checkAuthorizePassword()
}
}
private fun checkAuthorizePassword() {
val inputPassword = viewBinding.etPassword.text.toString()
if (TextUtils.isEmpty(inputPassword)) {
context?.let { CenterToasty.error(it, "请输入授权密码").show() }
return
}
val accountPassword = AccountPasswordManageKit.getInstance().accountPassword
if (TextUtils.isEmpty(accountPassword)) {
AccountPasswordManageKit.getInstance()
.loadAccountPassword(context as AppCompatActivity?,
AccountPasswordManageKit.AccountPasswordManageCallback {
checkPasswordAndDoNext(it,inputPassword)
})
} else {
checkPasswordAndDoNext(accountPassword, inputPassword)
}
}
private fun checkPasswordAndDoNext(accountPassword: String, password: String) {
if (!accountPassword.equals(password)) {
viewBinding.tvError.visibility = View.VISIBLE
} else {
RefundActivity.start(context as BaseActivity)
dismissAllowingStateLoss()
}
}
private fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) {
this.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(editable: Editable?) {
afterTextChanged.invoke(editable.toString())
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
})
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners
android:radius="16dp" />
<stroke android:width="2dp"
android:color="@color/color_D1D1DC"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners
android:topRightRadius="16dp"
android:topLeftRadius="16dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="637dp"
android:background="@drawable/shape_white_top_radius16">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="38dp"
android:layout_marginTop="35dp"
android:scaleType="center"
android:src="@mipmap/app_icon_dialog_authoize_password_close"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="37dp"
android:text="请输入授权密码"
android:textColor="@color/color_141C30"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/v_input"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginTop="160dp"
android:background="@drawable/shape_border_d1d1dc_solid_white_radius16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_authorize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="27dp"
android:layout_marginEnd="38dp"
android:src="@mipmap/app_icon_dialog_authoize_password"
app:layout_constraintLeft_toLeftOf="@id/v_input"
app:layout_constraintTop_toTopOf="@id/v_input"
app:layout_constraintBottom_toBottomOf="@id/v_input" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:singleLine="true"
android:inputType="numberPassword"
android:layout_marginEnd="19dp"
android:layout_marginStart="19dp"
android:gravity="center_vertical|left"
android:textSize="32sp"
android:textColor="@color/color_333333"
android:textColorHint="@color/color_CCCCCC"
android:hint="请输入默认授权密码"
android:maxLength="6"
app:layout_constraintLeft_toRightOf="@+id/iv_authorize"
app:layout_constraintRight_toRightOf="@id/v_input"
app:layout_constraintTop_toTopOf="@id/v_input"
app:layout_constraintBottom_toBottomOf="@id/v_input" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="16dp"
android:text="密码错误 请重新输入"
android:textColor="@color/color_FF4E33"
android:textSize="22sp"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/v_input" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_confirm"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:textSize="32sp"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="92dp"
android:background="@drawable/shape_111235_radius8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/app_confirm"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -20,4 +20,6 @@ ...@@ -20,4 +20,6 @@
<color name="color_D83773">#D83773</color> <color name="color_D83773">#D83773</color>
<color name="color_CCCCCC">#CCCCCC</color> <color name="color_CCCCCC">#CCCCCC</color>
<color name="color_111235">#111235</color> <color name="color_111235">#111235</color>
<color name="color_141C30">#141C30</color>
<color name="color_D1D1DC">#D1D1DC</color>
</resources> </resources>
\ No newline at end of file
...@@ -30,5 +30,6 @@ ...@@ -30,5 +30,6 @@
<string name="app_setting_new_password">新密码</string> <string name="app_setting_new_password">新密码</string>
<string name="app_setting_confirm_password">确认密码</string> <string name="app_setting_confirm_password">确认密码</string>
<string name="app_confirm_update">确认修改</string> <string name="app_confirm_update">确认修改</string>
<string name="app_confirm">确认</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment