布局优化
This commit is contained in:
@@ -7,22 +7,22 @@ import androidx.core.view.updateLayoutParams
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
|
||||
/**
|
||||
* 调料格子列表适配器,使用 list_item_cell 布局展示调料名称与用量
|
||||
* 第4个格子(position=3)为大格,其余为标准格
|
||||
*/
|
||||
class SeasoningAdapter(list: MutableList<SeasoningEntity>) :
|
||||
BaseQuickAdapter<SeasoningEntity, SeasoningAdapter.VH>(list) {
|
||||
class SeasoningAdapter(list: MutableList<GoodsItem>) :
|
||||
BaseQuickAdapter<GoodsItem, SeasoningAdapter.VH>(list) {
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val binding = ListItemCellBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: SeasoningEntity?) {
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: GoodsItem?) {
|
||||
item ?: return
|
||||
// 第4个格子(index=3)使用大尺寸,其余使用标准尺寸
|
||||
val isLarge = position == 3
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
@@ -104,6 +105,9 @@ class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
|
||||
// }
|
||||
// }
|
||||
|
||||
fun getTextSpan(item: GoodsItem): SpannableStringBuilder {
|
||||
return getTextSpan(item.toSeasoningEntity())
|
||||
}
|
||||
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||
val endIndex = if (item.sort == 9) 10 else 6
|
||||
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||
|
||||
@@ -78,13 +78,6 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
it.text = "设备配置"
|
||||
}, rightIconActon = {
|
||||
it.gone()
|
||||
// it.alpha = 0.0F
|
||||
// it.setImageResource(R.drawable.ic_setting)
|
||||
// it.setOnClickListener {_->
|
||||
// detector.setOnDelayedMultiClickListener(it) {
|
||||
// defaultDataSettingDialog()
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
loadQualitySpan(isEnable = false)
|
||||
@@ -174,31 +167,11 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
onLeftClick = { dismiss() }
|
||||
onRightClick = {
|
||||
dismiss()
|
||||
resetList()
|
||||
}
|
||||
onDismiss = { hideStatusBar() }
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun resetList() {
|
||||
runCatching {
|
||||
val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(
|
||||
this,
|
||||
"default_seasoning_list.json"
|
||||
)
|
||||
// val weightArray = WeightUtil.weightArray
|
||||
appViewModel.clearAllSeasoning {
|
||||
record?.list?.forEach { entity ->
|
||||
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
|
||||
appViewModel.saveSeasoning(entity) {
|
||||
updateGridData(entity)
|
||||
}
|
||||
}
|
||||
// loadSeasoning()
|
||||
}
|
||||
}.onFailure { it.printStackTrace() }
|
||||
}
|
||||
|
||||
private fun loadSeasoning() {
|
||||
appViewModel.loadSeasoning {
|
||||
seasoningItems.clear()
|
||||
@@ -208,31 +181,6 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initConfigData() {
|
||||
repeat(12) { num ->
|
||||
val firstOne = seasoningItems.firstOrNull { it.sort == num }
|
||||
if (firstOne == null) {
|
||||
seasoningItems.add(SeasoningEntity().also { it.sort = num })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setGridData(list: MutableList<SeasoningEntity>) {
|
||||
val gridLayout = binding.include.root
|
||||
list.forEach { entity ->
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGridData(entity: SeasoningEntity) {
|
||||
val gridLayout = binding.include.root
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
|
||||
private fun clickGridItem(sort: Int, entity: SeasoningEntity) {
|
||||
val currentAddress = AddressUtil.getWeighAddressArray().get(sort)
|
||||
// val seasoningEntity = list.first{it.sort == sort}
|
||||
|
||||
@@ -126,12 +126,6 @@
|
||||
android:textColor="@color/gray_b4"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<!-- <View-->
|
||||
<!-- android:id="@+id/viewPoint"-->
|
||||
<!-- android:layout_width="5dp"-->
|
||||
<!-- android:layout_height="5dp"-->
|
||||
<!-- android:layout_gravity="center_vertical"-->
|
||||
<!-- android:background="@drawable/bg_circle_green"/>-->
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
|
||||
Reference in New Issue
Block a user