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: admob integration #29

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions ads-admob/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions ads-admob/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsKotlinAndroid)
}

apply(from = "../gradlescripts/android-library.gradle")

val artifactGroupId by extra("io.voodoo.apps")
val artifactId by extra("ads-admob")
val artifactVersion by extra(rootProject.extra.get("SDK_VER"))

android {
namespace = "io.voodoo.apps.ads.admob"
}

dependencies {
implementation(project(":ads-api"))
implementation(libs.play.services.ads)

}

apply(from = "../gradlescripts/publisher.gradle")
Empty file added ads-admob/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions ads-admob/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions ads-admob/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.voodoo.apps.ads.admob.exception

import com.google.android.gms.ads.LoadAdError
import java.io.IOException

class AdMobAdLoadException(val error: LoadAdError) : IOException(error.message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.voodoo.apps.ads.admob.listener

import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.nativead.NativeAd

interface AdMobNativeAdViewListener {
fun onAdClicked(ad: NativeAd?)

fun onAdClosed(ad: NativeAd?)

fun onAdFailedToLoad(error: LoadAdError?)

fun onAdImpression(ad: NativeAd?)

fun onAdLoaded(ad: NativeAd?)

fun onAdOpened(ad: NativeAd?)

fun onAdSwipeGestureClicked(ad: NativeAd?)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.voodoo.apps.ads.admob.listener

import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.nativead.NativeAd

abstract class DefaultAdMobNativeAdViewListener : AdMobNativeAdViewListener {
override fun onAdClicked(ad: NativeAd?) {}

override fun onAdClosed(ad: NativeAd?) {}

override fun onAdFailedToLoad(error: LoadAdError?) {}

override fun onAdImpression(ad: NativeAd?) {}

override fun onAdLoaded(ad: NativeAd?) {}

override fun onAdOpened(ad: NativeAd?) {}

override fun onAdSwipeGestureClicked(ad: NativeAd?) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.voodoo.apps.ads.admob.listener

import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.nativead.NativeAd
import java.util.concurrent.CopyOnWriteArraySet

internal class MultiAdMobNativeAdViewListener : AdMobNativeAdViewListener {

// TODO: check the implementation, we're re-creating the backing list for every request (because we add a listener)
private val delegates = CopyOnWriteArraySet<AdMobNativeAdViewListener>()

fun add(listener: AdMobNativeAdViewListener) {
delegates.add(listener)
}

fun remove(listener: AdMobNativeAdViewListener) {
delegates.remove(listener)
}

override fun onAdClosed(ad: NativeAd?) {
delegates.forEach { it.onAdClosed(ad) }
}

override fun onAdFailedToLoad(error: LoadAdError?) {
delegates.forEach { it.onAdFailedToLoad(error) }
}

override fun onAdImpression(ad: NativeAd?) {
delegates.forEach { it.onAdImpression(ad) }
}

override fun onAdOpened(ad: NativeAd?) {
delegates.forEach { it.onAdOpened(ad) }
}

override fun onAdClicked(ad: NativeAd?) {
delegates.forEach { it.onAdClicked(ad) }
}

override fun onAdLoaded(ad: NativeAd?) {
delegates.forEach { it.onAdLoaded(ad) }
}

override fun onAdSwipeGestureClicked(ad: NativeAd?) {
delegates.forEach { it.onAdSwipeGestureClicked(ad) }
}
}
Loading