邮箱填充器
This commit is contained in:
parent
d6978460f0
commit
8a8c09c589
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -23,4 +23,6 @@ public class ExampleInstrumentedTest {
|
||||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
assertEquals("com.coldmint.rust.pro", appContext.getPackageName());
|
assertEquals("com.coldmint.rust.pro", appContext.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.coldmint.rust.pro
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.coldmint.rust.core.SourceFile
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class SourceFileUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testWriteValue() {
|
||||||
|
val sourceFile = SourceFile("[core]\nname:124")
|
||||||
|
//测试修改值
|
||||||
|
sourceFile.writeValue("name", "love")
|
||||||
|
assertEquals("[core]\nname:love", sourceFile.text)
|
||||||
|
//测试修改值2
|
||||||
|
sourceFile.text = "[core]\nname:124\nmsg:ni"
|
||||||
|
sourceFile.writeValue("msg", "happy")
|
||||||
|
sourceFile.writeValue("name", "loveMe")
|
||||||
|
assertEquals("[core]\nname:loveMe\nmsg:happy", sourceFile.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReadValue() {
|
||||||
|
val sourceFile = SourceFile("[core]\n\nname:124\nkey:value2")
|
||||||
|
//测试修改值
|
||||||
|
val value = sourceFile.readValue("name")
|
||||||
|
assertEquals("124", value)
|
||||||
|
//测试修改值2
|
||||||
|
sourceFile.text = "[core]\nname:124\nmsg:ni"
|
||||||
|
val value2 = sourceFile.readValue("msg")
|
||||||
|
assertEquals("ni", value2)
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import com.coldmint.rust.core.web.User.verification
|
||||||
import com.coldmint.rust.pro.base.BaseActivity
|
import com.coldmint.rust.pro.base.BaseActivity
|
||||||
import com.coldmint.rust.pro.databinding.ActivityLoginBinding
|
import com.coldmint.rust.pro.databinding.ActivityLoginBinding
|
||||||
import com.coldmint.rust.pro.tool.AppSettings
|
import com.coldmint.rust.pro.tool.AppSettings
|
||||||
|
import com.coldmint.rust.pro.tool.EmailAutoCompleteHelper
|
||||||
import com.coldmint.rust.pro.tool.GlobalMethod
|
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.gyf.immersionbar.ktx.immersionBar
|
import com.gyf.immersionbar.ktx.immersionBar
|
||||||
|
@ -43,6 +44,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
|
||||||
.navigationBarColor(R.color.white_200).navigationBarDarkIcon(true)
|
.navigationBarColor(R.color.white_200).navigationBarDarkIcon(true)
|
||||||
}
|
}
|
||||||
Log.d("应用识别码", appSettings.getValue(AppSettings.Setting.AppID, "无"))
|
Log.d("应用识别码", appSettings.getValue(AppSettings.Setting.AppID, "无"))
|
||||||
|
|
||||||
viewBinding.accountView.addTextChangedListener(object : TextWatcher {
|
viewBinding.accountView.addTextChangedListener(object : TextWatcher {
|
||||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||||
|
|
||||||
|
@ -68,6 +70,9 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
val emailAutoCompleteHelper = EmailAutoCompleteHelper(this)
|
||||||
|
emailAutoCompleteHelper.onBindAutoCompleteTextView(viewBinding.accountView)
|
||||||
|
|
||||||
viewBinding.passwordView.addTextChangedListener(object : TextWatcher {
|
viewBinding.passwordView.addTextChangedListener(object : TextWatcher {
|
||||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.coldmint.rust.core.dataBean.ApiResponse
|
||||||
import com.coldmint.rust.core.dataBean.RegisterRequestData
|
import com.coldmint.rust.core.dataBean.RegisterRequestData
|
||||||
import com.coldmint.rust.core.web.User
|
import com.coldmint.rust.core.web.User
|
||||||
import com.coldmint.rust.pro.databinding.ActivityRegisterBinding
|
import com.coldmint.rust.pro.databinding.ActivityRegisterBinding
|
||||||
|
import com.coldmint.rust.pro.tool.EmailAutoCompleteHelper
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|
||||||
class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
||||||
|
@ -106,38 +107,8 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
val emailAutoCompleteHelper = EmailAutoCompleteHelper(this)
|
||||||
viewBinding.mailHelpTextView.setOnClickListener {
|
emailAutoCompleteHelper.onBindAutoCompleteTextView(viewBinding.emailView)
|
||||||
//预填充qq号
|
|
||||||
val tail = "@qq.com"
|
|
||||||
val oldEmailValue = viewBinding.emailView.text.toString()
|
|
||||||
val hasOldQQ = oldEmailValue.endsWith(tail)
|
|
||||||
var oldQQ = ""
|
|
||||||
if (hasOldQQ) {
|
|
||||||
oldQQ = oldEmailValue.subSequence(0, oldEmailValue.length - tail.length).toString()
|
|
||||||
}
|
|
||||||
//显示对话框
|
|
||||||
MaterialDialog(this).show {
|
|
||||||
title(R.string.email).message(R.string.mail_helper_tip)
|
|
||||||
.input(
|
|
||||||
hintRes = R.string.qq_number,
|
|
||||||
maxLength = viewBinding.emailInputLayout.counterMaxLength - tail.length,
|
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER,
|
|
||||||
prefill = oldQQ
|
|
||||||
) { materialDialog, charSequence ->
|
|
||||||
val email = "${charSequence}${tail}"
|
|
||||||
viewBinding.emailView.setText(email)
|
|
||||||
Snackbar.make(
|
|
||||||
viewBinding.registerButton,
|
|
||||||
R.string.email_fill_complete,
|
|
||||||
Snackbar.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
.positiveButton(R.string.dialog_ok).negativeButton(R.string.dialog_close)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
viewBinding.registerButton.setOnClickListener(View.OnClickListener { v ->
|
viewBinding.registerButton.setOnClickListener(View.OnClickListener { v ->
|
||||||
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
|
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
|
||||||
|
@ -265,7 +236,6 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
||||||
fun checkEmail(email: String, updateView: Boolean = true): Boolean {
|
fun checkEmail(email: String, updateView: Boolean = true): Boolean {
|
||||||
return if (email.isBlank()) {
|
return if (email.isBlank()) {
|
||||||
if (updateView) {
|
if (updateView) {
|
||||||
viewBinding.mailHelpTextView.isVisible = true
|
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.emailView,
|
viewBinding.emailView,
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -279,12 +249,10 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
|
||||||
if (email.matches(Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$"))) {
|
if (email.matches(Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$"))) {
|
||||||
if (updateView) {
|
if (updateView) {
|
||||||
viewBinding.emailInputLayout.isErrorEnabled = false
|
viewBinding.emailInputLayout.isErrorEnabled = false
|
||||||
viewBinding.mailHelpTextView.isVisible = false
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
if (updateView) {
|
if (updateView) {
|
||||||
viewBinding.mailHelpTextView.isVisible = true
|
|
||||||
setErrorAndInput(
|
setErrorAndInput(
|
||||||
viewBinding.emailView,
|
viewBinding.emailView,
|
||||||
getString(R.string.email_error), viewBinding.emailInputLayout, false
|
getString(R.string.email_error), viewBinding.emailInputLayout, false
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package com.coldmint.rust.pro.tool
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import android.util.Log
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱自动完成助手
|
||||||
|
*/
|
||||||
|
class EmailAutoCompleteHelper(val context: Context) {
|
||||||
|
private val emailList =
|
||||||
|
listOf<String>(
|
||||||
|
"@qq.com",
|
||||||
|
"@gmail.com",
|
||||||
|
"@163.com",
|
||||||
|
"@live.com",
|
||||||
|
"@yahoo.com",
|
||||||
|
"@sina.com",
|
||||||
|
"@sohu.com",
|
||||||
|
"@139.com",
|
||||||
|
"@126.com",
|
||||||
|
"@aliyun.com", "@tom.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
private val adapter = ArrayAdapter<String>(
|
||||||
|
context,
|
||||||
|
android.R.layout.simple_expandable_list_item_1
|
||||||
|
)
|
||||||
|
|
||||||
|
//最大提示数量
|
||||||
|
val maxNum = 3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取邮箱提示列表
|
||||||
|
* @param string String
|
||||||
|
* @return List<String>?
|
||||||
|
*/
|
||||||
|
|
||||||
|
private fun updateList(string: String) {
|
||||||
|
adapter.clear()
|
||||||
|
val index = string.indexOf("@")
|
||||||
|
if (index > -1) {
|
||||||
|
val end = string.substring(index)
|
||||||
|
var num = 0
|
||||||
|
for (email in emailList) {
|
||||||
|
if (email.startsWith(end)) {
|
||||||
|
num++
|
||||||
|
val value = string.substring(0..index) + email.substring(
|
||||||
|
if (end.length > 1) {
|
||||||
|
end.length - 1
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
adapter.add(value)
|
||||||
|
}
|
||||||
|
if (num == maxNum) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var num = 0
|
||||||
|
for (email in emailList) {
|
||||||
|
num++
|
||||||
|
adapter.add(string + email)
|
||||||
|
if (num == maxNum) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定控件
|
||||||
|
* @param autoCompleteTextView MaterialAutoCompleteTextView
|
||||||
|
*/
|
||||||
|
fun onBindAutoCompleteTextView(autoCompleteTextView: MaterialAutoCompleteTextView) {
|
||||||
|
autoCompleteTextView.threshold = 0
|
||||||
|
autoCompleteTextView.setAdapter(adapter)
|
||||||
|
autoCompleteTextView.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) {
|
||||||
|
val text = p0.toString()
|
||||||
|
if (text.isNotBlank()) {
|
||||||
|
updateList(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun afterTextChanged(p0: Editable?) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/accountInputLayout"
|
android:id="@+id/accountInputLayout"
|
||||||
|
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/titleView"
|
android:layout_below="@id/titleView"
|
||||||
|
@ -24,7 +25,7 @@
|
||||||
app:counterEnabled="true"
|
app:counterEnabled="true"
|
||||||
app:counterMaxLength="30">
|
app:counterMaxLength="30">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||||
android:id="@+id/accountView"
|
android:id="@+id/accountView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -112,13 +112,14 @@
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
android:id="@+id/emailInputLayout"
|
android:id="@+id/emailInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:counterEnabled="true"
|
app:counterEnabled="true"
|
||||||
app:counterMaxLength="30">
|
app:counterMaxLength="30">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||||
android:id="@+id/emailView"
|
android:id="@+id/emailView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -128,14 +129,6 @@
|
||||||
android:maxLength="30"
|
android:maxLength="30"
|
||||||
android:maxLines="1" />
|
android:maxLines="1" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/mailHelpTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:text="@string/mail_helper"
|
|
||||||
android:textSize="13sp"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
|
|
@ -733,7 +733,7 @@
|
||||||
<string name="search_file_name">文件名</string>
|
<string name="search_file_name">文件名</string>
|
||||||
<string name="search_file_text">文件中包含内容</string>
|
<string name="search_file_text">文件中包含内容</string>
|
||||||
<string name="search_unit_name">欲搜索单位名</string>
|
<string name="search_unit_name">欲搜索单位名</string>
|
||||||
<string name="auto_save_describe">请您切换到其他程序时,自动保存代码。</string>
|
<string name="auto_save_describe">当您切换到其他程序时,自动保存代码。</string>
|
||||||
<string name="auto_save">自动保存</string>
|
<string name="auto_save">自动保存</string>
|
||||||
<string name="setting_auto_save">AutoSave</string>
|
<string name="setting_auto_save">AutoSave</string>
|
||||||
<string name="auto_save_toast">已自动保存。</string>
|
<string name="auto_save_toast">已自动保存。</string>
|
||||||
|
|
|
@ -5,11 +5,11 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdk 31
|
compileSdk 32
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 31
|
targetSdk 32
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
consumerProguardFiles "consumer-rules.pro"
|
consumerProguardFiles "consumer-rules.pro"
|
||||||
|
|
|
@ -420,10 +420,10 @@ class SourceFile(text: String) {
|
||||||
* @return 写入结果,键不存在返回假
|
* @return 写入结果,键不存在返回假
|
||||||
*/
|
*/
|
||||||
fun writeValue(key: String, value: String?): Boolean {
|
fun writeValue(key: String, value: String?): Boolean {
|
||||||
var key = key
|
var keyCode = key
|
||||||
key = "\n${key}:"
|
keyCode = "\n${keyCode}:"
|
||||||
val info = "\n${text}\n"
|
val info = "\n${text}\n"
|
||||||
val startnum = info.indexOf(key)
|
val startnum = info.indexOf(keyCode)
|
||||||
if (startnum > -1) {
|
if (startnum > -1) {
|
||||||
val symbolnum = info.indexOf(":", startnum)
|
val symbolnum = info.indexOf(":", startnum)
|
||||||
val endnum = info.indexOf("\n", symbolnum)
|
val endnum = info.indexOf("\n", symbolnum)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user