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

Update native ad click #11

Open
wants to merge 2 commits into
base: dev
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import kotlin.math.roundToInt
open class SASHuaweiNativeAdContent constructor(var huaweiNativeAd: NativeAd) :
SASMediationNativeAdContent {

private var onClickListener: View.OnClickListener
private lateinit var registerClickableViews: Array<out View>
private val nativeVideoAdElement = SASNativeVideoAdElement()

companion object {
Expand All @@ -21,6 +23,13 @@ open class SASHuaweiNativeAdContent constructor(var huaweiNativeAd: NativeAd) :
}

init {

onClickListener = View.OnClickListener{
if (registerClickableViews != null && registerClickableViews[0] != null) {
huaweiNativeAd.triggerClick(huaweiNativeAd.extraBundle)
}
}

lateinit var videoUrl: String
if (huaweiNativeAd.videoOperator.hasVideo()) {

Expand Down Expand Up @@ -129,10 +138,27 @@ open class SASHuaweiNativeAdContent constructor(var huaweiNativeAd: NativeAd) :

override fun unregisterView(view: View) {
Log.i(TAG, "unregisterView method called.")

if(registerClickableViews != null){
// clean all installed listeners on clickable views
for (clickableView in registerClickableViews) {
clickableView.setOnClickListener(null)
// this is MANDATORY as the view will continue to intercept clicks although
// its clickListener is null
clickableView.isClickable = false
}
}
}

override fun registerView(view: View, array: Array<out View>?) {
Log.i(TAG, "registerView method called.")

if (array != null) {
registerClickableViews = array
for (clickableView in array) {
clickableView.setOnClickListener(onClickListener)
}
}
}

override fun getAdChoicesUrl(): String {
Expand Down