66 lines
2.5 KiB
Kotlin
66 lines
2.5 KiB
Kotlin
package com.sw.platecabinet.fragment
|
|
|
|
import android.os.Bundle
|
|
import android.os.CountDownTimer
|
|
import com.sw.platecabinet.Constants
|
|
import com.sw.platecabinet.R
|
|
import com.sw.platecabinet.databinding.FragmentPlateOpenBinding
|
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
|
|
|
/**
|
|
* 餐盘柜提示界面
|
|
*/
|
|
class PlateOpenFragment :
|
|
BaseFragment<FragmentPlateOpenBinding>(FragmentPlateOpenBinding::inflate) {
|
|
private var totalTimeInMillis: Long = Constants.AUTO_CLOSE_TIME * 1000
|
|
internal val KEY_ACTION_TYPE = "actionType"
|
|
private var info: EquipmentUserInfo? = null
|
|
|
|
companion object {
|
|
@JvmStatic
|
|
fun newInstance(userInfo: EquipmentUserInfo?) =
|
|
PlateOpenFragment().apply {
|
|
arguments = Bundle().apply {
|
|
putParcelable(KEY_ACTION_TYPE, userInfo)
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun initialize() {
|
|
arguments?.let {
|
|
info = it.getParcelable(KEY_ACTION_TYPE)
|
|
info?.let {
|
|
if (!it.isBound()) {
|
|
binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
|
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 {
|
|
binding.ivType.setImageResource(R.drawable.ic_tip_success)
|
|
binding.tvTitle.text = "柜门开启"
|
|
binding.tvSubTitle.text = "餐盘取出后请关闭柜门"
|
|
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_success))
|
|
}
|
|
}
|
|
}
|
|
|
|
initCountTime()
|
|
}
|
|
|
|
fun initCountTime() {
|
|
object : CountDownTimer(totalTimeInMillis, 1000) {
|
|
override fun onTick(millisUntilFinished: Long) {
|
|
binding.tvAutoClose.text = (millisUntilFinished / 1000).toInt().toString()
|
|
}
|
|
|
|
override fun onFinish() {
|
|
activity?.finish()
|
|
}
|
|
}.start()
|
|
}
|
|
} |