package com.rokid.online.demo.android

import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.fragment.app.Fragment

class AsrFragment : Fragment(R.layout.fragment_asr) {

    private var host: DemoHost? = null

    override fun onAttach(context: Context) {
        super.onAttach(context)
        host = context as? DemoHost
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val h = host ?: return
        view.findViewById<Button>(R.id.btnAsrConnect).setOnClickListener { h.asrConnect() }
        view.findViewById<Button>(R.id.btnAsrStartMic).setOnClickListener { h.asrStartMic() }
        view.findViewById<Button>(R.id.btnAsrStopMic).setOnClickListener { h.asrStopMic() }
        view.findViewById<Button>(R.id.btnAsrClose).setOnClickListener { h.asrClose() }
    }

    override fun onDetach() {
        host = null
        super.onDetach()
    }
}
