105 lines
3.4 KiB
Kotlin
105 lines
3.4 KiB
Kotlin
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 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
|
|
}
|
|
if (recognizeAdapter.list.isEmpty()) {
|
|
loadEmptyView()
|
|
}
|
|
binding.ivClose.setOnClickListener {
|
|
dismiss()
|
|
activity?.isShowRecognizeDialog = true
|
|
activity?.goodsRecognizeDialog = null
|
|
activity?.startTime = System.currentTimeMillis()
|
|
}
|
|
binding.btnManuallyFind.setOnClickListener {
|
|
findGoods()
|
|
//dismiss()
|
|
}
|
|
binding.btnAgainRecognize.setOnClickListener {
|
|
dismiss()
|
|
activity?.isShowRecognizeDialog = true
|
|
activity?.recognizeFood()
|
|
}
|
|
}
|
|
|
|
private var emptyBinding: LayoutEmptyRecognizeBinding? = null
|
|
private fun loadEmptyView() {
|
|
if (emptyBinding == null) {
|
|
emptyBinding = LayoutEmptyRecognizeBinding.inflate(inflater, binding.rvRecognize, false)
|
|
}
|
|
emptyBinding?.root?.let {
|
|
recognizeAdapter.stateView = it
|
|
}
|
|
}
|
|
} |