设备联调优化,增加已采集物品弹窗
This commit is contained in:
@@ -4,10 +4,11 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
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.activity.FoodCollectionActivity
|
||||
import com.sw.inbound.adapter.CollectSearchAdapter
|
||||
import com.sw.inbound.databinding.DialogCollectSearchBinding
|
||||
import com.sw.inbound.databinding.LayoutEmptySearchBinding
|
||||
@@ -34,14 +35,31 @@ class CollectSearchDialog(
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private var activity: GoodsListActivity? = null
|
||||
private var activity: FoodCollectionActivity? = null
|
||||
override fun initView() {
|
||||
activity = getReceiptActivity()
|
||||
activity = getFoodCollectionActivity()
|
||||
binding.ivClose.setOnClickListener { dismiss() }
|
||||
binding.ivGoodsSearch.setOnClickListener { searchGoods() }
|
||||
binding.ivGoodsSearch.setOnClickListener {
|
||||
val searchName = binding.etInputGoods.text.toString().trim()
|
||||
if (searchName.isBlank()) {
|
||||
activity?.toast("请输入物品名称")
|
||||
return@setOnClickListener
|
||||
}
|
||||
getCollectGoods(searchName)
|
||||
}
|
||||
binding.etInputGoods.let { v ->
|
||||
v.addOnActionSearchListener {
|
||||
searchGoods()
|
||||
val searchName = binding.etInputGoods.text.toString().trim()
|
||||
if (searchName.isBlank()) {
|
||||
activity?.toast("请输入物品名称")
|
||||
return@addOnActionSearchListener
|
||||
}
|
||||
getCollectGoods(searchName)
|
||||
}
|
||||
v.addTextChangedListener {
|
||||
if (it.isNullOrBlank()) {
|
||||
getCollectGoods()
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.btnConfirm.setOnClickListener {
|
||||
@@ -56,55 +74,28 @@ class CollectSearchDialog(
|
||||
it.setEnableLoadMore(false)
|
||||
it.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
searchGoods()
|
||||
}
|
||||
it.setOnLoadMoreListener {
|
||||
searchGoods()
|
||||
val searchName = binding.etInputGoods.text.toString().trim()
|
||||
getCollectGoods(searchName)
|
||||
}
|
||||
//it.setOnLoadMoreListener {
|
||||
// searchGoods()
|
||||
//}
|
||||
}
|
||||
getCollectGoods()
|
||||
//binding.root.clickWithDebounce {
|
||||
// Thread {
|
||||
// FoodModule.initDefFoodData(activity!!) {
|
||||
// activity?.runOnUiThread {
|
||||
// activity?.toast("添加完成")
|
||||
// getCollectGoods()
|
||||
// }
|
||||
// }
|
||||
// }.start()
|
||||
//}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -140,9 +131,9 @@ class CollectSearchDialog(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteGoods(position:Int) {
|
||||
WarnDialog(context = context, content = "请确认是否删除该物品?", confirmBlock = {
|
||||
Thread{
|
||||
private fun deleteGoods(position: Int) {
|
||||
WarnDialog(context = context, content = "请确认是否删除物品:${list[position].goodsName}?", confirmBlock = {
|
||||
Thread {
|
||||
activity?.runOnUiThread {
|
||||
Loading.show(context)
|
||||
}
|
||||
@@ -151,9 +142,13 @@ class CollectSearchDialog(
|
||||
box?.removeByIds(filterIdList)
|
||||
activity?.runOnUiThread {
|
||||
Loading.dismiss()
|
||||
list.removeAt(position)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
//list.remove(list[position])
|
||||
//searchAdapter.notifyDataSetChanged()
|
||||
searchAdapter.removeAt(position)
|
||||
activity?.toast("删除成功")
|
||||
if (list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}).show()
|
||||
@@ -170,19 +165,28 @@ class CollectSearchDialog(
|
||||
}
|
||||
|
||||
private var box: Box<Food>? = null
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getCollectGoods() {
|
||||
private fun getCollectGoods(searchName:String?=null) {
|
||||
if (box == null) {
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
}
|
||||
box?.all?.distinctBy { it.name }?.forEach {
|
||||
list.clear()
|
||||
var queryList = box?.all?.distinctBy { it.name }
|
||||
if (searchName.isNullOrBlank().not()) {
|
||||
queryList = queryList?.filter { it.name?.contains(searchName) == true }
|
||||
}
|
||||
queryList?.forEach {
|
||||
list.add((SearchGoodsInfo.Record(goodsName = it.name)))
|
||||
}
|
||||
binding.rvSearch.layoutManager = GridLayoutManager(activity, 2, LinearLayoutManager.VERTICAL, false)
|
||||
binding.rvSearch.layoutManager =
|
||||
GridLayoutManager(activity, 2, LinearLayoutManager.VERTICAL, false)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
if (list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
}
|
||||
finishRefresh()
|
||||
binding.root.hideKeyboard()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user