This commit is contained in:
2025-11-10 13:47:02 +08:00
parent 1f752be517
commit 43c1512446
11 changed files with 104 additions and 39 deletions
@@ -63,7 +63,13 @@ class CollectSearchDialog(
}
}
binding.btnConfirm.setOnClickListener {
dismiss()
if (clickIndex == -1) {
dismiss()
return@setOnClickListener
}
deleteGoods(clickIndex) {
it.postDelayed({dismiss()}, 500)
}
}
binding.rvSearch.let {
it.layoutManager = GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL, false)
@@ -115,44 +121,54 @@ class CollectSearchDialog(
private val searchAdapter by lazy {
CollectSearchAdapter(list).apply {
isStateViewEnable = true
setOnItemClickListener { _, _, position ->
//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 ->
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 = "请确认是否删除物品:${list[position].goodsName}", 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.remove(list[position])
//searchAdapter.notifyDataSetChanged()
searchAdapter.removeAt(position)
activity?.toast("删除成功")
if (list.isEmpty()) {
loadEmptyView()
private fun deleteGoods(position: Int, deleteAction:()-> Unit = {}) {
WarnDialog(
context = context,
content = "请确认是否删除物品:${list[position].goodsName}",
confirmBlock = {
Thread {
activity?.runOnUiThread {
Loading.show(context)
}
}
}.start()
}).show()
val name = list[position].goodsName
val filterIdList = box?.all?.filter { it.name == name }?.map { it.id }
box?.removeByIds(filterIdList)
activity?.runOnUiThread {
Loading.dismiss()
//list.remove(list[position])
//searchAdapter.notifyDataSetChanged()
searchAdapter.removeAt(position)
activity?.toast("删除成功")
if (list.isEmpty()) {
loadEmptyView()
}
deleteAction()
}
}.start()
}).show()
}
private fun finishRefresh() {
@@ -168,7 +184,7 @@ class CollectSearchDialog(
private var box: Box<Food>? = null
@SuppressLint("NotifyDataSetChanged")
private fun getCollectGoods(searchName:String?=null) {
private fun getCollectGoods(searchName: String? = null) {
if (box == null) {
box = ObjectBox.boxStore.boxFor(Food::class)
}