优化登录

This commit is contained in:
Cold Mint 2022-04-23 20:41:25 +08:00
parent 6c3676e57e
commit 5d4f078664
17 changed files with 288 additions and 86 deletions

View File

@ -6,9 +6,6 @@ plugins {
}
android {
lintOptions {
baseline file("lint-baseline.xml")
}
signingConfigs {
debug {
storeFile file('keystore\\coldmint_debug.keystore')
@ -63,6 +60,9 @@ android {
buildFeatures {
viewBinding true
}
lint {
baseline file('lint-baseline.xml')
}
}

View File

@ -63,6 +63,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
} else {
viewBinding.root.setBackgroundResource(0)
}
setLoginButtonEnable()
}
})
@ -79,6 +80,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
override fun afterTextChanged(s: Editable?) {
val passWord = s.toString()
checkPassword(passWord)
setLoginButtonEnable()
}
})
@ -357,6 +359,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
val agree = appSettings.getValue(AppSettings.Setting.AgreePolicy, false)
viewBinding.checkbox.isChecked = agree
viewBinding.checkbox.setOnCheckedChangeListener { p0, p1 ->
setLoginButtonEnable()
appSettings.setValue(AppSettings.Setting.AgreePolicy, p1)
}
@ -407,38 +410,72 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
}
}
fun checkAccount(account: String): Boolean {
/**
* 检查账号
* @param account String
* @param updateView Boolean
* @return Boolean
*/
fun checkAccount(account: String, updateView: Boolean = true): Boolean {
return if (account.isBlank()) {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.please_enter_your_account_or_email),
viewBinding.accountInputLayout
)
if (updateView) {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.please_enter_your_account_or_email),
viewBinding.accountInputLayout
)
}
false
} else {
viewBinding.accountInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.accountInputLayout.isErrorEnabled = false
}
true
}
}
fun checkPassword(passWord: String): Boolean {
/**
* 设置登录按钮
*/
fun setLoginButtonEnable() {
viewBinding.button.isEnabled =
checkAccount(viewBinding.accountView.text.toString(), false) && checkPassword(
viewBinding.passwordView.text.toString(),
false
) && viewBinding.checkbox.isChecked
}
/**
* 检查密码
* @param passWord String
* @param updateView Boolean
* @return Boolean
*/
fun checkPassword(passWord: String, updateView: Boolean = true): Boolean {
return if (passWord.isBlank()) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.please_enter_your_password),
viewBinding.passwordInputLayout
)
if (updateView) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.please_enter_your_password),
viewBinding.passwordInputLayout
)
}
false
} else {
if (passWord.matches(Regex("^[a-zA-Z0-9_]{6,20}\$"))) {
viewBinding.passwordInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.passwordInputLayout.isErrorEnabled = false
}
true
} else {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.password_error),
viewBinding.passwordInputLayout, false
)
if (updateView) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.password_error),
viewBinding.passwordInputLayout, false
)
}
false
}
}

View File

@ -6,6 +6,7 @@ import android.text.InputType
import android.text.TextWatcher
import com.coldmint.rust.pro.base.BaseActivity
import android.view.View
import androidx.core.view.isVisible
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.GlobalMethod
import com.coldmint.rust.core.interfaces.ApiCallBack
@ -34,7 +35,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
override fun afterTextChanged(s: Editable?) {
val userName = s.toString()
checkUserName(userName)
setRegisterButtonEnable()
}
})
@ -50,6 +51,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
override fun afterTextChanged(s: Editable?) {
val account = s.toString()
checkAccount(account)
setRegisterButtonEnable()
}
})
@ -66,6 +68,24 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
override fun afterTextChanged(s: Editable?) {
val passWord = s.toString()
checkPassword(passWord)
setRegisterButtonEnable()
}
})
viewBinding.confirmPasswordView.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
val confirmPassword = p0.toString()
checkConfirmPassword(confirmPassword)
setRegisterButtonEnable()
}
})
@ -82,6 +102,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
override fun afterTextChanged(s: Editable?) {
val email = s.toString()
checkEmail(email)
setRegisterButtonEnable()
}
})
@ -125,6 +146,11 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
val passWord = viewBinding.passwordView.text.toString()
val userName = viewBinding.userNameView.text.toString()
val email = viewBinding.emailView.text.toString()
val confirmPassword = viewBinding.confirmPasswordView.text.toString()
if (!checkConfirmPassword(confirmPassword)) {
return@OnClickListener
}
if (!checkAccount(account)) {
return@OnClickListener
@ -231,49 +257,111 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
}
fun checkEmail(email: String): Boolean {
/**
* 检查邮箱
* @param email String
* @return Boolean
*/
fun checkEmail(email: String, updateView: Boolean = true): Boolean {
return if (email.isBlank()) {
setErrorAndInput(
viewBinding.emailView,
String.format(
getString(R.string.please_input_value),
viewBinding.emailInputLayout.hint.toString()
), viewBinding.emailInputLayout
)
if (updateView) {
viewBinding.mailHelpTextView.isVisible = true
setErrorAndInput(
viewBinding.emailView,
String.format(
getString(R.string.please_input_value),
viewBinding.emailInputLayout.hint.toString()
), viewBinding.emailInputLayout
)
}
false
} else {
if (email.matches(Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$"))) {
viewBinding.emailInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.emailInputLayout.isErrorEnabled = false
viewBinding.mailHelpTextView.isVisible = false
}
true
} else {
setErrorAndInput(
viewBinding.emailView,
getString(R.string.email_error), viewBinding.emailInputLayout, false
)
if (updateView) {
viewBinding.mailHelpTextView.isVisible = true
setErrorAndInput(
viewBinding.emailView,
getString(R.string.email_error), viewBinding.emailInputLayout, false
)
}
false
}
}
}
/**
* 检查确认密码
* @param confirmPassword String
* @return Boolean
*/
fun checkConfirmPassword(confirmPassword: String, updateView: Boolean = true): Boolean {
return if (confirmPassword.isBlank()) {
if (updateView) {
setErrorAndInput(
viewBinding.confirmPasswordView, String.format(
getString(R.string.please_input_value),
viewBinding.confirmPasswordInputLayout.hint.toString()
), viewBinding.confirmPasswordInputLayout
)
}
false
} else {
val passWord = viewBinding.passwordView.text.toString()
if (passWord == confirmPassword) {
if (updateView) {
viewBinding.confirmPasswordInputLayout.isErrorEnabled = false
}
true
} else {
if (updateView) {
setErrorAndInput(
viewBinding.confirmPasswordView,
getString(R.string.confirm_password_error),
viewBinding.confirmPasswordInputLayout,
false
)
}
false
}
fun checkPassword(passWord: String): Boolean {
}
}
/**
* 检查密码
* @param passWord String
* @return Boolean
*/
fun checkPassword(passWord: String, updateView: Boolean = true): Boolean {
return if (passWord.isBlank()) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.please_enter_your_password),
viewBinding.passwordInputLayout
)
if (updateView) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.please_enter_your_password),
viewBinding.passwordInputLayout
)
}
false
} else {
if (passWord.matches(Regex("^[a-zA-Z0-9_]{6,20}\$"))) {
viewBinding.passwordInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.passwordInputLayout.isErrorEnabled = false
}
true
} else {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.password_error),
viewBinding.passwordInputLayout, false
)
if (updateView) {
setErrorAndInput(
viewBinding.passwordView,
getString(R.string.password_error),
viewBinding.passwordInputLayout, false
)
}
false
}
}
@ -284,19 +372,23 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
* @param userName String
* @return Boolean
*/
fun checkUserName(userName: String): Boolean {
fun checkUserName(userName: String, updateView: Boolean = true): Boolean {
return if (userName.isBlank()) {
setErrorAndInput(
viewBinding.userNameView,
String.format(
getString(R.string.please_input_value),
viewBinding.userNameInputLayout.hint.toString()
),
viewBinding.userNameInputLayout
)
if (updateView) {
setErrorAndInput(
viewBinding.userNameView,
String.format(
getString(R.string.please_input_value),
viewBinding.userNameInputLayout.hint.toString()
),
viewBinding.userNameInputLayout
)
}
false
} else {
viewBinding.userNameInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.userNameInputLayout.isErrorEnabled = false
}
true
}
}
@ -306,28 +398,52 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
* @param account String
* @return Boolean
*/
fun checkAccount(account: String): Boolean {
fun checkAccount(account: String, updateView: Boolean = true): Boolean {
if (account.isBlank()) {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.please_enter_your_account), viewBinding.accountInputLayout
)
if (updateView) {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.please_enter_your_account), viewBinding.accountInputLayout
)
}
return false
} else {
return if (account.matches(Regex("^[A-Za-z0-9_]+\$"))) {
viewBinding.accountInputLayout.isErrorEnabled = false
if (updateView) {
viewBinding.accountInputLayout.isErrorEnabled = false
}
true
} else {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.account_error), viewBinding.accountInputLayout, false
)
if (updateView) {
setErrorAndInput(
viewBinding.accountView,
getString(R.string.account_error), viewBinding.accountInputLayout, false
)
}
false
}
}
}
/**
* 设置注册按钮启用状态
*/
fun setRegisterButtonEnable() {
val account = viewBinding.accountView.text.toString()
val passWord = viewBinding.passwordView.text.toString()
val userName = viewBinding.userNameView.text.toString()
val email = viewBinding.emailView.text.toString()
val confirmPassword = viewBinding.confirmPasswordView.text.toString()
viewBinding.registerButton.isEnabled =
checkConfirmPassword(confirmPassword, false) && checkAccount(
account,
false
) && checkUserName(userName, false) && checkPassword(
passWord
) && checkEmail(email, false)
}
override fun getViewBindingObject(): ActivityRegisterBinding {
return ActivityRegisterBinding.inflate(layoutInflater)
}

View File

@ -63,6 +63,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/passwordInputLayout"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="@string/login" />
@ -75,7 +76,6 @@
android:text="@string/agreement_agreed" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -103,6 +103,26 @@
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/confirmPasswordInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
app:counterEnabled="true"
app:counterMaxLength="20"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/confirmPasswordView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/confirm_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="20" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/emailInputLayout"
android:layout_width="match_parent"
@ -124,9 +144,10 @@
android:id="@+id/mailHelpTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/mail_helper"
android:textColor="?android:colorPrimary"
android:textSize="13sp" />
android:textSize="13sp"
android:visibility="gone" />
</com.google.android.material.textfield.TextInputLayout>
@ -135,6 +156,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="@string/register" />
</LinearLayout>

View File

@ -825,4 +825,6 @@
<string name="qq_number">QQ号</string>
<string name="mail_helper_tip">建议您使用QQ邮箱注册请输入QQ号我们会自动填充您的QQ邮箱。</string>
<string name="email_fill_complete">邮箱地址填充完成。</string>
<string name="confirm_password">确认密码</string>
<string name="confirm_password_error">两次密码不一致。</string>
</resources>

View File

@ -156,7 +156,6 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte
translatorListener.beforeTranslate()
translatorListener.onTranslateComplete(code)
}
} else {
val tokenizer = StringTokenizer(code, split, true)
//缓存翻译数据,以便加速重复数据的翻译
@ -166,6 +165,8 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte
//保存完整的翻译结果
val translationResult = StringBuilder()
var codeBlockType = CompileConfiguration.CodeBlockType.Key
//保存资源引用值(应该看做整体处理)
val referenceResult = StringBuilder()
handler.post {
translatorListener.beforeTranslate()
}
@ -177,23 +178,46 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte
codeResult.delete(0, codeResult.length)
when (code) {
"\n" -> {
if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) {
val referenceValue = referenceResult.toString()
val codeInfo =
codeDataBase.getCodeDao().findCodeByCode(referenceValue)
if (codeInfo == null) {
translationResult.append(referenceResult)
}else{
// tr
}
}
codeBlockType = CompileConfiguration.CodeBlockType.Key
codeResult.append(code)
}
"\r" -> {
}
" ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> codeResult.append(
code
)
":" -> {
if (codeBlockType == CompileConfiguration.CodeBlockType.Key) {
codeBlockType =
CompileConfiguration.CodeBlockType.Value
" ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> {
if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) {
referenceResult.append(code)
} else {
codeResult.append(
code
)
}
}
":" -> {
if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) {
referenceResult.append(code)
} else {
if (codeBlockType == CompileConfiguration.CodeBlockType.Key) {
codeBlockType =
CompileConfiguration.CodeBlockType.Value
}
codeResult.append(code)
}
codeResult.append(code)
}
else -> if (codeBlockType == CompileConfiguration.CodeBlockType.Note) {
codeResult.append(code)
} else if (codeBlockType == CompileConfiguration.CodeBlockType.Reference) {
//资源引用值应该被整体处理
referenceResult.append(code)
} else {
if (code.startsWith("#")) {
codeBlockType = CompileConfiguration.CodeBlockType.Note
@ -258,7 +282,7 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte
if (!tag.isNullOrBlank()) {
//如果此类型为特殊标注,那么设置为注释
codeBlockType =
CompileConfiguration.CodeBlockType.Note
CompileConfiguration.CodeBlockType.Reference
}
}
codeResult.append(codeInfo.translate)

View File

@ -118,10 +118,11 @@ data class CompileConfiguration(
/**
* 代码块类
* 注释变量名
* 注释变量名,引用
* Reference 引用是一种特殊的数据类型编译器会尝试编译此值若无法编译则使用原始值
*/
enum class CodeBlockType {
Key, Value, Section, Note, VariableName
Key, Value, Section, Note, VariableName, Reference
}
/**

View File

@ -7,7 +7,7 @@ buildscript {
maven { url 'https://repo1.maven.org/maven2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
// classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Sat Mar 26 20:50:56 CST 2022
sdk.dir=D\:\\Document\\AndroidSdk
#Sat Apr 23 18:41:07 CST 2022
sdk.dir=D\:\\Android_SDK