优化登录
This commit is contained in:
parent
6c3676e57e
commit
5d4f078664
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
if (updateView) {
|
||||
setErrorAndInput(
|
||||
viewBinding.accountView,
|
||||
getString(R.string.please_enter_your_account_or_email),
|
||||
viewBinding.accountInputLayout
|
||||
)
|
||||
}
|
||||
false
|
||||
} else {
|
||||
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()) {
|
||||
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}\$"))) {
|
||||
if (updateView) {
|
||||
viewBinding.passwordInputLayout.isErrorEnabled = false
|
||||
}
|
||||
true
|
||||
} else {
|
||||
if (updateView) {
|
||||
setErrorAndInput(
|
||||
viewBinding.passwordView,
|
||||
getString(R.string.password_error),
|
||||
viewBinding.passwordInputLayout, false
|
||||
)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,8 +257,15 @@ 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()) {
|
||||
if (updateView) {
|
||||
viewBinding.mailHelpTextView.isVisible = true
|
||||
setErrorAndInput(
|
||||
viewBinding.emailView,
|
||||
String.format(
|
||||
|
@ -240,40 +273,95 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
|||
viewBinding.emailInputLayout.hint.toString()
|
||||
), viewBinding.emailInputLayout
|
||||
)
|
||||
}
|
||||
false
|
||||
} else {
|
||||
if (email.matches(Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$"))) {
|
||||
if (updateView) {
|
||||
viewBinding.emailInputLayout.isErrorEnabled = false
|
||||
viewBinding.mailHelpTextView.isVisible = false
|
||||
}
|
||||
true
|
||||
} else {
|
||||
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()) {
|
||||
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}\$"))) {
|
||||
if (updateView) {
|
||||
viewBinding.passwordInputLayout.isErrorEnabled = false
|
||||
}
|
||||
true
|
||||
} else {
|
||||
if (updateView) {
|
||||
setErrorAndInput(
|
||||
viewBinding.passwordView,
|
||||
getString(R.string.password_error),
|
||||
viewBinding.passwordInputLayout, false
|
||||
)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -284,8 +372,9 @@ 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()) {
|
||||
if (updateView) {
|
||||
setErrorAndInput(
|
||||
viewBinding.userNameView,
|
||||
String.format(
|
||||
|
@ -294,9 +383,12 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
|||
),
|
||||
viewBinding.userNameInputLayout
|
||||
)
|
||||
}
|
||||
false
|
||||
} else {
|
||||
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()) {
|
||||
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_]+\$"))) {
|
||||
if (updateView) {
|
||||
viewBinding.accountInputLayout.isErrorEnabled = false
|
||||
}
|
||||
true
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
|
@ -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(
|
||||
" ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -118,10 +118,11 @@ data class CompileConfiguration(
|
|||
|
||||
/**
|
||||
* 代码块类
|
||||
* 键,值,节,注释,变量名
|
||||
* 键,值,节,注释,变量名,引用
|
||||
* Reference 引用是一种特殊的数据类型,编译器会尝试编译此值,若无法编译则使用原始值
|
||||
*/
|
||||
enum class CodeBlockType {
|
||||
Key, Value, Section, Note, VariableName
|
||||
Key, Value, Section, Note, VariableName, Reference
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user