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

    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.btnInitSdk).setOnClickListener {
            h.initSdk(BuildConfig.DEMO_UID, BuildConfig.DEMO_DEVICE_ID)
        }
        view.findViewById<Button>(R.id.btnReleaseSdk).setOnClickListener { h.closeAll() }
    }

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