优化配置页面调料格式显示
This commit is contained in:
@@ -1,79 +1,38 @@
|
|||||||
package com.shuwei.dish.match.adapter
|
//package com.shuwei.dish.match.adapter
|
||||||
|
//
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.graphics.Typeface
|
//import android.view.LayoutInflater
|
||||||
import android.text.SpannableStringBuilder
|
//import android.view.ViewGroup
|
||||||
import android.text.style.AbsoluteSizeSpan
|
//import androidx.core.view.updateLayoutParams
|
||||||
import android.text.style.ForegroundColorSpan
|
//import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import android.text.style.LineHeightSpan
|
//import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import android.text.style.StyleSpan
|
//import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||||
import android.view.LayoutInflater
|
//import com.shuwei.dish.match.model.GoodsItem
|
||||||
import android.view.ViewGroup
|
//import com.shuwei.dish.match.utils.ext.dp
|
||||||
import androidx.core.graphics.toColorInt
|
//
|
||||||
import androidx.core.view.updateLayoutParams
|
///**
|
||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
// * 调料格子列表适配器,使用 list_item_cell 布局展示调料名称与用量
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
// */
|
||||||
import com.shuwei.dish.match.databinding.ListItemCellBinding
|
//class SeasoningAdapter(list: MutableList<GoodsItem>) :
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
// BaseQuickAdapter<GoodsItem, SeasoningAdapter.VH>(list) {
|
||||||
import com.shuwei.dish.match.utils.ext.appendText
|
//
|
||||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
// override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
// val binding = ListItemCellBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
// return VH(binding)
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* 调料格子列表适配器,使用 list_item_cell 布局展示调料名称与用量
|
// override fun onBindViewHolder(holder: VH, position: Int, item: GoodsItem?) {
|
||||||
* 第4个格子(position=3)为大格,其余为标准格
|
// item ?: return
|
||||||
*/
|
// holder.binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
class SeasoningAdapter(list: MutableList<GoodsItem>) :
|
// width = 226.dp
|
||||||
BaseQuickAdapter<GoodsItem, SeasoningAdapter.VH>(list) {
|
// height = 120.dp
|
||||||
|
// leftMargin = 7.dp
|
||||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
// rightMargin = 8.dp
|
||||||
val binding = ListItemCellBinding.inflate(LayoutInflater.from(context), parent, false)
|
// topMargin = 7.dp
|
||||||
return VH(binding)
|
// bottomMargin = 8.dp
|
||||||
}
|
// }
|
||||||
|
// holder.binding.tvCell.text = TextCellAdapter.getTextSpan(item.toSeasoningEntity())
|
||||||
override fun onBindViewHolder(holder: VH, position: Int, item: GoodsItem?) {
|
// }
|
||||||
item ?: return
|
//
|
||||||
// 第10个格子(index=9)使用大尺寸,其余使用标准尺寸
|
// inner class VH(val binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
||||||
val isLarge = position == 9
|
//}
|
||||||
holder.binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
||||||
width = if (isLarge) 467.dp else 226.dp
|
|
||||||
height = if (isLarge) 255.dp else 120.dp
|
|
||||||
leftMargin = 7.dp
|
|
||||||
rightMargin = 8.dp
|
|
||||||
topMargin = 7.dp
|
|
||||||
bottomMargin = 8.dp
|
|
||||||
}
|
|
||||||
holder.binding.tvCell.text = getTextSpan(position, item)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class VH(val binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
|
||||||
|
|
||||||
fun getTextSpan(position: Int, item: GoodsItem): SpannableStringBuilder {
|
|
||||||
val endIndex = if (position == 9) 10 else 6
|
|
||||||
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
|
||||||
if (name.length > endIndex) {
|
|
||||||
name = "${name.substring(0, endIndex)}…"
|
|
||||||
}
|
|
||||||
return buildSpannableString {
|
|
||||||
appendText(
|
|
||||||
name,
|
|
||||||
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
|
||||||
StyleSpan(Typeface.BOLD),
|
|
||||||
AbsoluteSizeSpan(28, true),
|
|
||||||
LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
|
||||||
fm.descent += 10.dp // 增加行间距
|
|
||||||
}
|
|
||||||
)
|
|
||||||
append("\n")
|
|
||||||
val weight = item.useWeight ?: 0.toDouble()
|
|
||||||
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
|
||||||
appendText(
|
|
||||||
// "${DecimalFormat("#").format(weight)}g",
|
|
||||||
"${weight.roundedOneDecimalPlace()}g",
|
|
||||||
ForegroundColorSpan(weightColor.toColorInt()),
|
|
||||||
AbsoluteSizeSpan(30, true)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,137 +1,137 @@
|
|||||||
package com.shuwei.dish.match.adapter
|
//package com.shuwei.dish.match.adapter
|
||||||
|
//
|
||||||
import android.graphics.Typeface
|
//import android.graphics.Typeface
|
||||||
import android.icu.text.DecimalFormat
|
//import android.icu.text.DecimalFormat
|
||||||
import android.text.SpannableStringBuilder
|
//import android.text.SpannableStringBuilder
|
||||||
import android.text.style.AbsoluteSizeSpan
|
//import android.text.style.AbsoluteSizeSpan
|
||||||
import android.text.style.ForegroundColorSpan
|
//import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.LineHeightSpan
|
//import android.text.style.LineHeightSpan
|
||||||
import android.text.style.StyleSpan
|
//import android.text.style.StyleSpan
|
||||||
import android.view.LayoutInflater
|
//import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
//import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
//import android.widget.FrameLayout
|
||||||
import android.widget.TextView
|
//import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
//import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.toColorInt
|
//import androidx.core.graphics.toColorInt
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
//import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
//import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
//import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemCellBinding
|
//import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
//import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
//import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.ext.appendText
|
//import com.shuwei.dish.match.utils.ext.appendText
|
||||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
//import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
//import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
//import com.shuwei.dish.match.utils.ext.dp
|
||||||
import com.shuwei.dish.match.utils.ext.invisible
|
//import com.shuwei.dish.match.utils.ext.invisible
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
//import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
//import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
//
|
||||||
class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
|
//class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
|
||||||
RecyclerView.Adapter<TextCellAdapter.VH>() {
|
// RecyclerView.Adapter<TextCellAdapter.VH>() {
|
||||||
|
//
|
||||||
inner class VH(var binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
// inner class VH(var binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
||||||
|
//
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
// val inflater = LayoutInflater.from(parent.context)
|
||||||
val binding = ListItemCellBinding.inflate(inflater, parent, false)
|
// val binding = ListItemCellBinding.inflate(inflater, parent, false)
|
||||||
return VH(binding)
|
// return VH(binding)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onBindViewHolder(holder: VH, position: Int) {
|
// override fun onBindViewHolder(holder: VH, position: Int) {
|
||||||
val item = list[position]
|
// val item = list[position]
|
||||||
holder.binding.run {
|
// holder.binding.run {
|
||||||
if (position == 10 || position == 11 || position == 13 || position == 14) {
|
// if (position == 10 || position == 11 || position == 13 || position == 14) {
|
||||||
root.invisible()
|
// root.invisible()
|
||||||
} else {
|
|
||||||
root.visible()
|
|
||||||
}
|
|
||||||
loadCell(tvCell, item)
|
|
||||||
//root.setBackgroundResource(R.color.dish_green)
|
|
||||||
(root.layoutParams as RecyclerView.LayoutParams).let {
|
|
||||||
// it.bottomMargin = 15.dp
|
|
||||||
it.width = 226.dp
|
|
||||||
it.height = 120.dp
|
|
||||||
// it.rightMargin = 0
|
|
||||||
// it.leftMargin = if (position % 3 == 0) 0 else 15.dp
|
|
||||||
|
|
||||||
it.leftMargin = 7.dp
|
|
||||||
it.rightMargin = 8.dp
|
|
||||||
it.topMargin = 7.dp
|
|
||||||
it.bottomMargin = 8.dp
|
|
||||||
}
|
|
||||||
if (item.pageType == 1) {
|
|
||||||
root.clickWithDebounce { onCellClick?.invoke(position) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemCount() = list.size
|
|
||||||
|
|
||||||
var onCellClick: ((positon: Int) -> Unit)? = null
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
|
||||||
val child: TextView = frameLayout.getChildAt(0) as TextView
|
|
||||||
child.text = getTextSpan(item)
|
|
||||||
}
|
|
||||||
fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
|
||||||
tvCell.text = getTextSpan(item)
|
|
||||||
}
|
|
||||||
// fun loadCell2(tvCell: TextView, item: SeasoningEntity) {
|
|
||||||
// if (item.goodsName.isNullOrBlank()) {
|
|
||||||
// tvCell.run {
|
|
||||||
// text = buildSpannableString {
|
|
||||||
// appendText(
|
|
||||||
// "未配置",
|
|
||||||
// ForegroundColorSpan("#999999".toColorInt()),
|
|
||||||
// StyleSpan(Typeface.BOLD),
|
|
||||||
// AbsoluteSizeSpan(28, true),
|
|
||||||
// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
|
||||||
// fm.descent += 10.dp // 增加行间距
|
|
||||||
// }
|
|
||||||
// )}
|
|
||||||
// //setTextColor(ContextCompat.getColor(context, R.color.black999))
|
|
||||||
// }
|
|
||||||
// } else {
|
// } else {
|
||||||
//// if (item.pageType == 1) {
|
// root.visible()
|
||||||
//// tvCell.run {
|
// }
|
||||||
//// text = item.goodsName
|
// loadCell(tvCell, item)
|
||||||
//// setTextColor(ContextCompat.getColor(context, R.color.black))
|
// //root.setBackgroundResource(R.color.dish_green)
|
||||||
//// }
|
// (root.layoutParams as RecyclerView.LayoutParams).let {
|
||||||
//// } else {
|
//// it.bottomMargin = 15.dp
|
||||||
// tvCell.text = getTextSpan(item)
|
// it.width = 226.dp
|
||||||
//// }
|
// it.height = 120.dp
|
||||||
|
//// it.rightMargin = 0
|
||||||
|
//// it.leftMargin = if (position % 3 == 0) 0 else 15.dp
|
||||||
|
//
|
||||||
|
// it.leftMargin = 7.dp
|
||||||
|
// it.rightMargin = 8.dp
|
||||||
|
// it.topMargin = 7.dp
|
||||||
|
// it.bottomMargin = 8.dp
|
||||||
|
// }
|
||||||
|
// if (item.pageType == 1) {
|
||||||
|
// root.clickWithDebounce { onCellClick?.invoke(position) }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
//
|
||||||
val endIndex = if (item.sort == 9) 10 else 6
|
// override fun getItemCount() = list.size
|
||||||
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
//
|
||||||
if (name.length > endIndex) {
|
// var onCellClick: ((positon: Int) -> Unit)? = null
|
||||||
name = "${name.substring(0, endIndex)}…"
|
//
|
||||||
}
|
// companion object {
|
||||||
return buildSpannableString {
|
// fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
||||||
appendText(
|
// val child: TextView = frameLayout.getChildAt(0) as TextView
|
||||||
name,
|
// child.text = getTextSpan(item)
|
||||||
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
// }
|
||||||
StyleSpan(Typeface.BOLD),
|
// fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
||||||
AbsoluteSizeSpan(28, true),
|
// tvCell.text = getTextSpan(item)
|
||||||
LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
// }
|
||||||
fm.descent += 10.dp // 增加行间距
|
//// fun loadCell2(tvCell: TextView, item: SeasoningEntity) {
|
||||||
}
|
//// if (item.goodsName.isNullOrBlank()) {
|
||||||
)
|
//// tvCell.run {
|
||||||
append("\n")
|
//// text = buildSpannableString {
|
||||||
val weight = item.useWeight ?: 0.toDouble()
|
//// appendText(
|
||||||
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
//// "未配置",
|
||||||
appendText(
|
//// ForegroundColorSpan("#999999".toColorInt()),
|
||||||
// "${DecimalFormat("#").format(weight)}g",
|
//// StyleSpan(Typeface.BOLD),
|
||||||
"${weight.roundedOneDecimalPlace()}g",
|
//// AbsoluteSizeSpan(28, true),
|
||||||
ForegroundColorSpan(weightColor.toColorInt()),
|
//// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||||
AbsoluteSizeSpan(30, true)
|
//// fm.descent += 10.dp // 增加行间距
|
||||||
)
|
//// }
|
||||||
}
|
//// )}
|
||||||
}
|
//// //setTextColor(ContextCompat.getColor(context, R.color.black999))
|
||||||
}
|
//// }
|
||||||
|
//// } else {
|
||||||
}
|
////// if (item.pageType == 1) {
|
||||||
|
////// tvCell.run {
|
||||||
|
////// text = item.goodsName
|
||||||
|
////// setTextColor(ContextCompat.getColor(context, R.color.black))
|
||||||
|
////// }
|
||||||
|
////// } else {
|
||||||
|
//// tvCell.text = getTextSpan(item)
|
||||||
|
////// }
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||||
|
// val endIndex = if (item.sort == 9) 10 else 6
|
||||||
|
// var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||||
|
// if (name.length > endIndex) {
|
||||||
|
// name = "${name.substring(0, endIndex)}…"
|
||||||
|
// }
|
||||||
|
// return buildSpannableString {
|
||||||
|
// appendText(
|
||||||
|
// name,
|
||||||
|
// ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
||||||
|
// StyleSpan(Typeface.BOLD),
|
||||||
|
// AbsoluteSizeSpan(28, true),
|
||||||
|
// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||||
|
// fm.descent += 10.dp // 增加行间距
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
// append("\n")
|
||||||
|
// val weight = item.useWeight ?: 0.toDouble()
|
||||||
|
// val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
||||||
|
// appendText(
|
||||||
|
//// "${DecimalFormat("#").format(weight)}g",
|
||||||
|
// "${weight.roundedOneDecimalPlace()}g",
|
||||||
|
// ForegroundColorSpan(weightColor.toColorInt()),
|
||||||
|
// AbsoluteSizeSpan(30, true)
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
@@ -9,17 +9,12 @@ import android.text.style.LineHeightSpan
|
|||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
|
import android.widget.FrameLayout
|
||||||
import androidx.core.graphics.toColorInt
|
import androidx.core.graphics.toColorInt
|
||||||
import com.google.android.flexbox.FlexDirection
|
import androidx.core.view.forEach
|
||||||
import com.google.android.flexbox.FlexboxLayoutManager
|
|
||||||
import com.google.android.flexbox.FlexWrap
|
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
|
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
|
||||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
|
||||||
import com.shuwei.dish.match.utils.AddressUtil
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
import com.shuwei.dish.match.utils.MultiClickDetector
|
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.ext.appendText
|
import com.shuwei.dish.match.utils.ext.appendText
|
||||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||||
@@ -27,10 +22,12 @@ import com.shuwei.dish.match.utils.ext.dp
|
|||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import com.shuwei.dish.match.adapter.SeasoningAdapter
|
|
||||||
import com.shuwei.dish.match.databinding.ActivityDeviceConfigBinding
|
import com.shuwei.dish.match.databinding.ActivityDeviceConfigBinding
|
||||||
import com.shuwei.dish.match.dialog.BottomDialog2
|
import com.shuwei.dish.match.dialog.BottomDialog2
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.SpTool
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
|
import com.shuwei.dish.match.utils.TextCellTool
|
||||||
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
|
|
||||||
class DeviceConfigActivity : BaseActivity() {
|
class DeviceConfigActivity : BaseActivity() {
|
||||||
@@ -56,7 +53,8 @@ class DeviceConfigActivity : BaseActivity() {
|
|||||||
private lateinit var binding: ActivityDeviceConfigBinding
|
private lateinit var binding: ActivityDeviceConfigBinding
|
||||||
|
|
||||||
private var cookMode: Int = 0
|
private var cookMode: Int = 0
|
||||||
// private val weightArray = SparseIntArray()
|
|
||||||
|
// private val weightArray = SparseIntArray()
|
||||||
private val weightArray = SparseArray<Double>()
|
private val weightArray = SparseArray<Double>()
|
||||||
private val addressArray = AddressUtil.getWeighAddressArray()
|
private val addressArray = AddressUtil.getWeighAddressArray()
|
||||||
|
|
||||||
@@ -117,7 +115,7 @@ class DeviceConfigActivity : BaseActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
addWeighListener()
|
addWeighListener()
|
||||||
setupRecyclerView()
|
addGridItemListener()
|
||||||
loadSeasoning()
|
loadSeasoning()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,61 +123,56 @@ class DeviceConfigActivity : BaseActivity() {
|
|||||||
WeightUtil.addWeightListener(
|
WeightUtil.addWeightListener(
|
||||||
weightKey = TAG,
|
weightKey = TAG,
|
||||||
getWeight = { address, state, weight ->
|
getWeight = { address, state, weight ->
|
||||||
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
||||||
weightArray.put(address, weight)
|
weightArray.put(address, weight)
|
||||||
// val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
||||||
// item?.let {
|
item?.let {
|
||||||
// it.useWeight = weight.toDouble()
|
it.useWeight = weight
|
||||||
//// updateGridData(it)
|
updateGridData(it)
|
||||||
// }
|
}
|
||||||
Log.d(TAG, "addWeighListener: update-----------------------")
|
Log.d(TAG, "addWeighListener: update-----------------------")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
private val seasoningItems = MutableList(12) { GoodsItem() }
|
|
||||||
private val seasoningAdapter by lazy {
|
private var seasoningItems = mutableListOf<SeasoningEntity>()
|
||||||
SeasoningAdapter(seasoningItems).apply {
|
|
||||||
setOnItemClickListener { adapter, _, position ->
|
private fun updateGridData(entity: SeasoningEntity) {
|
||||||
val item = adapter.getItem(position) ?: return@setOnItemClickListener
|
val gridLayout = binding.include.root
|
||||||
clickGridItem(position,item.toSeasoningEntity())
|
val tag = entity.sort.toString()
|
||||||
|
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||||
|
TextCellTool.loadLayout(frameLayout, entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addGridItemListener() {
|
||||||
|
binding.include.root.forEach { child ->
|
||||||
|
child.clickWithDebounce {
|
||||||
|
val sort = child.tag.toString().toInt()
|
||||||
|
val entity = seasoningItems.firstOrNull { it.sort == sort }
|
||||||
|
?: SeasoningEntity().also { it.sort = sort }
|
||||||
|
clickGridItem(sort, entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
|
||||||
// 初始化 FlexboxLayoutManager,横向排列(FlexDirection.ROW)
|
|
||||||
val flexboxLayoutManager = FlexboxLayoutManager(this).apply {
|
|
||||||
flexDirection = FlexDirection.ROW
|
|
||||||
flexWrap = FlexWrap.WRAP
|
|
||||||
}
|
|
||||||
binding.rvSeasoning.layoutManager = flexboxLayoutManager
|
|
||||||
binding.rvSeasoning.adapter = seasoningAdapter
|
|
||||||
}
|
|
||||||
|
|
||||||
val detector = MultiClickDetector(targetCount = 10, intervalMs = 800)
|
|
||||||
|
|
||||||
private fun defaultDataSettingDialog() {
|
|
||||||
val remindBinding = LayoutFoodRemindBinding.inflate(layoutInflater)
|
|
||||||
remindBinding.tvDialogTitle.text = "温馨提示"
|
|
||||||
remindBinding.tvDialogContent.text =
|
|
||||||
"您好,使用默认配置作为您的调料数据,则已有配置将被清除,确认吗?"
|
|
||||||
CommonDialog(this).apply {
|
|
||||||
messageView = remindBinding.root
|
|
||||||
leftText = "取消"
|
|
||||||
rightText = "确认"
|
|
||||||
onLeftClick = { dismiss() }
|
|
||||||
onRightClick = {
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
onDismiss = { hideStatusBar() }
|
|
||||||
}.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadSeasoning() {
|
private fun loadSeasoning() {
|
||||||
|
Log.d(TAG, "loadSeasoning,start-----------------------")
|
||||||
appViewModel.loadSeasoning { list ->
|
appViewModel.loadSeasoning { list ->
|
||||||
|
Log.d(TAG, "loadSeasoning,list.size=${list.size}-----------------------")
|
||||||
seasoningItems.clear()
|
seasoningItems.clear()
|
||||||
// 将 SeasoningEntity 转为 GoodsItem 后提交给 adapter
|
// 补全缺失的格子:对 0~11 中没有对应 sort 的位置,追加空实体
|
||||||
val goodsItems = list.map { it.toGoodsItem() }
|
val existingSorts = list.map { it.sort }.toSet()
|
||||||
seasoningAdapter.submitList(goodsItems)
|
for (index in 0 until 12) {
|
||||||
|
if (index !in existingSorts) {
|
||||||
|
list.add(SeasoningEntity().also { it.sort = index })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seasoningItems.addAll(list)
|
||||||
|
// 按 sort 字段找到对应 FrameLayout,填充数据
|
||||||
|
list.forEach { entity ->
|
||||||
|
val tag = entity.sort.toString()
|
||||||
|
val frameLayout = binding.include.root.findViewWithTag<FrameLayout>(tag)
|
||||||
|
frameLayout?.let { TextCellTool.loadLayout(it, entity) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,25 +184,11 @@ class DeviceConfigActivity : BaseActivity() {
|
|||||||
clickName = entity.goodsName
|
clickName = entity.goodsName
|
||||||
).show(this) { item ->
|
).show(this) { item ->
|
||||||
syncItem(entity, item)
|
syncItem(entity, item)
|
||||||
//3-调料
|
|
||||||
entity.materialType = 3
|
entity.materialType = 3
|
||||||
entity.sort = sort
|
entity.sort = sort
|
||||||
saveSeasoning(entity) {
|
saveSeasoning(entity) {
|
||||||
// 更新 adapter 中对应位置的数据
|
val frameLayout = binding.include.root.findViewWithTag<FrameLayout>(sort.toString())
|
||||||
val goodsItem = GoodsItem(
|
frameLayout?.let { TextCellTool.loadLayout(it, entity) }
|
||||||
goodsId = entity.goodsId,
|
|
||||||
goodsName = entity.goodsName,
|
|
||||||
popularName = entity.popularName,
|
|
||||||
zjmCode = entity.zjmCode,
|
|
||||||
materId = entity.materId,
|
|
||||||
materialType = entity.materialType,
|
|
||||||
useWeight = entity.useWeight,
|
|
||||||
relateionType = entity.relateionType,
|
|
||||||
allEdible = entity.allEdible,
|
|
||||||
goodsOrRelationCode = entity.goodsOrRelationCode,
|
|
||||||
rawMaterialsType = entity.rawMaterialsType
|
|
||||||
)
|
|
||||||
seasoningAdapter.set(sort, goodsItem)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ import android.util.Log
|
|||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.util.forEach
|
import androidx.core.util.forEach
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.TextCellAdapter
|
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
||||||
@@ -26,6 +24,7 @@ import androidx.lifecycle.repeatOnLifecycle
|
|||||||
import com.shuwei.dish.match.model.toDTO
|
import com.shuwei.dish.match.model.toDTO
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.AddressUtil
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
|
import com.shuwei.dish.match.utils.TextCellTool
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
@@ -222,7 +221,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
val gridLayout = binding.include.root
|
val gridLayout = binding.include.root
|
||||||
val tag = entity.sort.toString()
|
val tag = entity.sort.toString()
|
||||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||||
TextCellAdapter.loadLayout(frameLayout , entity)
|
TextCellTool.loadLayout(frameLayout , entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCookingSeasoning(address: Int): Double {
|
private fun getCookingSeasoning(address: Int): Double {
|
||||||
@@ -444,7 +443,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
list.forEach { entity ->
|
list.forEach { entity ->
|
||||||
val tag = entity.sort.toString()
|
val tag = entity.sort.toString()
|
||||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
TextCellTool.loadLayout(frameLayout, entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.shuwei.dish.match.utils
|
||||||
|
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.text.SpannableStringBuilder
|
||||||
|
import android.text.style.AbsoluteSizeSpan
|
||||||
|
import android.text.style.ForegroundColorSpan
|
||||||
|
import android.text.style.LineHeightSpan
|
||||||
|
import android.text.style.StyleSpan
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.graphics.toColorInt
|
||||||
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
|
import com.shuwei.dish.match.utils.ext.appendText
|
||||||
|
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||||
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
|
|
||||||
|
object TextCellTool {
|
||||||
|
|
||||||
|
fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
||||||
|
val child: TextView = frameLayout.getChildAt(0) as TextView
|
||||||
|
child.text = getTextSpan(item)
|
||||||
|
}
|
||||||
|
fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
||||||
|
tvCell.text = getTextSpan(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||||
|
val endIndex = if (item.sort == 9) 10 else 6
|
||||||
|
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||||
|
if (name.length > endIndex) {
|
||||||
|
name = "${name.take(endIndex)}…"
|
||||||
|
}
|
||||||
|
return buildSpannableString {
|
||||||
|
appendText(
|
||||||
|
name,
|
||||||
|
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
||||||
|
StyleSpan(Typeface.BOLD),
|
||||||
|
AbsoluteSizeSpan(28, true),
|
||||||
|
LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||||
|
fm.descent += 10.dp // 增加行间距
|
||||||
|
}
|
||||||
|
)
|
||||||
|
append("\n")
|
||||||
|
val weight = item.useWeight ?: 0.toDouble()
|
||||||
|
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
||||||
|
appendText(
|
||||||
|
// "${DecimalFormat("#").format(weight)}g",
|
||||||
|
"${weight.roundedOneDecimalPlace()}g",
|
||||||
|
ForegroundColorSpan(weightColor.toColorInt()),
|
||||||
|
AbsoluteSizeSpan(30, true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -128,10 +128,11 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<include
|
||||||
android:id="@+id/rvSeasoning"
|
android:id="@+id/include"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="725dp" />
|
android:layout_height="wrap_content"
|
||||||
|
layout="@layout/layout_grid" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user