初始代码提交
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.databinding.ListItemCollectSearchBinding
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
|
||||
class CollectSearchAdapter(var list: MutableList<SearchGoodsInfo.Record>) :
|
||||
BaseQuickAdapter<SearchGoodsInfo.Record, CollectSearchAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemCollectSearchBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemCollectSearchBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: SearchGoodsInfo.Record?) {
|
||||
holder.binding.let {
|
||||
it.tvGoodsName.run {
|
||||
text = item!!.goodsName
|
||||
setTextColor(if (item!!.isSelected) "#FF0032C8".toColorInt() else "#FF666666".toColorInt())
|
||||
//setTextColor("#FF666666".toColorInt())
|
||||
}
|
||||
it.root.run {
|
||||
if (item!!.isSelected) {
|
||||
setShapeDrawable(
|
||||
solidColor = "#FFEAF0FF",
|
||||
strokeColor = "#FF0033CC",
|
||||
strokeWidth = 2.dp,
|
||||
radius = 10.dp
|
||||
)
|
||||
} else {
|
||||
setShapeDrawable(
|
||||
solidColor = "#FFF5F5F5",
|
||||
radius = 10.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
// it.root.run {
|
||||
// setShapeDrawable(
|
||||
// solidColor = "#FFF5F5F5",
|
||||
// radius = 10.dp
|
||||
// )
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.databinding.ListItemDropdownBinding
|
||||
import com.sw.inbound.model.response.DictType
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
|
||||
class DropdownAdapter(var list: MutableList<DictType>) :
|
||||
BaseQuickAdapter<DictType, DropdownAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemDropdownBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemDropdownBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: DictType?) {
|
||||
holder.binding.tvDropdown.text = item?.value
|
||||
holder.binding.divider.run {
|
||||
if (position == list.size - 1) gone() else visible()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.core.net.toUri
|
||||
import coil.load
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.databinding.ListItemFoodCollectionBinding
|
||||
import com.sw.inbound.objbox.FoodCollectionBean
|
||||
import kotlin.let
|
||||
import kotlin.run
|
||||
|
||||
class FoodCollectionAdapter (var list: MutableList<FoodCollectionBean>) :
|
||||
BaseQuickAdapter<FoodCollectionBean, FoodCollectionAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemFoodCollectionBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemFoodCollectionBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodCollectionBean?) {
|
||||
val binding = holder.binding
|
||||
item?.let {
|
||||
binding.ivFinish.visibility = if (it.isFinish) View.VISIBLE else View.GONE
|
||||
binding.ivDelete.visibility = if (it.isShowCamera) View.GONE else View.VISIBLE
|
||||
binding.imageView.run {
|
||||
if (it.isShowCamera) {
|
||||
scaleType = ImageView.ScaleType.CENTER
|
||||
setImageResource(R.mipmap.ic_camera256)
|
||||
} else {
|
||||
scaleType = ImageView.ScaleType.FIT_CENTER
|
||||
//setImageURI(it.imageUri)
|
||||
//load(it.bitmap)
|
||||
// setImageBitmap(it.bitmap!!)
|
||||
setImageURI(it.imageFile?.toUri())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.databinding.ListItemGoodsSearchBinding
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
|
||||
class GoodsSearchAdapter(var list: MutableList<SearchGoodsInfo.Record>) :
|
||||
BaseQuickAdapter<SearchGoodsInfo.Record, GoodsSearchAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemGoodsSearchBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemGoodsSearchBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: SearchGoodsInfo.Record?) {
|
||||
holder.binding.let {
|
||||
it.tvGoodsName.run {
|
||||
text = item!!.goodsName
|
||||
setTextColor(if (item!!.isSelected) "#FF0032C8".toColorInt() else "#FF666666".toColorInt())
|
||||
}
|
||||
it.root.run {
|
||||
if (item!!.isSelected) {
|
||||
setShapeDrawable(
|
||||
solidColor = "#FFEAF0FF",
|
||||
strokeColor = "#FF0033CC",
|
||||
strokeWidth = 2.dp,
|
||||
radius = 10.dp
|
||||
)
|
||||
} else {
|
||||
setShapeDrawable(
|
||||
solidColor = "#FFF5F5F5",
|
||||
radius = 10.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.databinding.ListItemReceiptGoodsBinding
|
||||
import com.sw.inbound.dialog.WarnDialog
|
||||
import com.sw.inbound.ext.toFormattedString
|
||||
import com.sw.inbound.ext.toSafeDouble
|
||||
import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.ifNullOrBlank
|
||||
import com.sw.inbound.utils.ext.ifNullOrZero
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
|
||||
class ReceiptGoodsAdapter(var list: MutableList<GoodsInfo>) :
|
||||
BaseQuickAdapter<GoodsInfo, ReceiptGoodsAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemReceiptGoodsBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemReceiptGoodsBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: GoodsInfo?) {
|
||||
holder.binding.run {
|
||||
root.updateLayoutParams<RecyclerView.LayoutParams> {
|
||||
height = 100.dp
|
||||
topMargin = 2.dp
|
||||
bottomMargin = 3.dp
|
||||
}
|
||||
root.setShapeDrawable(
|
||||
solidColor = if (item!!.isSelected) "#FFD5E1FF" else "#FFFFFFFF",
|
||||
radius = 6.dp
|
||||
)
|
||||
root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
updateTextView(
|
||||
tvGoodsName, tvProcurementUnit,
|
||||
tvProcurementCount, tvGoodsWeight,
|
||||
etReceiptCount, etReceiptAmount
|
||||
//tvReceiptCount, tvProcurementPrice, tvProcurementAmount,
|
||||
)
|
||||
tvGoodsName.text = item.goodName.ifNullOrBlank("-")
|
||||
tvProcurementUnit.text = item.unitName.ifNullOrBlank("-")
|
||||
val realCount = item.receiveCount?:0.toDouble()
|
||||
tvProcurementCount.text = if (realCount == 0.toDouble()) "-" else realCount.removeTrailingZeros()
|
||||
//tvProcurementPrice.text = item.recUnitPriceTaxInBak.toSafeDouble(2).ifNullOrZero("-")
|
||||
//tvProcurementAmount.text = item.recPriceExItem.toSafeDouble(2).ifNullOrZero("-")
|
||||
//tvReceiptCount.text = item.receivedNum.toSafeDouble(2).ifNullOrZero("-")
|
||||
|
||||
tvGoodsWeight.text = doubleFormat(item.goodsWeight?.toDouble())
|
||||
|
||||
tvReceiptPrice.text = doubleFormat(item.recUnitPriceTaxIn)
|
||||
|
||||
if (item.unitHint.isNullOrBlank().not()) {
|
||||
unitDivider.visible()
|
||||
tvUnitHint.run {
|
||||
visible()
|
||||
text = item.unitHint?.replace(",", "\n")
|
||||
}
|
||||
}
|
||||
|
||||
tvState.gone()
|
||||
ivState.run {
|
||||
visible()
|
||||
setImageResource(
|
||||
if (item.isSelected.not()) R.mipmap.ic_receipt_no
|
||||
else if (item.isLocalGoods) R.mipmap.ic_receipt_local
|
||||
else if ((item.receivedNum?:0.toDouble()) < (item.receiveCount?:0.toDouble())) R.mipmap.ic_receipt_part
|
||||
else R.mipmap.ic_receipt_all
|
||||
)
|
||||
}
|
||||
etReceiptCount.run {
|
||||
isEnabled = item.receivedNum != null && item.receivedNum != 0.toDouble()
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = if (isEnabled) 20.dp else 0
|
||||
bottomMargin = if (isEnabled) 20.dp else 0
|
||||
leftMargin = if (isEnabled) 20.dp else 0
|
||||
rightMargin = if (isEnabled) 20.dp else 0
|
||||
}
|
||||
if (isEnabled) {
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 8.dp)
|
||||
val unit = item.unitName
|
||||
inputType = if (unit == "千克" || unit == "公斤" || unit == "斤") {
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
} else {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
setText(item.receivedNum?.removeTrailingZeros())
|
||||
setSelection(length())
|
||||
} else {
|
||||
setText("-")
|
||||
}
|
||||
}
|
||||
etReceiptAmount.run {
|
||||
isEnabled = item.recPriceInItem != null && item.recPriceInItem != 0.toDouble()
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = if (isEnabled) 20.dp else 0
|
||||
bottomMargin = if (isEnabled) 20.dp else 0
|
||||
leftMargin = if (isEnabled) 20.dp else 0
|
||||
rightMargin = if (isEnabled) 20.dp else 0
|
||||
}
|
||||
if (isEnabled) {
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 6.dp)
|
||||
setText(item.recPriceInItem?.removeTrailingZeros())
|
||||
setSelection(length())
|
||||
} else {
|
||||
setText("-")
|
||||
val colorString = if (item.isSelected) "#FFD5E1FF" else "#FFFFFFFF"
|
||||
setBackgroundColor(colorString.toColorInt())
|
||||
}
|
||||
}
|
||||
addEditListener(etReceiptCount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("数量不能为0")
|
||||
etReceiptCount.setText(item.receivedNum?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.receivedNum = it
|
||||
item.recUnitPriceTaxIn = item.recPriceInItem!! / it
|
||||
tvReceiptPrice.text = "${item.recUnitPriceTaxIn?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
addEditListener(etReceiptAmount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("金额不能为0")
|
||||
etReceiptAmount.setText(item.recPriceInItem?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.recPriceInItem = it
|
||||
item.recUnitPriceTaxIn = it / item.receivedNum!!
|
||||
tvReceiptPrice.text = "${item.recUnitPriceTaxIn?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
ivClear.run {
|
||||
visible()
|
||||
setOnClickListener {
|
||||
if (item.isLocalGoods) {
|
||||
//删除行数据弹窗
|
||||
showWarnDialog(content = "请确认是否删除该条采购数据,删除后不可恢复?") {
|
||||
list.removeAt(position)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
return@setOnClickListener
|
||||
}
|
||||
//清除数据,恢复默认
|
||||
showWarnDialog(content = "请确认是否清除添加的收货信息,清除后不可恢复?") {
|
||||
item.receivedNum = item.receivedNumBak
|
||||
item.recPriceInItem = 0.0
|
||||
item.recUnitPriceTaxIn = 0.0
|
||||
item.unitName = item.unitNameBak
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showWarnDialog(content:String, callback:()-> Unit) {
|
||||
WarnDialog(context = context, content = content, confirmBlock = callback).show()
|
||||
}
|
||||
|
||||
private fun updateTextView(vararg views: TextView) {
|
||||
views.forEach {
|
||||
it.setTextColor("#FF1E2832".toColorInt())
|
||||
it.paint.isFakeBoldText = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun addEditListener(editText: EditText, action: (Double) -> Unit) {
|
||||
editText.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (editText.isFocused.not()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it.toString()
|
||||
if (input.startsWith(".")) {
|
||||
setText("0.")
|
||||
setSelection(length())
|
||||
} else if (input.contains(".")) {
|
||||
val index = input.indexOf(".")
|
||||
if (input.length - index > 3) {
|
||||
setText(input.substring(0, index + 3))
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
val value = if (input == "0.") 0.0 else input.toDouble()
|
||||
action(value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun doubleFormat(num:Double?): String{
|
||||
val realNum = num?:0.toDouble()
|
||||
return if (realNum == 0.toDouble()) "-" else realNum.toFormattedString(2)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import coil.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.databinding.ListItemRecognizeBinding
|
||||
import com.sw.inbound.ext.toFormattedString
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable2
|
||||
|
||||
class RecognizeAdapter(var list: MutableList<SearchGoodsInfo.Record>) :
|
||||
BaseQuickAdapter<SearchGoodsInfo.Record, RecognizeAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemRecognizeBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemRecognizeBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: SearchGoodsInfo.Record?) {
|
||||
holder.binding.let {
|
||||
it.tvRecName.run {
|
||||
text = if (item!!.score == 0) item.goodsName else "${item.goodsName}\n${((item.score)/100.0).toFormattedString(2)}%"
|
||||
setShapeDrawable2(
|
||||
solidColor = "#DEF5F5F5",
|
||||
bottomRightRadius = 12.dp,
|
||||
bottomLeftRadius = 12.dp
|
||||
)
|
||||
}
|
||||
it.ivRecImage.run {
|
||||
load(item!!.relativeUrl) {
|
||||
transformations(RoundedCornersTransformation(radius = 12.dp.toFloat()))
|
||||
}
|
||||
scaleType = ImageView.ScaleType.CENTER_CROP
|
||||
}
|
||||
//it.root.run {
|
||||
// setShapeDrawable(
|
||||
// //strokeColor = if (item.isSelected) "#FF0033CC" else "#FFDCDCF0",
|
||||
// strokeColor = "#FFDCDCF0",
|
||||
// strokeWidth = 2.dp,
|
||||
// radius = 12.dp
|
||||
// )
|
||||
// //setPadding(if (item.isSelected) 2.dp else 0)
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.databinding.ListItemSelfProcurementBinding
|
||||
import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
|
||||
class SelfProcurementAdapter(var list: MutableList<GoodsInfo>) :
|
||||
BaseQuickAdapter<GoodsInfo, SelfProcurementAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemSelfProcurementBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemSelfProcurementBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: GoodsInfo?) {
|
||||
holder.binding.run {
|
||||
root.updateLayoutParams<RecyclerView.LayoutParams> {
|
||||
height = 100.dp
|
||||
topMargin = 2.dp
|
||||
bottomMargin = 3.dp
|
||||
}
|
||||
root.setShapeDrawable(
|
||||
solidColor = if (item!!.isSelected) "#FFD5E1FF" else "#FFFFFFFF",
|
||||
radius = 6.dp
|
||||
)
|
||||
root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
updateTextView(
|
||||
tvGoodsName, tvGoodsUnit,
|
||||
etGoodsCount, tvGoodsWeight, tvGoodsPrice,
|
||||
etGoodsAmount
|
||||
)
|
||||
tvGoodsName.text = item.goodName
|
||||
tvGoodsUnit.text = item.unitName
|
||||
if (item.unitHint.isNullOrBlank().not()) {
|
||||
unitDivider.visible()
|
||||
tvUnitHint.run {
|
||||
visible()
|
||||
text = item.unitHint?.replace(",", "\n")
|
||||
}
|
||||
}
|
||||
etGoodsCount.run {
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = 20.dp
|
||||
bottomMargin = 20.dp
|
||||
}
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 8.dp)
|
||||
isEnabled = true
|
||||
setText(item.goodsCount?.removeTrailingZeros())
|
||||
val unit = item.unitName
|
||||
inputType = if (unit == "千克" || unit == "公斤" || unit == "斤") {
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
} else {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
if (isEnabled) {
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
tvGoodsWeight.text = item.goodsWeight?.toDouble()?.removeTrailingZeros()
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
etGoodsAmount.run {
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = 20.dp
|
||||
bottomMargin = 20.dp
|
||||
}
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 6.dp)
|
||||
isEnabled = true
|
||||
setText(item.goodsPrice?.removeTrailingZeros())
|
||||
if (isEnabled) {
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
|
||||
tvState.gone()
|
||||
ivState.visible()
|
||||
|
||||
addEditListener(etGoodsCount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("数量不能为0")
|
||||
etGoodsCount.setText(item.goodsCount?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.goodsCount = it
|
||||
item.goodsUnitPrice = item.goodsPrice!! / it
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
addEditListener(etGoodsAmount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("金额不能为0")
|
||||
etGoodsAmount.setText(item.goodsPrice?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.goodsPrice = it
|
||||
item.goodsUnitPrice = it / item.goodsCount!!
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTextView(vararg views: TextView) {
|
||||
views.forEach {
|
||||
it.setTextColor("#FF1E2832".toColorInt())
|
||||
it.paint.isFakeBoldText = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun addEditListener(editText: EditText, action: (Double) -> Unit) {
|
||||
editText.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (editText.isFocused.not()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it.toString()
|
||||
if (input.startsWith(".")) {
|
||||
setText("0.")
|
||||
setSelection(length())
|
||||
} else if (input.contains(".")) {
|
||||
val index = input.indexOf(".")
|
||||
if (input.length - index > 3) {
|
||||
setText(input.substring(0, index + 3))
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
val value = if (input == "0.") 0.0 else input.toDouble()
|
||||
action(value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user