接口调试、增加人脸识别后主副屏支付金额逻辑、其它优化
This commit is contained in:
@@ -10,7 +10,9 @@ import com.sw.dualscreen.databinding.ActivityCollectedFoodBinding
|
||||
import com.sw.dualscreen.databinding.LayoutEmptySearchBinding
|
||||
import com.sw.dualscreen.dialog.WarnDialog
|
||||
import com.sw.dualscreen.ext.addOnActionSearchListener
|
||||
import com.sw.dualscreen.ext.gone
|
||||
import com.sw.dualscreen.ext.hideKeyboard
|
||||
import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.objbox.CollectedFoodInfo
|
||||
import com.sw.dualscreen.objbox.Food
|
||||
import com.sw.dualscreen.objbox.ObjectBox
|
||||
@@ -21,6 +23,11 @@ import io.objectbox.Box
|
||||
import io.objectbox.kotlin.boxFor
|
||||
|
||||
class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
|
||||
companion object {
|
||||
private const val PAGE_SIZE = 100
|
||||
}
|
||||
|
||||
private val viewModel by viewModels<UserViewModel>()
|
||||
override fun getViewModel(): BaseViewModel {
|
||||
return viewModel
|
||||
@@ -33,7 +40,7 @@ class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
private val list: MutableList<CollectedFoodInfo> = mutableListOf()
|
||||
private val adapter by lazy {
|
||||
CollectedFoodNewAdapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
// isStateViewEnable = true
|
||||
addOnItemChildClickListener(R.id.ivDeleteFood) { _, _, position ->
|
||||
deleteGoods(position)
|
||||
}
|
||||
@@ -42,6 +49,7 @@ class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
|
||||
override fun initialize() {
|
||||
super.initialize()
|
||||
//binding.root.setOnClickListener { it.hideKeyboard() }
|
||||
binding.rvFoodList.let {
|
||||
it.layoutManager = LinearLayoutManager(this)
|
||||
it.adapter = adapter
|
||||
@@ -65,14 +73,30 @@ class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
ToastUtils.showToast("请输入物品名称")
|
||||
return@addOnActionSearchListener
|
||||
}
|
||||
pageNo = 1
|
||||
getCollectGoods(searchName)
|
||||
}
|
||||
v.addTextChangedListener {
|
||||
if (it.isNullOrBlank()) {
|
||||
pageNo = 1
|
||||
getCollectGoods()
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
it.setEnableLoadMore(false)
|
||||
it.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
getCollectGoods()
|
||||
}
|
||||
it.setOnLoadMoreListener {
|
||||
getCollectGoods()
|
||||
}
|
||||
}
|
||||
binding.emptyInclude.root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
getCollectGoods()
|
||||
}
|
||||
|
||||
@@ -81,54 +105,81 @@ class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getCollectGoods(searchName: String? = null) {
|
||||
if (box == null) {
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
}
|
||||
list.clear()
|
||||
val totalList = box?.all
|
||||
?.filter { it.name!=null }
|
||||
?.groupBy { it.name!! }
|
||||
?.map { CollectedFoodInfo(foodName = it.key, foodCount = it.value.size) }
|
||||
//var queryMap:Map<String, List<Food>> ?= null
|
||||
if (searchName.isNullOrBlank().not()) {
|
||||
//queryMap = totalMap?.filter { it.key.contains(searchName) }
|
||||
val temp = totalList?.filter { it.foodName?.contains(searchName) == true}
|
||||
if (temp.isNullOrEmpty().not()) {
|
||||
list.addAll(temp)
|
||||
}
|
||||
} else {
|
||||
if (totalList.isNullOrEmpty().not()) {
|
||||
list.addAll(totalList)
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
if (list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
}
|
||||
binding.root.hideKeyboard()
|
||||
// if (box == null) {
|
||||
// box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
// }
|
||||
// list.clear()
|
||||
// val totalList = box?.all
|
||||
// ?.filter { it.name!=null }
|
||||
// ?.groupBy { it.name!! }
|
||||
// ?.map { CollectedFoodInfo(foodName = it.key, foodCount = it.value.size) }
|
||||
// //var queryMap:Map<String, List<Food>> ?= null
|
||||
// if (searchName.isNullOrBlank().not()) {
|
||||
// //queryMap = totalMap?.filter { it.key.contains(searchName) }
|
||||
// val temp = totalList?.filter { it.foodName?.contains(searchName) == true}
|
||||
// if (temp.isNullOrEmpty().not()) {
|
||||
// list.addAll(temp)
|
||||
// }
|
||||
// } else {
|
||||
// if (totalList.isNullOrEmpty().not()) {
|
||||
// list.addAll(totalList)
|
||||
// }
|
||||
// }
|
||||
// adapter.notifyDataSetChanged()
|
||||
// if (list.isEmpty()) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
|
||||
viewModel.getCollectedFoodList(pageNo = pageNo) {
|
||||
if (it.isNotEmpty()) {
|
||||
list.addAll(it)
|
||||
runOnUiThread {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
viewModel.getCollectedFoodList(
|
||||
pageNo = pageNo,
|
||||
pageSize = PAGE_SIZE,
|
||||
foodName = searchName ?: ""
|
||||
) { items ->
|
||||
runOnUiThread {
|
||||
loadFoodList(items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadFoodList(items: List<CollectedFoodInfo>) {
|
||||
finishRefresh()
|
||||
if (pageNo == 1 && items.isEmpty()) {
|
||||
list.clear()
|
||||
adapter.notifyDataSetChanged()
|
||||
loadEmptyView()
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
return
|
||||
}
|
||||
binding.refreshLayout.visible()
|
||||
binding.emptyInclude.root.gone()
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(items)
|
||||
val isEnableLoadMore = items.size >= PAGE_SIZE
|
||||
if (isEnableLoadMore) {
|
||||
pageNo++
|
||||
}
|
||||
binding.refreshLayout.setEnableLoadMore(isEnableLoadMore)
|
||||
adapter.notifyDataSetChanged()
|
||||
binding.root.hideKeyboard()
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
|
||||
private var emptyBinding: LayoutEmptySearchBinding? = null
|
||||
// private var emptyBinding: LayoutEmptySearchBinding? = null
|
||||
private fun loadEmptyView() {
|
||||
if (emptyBinding == null) {
|
||||
emptyBinding =
|
||||
LayoutEmptySearchBinding.inflate(layoutInflater, binding.rvFoodList, false)
|
||||
}
|
||||
emptyBinding?.root?.let { layout ->
|
||||
layout.setOnClickListener { layout.hideKeyboard() }
|
||||
adapter.stateView = layout
|
||||
}
|
||||
binding.refreshLayout.gone()
|
||||
binding.emptyInclude.root.visible()
|
||||
//if (emptyBinding == null) {
|
||||
// emptyBinding =
|
||||
// LayoutEmptySearchBinding.inflate(layoutInflater, binding.rvFoodList, false)
|
||||
//}
|
||||
//emptyBinding?.root?.let { layout ->
|
||||
// layout.setOnClickListener { layout.hideKeyboard() }
|
||||
// adapter.stateView = layout
|
||||
//}
|
||||
}
|
||||
|
||||
private fun deleteGoods(position: Int) {
|
||||
@@ -154,4 +205,16 @@ class CollectedFoodActivity : BaseActivity<ActivityCollectedFoodBinding>() {
|
||||
}.start()
|
||||
}).show()
|
||||
}
|
||||
|
||||
|
||||
private fun finishRefresh() {
|
||||
binding.refreshLayout.let {
|
||||
if (pageNo == 1) {
|
||||
it.finishRefresh(500)
|
||||
} else {
|
||||
it.finishLoadMore(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user