优化
This commit is contained in:
@@ -22,7 +22,6 @@ import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.objbox.Food
|
||||
import com.sw.inbound.objbox.FoodCollectionBean
|
||||
import com.sw.inbound.objbox.FoodModule
|
||||
import com.sw.inbound.objbox.Food_
|
||||
import com.sw.inbound.objbox.ObjectBox
|
||||
import com.sw.inbound.utils.BitmapCropper
|
||||
import com.sw.inbound.utils.BitmapSaver
|
||||
@@ -153,25 +152,25 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
binding.btnTakePhoto.clickWithDebounce {
|
||||
takePhoto()
|
||||
}
|
||||
binding.btnAddDefault.clickWithDebounce {
|
||||
Thread{
|
||||
FoodModule.initDefFoodData(this) {
|
||||
runOnUiThread {
|
||||
toast("添加完成")
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
binding.btnRemoveDefault.clickWithDebounce {
|
||||
initBox()
|
||||
val list = box?.all?.filter { it.foodIdx == FoodModule.DEFAULT_FOOD_INDEX }
|
||||
if (list.isNullOrEmpty()) {
|
||||
toast("不存在默认数据")
|
||||
return@clickWithDebounce
|
||||
}
|
||||
box?.removeByIds(list.map { it.id })
|
||||
toast("移除完成")
|
||||
}
|
||||
// binding.btnAddDefault.clickWithDebounce {
|
||||
// Thread{
|
||||
// FoodModule.initDefFoodData(this) {
|
||||
// runOnUiThread {
|
||||
// toast("添加完成")
|
||||
// }
|
||||
// }
|
||||
// }.start()
|
||||
// }
|
||||
// binding.btnRemoveDefault.clickWithDebounce {
|
||||
// initBox()
|
||||
// val list = box?.all?.filter { it.foodIdx == FoodModule.DEFAULT_FOOD_INDEX }
|
||||
// if (list.isNullOrEmpty()) {
|
||||
// toast("不存在默认数据")
|
||||
// return@clickWithDebounce
|
||||
// }
|
||||
// box?.removeByIds(list.map { it.id })
|
||||
// toast("移除完成")
|
||||
// }
|
||||
binding.btnClearData.setOnClickListener { clearData() }
|
||||
binding.rvSearch.let {
|
||||
it.layoutManager = GridLayoutManager(this, 2, LinearLayoutManager.VERTICAL, false)
|
||||
@@ -188,31 +187,31 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
searchGoods()
|
||||
}
|
||||
}
|
||||
binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
if (checkedId == R.id.rbCollected) {
|
||||
binding.llSearchInput.gone()
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(false)
|
||||
it.setEnableLoadMore(false)
|
||||
}
|
||||
getCollectedGoods()
|
||||
return@setOnCheckedChangeListener
|
||||
}
|
||||
if (checkedId == R.id.rbSearch) {
|
||||
binding.llSearchInput.visible()
|
||||
pageNo = 1
|
||||
clickIndex = -1
|
||||
searchGoodsList.clear()
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
it.setEnableLoadMore(false)
|
||||
}
|
||||
loadEmptyView()
|
||||
return@setOnCheckedChangeListener
|
||||
}
|
||||
}
|
||||
binding.radioGroup.check(R.id.rbCollected)
|
||||
// binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
// if (checkedId == R.id.rbCollected) {
|
||||
// binding.llSearchInput.gone()
|
||||
// binding.refreshLayout.let {
|
||||
// it.setEnableRefresh(false)
|
||||
// it.setEnableLoadMore(false)
|
||||
// }
|
||||
// getCollectedGoods()
|
||||
// return@setOnCheckedChangeListener
|
||||
// }
|
||||
// if (checkedId == R.id.rbSearch) {
|
||||
// binding.llSearchInput.visible()
|
||||
// pageNo = 1
|
||||
// clickIndex = -1
|
||||
// searchGoodsList.clear()
|
||||
// searchAdapter.notifyDataSetChanged()
|
||||
// binding.refreshLayout.let {
|
||||
// it.setEnableRefresh(true)
|
||||
// it.setEnableLoadMore(false)
|
||||
// }
|
||||
// loadEmptyView()
|
||||
// return@setOnCheckedChangeListener
|
||||
// }
|
||||
// }
|
||||
// binding.radioGroup.check(R.id.rbCollected)
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.sw.inbound.databinding.ActivityGoodsListBinding
|
||||
import com.sw.inbound.databinding.LayoutCameraPreviewBinding
|
||||
import com.sw.inbound.databinding.ListItemReceiptGoodsBinding
|
||||
import com.sw.inbound.databinding.ListItemSelfProcurementBinding
|
||||
import com.sw.inbound.dialog.DialogManager
|
||||
import com.sw.inbound.dialog.DropdownPopup
|
||||
import com.sw.inbound.dialog.GoodsRecognizeDialog
|
||||
import com.sw.inbound.dialog.GoodsSearchDialog
|
||||
@@ -60,7 +61,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
public const val IS_NEW_RECEIPT = "isNewReceipt"
|
||||
|
||||
const val PAGE_SIZE = 10
|
||||
private const val DELAY_TIME = 30 * 1000
|
||||
private const val DELAY_TIME = 10 * 1000
|
||||
}
|
||||
|
||||
var isReceiptPage: Boolean = false
|
||||
@@ -164,10 +165,12 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
//}
|
||||
if (weight < 200) {
|
||||
if (abs(weight) < 10) {
|
||||
if (goodsRecognizeDialog?.isShowing == true) {
|
||||
goodsRecognizeDialog?.dismiss()
|
||||
isShowRecognizeDialog = true
|
||||
goodsRecognizeDialog = null
|
||||
if (DialogManager.getDialogList().size == 1 &&
|
||||
DialogManager.contains("GoodsRecognizeDialog") &&
|
||||
goodsRecognizeDialog?.isShowing == true) {
|
||||
goodsRecognizeDialog?.dismiss()
|
||||
isShowRecognizeDialog = true
|
||||
goodsRecognizeDialog = null
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,4 +47,14 @@ abstract class BaseDialog(
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
DialogManager.addDialog(this)
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
super.dismiss()
|
||||
DialogManager.removeDialog(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.sw.inbound.dialog
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.activity.GoodsListActivity
|
||||
import com.sw.inbound.adapter.CollectSearchAdapter
|
||||
import com.sw.inbound.databinding.DialogCollectSearchBinding
|
||||
import com.sw.inbound.databinding.LayoutEmptySearchBinding
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.objbox.Food
|
||||
import com.sw.inbound.objbox.ObjectBox
|
||||
import com.sw.inbound.utils.ext.addOnActionSearchListener
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import io.objectbox.Box
|
||||
import io.objectbox.kotlin.boxFor
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class CollectSearchDialog(
|
||||
context: Context
|
||||
) : BaseDialog(context) {
|
||||
|
||||
private lateinit var inflater: LayoutInflater
|
||||
private var emptyBinding: LayoutEmptySearchBinding? = null
|
||||
private lateinit var binding: DialogCollectSearchBinding
|
||||
override fun getRootView(): View {
|
||||
inflater = LayoutInflater.from(context)
|
||||
binding = DialogCollectSearchBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private var activity: GoodsListActivity? = null
|
||||
override fun initView() {
|
||||
activity = getReceiptActivity()
|
||||
binding.ivClose.setOnClickListener { dismiss() }
|
||||
binding.ivGoodsSearch.setOnClickListener { searchGoods() }
|
||||
binding.etInputGoods.let { v ->
|
||||
v.addOnActionSearchListener {
|
||||
searchGoods()
|
||||
}
|
||||
}
|
||||
binding.btnConfirm.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
binding.rvSearch.let {
|
||||
it.layoutManager = GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL, false)
|
||||
it.adapter = searchAdapter
|
||||
}
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
it.setEnableLoadMore(false)
|
||||
it.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
searchGoods()
|
||||
}
|
||||
it.setOnLoadMoreListener {
|
||||
searchGoods()
|
||||
}
|
||||
}
|
||||
getCollectGoods()
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
|
||||
companion object {
|
||||
private const val PAGE_SIZE = 10
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun searchGoods() {
|
||||
val searchName = binding.etInputGoods.text.toString().trim()
|
||||
if (searchName.isBlank()) {
|
||||
activity?.toast("请输入物品名称")
|
||||
finishRefresh()
|
||||
return
|
||||
}
|
||||
activity?.searchGoods(
|
||||
searchName = searchName,
|
||||
pageNo = pageNo,
|
||||
pageSize = PAGE_SIZE
|
||||
) { records ->
|
||||
finishRefresh()
|
||||
binding.etInputGoods.hideKeyboard()
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
if (list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
return@searchGoods
|
||||
}
|
||||
val enableLoadMore = records.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(enableLoadMore)
|
||||
if (enableLoadMore) {
|
||||
pageNo++
|
||||
}
|
||||
binding.rvSearch.layoutManager =
|
||||
GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadEmptyView() {
|
||||
binding.rvSearch.layoutManager =
|
||||
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
if (emptyBinding == null) {
|
||||
emptyBinding = LayoutEmptySearchBinding.inflate(inflater, binding.rvSearch, false)
|
||||
}
|
||||
emptyBinding?.root?.let { layout ->
|
||||
layout.setOnClickListener { layout.hideKeyboard() }
|
||||
searchAdapter.stateView = layout
|
||||
}
|
||||
}
|
||||
|
||||
private var clickIndex = -1
|
||||
|
||||
private val list: MutableList<SearchGoodsInfo.Record> = mutableListOf()
|
||||
private val searchAdapter by lazy {
|
||||
CollectSearchAdapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
setOnItemClickListener { _, _, position ->
|
||||
this@CollectSearchDialog.clickIndex = position
|
||||
if (list[position].isSelected) {
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
list.forEach { item ->
|
||||
item.isSelected = false
|
||||
}
|
||||
list[position].isSelected = true
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
||||
deleteGoods(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteGoods(position:Int) {
|
||||
WarnDialog(context = context, content = "请确认是否删除该物品?", confirmBlock = {
|
||||
Thread{
|
||||
activity?.runOnUiThread {
|
||||
Loading.show(context)
|
||||
}
|
||||
val name = list[position].goodsName
|
||||
val filterIdList = box?.all?.filter { it.name == name }?.map { it.id }
|
||||
box?.removeByIds(filterIdList)
|
||||
activity?.runOnUiThread {
|
||||
Loading.dismiss()
|
||||
list.removeAt(position)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
activity?.toast("删除成功")
|
||||
}
|
||||
}.start()
|
||||
}).show()
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
binding.refreshLayout.let {
|
||||
if (pageNo == 1) {
|
||||
it.finishRefresh(500)
|
||||
} else {
|
||||
it.finishLoadMore(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var box: Box<Food>? = null
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getCollectGoods() {
|
||||
if (box == null) {
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
}
|
||||
box?.all?.distinctBy { it.name }?.forEach {
|
||||
list.add((SearchGoodsInfo.Record(goodsName = it.name)))
|
||||
}
|
||||
binding.rvSearch.layoutManager = GridLayoutManager(activity, 2, LinearLayoutManager.VERTICAL, false)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
if (list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sw.inbound.dialog
|
||||
|
||||
object DialogManager {
|
||||
|
||||
private var dialogList:MutableList<BaseDialog> = mutableListOf()
|
||||
|
||||
fun addDialog(dialog: BaseDialog) {
|
||||
if (dialogList.contains(dialog).not()) {
|
||||
val className = dialog.javaClass.simpleName
|
||||
val item = dialogList.firstOrNull { it.javaClass.simpleName == className }
|
||||
item?.dismiss()
|
||||
dialogList.add(dialog)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeDialog(dialog: BaseDialog) {
|
||||
dialogList.remove(dialog)
|
||||
}
|
||||
|
||||
fun getDialogList():MutableList<BaseDialog> {
|
||||
return dialogList
|
||||
}
|
||||
|
||||
fun dismissAll() {
|
||||
dialogList.forEach {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissAllExcept(dialog: BaseDialog) {
|
||||
dialogList.forEach {
|
||||
if (it != dialog) {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun contains(vararg className: String):Boolean {
|
||||
val item = dialogList.firstOrNull { className.contains(it.javaClass.simpleName) }
|
||||
return item != null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -187,8 +187,12 @@ class GoodsStoreDialog(
|
||||
}
|
||||
val id = unitTag.toString()
|
||||
val count = getUnitCount(id)
|
||||
if (count.isBlank() || "0" == count) {
|
||||
binding.etProcurementCount.setText("")
|
||||
return@readWeightInfo
|
||||
}
|
||||
val currentCount = binding.etProcurementCount.text.toString().trim()
|
||||
if (currentCount == count || count.isBlank() || "0" == count) {
|
||||
if (currentCount == count) {
|
||||
return@readWeightInfo
|
||||
}
|
||||
binding.etProcurementCount.let {
|
||||
|
||||
@@ -96,7 +96,7 @@ object FoodModule {
|
||||
nameScoreList.add(IdNameScore(id = it.id, name = box.get(it.id).name?:"", score = it.score))
|
||||
}
|
||||
Timber.tag("FoodModule").d("queryFood数据:${nameScoreList.toJsonString()}")
|
||||
idScoreList.filter { it.score < 0.01 }.forEach {
|
||||
idScoreList.filter { it.score < 0.10 }.forEach {
|
||||
val food = box.get(it.id)
|
||||
//FoodQueryResult(id = it.id, name = food.name, foodIdx = food.foodIdx, score = it.score)
|
||||
food.name?.let { key ->
|
||||
|
||||
@@ -34,9 +34,9 @@ object SensorScaleUtils {
|
||||
// SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
|
||||
// else -> "未知"
|
||||
//}
|
||||
if (state != SensorScale.STATE_STABLE) {
|
||||
return
|
||||
}
|
||||
// if (state != SensorScale.STATE_STABLE) {
|
||||
// return
|
||||
// }
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
weightCallback?.invoke((value * 1000).toInt())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user