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 TtsFragment : Fragment(R.layout.fragment_tts) {

    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.btnTtsConnect).setOnClickListener { h.ttsConnect() }
        view.findViewById<Button>(R.id.btnTtsSpeakDefault).setOnClickListener { h.ttsSpeakDefault() }
        view.findViewById<Button>(R.id.btnTtsStop).setOnClickListener { h.ttsStop() }
        view.findViewById<Button>(R.id.btnTtsClose).setOnClickListener { h.ttsClose() }
    }

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