package com.gh.gamecenter.common.view

import android.content.Context
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.core.runOnUiThread
import splitties.views.dsl.core.Ui

open class AsyncUi<T : Ui>(context: Context) :
    AsyncCell(context) {

    var ui: T? = null

    override fun inflate() {
        runOnIoThread(true) {
            ui = provideUi(context)
            val view = ui!!.root
            runOnUiThread {
                isInflated = true
                addView(createDataBindingView(view))

                if (delayFirstTimeBindView) {
                    post { bindView() }
                } else {
                    bindView()
                }
                post { bindView() }
            }
        }
    }

    open fun provideUi(context: Context): T? = null

}