package com.jld.vod.service

import android.accessibilityservice.AccessibilityService
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.view.WindowManager
import com.jld.vod.model.bean.PositionAdvertBean
import com.jld.vod.utils.LogUtils
import com.jld.vod.view.widget.CustomAdDialog
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

/**
 * 固定位置广告服务
 */
class PositionAdvertService : Service() {
    private var mCustom : CustomAdDialog? = null

    override fun onCreate() {
        EventBus.getDefault().register(this)
        super.onCreate()
    }


    /**
     * 接收广告数据
     */
    @Subscribe
    fun onReceive( positionAdvert :List<PositionAdvertBean>) {
        LogUtils.logD("我收到了消息"+positionAdvert)

        if (mCustom == null)
        {
            mCustom = CustomAdDialog(this)
            mCustom!!.getWindow()!!.setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
            mCustom!!.setDataList(positionAdvert)
            mCustom!!.show()
        }
        mCustom!!.setOnClickBottomListener(object : CustomAdDialog.OnClickBottomListener{
            override fun onBtnCloseClick() {
                mCustom!!.dismiss()
                mCustom = null
            }
        })
    }


    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

}