增加人脸采集功能;
识别人脸成功后打开有餐盘的第一个柜子; 扫码打开已绑定的柜子,无则打开第一个空柜子并放入餐盘; 设置页面问题优化;
This commit is contained in:
@@ -1,317 +1,317 @@
|
||||
package com.sw.platecabinet.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextUtils
|
||||
import android.text.TextWatcher
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.comn.SerialApi
|
||||
import com.sw.plate.utils.comn.SerialPortManager
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.activity.MainActivity
|
||||
import com.sw.platecabinet.activity.PageType
|
||||
import com.sw.platecabinet.adapter.GenericItemAdapter
|
||||
import com.sw.platecabinet.adapter.GridSpacingItemDecoration
|
||||
import com.sw.platecabinet.adapter.dpToPx
|
||||
import com.sw.platecabinet.databinding.FragmentBindPlateBinding
|
||||
import com.sw.platecabinet.databinding.ItemSearchUserInfoBinding
|
||||
import com.sw.platecabinet.dialog.UserBindRemindDialog
|
||||
import com.sw.platecabinet.ext.maskName
|
||||
import com.sw.platecabinet.ext.maskPhone
|
||||
import com.sw.platecabinet.model.ErrorInfo
|
||||
import com.sw.platecabinet.model.request.BindParam
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.model.response.SearchResult
|
||||
import com.sw.platecabinet.utils.Debouncer
|
||||
import com.sw.platecabinet.utils.KeyboardUtils
|
||||
import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||
import com.sw.platecabinet.viewmodel.UserViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* 餐盘柜绑定
|
||||
*/
|
||||
class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
FragmentBindPlateBinding::inflate
|
||||
) {
|
||||
private lateinit var adapter: GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding>
|
||||
internal val KEY_ACTION_TYPE = "actionType"
|
||||
private var info: EquipmentUserInfo? = null
|
||||
private var checkedItem: SearchResult.Member? = null
|
||||
private var lastText = ""
|
||||
private val debouncer = Debouncer(2000)
|
||||
|
||||
private val userViewModel by viewModels<UserViewModel>()
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(userInfo: EquipmentUserInfo?) =
|
||||
BindPlateFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(KEY_ACTION_TYPE, userInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun initialize() {
|
||||
arguments?.let { args ->
|
||||
info = args.getParcelable(KEY_ACTION_TYPE)
|
||||
info?.let {
|
||||
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||
if (!TextUtils.isEmpty(it.plateNumber)) {
|
||||
// binding.etCode.text = Editable.Factory.getInstance().newEditable(it.plateNumber)
|
||||
binding.etCode.apply {
|
||||
setText(it.plateNumber)
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
initView()
|
||||
initListener()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
adapter = createAdapter()
|
||||
binding.recyclerview.layoutManager = GridLayoutManager(context, 2)
|
||||
// 添加间距装饰(12dp)
|
||||
binding.recyclerview.addItemDecoration(
|
||||
GridSpacingItemDecoration(
|
||||
spanCount = 2,
|
||||
spacing = requireContext().dpToPx(6),
|
||||
includeEdge = false // 包含边缘间距
|
||||
)
|
||||
)
|
||||
binding.recyclerview.adapter = adapter
|
||||
binding.recyclerview.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
val lastVisibleItem = layoutManager.findLastVisibleItemPosition()
|
||||
val totalItems = layoutManager.itemCount
|
||||
|
||||
if (!viewModel.isLoading && viewModel.canLoadMore
|
||||
&& lastVisibleItem >= totalItems - 3
|
||||
) {
|
||||
viewModel.getSearchMemberList(
|
||||
param = lastText,
|
||||
pageNum = viewModel.currentPage
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
(activity as MainActivity).registerKeyEventInfo {
|
||||
// binding.etCode.text.clear()
|
||||
// binding.etCode.postDelayed({
|
||||
// binding.etCode.text.clear()
|
||||
// binding.etCode.text = Editable.Factory.getInstance().newEditable(it)
|
||||
activity?.runOnUiThread {
|
||||
if (binding.etUserInfo.isFocused) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
binding.etCode.apply {
|
||||
if (it.length > 6) {
|
||||
setText(it.substring(0, 6))
|
||||
} else {
|
||||
setText(it)
|
||||
}
|
||||
if (length() > 0) {
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
binding.etUserInfo.requestFocus()
|
||||
}
|
||||
// }, 50)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
binding.etCode.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(
|
||||
s: CharSequence?,
|
||||
start: Int,
|
||||
count: Int,
|
||||
after: Int
|
||||
) {
|
||||
Timber.d("beforeTextChanged s = ${s.toString()}, start = $start, count = $count, after = $after")
|
||||
}
|
||||
|
||||
override fun onTextChanged(
|
||||
s: CharSequence?,
|
||||
start: Int,
|
||||
before: Int,
|
||||
count: Int
|
||||
) {
|
||||
Timber.d("onTextChanged s = ${s.toString()}, start = $start, count = $count, before = $before")
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
Timber.d("afterTextChanged s = ${s.toString()}")
|
||||
}
|
||||
})
|
||||
binding.etUserInfo.setOnEditorActionListener { _, actionId, keyEvent ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
val currentText = binding.etUserInfo.text.toString()
|
||||
val containsNewlines = currentText.contains('\n') || currentText.contains('\r')
|
||||
if (containsNewlines) {
|
||||
Timber.d("非用户主动搜索")
|
||||
true
|
||||
}
|
||||
debouncer.debounce {
|
||||
// 执行搜索操作
|
||||
viewModel.getSearchMemberList(param = currentText, pageNum = 1)
|
||||
// 隐藏键盘
|
||||
KeyboardUtils.hideKeyboard(requireActivity())
|
||||
}
|
||||
true // 表示已处理该事件
|
||||
} else {
|
||||
false // 未处理其他动作
|
||||
}
|
||||
}
|
||||
binding.ivSearch.setOnClickListener {
|
||||
debouncer.debounce {
|
||||
// 执行搜索操作
|
||||
viewModel.getSearchMemberList(
|
||||
param = binding.etUserInfo.text.toString(),
|
||||
pageNum = 1
|
||||
)
|
||||
// 隐藏键盘
|
||||
KeyboardUtils.hideKeyboard(requireActivity())
|
||||
}
|
||||
}
|
||||
binding.llBind.setOnClickListener {
|
||||
if (equipmentBoxCode.isNullOrBlank().not()) {
|
||||
showBindDialog()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (info == null || info!!.equipmentCode?.isEmpty() == true || info!!.equipmentBoxCode?.isEmpty() == true) {
|
||||
ToastUtils.showToast("传入的设备信息异常")
|
||||
return@setOnClickListener
|
||||
}
|
||||
val plateNumber = binding.etCode.text.toString()
|
||||
if (plateNumber.isEmpty()) {
|
||||
ToastUtils.showToast("请输入餐盘号")
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (checkedItem == null) {
|
||||
ToastUtils.showToast("请选择要绑定的会员")
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (checkedItem!!.id == null) {
|
||||
ToastUtils.showToast("选中的会员信息异常")
|
||||
return@setOnClickListener
|
||||
}
|
||||
val bindParam = BindParam(
|
||||
equipmentId = info?.equipmentId,
|
||||
equipmentCode = info?.equipmentCode,
|
||||
equipmentBoxCode = info?.equipmentBoxCode,
|
||||
faceId = checkedItem?.faceId,
|
||||
plateNumber = plateNumber
|
||||
)
|
||||
viewModel.bindPlate(bindParam) { pair ->
|
||||
updateBindState(pair)
|
||||
}
|
||||
KeyboardUtils.hideKeyboard(requireActivity())
|
||||
}
|
||||
binding.tvBack.setOnClickListener { activity?.finish() }
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听数据变化
|
||||
*/
|
||||
override fun registerDataChange() {
|
||||
super.registerDataChange()
|
||||
lifecycleScope.launch {
|
||||
viewModel.searchMemberList.collect {
|
||||
adapter.updateData(it)
|
||||
}
|
||||
}
|
||||
// lifecycleScope.launch {
|
||||
// viewModel.bindStateChange.collect {
|
||||
// updateBindState(it)
|
||||
//package com.sw.platecabinet.fragment
|
||||
//
|
||||
//import android.annotation.SuppressLint
|
||||
//import android.os.Bundle
|
||||
//import android.text.Editable
|
||||
//import android.text.TextUtils
|
||||
//import android.text.TextWatcher
|
||||
//import android.view.inputmethod.EditorInfo
|
||||
//import androidx.fragment.app.viewModels
|
||||
//import androidx.lifecycle.lifecycleScope
|
||||
//import androidx.recyclerview.widget.GridLayoutManager
|
||||
//import androidx.recyclerview.widget.LinearLayoutManager
|
||||
//import androidx.recyclerview.widget.RecyclerView
|
||||
//import com.sw.plate.utils.ToastUtils
|
||||
//import com.sw.plate.utils.comn.SerialApi
|
||||
//import com.sw.plate.utils.comn.SerialPortManager
|
||||
//import com.sw.platecabinet.R
|
||||
//import com.sw.platecabinet.activity.MainActivity
|
||||
//import com.sw.platecabinet.activity.PageType
|
||||
//import com.sw.platecabinet.adapter.GenericItemAdapter
|
||||
//import com.sw.platecabinet.adapter.GridSpacingItemDecoration
|
||||
//import com.sw.platecabinet.adapter.dpToPx
|
||||
//import com.sw.platecabinet.databinding.FragmentBindPlateBinding
|
||||
//import com.sw.platecabinet.databinding.ItemSearchUserInfoBinding
|
||||
//import com.sw.platecabinet.dialog.UserBindRemindDialog
|
||||
//import com.sw.platecabinet.ext.maskName
|
||||
//import com.sw.platecabinet.ext.maskPhone
|
||||
//import com.sw.platecabinet.model.ErrorInfo
|
||||
//import com.sw.platecabinet.model.request.BindParam
|
||||
//import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
//import com.sw.platecabinet.model.response.SearchResult
|
||||
//import com.sw.platecabinet.utils.Debouncer
|
||||
//import com.sw.platecabinet.utils.KeyboardUtils
|
||||
//import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||
//import com.sw.platecabinet.viewmodel.UserViewModel
|
||||
//import kotlinx.coroutines.launch
|
||||
//import timber.log.Timber
|
||||
//
|
||||
///**
|
||||
// * 餐盘柜绑定
|
||||
// */
|
||||
//class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
// FragmentBindPlateBinding::inflate
|
||||
//) {
|
||||
// private lateinit var adapter: GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding>
|
||||
// internal val KEY_ACTION_TYPE = "actionType"
|
||||
// private var info: EquipmentUserInfo? = null
|
||||
// private var checkedItem: SearchResult.Member? = null
|
||||
// private var lastText = ""
|
||||
// private val debouncer = Debouncer(2000)
|
||||
//
|
||||
// private val userViewModel by viewModels<UserViewModel>()
|
||||
//
|
||||
// companion object {
|
||||
// @JvmStatic
|
||||
// fun newInstance(userInfo: EquipmentUserInfo?) =
|
||||
// BindPlateFragment().apply {
|
||||
// arguments = Bundle().apply {
|
||||
// putParcelable(KEY_ACTION_TYPE, userInfo)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @SuppressLint("SetTextI18n")
|
||||
// override fun initialize() {
|
||||
// arguments?.let { args ->
|
||||
// info = args.getParcelable(KEY_ACTION_TYPE)
|
||||
// info?.let {
|
||||
// binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||
// if (!TextUtils.isEmpty(it.plateNumber)) {
|
||||
//// binding.etCode.text = Editable.Factory.getInstance().newEditable(it.plateNumber)
|
||||
// binding.etCode.apply {
|
||||
// setText(it.plateNumber)
|
||||
// setSelection(length())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun createAdapter(): GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding> {
|
||||
return GenericItemAdapter(
|
||||
items = emptyList(),
|
||||
bindingInflater = ItemSearchUserInfoBinding::inflate,
|
||||
bindCallback = { item, position ->
|
||||
this.tvName.text = item.name.maskName()
|
||||
this.tvPhone.text = item.phone.maskPhone()
|
||||
if (item.id != checkedItem?.id) {
|
||||
this.llRoot.setBackgroundResource(R.drawable.grid_item_bind)
|
||||
} else {
|
||||
this.llRoot.setBackgroundResource(R.drawable.grid_item_unbind)
|
||||
}
|
||||
|
||||
this.llRoot.setOnClickListener {
|
||||
Timber.d("itemClick ${item.name}, position = $position")
|
||||
checkedItem = item
|
||||
adapter.notifyDataSetChanged()
|
||||
//TODO 调用接口查询用户是否已绑盘
|
||||
this@BindPlateFragment.equipmentBoxCode = null
|
||||
(activity as? MainActivity)?.showWaitingDialog("查询中,请稍后……")
|
||||
userViewModel.getUserInfoById(memberId = item.faceId) {
|
||||
(activity as? MainActivity)?.hideWaitingDialog()
|
||||
this@BindPlateFragment.equipmentBoxCode = it?.equipmentBoxCode
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private var equipmentBoxCode:String? = null
|
||||
|
||||
private fun showBindDialog() {
|
||||
UserBindRemindDialog(
|
||||
activity = requireActivity(),
|
||||
content = "您已绑定编号为${equipmentBoxCode}的柜子,请解绑后重试"
|
||||
)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
|
||||
if (pair.first == null) return // 解绑状态过滤
|
||||
val errorInfo = pair.second
|
||||
if (errorInfo.isSuccess()) {
|
||||
if (errorInfo.equipmentUserInfo == null) {
|
||||
ToastUtils.showToast("数据异常")
|
||||
return
|
||||
}
|
||||
// if (errorInfo.equipmentUserInfo.isOtherEquipment()) {
|
||||
// MainActivity.start(
|
||||
// requireContext(),
|
||||
// pageType = PageType.PLATE_TIP,
|
||||
// equipmentUserInfo = errorInfo.equipmentUserInfo,
|
||||
// isAdmin = true
|
||||
// )
|
||||
// } else {
|
||||
SerialApi.openPlate(
|
||||
errorInfo.equipmentUserInfo.equipmentBoxCode!!.toInt(),
|
||||
object : SerialPortManager.SendCallback {
|
||||
override fun onSuccess() {
|
||||
ToastUtils.showToast("绑定成功")
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
override fun onFail(e: Exception?) {
|
||||
ToastUtils.showToast("绑定失败")
|
||||
}
|
||||
})
|
||||
// initView()
|
||||
// initListener()
|
||||
// }
|
||||
//
|
||||
// private fun initView() {
|
||||
// adapter = createAdapter()
|
||||
// binding.recyclerview.layoutManager = GridLayoutManager(context, 2)
|
||||
// // 添加间距装饰(12dp)
|
||||
// binding.recyclerview.addItemDecoration(
|
||||
// GridSpacingItemDecoration(
|
||||
// spanCount = 2,
|
||||
// spacing = requireContext().dpToPx(6),
|
||||
// includeEdge = false // 包含边缘间距
|
||||
// )
|
||||
// )
|
||||
// binding.recyclerview.adapter = adapter
|
||||
// binding.recyclerview.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
// override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
// super.onScrolled(recyclerView, dx, dy)
|
||||
// val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
// val lastVisibleItem = layoutManager.findLastVisibleItemPosition()
|
||||
// val totalItems = layoutManager.itemCount
|
||||
//
|
||||
// if (!viewModel.isLoading && viewModel.canLoadMore
|
||||
// && lastVisibleItem >= totalItems - 3
|
||||
// ) {
|
||||
// viewModel.getSearchMemberList(
|
||||
// param = lastText,
|
||||
// pageNum = viewModel.currentPage
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
ToastUtils.showToast(errorInfo.msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
// })
|
||||
// (activity as MainActivity).registerKeyEventInfo {
|
||||
//// binding.etCode.text.clear()
|
||||
//// binding.etCode.postDelayed({
|
||||
//// binding.etCode.text.clear()
|
||||
//// binding.etCode.text = Editable.Factory.getInstance().newEditable(it)
|
||||
// activity?.runOnUiThread {
|
||||
// if (binding.etUserInfo.isFocused) {
|
||||
// return@runOnUiThread
|
||||
// }
|
||||
// binding.etCode.apply {
|
||||
// if (it.length > 6) {
|
||||
// setText(it.substring(0, 6))
|
||||
// } else {
|
||||
// setText(it)
|
||||
// }
|
||||
// if (length() > 0) {
|
||||
// setSelection(length())
|
||||
// }
|
||||
// }
|
||||
// binding.etUserInfo.requestFocus()
|
||||
// }
|
||||
//// }, 50)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private fun initListener() {
|
||||
// binding.etCode.addTextChangedListener(object : TextWatcher {
|
||||
// override fun beforeTextChanged(
|
||||
// s: CharSequence?,
|
||||
// start: Int,
|
||||
// count: Int,
|
||||
// after: Int
|
||||
// ) {
|
||||
// Timber.d("beforeTextChanged s = ${s.toString()}, start = $start, count = $count, after = $after")
|
||||
// }
|
||||
//
|
||||
// override fun onTextChanged(
|
||||
// s: CharSequence?,
|
||||
// start: Int,
|
||||
// before: Int,
|
||||
// count: Int
|
||||
// ) {
|
||||
// Timber.d("onTextChanged s = ${s.toString()}, start = $start, count = $count, before = $before")
|
||||
// }
|
||||
//
|
||||
// override fun afterTextChanged(s: Editable?) {
|
||||
// Timber.d("afterTextChanged s = ${s.toString()}")
|
||||
// }
|
||||
// })
|
||||
// binding.etUserInfo.setOnEditorActionListener { _, actionId, keyEvent ->
|
||||
// if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
// val currentText = binding.etUserInfo.text.toString()
|
||||
// val containsNewlines = currentText.contains('\n') || currentText.contains('\r')
|
||||
// if (containsNewlines) {
|
||||
// Timber.d("非用户主动搜索")
|
||||
// true
|
||||
// }
|
||||
// debouncer.debounce {
|
||||
// // 执行搜索操作
|
||||
// viewModel.getSearchMemberList(param = currentText, pageNum = 1)
|
||||
// // 隐藏键盘
|
||||
// KeyboardUtils.hideKeyboard(requireActivity())
|
||||
// }
|
||||
// true // 表示已处理该事件
|
||||
// } else {
|
||||
// false // 未处理其他动作
|
||||
// }
|
||||
// }
|
||||
// binding.ivSearch.setOnClickListener {
|
||||
// debouncer.debounce {
|
||||
// // 执行搜索操作
|
||||
// viewModel.getSearchMemberList(
|
||||
// param = binding.etUserInfo.text.toString(),
|
||||
// pageNum = 1
|
||||
// )
|
||||
// // 隐藏键盘
|
||||
// KeyboardUtils.hideKeyboard(requireActivity())
|
||||
// }
|
||||
// }
|
||||
// binding.llBind.setOnClickListener {
|
||||
// if (equipmentBoxCode.isNullOrBlank().not()) {
|
||||
// showBindDialog()
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
// if (info == null || info!!.equipmentCode?.isEmpty() == true || info!!.equipmentBoxCode?.isEmpty() == true) {
|
||||
// ToastUtils.showToast("传入的设备信息异常")
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
// val plateNumber = binding.etCode.text.toString()
|
||||
// if (plateNumber.isEmpty()) {
|
||||
// ToastUtils.showToast("请输入餐盘号")
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
// if (checkedItem == null) {
|
||||
// ToastUtils.showToast("请选择要绑定的会员")
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
// if (checkedItem!!.id == null) {
|
||||
// ToastUtils.showToast("选中的会员信息异常")
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
// val bindParam = BindParam(
|
||||
// equipmentId = info?.equipmentId,
|
||||
// equipmentCode = info?.equipmentCode,
|
||||
// equipmentBoxCode = info?.equipmentBoxCode,
|
||||
// faceId = checkedItem?.faceId,
|
||||
// plateNumber = plateNumber
|
||||
// )
|
||||
// viewModel.bindPlate(bindParam) { pair ->
|
||||
// updateBindState(pair)
|
||||
// }
|
||||
// KeyboardUtils.hideKeyboard(requireActivity())
|
||||
// }
|
||||
// binding.tvBack.setOnClickListener { activity?.finish() }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 监听数据变化
|
||||
// */
|
||||
// override fun registerDataChange() {
|
||||
// super.registerDataChange()
|
||||
// lifecycleScope.launch {
|
||||
// viewModel.searchMemberList.collect {
|
||||
// adapter.updateData(it)
|
||||
// }
|
||||
// }
|
||||
//// lifecycleScope.launch {
|
||||
//// viewModel.bindStateChange.collect {
|
||||
//// updateBindState(it)
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// private fun createAdapter(): GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding> {
|
||||
// return GenericItemAdapter(
|
||||
// items = emptyList(),
|
||||
// bindingInflater = ItemSearchUserInfoBinding::inflate,
|
||||
// bindCallback = { item, position ->
|
||||
// this.tvName.text = item.name.maskName()
|
||||
// this.tvPhone.text = item.phone.maskPhone()
|
||||
// if (item.id != checkedItem?.id) {
|
||||
// this.llRoot.setBackgroundResource(R.drawable.grid_item_bind)
|
||||
// } else {
|
||||
// this.llRoot.setBackgroundResource(R.drawable.grid_item_unbind)
|
||||
// }
|
||||
//
|
||||
// this.llRoot.setOnClickListener {
|
||||
// Timber.d("itemClick ${item.name}, position = $position")
|
||||
// checkedItem = item
|
||||
// adapter.notifyDataSetChanged()
|
||||
// //TODO 调用接口查询用户是否已绑盘
|
||||
// this@BindPlateFragment.equipmentBoxCode = null
|
||||
// (activity as? MainActivity)?.showWaitingDialog("查询中,请稍后……")
|
||||
// userViewModel.getUserInfoById(memberId = item.faceId) {
|
||||
// (activity as? MainActivity)?.hideWaitingDialog()
|
||||
// this@BindPlateFragment.equipmentBoxCode = it?.equipmentBoxCode
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// private var equipmentBoxCode:String? = null
|
||||
//
|
||||
// private fun showBindDialog() {
|
||||
// UserBindRemindDialog(
|
||||
// activity = requireActivity(),
|
||||
// content = "您已绑定编号为${equipmentBoxCode}的柜子,请解绑后重试"
|
||||
// )
|
||||
// .show()
|
||||
// }
|
||||
//
|
||||
// private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
|
||||
// if (pair.first == null) return // 解绑状态过滤
|
||||
// val errorInfo = pair.second
|
||||
// if (errorInfo.isSuccess()) {
|
||||
// if (errorInfo.equipmentUserInfo == null) {
|
||||
// ToastUtils.showToast("数据异常")
|
||||
// return
|
||||
// }
|
||||
//// if (errorInfo.equipmentUserInfo.isOtherEquipment()) {
|
||||
//// MainActivity.start(
|
||||
//// requireContext(),
|
||||
//// pageType = PageType.PLATE_TIP,
|
||||
//// equipmentUserInfo = errorInfo.equipmentUserInfo,
|
||||
//// isAdmin = true
|
||||
//// )
|
||||
//// } else {
|
||||
// SerialApi.openPlate(
|
||||
// errorInfo.equipmentUserInfo.equipmentBoxCode!!.toInt(),
|
||||
// object : SerialPortManager.SendCallback {
|
||||
// override fun onSuccess() {
|
||||
// ToastUtils.showToast("绑定成功")
|
||||
// activity?.finish()
|
||||
// }
|
||||
//
|
||||
// override fun onFail(e: Exception?) {
|
||||
// ToastUtils.showToast("绑定失败")
|
||||
// }
|
||||
// })
|
||||
//// }
|
||||
// } else {
|
||||
// ToastUtils.showToast(errorInfo.msg)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -41,12 +41,14 @@ class PlateOpenFragment :
|
||||
binding.tvTitle.text = "暂无餐盘信息"
|
||||
binding.tvSubTitle.text = "请联系管理员"
|
||||
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
||||
} else if (it.isOtherEquipment()) {
|
||||
binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
||||
binding.tvTitle.text = "暂无餐盘信息"
|
||||
binding.tvSubTitle.text = "您的餐盘绑定在${it.equipmentName ?: " "}号柜上"
|
||||
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
||||
} else {
|
||||
}
|
||||
// else if (it.isOtherEquipment()) {
|
||||
// binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
||||
// binding.tvTitle.text = "暂无餐盘信息"
|
||||
// binding.tvSubTitle.text = "您的餐盘绑定在${it.equipmentName ?: " "}号柜上"
|
||||
// binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
||||
// }
|
||||
else {
|
||||
binding.ivType.setImageResource(R.drawable.ic_tip_success)
|
||||
binding.tvTitle.text = "柜门开启"
|
||||
binding.tvSubTitle.text = "餐盘取出后请关闭柜门"
|
||||
|
||||
@@ -11,7 +11,9 @@ import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.comn.SerialApi
|
||||
import com.sw.plate.utils.comn.SerialPortManager
|
||||
import com.sw.platecabinet.GlobalData
|
||||
import com.sw.platecabinet.MyApp
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.activity.BaseActivity
|
||||
import com.sw.platecabinet.activity.MainActivity
|
||||
import com.sw.platecabinet.activity.PageType
|
||||
import com.sw.platecabinet.adapter.GenericItemAdapter
|
||||
@@ -24,6 +26,8 @@ import com.sw.platecabinet.ext.formatNumber
|
||||
import com.sw.platecabinet.ext.maskName
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.utils.ListArrangementUtil
|
||||
import com.sw.platecabinet.utils.PlateUtils
|
||||
import com.sw.platecabinet.utils.SpTool
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -80,11 +84,23 @@ class SettingListFragment :
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
viewModel.getEquipmentList{
|
||||
// viewModel.getEquipmentList{
|
||||
// updateAdapter(it)
|
||||
// }
|
||||
MyApp.plateList?.let {
|
||||
updateAdapter(it)
|
||||
}
|
||||
}
|
||||
|
||||
// private fun getPlateData(block: (List<EquipmentUserInfo>) -> Unit) {
|
||||
// MyApp.plateList?.let {
|
||||
// block(it)
|
||||
// }
|
||||
//// viewModel.getEquipmentList { items ->
|
||||
//// block(items)
|
||||
//// }
|
||||
// }
|
||||
|
||||
private fun createItemAdapter(): GenericItemAdapter<EquipmentUserInfo, ItemBindViewBinding> {
|
||||
return GenericItemAdapter(
|
||||
items = emptyList(),
|
||||
@@ -110,7 +126,7 @@ class SettingListFragment :
|
||||
item: EquipmentUserInfo,
|
||||
position: Int
|
||||
) {
|
||||
if (item.isPlaceholder() == true) {
|
||||
if (item.isPlaceholder()) {
|
||||
this.llRoot.isVisible = false
|
||||
return
|
||||
}
|
||||
@@ -133,7 +149,9 @@ class SettingListFragment :
|
||||
this.llBindInfo.visibility = View.VISIBLE
|
||||
this.tvUnbind.visibility = View.GONE
|
||||
|
||||
this.tvName.text = item.name.maskName()
|
||||
// this.tvName.text = item.name.maskName()
|
||||
this.tvName.text = item.plateNumber
|
||||
|
||||
this.tvLastTime.text = DateTimeUtils.getTimeAgo(date)
|
||||
} else {
|
||||
this.llRoot.setBackgroundResource(R.drawable.grid_item_unbind)
|
||||
@@ -143,45 +161,25 @@ class SettingListFragment :
|
||||
this.llBindInfo.visibility = View.GONE
|
||||
this.tvUnbind.visibility = View.VISIBLE
|
||||
}
|
||||
this.llRoot.setOnClickListener {
|
||||
Timber.d("itemClick llRoot ${item.name}, position = $position")
|
||||
if (item.isBound()) {
|
||||
MainActivity.start(
|
||||
requireContext(),
|
||||
pageType = PageType.UNBIND_PLATE,
|
||||
equipmentUserInfo = item
|
||||
)
|
||||
} else {
|
||||
MainActivity.start(
|
||||
requireContext(),
|
||||
pageType = PageType.BIND_PLATE,
|
||||
equipmentUserInfo = item
|
||||
)
|
||||
}
|
||||
}
|
||||
// this.llRoot.setOnClickListener {
|
||||
//// Timber.d("itemClick llRoot ${item.name}, position = $position")
|
||||
// if (item.isBound()) {
|
||||
// MainActivity.start(
|
||||
// requireContext(),
|
||||
// pageType = PageType.UNBIND_PLATE,
|
||||
// equipmentUserInfo = item
|
||||
// )
|
||||
// } else {
|
||||
// MainActivity.start(
|
||||
// requireContext(),
|
||||
// pageType = PageType.BIND_PLATE,
|
||||
// equipmentUserInfo = item
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
this.llOpen.setOnClickListener {
|
||||
Timber.d("itemClick llOpen equipmentBoxCode = ${item.equipmentBoxCode}")
|
||||
val equipmentBoxCode: Int = item.equipmentBoxCode?.toInt() ?: -1
|
||||
if (equipmentBoxCode < 0) {
|
||||
ToastUtils.showToast("餐盘柜编号错误")
|
||||
return@setOnClickListener
|
||||
}
|
||||
showWaitingDialog("请稍等")
|
||||
SerialApi.openPlate(equipmentBoxCode, object : SerialPortManager.SendCallback {
|
||||
override fun onSuccess() {
|
||||
hideWaitingDialog()
|
||||
MainActivity.start(
|
||||
requireContext(),
|
||||
pageType = PageType.PLATE_TIP,
|
||||
isAdmin = true
|
||||
)
|
||||
}
|
||||
|
||||
override fun onFail(e: Exception?) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("柜门打开失败")
|
||||
}
|
||||
})
|
||||
// item.faceId = null
|
||||
PlateUtils.open(requireActivity(), item.equipmentBoxCode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
package com.sw.platecabinet.fragment
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.platecabinet.GlobalKey
|
||||
import com.sw.platecabinet.activity.UnBindDialogActivity
|
||||
import com.sw.platecabinet.databinding.FragmentUnbindPlateBinding
|
||||
import com.sw.platecabinet.ext.maskName
|
||||
import com.sw.platecabinet.ext.maskPhone
|
||||
import com.sw.platecabinet.model.ErrorInfo
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 餐盘柜绑定
|
||||
*/
|
||||
class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPlateBinding>(
|
||||
FragmentUnbindPlateBinding::inflate
|
||||
) {
|
||||
internal val ARG_PARAM1 = "param1"
|
||||
private var info: EquipmentUserInfo? = null
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(param1: EquipmentUserInfo?) =
|
||||
UnBindPlateFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(ARG_PARAM1, param1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val dialogLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
viewModel.unbindPlate(info?.id) { pair ->
|
||||
updateBindState(pair)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun initialize() {
|
||||
arguments?.let { args ->
|
||||
info = args.getParcelable(ARG_PARAM1)
|
||||
info?.let {
|
||||
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||
binding.tvPlateNumberValue.text = it.plateNumber
|
||||
binding.tvNameValue.text = it.name.maskName()
|
||||
binding.tvPhoneValue.text = it.phone.maskPhone()
|
||||
val timeInfo = DateTimeUtils.parseDateTime(it.updateTime)
|
||||
val timeAgo = DateTimeUtils.getTimeAgo(timeInfo)
|
||||
binding.tvUpdateTimeValue.text = timeAgo
|
||||
}
|
||||
}
|
||||
binding.llUnbind.setOnClickListener {
|
||||
if (info == null) return@setOnClickListener
|
||||
val intent = Intent(requireContext(), UnBindDialogActivity::class.java).apply {
|
||||
putExtra(GlobalKey.PARAM_EQUIPMENT_INFO, info)
|
||||
}
|
||||
dialogLauncher.launch(intent)
|
||||
requireActivity().overridePendingTransition(0, 0)
|
||||
}
|
||||
binding.tvBack.setOnClickListener {
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerDataChange() {
|
||||
super.registerDataChange()
|
||||
// lifecycleScope.launch {
|
||||
// viewModel.bindStateChange.collect {
|
||||
// updateBindState(it)
|
||||
//package com.sw.platecabinet.fragment
|
||||
//
|
||||
//import android.app.Activity
|
||||
//import android.content.Intent
|
||||
//import android.os.Bundle
|
||||
//import androidx.activity.result.contract.ActivityResultContracts
|
||||
//import androidx.lifecycle.lifecycleScope
|
||||
//import com.sw.inbound.utils.DateTimeUtils
|
||||
//import com.sw.plate.utils.ToastUtils
|
||||
//import com.sw.platecabinet.GlobalKey
|
||||
//import com.sw.platecabinet.activity.UnBindDialogActivity
|
||||
//import com.sw.platecabinet.databinding.FragmentUnbindPlateBinding
|
||||
//import com.sw.platecabinet.ext.maskName
|
||||
//import com.sw.platecabinet.ext.maskPhone
|
||||
//import com.sw.platecabinet.model.ErrorInfo
|
||||
//import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
///**
|
||||
// * 餐盘柜绑定
|
||||
// */
|
||||
//class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPlateBinding>(
|
||||
// FragmentUnbindPlateBinding::inflate
|
||||
//) {
|
||||
// internal val ARG_PARAM1 = "param1"
|
||||
// private var info: EquipmentUserInfo? = null
|
||||
//
|
||||
// companion object {
|
||||
// @JvmStatic
|
||||
// fun newInstance(param1: EquipmentUserInfo?) =
|
||||
// UnBindPlateFragment().apply {
|
||||
// arguments = Bundle().apply {
|
||||
// putParcelable(ARG_PARAM1, param1)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private val dialogLauncher = registerForActivityResult(
|
||||
// ActivityResultContracts.StartActivityForResult()
|
||||
// ) { result ->
|
||||
// if (result.resultCode == Activity.RESULT_OK) {
|
||||
// viewModel.unbindPlate(info?.id) { pair ->
|
||||
// updateBindState(pair)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
|
||||
if (pair.first == null) return // 绑定状态过滤
|
||||
val errorInfo = pair.second
|
||||
if (errorInfo.isSuccess()) {
|
||||
ToastUtils.showToast("解绑成功")
|
||||
// activity?.finish()
|
||||
// 关闭宿主 Activity
|
||||
requireActivity().finish()
|
||||
requireActivity().overridePendingTransition(0, 0)
|
||||
} else {
|
||||
ToastUtils.showToast(errorInfo.msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
//
|
||||
// override fun initialize() {
|
||||
// arguments?.let { args ->
|
||||
// info = args.getParcelable(ARG_PARAM1)
|
||||
// info?.let {
|
||||
// binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||
// binding.tvPlateNumberValue.text = it.plateNumber
|
||||
// binding.tvNameValue.text = it.name.maskName()
|
||||
// binding.tvPhoneValue.text = it.phone.maskPhone()
|
||||
// val timeInfo = DateTimeUtils.parseDateTime(it.updateTime)
|
||||
// val timeAgo = DateTimeUtils.getTimeAgo(timeInfo)
|
||||
// binding.tvUpdateTimeValue.text = timeAgo
|
||||
// }
|
||||
// }
|
||||
// binding.llUnbind.setOnClickListener {
|
||||
// if (info == null) return@setOnClickListener
|
||||
// val intent = Intent(requireContext(), UnBindDialogActivity::class.java).apply {
|
||||
// putExtra(GlobalKey.PARAM_EQUIPMENT_INFO, info)
|
||||
// }
|
||||
// dialogLauncher.launch(intent)
|
||||
// requireActivity().overridePendingTransition(0, 0)
|
||||
// }
|
||||
// binding.tvBack.setOnClickListener {
|
||||
// activity?.finish()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun registerDataChange() {
|
||||
// super.registerDataChange()
|
||||
//// lifecycleScope.launch {
|
||||
//// viewModel.bindStateChange.collect {
|
||||
//// updateBindState(it)
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
// private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
|
||||
// if (pair.first == null) return // 绑定状态过滤
|
||||
// val errorInfo = pair.second
|
||||
// if (errorInfo.isSuccess()) {
|
||||
// ToastUtils.showToast("解绑成功")
|
||||
//// activity?.finish()
|
||||
// // 关闭宿主 Activity
|
||||
// requireActivity().finish()
|
||||
// requireActivity().overridePendingTransition(0, 0)
|
||||
// } else {
|
||||
// ToastUtils.showToast(errorInfo.msg)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user