package xn.hxp.weidith

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import xn.hxp.R
import xn.hxp.utils.AudioPlayer

// 更换RFID 标签
class AirBottleNewDialog(private val ct: Context,private var rfids:String?,private val lintDate: ILintDate) : Dialog(ct) {

    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.air_bottle_new_dialog)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
    }
    private var mHandler: Handler = Handler(Looper.getMainLooper())
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        findViewById<Button>(R.id.butClos).setOnClickListener {
            dismiss()
        }
        if (rfids!=null){
            findViewById<TextView>(R.id.rfids).text = "$rfids"
        }
        findViewById<Button>(R.id.butDetermine).setOnClickListener {
            val trim = findViewById<EditText>(R.id.cont).text.toString().trim()
            if (trim.isEmpty()) {
                return@setOnClickListener
            } else {
                lintDate.onLintDate(trim)
                dismiss()
            }
        }
        mHandler.postDelayed({
            dismiss()
        }, 1000 * 15) // 15秒后关闭对话框

    }

    interface ILintDate {
        fun onLintDate(cont: String)
    }

    override fun onStop() {
        super.onStop()
        mHandler.removeCallbacksAndMessages(null)
    }
}