Skip to content

Commit

Permalink
修复热启动开屏问题和添加生命周期绑定方法
Browse files Browse the repository at this point in the history
修复热启动开屏问题和添加生命周期绑定方法
  • Loading branch information
Espoir committed Nov 14, 2023
1 parent 8437cd5 commit 8833e34
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.espoir.easyadvapp.ad
// EasyAdv.splashConfig()
// .setCodeId(codeId)
// .setActivity(activity)
// .isHotSplash(true)
// .setWidth(activity.getScreenWidth())
// .setHeight(activity.getScreenHeight())
// .setContainer(container)
Expand Down
4 changes: 4 additions & 0 deletions easyadv/src/main/java/com/espoir/easyadv/AdvControl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class AdvControl {
config.listener(CallbackType.ERROR, EasyAdv.ERROR_SDK, "sdk init fail")
return
}
if (config.isHotSplash) {
splashAdvEngine?.showSplashAdv(config)
return
}
showSplashAdvTime = System.currentTimeMillis()
//等待sdk初始化完成
while (!splashAdvFlag) {
Expand Down
8 changes: 7 additions & 1 deletion easyadv/src/main/java/com/espoir/easyadv/EasyAdv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ object EasyAdv {
fun rewardVideoConfig() = RewardVideoAdvConfig()

internal fun showSplashAdv(config: SplashAdvConfig) {
advControl?.showSplashAdv(config, splashAdvEngine)
if (config.isHotSplash) {
if (isInitSdkSuccess) {
advControl?.showSplashAdv(config, splashAdvEngine)
}
} else {
advControl?.showSplashAdv(config, splashAdvEngine)
}
}

internal fun showFullScreenVideoAdv(config: FullScreenVideoAdvConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.espoir.easyadv.config

import android.app.Activity
import android.view.ViewGroup
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.espoir.easyadv.BannerAdvListener
import com.espoir.easyadv.CallbackType
Expand All @@ -13,6 +15,8 @@ open class BannerAdvConfig : BaseAdvConfig() {
var codeId: String = ""
var container: ViewGroup? = null
internal var bannerAdvListener: BannerAdvListener? = null
internal var lifecycleOwner: LifecycleOwner? = null
internal var lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY

fun setCodeId(codeId: String) = apply {
this.codeId = codeId
Expand All @@ -30,6 +34,11 @@ open class BannerAdvConfig : BaseAdvConfig() {
this.activity = WeakReference(activity)
}

fun lifecycle(lifecycleOwner: LifecycleOwner, lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY) = apply {
this.lifecycleOwner = lifecycleOwner
this.lifeEvent = lifeEvent
}

fun setWidth(width: Int) = apply {
this.width = width
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.espoir.easyadv.config

import android.app.Activity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd
import com.espoir.easyadv.CallbackType
import com.espoir.easyadv.EasyAdv
Expand All @@ -11,6 +13,8 @@ import java.lang.ref.WeakReference
open class FullScreenVideoAdvConfig : BaseAdvConfig() {
var codeId: String = ""
internal var fullScreenVideoAdvListener: FullScreenVideoAdvListener? = null
internal var lifecycleOwner: LifecycleOwner? = null
internal var lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY

fun setCodeId(codeId: String) = apply {
this.codeId = codeId
Expand All @@ -24,6 +28,11 @@ open class FullScreenVideoAdvConfig : BaseAdvConfig() {
this.activity = WeakReference(activity)
}

fun lifecycle(lifecycleOwner: LifecycleOwner, lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY) = apply {
this.lifecycleOwner = lifecycleOwner
this.lifeEvent = lifeEvent
}

fun setWidth(width: Int) = apply {
this.width = width
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.espoir.easyadv.config

import android.app.Activity
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.bytedance.sdk.openadsdk.TTAdConstant
import com.bytedance.sdk.openadsdk.mediation.manager.MediationAdEcpmInfo
import com.espoir.easyadv.CallbackType
Expand All @@ -16,6 +18,8 @@ class RewardVideoAdvConfig : BaseAdvConfig() {
internal var interceptors = mutableListOf<AdvInterceptor>()
var extraMap = hashMapOf<String, String>()
var rewardVideoAdvListener: RewardVideoAdvListener? = null
internal var lifecycleOwner: LifecycleOwner? = null
internal var lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY

fun setCodeId(codeId: String) = apply {
this.codeId = codeId
Expand All @@ -33,6 +37,11 @@ class RewardVideoAdvConfig : BaseAdvConfig() {
this.activity = WeakReference(activity)
}

fun lifecycle(lifecycleOwner: LifecycleOwner, lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY) = apply {
this.lifecycleOwner = lifecycleOwner
this.lifeEvent = lifeEvent
}

fun setWidth(width: Int) = apply {
this.width = width
}
Expand Down
14 changes: 14 additions & 0 deletions easyadv/src/main/java/com/espoir/easyadv/config/SplashAdvConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.espoir.easyadv.config
import android.app.Activity
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.bytedance.sdk.openadsdk.TTSplashAd
import com.espoir.easyadv.CallbackType
import com.espoir.easyadv.EasyAdv
Expand All @@ -12,7 +14,10 @@ import java.lang.ref.WeakReference
class SplashAdvConfig : BaseAdvConfig() {
var codeId: String = ""
var container: ViewGroup? = null
internal var isHotSplash: Boolean = false
internal var splashAdvListener: SplashAdvListener? = null
internal var lifecycleOwner: LifecycleOwner? = null
internal var lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY

fun setCodeId(codeId: String) = apply {
this.codeId = codeId
Expand All @@ -30,6 +35,15 @@ class SplashAdvConfig : BaseAdvConfig() {
this.activity = WeakReference(activity)
}

fun lifecycle(lifecycleOwner: LifecycleOwner, lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY) = apply {
this.lifecycleOwner = lifecycleOwner
this.lifeEvent = lifeEvent
}

fun isHotSplash(isHotSplash: Boolean) = apply {
this.isHotSplash = isHotSplash
}

fun setWidth(width: Int) = apply {
this.width = width
}
Expand Down

0 comments on commit 8833e34

Please sign in to comment.