初始代码提交
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
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.LinearLayoutManager
|
||||
import com.sw.inbound.activity.GoodsListActivity
|
||||
import com.sw.inbound.adapter.RecognizeAdapter
|
||||
import com.sw.inbound.databinding.DialogGoodsRecognizeBinding
|
||||
import com.sw.inbound.databinding.LayoutEmptyRecognizeBinding
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import java.io.File
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class GoodsRecognizeDialog(
|
||||
context: Context,
|
||||
var goodsFile: File? = null,
|
||||
var goodsName: String? = null,
|
||||
var list: MutableList<SearchGoodsInfo.Record>,
|
||||
//var closeCallback:()->Unit,
|
||||
var findGoods: () -> Unit
|
||||
) : BaseDialog(context) {
|
||||
|
||||
private lateinit var binding: DialogGoodsRecognizeBinding
|
||||
private lateinit var inflater: LayoutInflater
|
||||
override fun getRootView(): View {
|
||||
inflater = LayoutInflater.from(context)
|
||||
binding = DialogGoodsRecognizeBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
// override fun show() {
|
||||
// super.show()
|
||||
// binding.ivGoods.load(goodsFile)
|
||||
// binding.tvGoods.text = goodsName
|
||||
// }
|
||||
|
||||
private val recognizeAdapter by lazy {
|
||||
RecognizeAdapter(list).apply {
|
||||
// isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
if (list[position].isSelected) {
|
||||
showGoodsStoreDialog(position)
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
list.forEach { item ->
|
||||
item.isSelected = false
|
||||
}
|
||||
list[position].isSelected = true
|
||||
notifyDataSetChanged()
|
||||
showGoodsStoreDialog(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showGoodsStoreDialog(position: Int) {
|
||||
GoodsStoreDialog(
|
||||
context = context,
|
||||
funcType = 0,
|
||||
goods = list[position]
|
||||
) {
|
||||
activity?.addGoods(it)
|
||||
//activity?.startTime = System.currentTimeMillis()
|
||||
dismiss()
|
||||
}.show()
|
||||
}
|
||||
|
||||
private var activity: GoodsListActivity? = null
|
||||
override fun initView() {
|
||||
activity = getReceiptActivity()
|
||||
binding.rvRecognize.let {
|
||||
it.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
it.adapter = recognizeAdapter
|
||||
}
|
||||
val isEmpty = list.isEmpty()
|
||||
if (isEmpty) {
|
||||
// loadEmptyView()
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
} else {
|
||||
binding.rvRecognize.visible()
|
||||
binding.flEmptyLayout.gone()
|
||||
}
|
||||
// if (recognizeAdapter.list.isEmpty()) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
binding.ivClose.setOnClickListener {
|
||||
dismiss()
|
||||
activity?.delayRecognizeFood()
|
||||
//activity?.startTime = System.currentTimeMillis()
|
||||
}
|
||||
binding.btnManuallyFind.setOnClickListener {
|
||||
findGoods()
|
||||
//dismiss()
|
||||
}
|
||||
binding.btnAgainRecognize.setOnClickListener {
|
||||
//dismiss()
|
||||
activity?.againRecognizeFood { goodsList ->
|
||||
//binding.rvRecognize.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
if (goodsList.isEmpty()) {
|
||||
// loadEmptyView()
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
return@againRecognizeFood
|
||||
}
|
||||
list.clear()
|
||||
list.addAll(goodsList)
|
||||
// recognizeAdapter.isStateViewEnable = false
|
||||
recognizeAdapter.notifyDataSetChanged()
|
||||
|
||||
binding.rvRecognize.visible()
|
||||
binding.flEmptyLayout.gone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private var emptyBinding: LayoutEmptyRecognizeBinding? = null
|
||||
private fun loadEmptyView() {
|
||||
// if (emptyBinding == null) {
|
||||
// emptyBinding = LayoutEmptyRecognizeBinding.inflate(inflater, binding.flEmptyLayout, false)
|
||||
// }
|
||||
// binding.flEmptyLayout.removeAllViews()
|
||||
// emptyBinding?.root.let {
|
||||
// binding.flEmptyLayout.addView(it)
|
||||
// }
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
// emptyBinding?.root?.let {
|
||||
// recognizeAdapter.isStateViewEnable = true
|
||||
// recognizeAdapter.stateView = it
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
override fun dismiss() {
|
||||
super.dismiss()
|
||||
activity?.run {
|
||||
isShowRecognizeDialog = true
|
||||
goodsRecognizeDialog = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user