package com.yidian.yac.newscontent.utils

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import com.stx.xhb.androidx.XBanner
import org.jetbrains.annotations.NotNull

/**
 * @description: 扩展方法类
 * @author: huyajun
 * @date:  2021/4/29
 **/

fun XBanner.addLifecycle(lifecycle: Lifecycle) {
    lifecycle.addObserver(object : LifecycleObserver {
        @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
        fun onResume(@NotNull owner: LifecycleOwner) {
            startAutoPlay()
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
        fun onPause(@NotNull owner: LifecycleOwner) {
            stopAutoPlay()
        }
    })

}