Commit 5fa0259e authored by shiyl's avatar shiyl

优化验收相关的UI效果

parent 6bddf689
package com.yidian.common.utils
import android.text.Editable
import android.text.InputFilter
import android.text.TextUtils
import android.text.TextWatcher
import android.widget.EditText
import java.io.Serializable
import java.util.regex.Pattern
/**
* 检查工具类
*/
abstract class ValidationUtils : Serializable {
/**
* 检查输入是否超出规定长度
*
* @param length
* @param value
* @return
*/
fun checkLength(value: String?, length: Int): Boolean {
return (if (value == null || "" == value.trim { it <= ' ' }) 0 else value.length) <= length
}
/**
* 检查是否为整数
*
* @param value
* @return
*/
fun checkInteger(value: String?): Boolean {
val p = Pattern.compile("^\\d*$")
val m = p.matcher(value)
return m.matches()
}
companion object {
private const val serialVersionUID = -7712299555022613697L
/**
* 匹配正则表达式
*
* @param reg 正则表达式
* @param content 匹配内容
* @return
*/
fun pattern(reg: String?, content: String?): Boolean {
val pattern = Pattern.compile(reg)
val matcher = pattern.matcher(content)
return matcher.matches()
}
/**
* 是否为null/字符串""
*
* @param str
* @return
*/
fun isNull(str: String?): Boolean {
return str == null || str == "" || str == "0"
}
/**
* 价格输入控制
* 小数点后两位
*
* @param editText
*/
fun setPricePoint(editText: EditText) {
editText.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(
s: CharSequence, start: Int, before: Int,
count: Int
) {
var s = s
if (s.toString().contains(".")) {
if (s.length - 1 - s.toString().indexOf(".") > 2) {
s = s.toString().subSequence(
0,
s.toString().indexOf(".") + 3
)
editText.setText(s)
editText.setSelection(editText.text.length)
}
}
if (s.toString().trim { it <= ' ' }.substring(0) == ".") {
s = "0$s"
editText.setText(s)
editText.setSelection(2)
}
if (s.toString().startsWith("0")
&& s.toString().trim { it <= ' ' }.length > 1
) {
if (s.toString().substring(1, 2) != ".") {
editText.setText(s.subSequence(0, 1))
editText.setSelection(1)
return
}
}
}
override fun beforeTextChanged(
s: CharSequence, start: Int, count: Int,
after: Int
) {
}
override fun afterTextChanged(s: Editable) {}
})
}
/**
* 手机号码匹配 *
* rg\iuyt qwertyuio[po0`124`569hqw23
*
* @param mobiles
* @return
*/
fun isMobile(mobiles: String?): Boolean {
val p = Pattern.compile("^1[3,4,5,7,8]\\d{9}$")
val m = p.matcher(mobiles)
return m.matches()
}
/**
* 银行卡号匹配 *
* rg\iuyt qwertyuio[po0`124`569hqw23
*
* @param mobiles
* @return
*/
fun isBankCard(mobiles: String?): Boolean {
val p = Pattern.compile("^\\d{16}|\\d{17}|\\d{18}|\\d{19}$")
val m = p.matcher(mobiles)
return m.matches()
}
/**
* 验证邮箱地址是否正确
*
* @param email
* @return
*/
fun isEmail(email: String?): Boolean {
var flag = false
flag = try {
val check = "^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"
val regex = Pattern.compile(check)
val matcher = regex.matcher(email)
matcher.matches()
} catch (e: Exception) {
false
}
return flag
}
fun length(str: String): Int {
var str = str
str = str.replace("[^\\x00-\\xff]".toRegex(), "**")
return str.length
}
fun equlse(v: String?, v1: String?): Boolean {
if (v == null || v1 == null) {
return false
}
return v == v1
}
/**
* 只要有一个 引用相等 都返回True
*
* @param value
* @param v
* @return
* @Title: orEqulse
* @return: boolean
*/
fun orEqulse(value: String?, vararg v: String?): Boolean {
if (value == null) {
return false
}
if (v.size > 0) {
for (i in v) {
if (equlse(value, i)) {
return true
}
}
}
return false
}
/**
* 字符串函数 模仿数据库 REGIHT()
*
* @param value
* @param count
* @return
*/
fun right(value: String, count: Int): String {
return value.substring(value.length - count)
}
/**
* 字符串函数 模仿数据库 LEFT()
*
* @param value
* @param count
* @return
*/
fun left(value: String, count: Int): String {
return if (value.length >= count) {
value.substring(0, count) + "..."
} else {
value
}
}
/**
* 检查身份证号码
*/
fun isIDCardNum(num: String?): Boolean {
if (TextUtils.isEmpty(num)) {
return false
}
val regex = "(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])"
val pattern = Pattern.compile(regex)
return pattern.matcher(num).matches()
}
}
}
......@@ -19,18 +19,25 @@ class ChooseStoreApter : BaseQuickAdapter<GetShopListBean, BaseViewHolder>(R.lay
override fun convert(holder: BaseViewHolder, item: GetShopListBean) {
val position = holder.layoutPosition
holder.getView<TextView>(R.id.tv_store_name).text = item.shop_name
holder.getView<TextView>(R.id.tv_store_address).text = item.address
val tvStoreName = holder.getView<TextView>(R.id.tv_store_name)
val tvStoreAddress = holder.getView<TextView>(R.id.tv_store_address)
tvStoreName.text = item.shop_name
tvStoreAddress.text = item.address
val ivStoreSelect = holder.getView<ImageView>(R.id.iv_store_select)
if (item.isSelected) {
ivStoreSelect.background = ContextCompat.getDrawable(context, R.drawable.icon_protocol_checked)
} else {
ivStoreSelect.background = ContextCompat.getDrawable(context, R.drawable.icon_protocol_unchecked)
}
// 选择门店
// 选择门店(增大选择触控区域,故增加点击事件)
ivStoreSelect.clickAntiShake {
item.isSelected = !item.isSelected
notifyItemChanged(position)
updateSelected(item, position)
}
tvStoreName.clickAntiShake {
updateSelected(item, position)
}
tvStoreAddress.clickAntiShake {
updateSelected(item, position)
}
// 点击编辑
holder.getView<ImageView>(R.id.iv_store_edit).clickAntiShake {
......@@ -46,4 +53,12 @@ class ChooseStoreApter : BaseQuickAdapter<GetShopListBean, BaseViewHolder>(R.lay
context.startActivity(intent)
}
}
/**
* 更新选中
*/
private fun updateSelected(item: GetShopListBean, position: Int) {
item.isSelected = !item.isSelected
notifyItemChanged(position)
}
}
......@@ -7,13 +7,14 @@ import android.widget.Toast
import com.tbruyelle.rxpermissions3.Permission
import com.tbruyelle.rxpermissions3.RxPermissions
import com.yidian.common.base.BaseActivity
import com.yidian.common.extensions.hideKeyBoard
import com.yidian.common.utils.EditTextUtils
import com.yidian.common.utils.ToastUtils
import com.yidian.common.utils.ValidationUtils
import com.yidian.shenghuoquan.newscontent.databinding.ActivityStoreEditBinding
import com.yidian.shenghuoquan.newscontent.http.ApiService
import com.yidian.shenghuoquan.newscontent.utils.StorageUtil
import com.yidian.shenghuoquan.newscontent.widget.CommonTopBarView
import io.reactivex.rxjava3.functions.Consumer
/**
* 新增/编辑门店
......@@ -90,6 +91,7 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
* 保存(新建和编辑)
*/
override fun onDoAction() {
hideKeyBoard()
if (isAddStore) {
toAddStore()
} else {
......@@ -110,7 +112,7 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
requestParams["address"] = store.title
ApiService.addStore(requestParams) {
if (it) {
Toast.makeText(this@EditStoreActivity, "保存成功", Toast.LENGTH_SHORT).show()
ToastUtils.showLongSafe("保存成功,门店经纬度:${store.longitude}, ${store.latitude}")
finish()
}
}
......@@ -131,7 +133,7 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
requestParams["address"] = store.title
ApiService.updateStore(requestParams) {
if (it) {
Toast.makeText(this@EditStoreActivity, "保存成功", Toast.LENGTH_SHORT).show()
ToastUtils.showLongSafe("保存成功,门店经纬度:${store.longitude}, ${store.latitude}")
finish()
}
}
......@@ -152,10 +154,6 @@ class EditStoreActivity : BaseActivity<ActivityStoreEditBinding>(), CommonTopBar
ToastUtils.showShortSafe("请输入联系电话")
return false
}
if (storePhoneNum.length != 11) {
ToastUtils.showShortSafe("请输入11位手机号")
return false
}
return true
}
......
......@@ -50,7 +50,6 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
override fun init(savedInstanceState: Bundle?) {
super.init(savedInstanceState)
initTitleBar(viewBind.include.toolbar, viewBind.include.tvTitle, "选择门店地址")
initAmap(savedInstanceState)
initList()
initClick()
......
......@@ -24,8 +24,9 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/dp60"
android:orientation="horizontal">
<TextView
......@@ -38,8 +39,8 @@
<EditText
android:id="@+id/store_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_height="24dp"
android:background="@null"
android:hint="请输入店名"
android:maxLength="20"
......@@ -122,13 +123,13 @@
<EditText
android:id="@+id/store_phone_num"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="24dp"
android:layout_gravity="center_vertical|start"
android:layout_weight="1"
android:background="@null"
android:digits="0123456789-"
android:hint="请输入联系电话"
android:inputType="number"
android:maxLength="11"
android:maxLength="12"
android:textColor="#333333"
android:textSize="16sp" />
......
......@@ -10,8 +10,8 @@
<ImageView
android:id="@+id/iv_store_select"
android:layout_width="@dimen/dp24"
android:layout_height="@dimen/dp24"
android:layout_width="@dimen/dp34"
android:layout_height="@dimen/dp34"
android:background="@drawable/icon_protocol_unchecked"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -50,8 +50,8 @@
<ImageView
android:id="@+id/iv_store_edit"
android:layout_width="@dimen/dp24"
android:layout_height="@dimen/dp24"
android:layout_width="@dimen/dp30"
android:layout_height="@dimen/dp30"
android:background="@drawable/icon_edit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
......
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