Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom AdEventListener to Manilo #133

Open
wants to merge 3 commits into
base: dev-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kohii-ads/api/kohii-ads.api
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public final class kohii/v1/ads/Manilo : kohii/v1/exoplayer/Kohii, com/google/ad
public synthetic fun <init> (Landroid/content/Context;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkohii/v1/core/Master;Lkohii/v1/core/PlayableCreator;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lkohii/v1/core/Master;Lkohii/v1/core/PlayableCreator;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addAdEventListener (Lcom/google/ads/interactivemedia/v3/api/AdEvent$AdEventListener;)V
public fun onAdEvent (Lcom/google/ads/interactivemedia/v3/api/AdEvent;)V
public final fun removeAdEventListener (Lcom/google/ads/interactivemedia/v3/api/AdEvent$AdEventListener;)V
public final fun removeAllAdEventListener ()V
}

public final class kohii/v1/ads/Manilo$Companion {
Expand Down
14 changes: 14 additions & 0 deletions kohii-ads/src/main/java/kohii/v1/ads/Manilo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Manilo(
rendererProviderFactory: RendererProviderFactory = { PlayerViewProvider() }
) : Kohii(master, playableCreator, rendererProviderFactory), AdEventListener {

private val adEventListeners = mutableSetOf<AdEventListener>()

private constructor(context: Context) : this(Master[context])

/**
Expand Down Expand Up @@ -198,9 +200,21 @@ class Manilo(
}

// AdEventListener
fun addAdEventListener(listener: AdEventListener) {
adEventListeners.add(listener)
}

fun removeAdEventListener(listener: AdEventListener) {
adEventListeners.remove(listener)
}

fun removeAllAdEventListener() {
adEventListeners.clear()
}

// This callback only works when [Manilo] uses a default [ImaAdsLoader.Builder].
override fun onAdEvent(adEvent: AdEvent) {
"AdEvent: $adEvent".logInfo()
adEventListeners.forEach { it.onAdEvent(adEvent) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import kohii.v1.sample.common.ViewBindingFragment
import kohii.v1.sample.databinding.FragmentAdsListBinding
import okio.buffer
import okio.source
import timber.log.Timber

class AdsContainerFragment :
ViewBindingFragment<FragmentAdsListBinding>(FragmentAdsListBinding::inflate) {
Expand Down Expand Up @@ -93,6 +94,10 @@ class AdsContainerFragment :

manilo.register(this).addBucket(requireBinding().playerContainer)

manilo.addAdEventListener {
Timber.d("AdEventListener received : $it")
}

val layoutManager = LinearLayoutManager(view.context)
requireBinding().adsContainer.layoutManager = layoutManager
requireBinding().adsContainer.adapter = object : Adapter<ViewHolder>() {
Expand Down