package com.convenient.android.common.base.view

import android.annotation.SuppressLint
import android.os.Handler
import android.os.Looper
import android.os.Message
import com.convenient.android.common.base.ActivitysUtils

/**
 * @classname：BaseActivity
 * @description：初始化Handler对象,采用静态内部类的实现方式
 */
typealias HandlerCallback = (msg : Message)-> Unit

@SuppressLint("HandlerLeak")
class BaseActivityHandler(var baseActivity: BaseActivity) : Handler(Looper.getMainLooper()) {

    var callback : HandlerCallback? = null

    override fun handleMessage(msg: Message) {
        super.handleMessage(msg)
        when {
            ActivitysUtils.isActivityAlive(baseActivity) -> callback?.invoke(msg)
        }
    }

    fun setHandlerCallBack(handlerCallBack: HandlerCallback) {
        callback = handlerCallBack
    }
}