Skip to content

Commit

Permalink
fix: version update / facebook audience
Browse files Browse the repository at this point in the history
  • Loading branch information
steadymoka committed Dec 12, 2022
1 parent dde22c1 commit 6b20927
Show file tree
Hide file tree
Showing 25 changed files with 1,236 additions and 181 deletions.
12 changes: 6 additions & 6 deletions adhelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ dependencies {
implementation project(':base')
implementation project(':dialog')

implementation "com.google.android.gms:play-services-ads:21.1.0"
implementation "com.facebook.android:audience-network-sdk:5.5.0"
implementation "com.google.android.gms:play-services-ads:21.3.0"
implementation "com.facebook.android:audience-network-sdk:6.12.0"

implementation "androidx.core:core-ktx:1.1.0"
implementation "androidx.appcompat:appcompat:1.5.0"
implementation "androidx.constraintlayout:constraintlayout:2.2.0-alpha03"
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.appcompat:appcompat:1.5.1"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.cardview:cardview:1.0.0"
}
31 changes: 17 additions & 14 deletions adhelper/src/main/java/moka/land/adhelper/BannerAdView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,26 @@ class BannerAdView constructor(context: Context, attributeSet: AttributeSet? = n
_view.bannerContainer.removeAllViews()
_view.bannerContainer.addView(facebookBannerAd)

facebookBannerAd?.setAdListener(object : AdListener {
override fun onAdLoaded(ad: Ad) {
callback?.invoke(true)
}
val config = facebookBannerAd
?.buildLoadAdConfig()
?.withAdListener(object : AdListener {
override fun onAdLoaded(ad: Ad) {
callback?.invoke(true)
}

override fun onError(ad: Ad?, error: AdError?) {
_view.bannerContainer.removeAllViews()
fail()
}
override fun onError(ad: Ad?, error: AdError?) {
_view.bannerContainer.removeAllViews()
fail()
}

override fun onAdClicked(p0: Ad?) {
}
override fun onAdClicked(p0: Ad?) {
}

override fun onLoggingImpression(p0: Ad?) {
}
})
facebookBannerAd?.loadAd()
override fun onLoggingImpression(p0: Ad?) {
}
})
?.build()
facebookBannerAd?.loadAd(config)
}

private fun loadAdmobBannerAd(fail: () -> Unit) {
Expand Down
49 changes: 26 additions & 23 deletions adhelper/src/main/java/moka/land/adhelper/InterstitialAdHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,38 @@ class InterstitialAdHelper private constructor(

fun showAudience(key: String, success: () -> Unit, fail: () -> Unit) {
val interstitialAd = InterstitialAd(context, key)
interstitialAd.setAdListener(object : InterstitialAdListener {
override fun onInterstitialDisplayed(p0: Ad?) {
}
val config = interstitialAd
.buildLoadAdConfig()
.withAdListener(object : InterstitialAdListener {
override fun onInterstitialDisplayed(p0: Ad?) {
}

override fun onAdClicked(p0: Ad?) {
}
override fun onAdClicked(p0: Ad?) {
}

override fun onInterstitialDismissed(p0: Ad?) {
log("show_facebook_InterstitialAd dismissed")
onClose?.invoke()
}
override fun onInterstitialDismissed(p0: Ad?) {
log("show_facebook_InterstitialAd dismissed")
onClose?.invoke()
}

override fun onError(p0: Ad?, p1: AdError?) {
log("show_facebook_InterstitialAd fail")
fail()
}
override fun onError(p0: Ad?, p1: AdError?) {
log("show_facebook_InterstitialAd fail")
fail()
}

override fun onAdLoaded(p0: Ad?) {
log("Success audience network ad")
if (null == onShow || onShow?.invoke() == true) {
interstitialAd.show()
override fun onAdLoaded(p0: Ad?) {
log("Success audience network ad")
if (null == onShow || onShow?.invoke() == true) {
interstitialAd.show()
}
success()
}
success()
}

override fun onLoggingImpression(p0: Ad?) {
}
})
interstitialAd.loadAd()
override fun onLoggingImpression(p0: Ad?) {
}
})
.build()
interstitialAd.loadAd(config)
}

companion object {
Expand Down
44 changes: 24 additions & 20 deletions adhelper/src/main/java/moka/land/adhelper/NativeAdView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,35 @@ class NativeAdView constructor(context: Context, attributeSet: AttributeSet? = n
findViewById<FrameLayout>(R.id.frameLayout_media).visibleOrGone(option.media)

audienceNativeAd = NativeAd(context, option.fbAudienceKey)
audienceNativeAd!!.setAdListener(object : NativeAdListener {
override fun onMediaDownloaded(p0: Ad?) {
}

override fun onAdLoaded(ad: Ad) {
if (ad != audienceNativeAd) {
return
val config = audienceNativeAd
?.buildLoadAdConfig()
?.withMediaCacheFlag(NativeAdBase.MediaCacheFlag.ALL)
?.withAdListener(object : NativeAdListener {
override fun onMediaDownloaded(p0: Ad?) {
}

inflateNativeAdViews(audienceNativeAd!!)
callback?.invoke(true)
}
override fun onAdLoaded(ad: Ad) {
if (ad != audienceNativeAd) {
return
}

override fun onError(ad: Ad?, error: AdError?) {
log("=== Audience's ad failed to load / ${error?.errorCode} / ${error?.errorMessage}")
fail()
}
inflateNativeAdViews(audienceNativeAd!!)
callback?.invoke(true)
}

override fun onAdClicked(p0: Ad?) {
}
override fun onError(ad: Ad?, error: AdError?) {
log("=== Audience's ad failed to load / ${error?.errorCode} / ${error?.errorMessage}")
fail()
}

override fun onLoggingImpression(p0: Ad?) {
}
})
audienceNativeAd!!.loadAd(NativeAdBase.MediaCacheFlag.ALL)
override fun onAdClicked(p0: Ad?) {
}

override fun onLoggingImpression(p0: Ad?) {
}
})
?.build()
audienceNativeAd!!.loadAd(config)
}

private fun inflateNativeAdViews(facebookNativeAd: NativeAd) {
Expand Down
66 changes: 33 additions & 33 deletions adhelper/src/main/java/moka/land/adhelper/RewardedAdHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ class RewardedAdHelper private constructor() {
onRewarded = null
}

/**
*/

private fun loadRewardedVideoAd_admob(callback: (isSuccessLoad: Boolean) -> Unit) {
val adRequest = AdRequest.Builder().build()
RewardedAd.load(context!!, admobKey!!, adRequest, object : RewardedAdLoadCallback() {
Expand Down Expand Up @@ -139,43 +136,46 @@ class RewardedAdHelper private constructor() {
}

private fun loadRewardedVideoAd_audience(callback: (isSuccessLoad: Boolean) -> Unit) {
mAd_audience!!.setAdListener(object : com.facebook.ads.RewardedVideoAdListener {
override fun onError(ad: Ad, error: AdError) {
// Rewarded video ad failed to load
log("Rewarded video audience ad failed to load: ${error.errorMessage}")
callback(false)
}
val config = mAd_audience!!
.buildLoadAdConfig()
.withAdListener(object : com.facebook.ads.RewardedVideoAdListener {
override fun onError(ad: Ad, error: AdError) {
// Rewarded video ad failed to load
log("Rewarded video audience ad failed to load: ${error.errorMessage}")
callback(false)
}

override fun onAdLoaded(ad: Ad) {
// Rewarded video ad is loaded and ready to be displayed
callback(true)
}
override fun onAdLoaded(ad: Ad) {
// Rewarded video ad is loaded and ready to be displayed
callback(true)
}

override fun onAdClicked(ad: Ad) {
// Rewarded video ad clicked
}
override fun onAdClicked(ad: Ad) {
// Rewarded video ad clicked
}

override fun onLoggingImpression(ad: Ad) {
// Rewarded Video ad impression - the event will fire when the
// video starts playing
}
override fun onLoggingImpression(ad: Ad) {
// Rewarded Video ad impression - the event will fire when the
// video starts playing
}

override fun onRewardedVideoCompleted() {
// Rewarded Video View Complete - the video has been played to the end.
// You can use this event to initialize your reward
override fun onRewardedVideoCompleted() {
// Rewarded Video View Complete - the video has been played to the end.
// You can use this event to initialize your reward

// Call method to give reward
onRewarded?.invoke()
}
// Call method to give reward
onRewarded?.invoke()
}

override fun onRewardedVideoClosed() {
// The Rewarded Video ad was closed - this can occur during the video
// by closing the app, or closing the end card.
mAd_audience?.loadAd()
}
})
override fun onRewardedVideoClosed() {
// The Rewarded Video ad was closed - this can occur during the video
// by closing the app, or closing the end card.
mAd_audience?.loadAd()
}
})
.build()

mAd_audience?.loadAd()
mAd_audience?.loadAd(config)
}
}

Expand Down
26 changes: 14 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ dependencies {

/* Kotlin & Coroutine */
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1")

/* Koin */
implementation("io.insert-koin:koin-android:3.2.0")
Expand All @@ -88,23 +88,23 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.5.0")
implementation("androidx.core:core-ktx:1.8.0")
implementation("androidx.multidex:multidex:2.0.1")
implementation("androidx.exifinterface:exifinterface:1.2.0")
implementation("androidx.exifinterface:exifinterface:1.3.3")

implementation("androidx.viewpager2:viewpager2:1.0.0")
implementation("androidx.recyclerview:recyclerview:1.2.0-alpha05")
implementation("androidx.recyclerview:recyclerview:1.3.0-beta02")
implementation("androidx.cardview:cardview:1.0.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.0-beta8")
implementation("com.google.android.material:material:1.1.0")
implementation("androidx.coordinatorlayout:coordinatorlayout:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.6.1")
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")

implementation("androidx.work:work-runtime-ktx:2.2.0")
implementation("androidx.work:work-runtime-ktx:2.7.1")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.1")
implementation("androidx.navigation:navigation-ui-ktx:2.5.1")

implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0")
// implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
// implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.2.0")
// kapt("androidx.lifecycle:lifecycle-compiler:2.2.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.1")
kapt("androidx.lifecycle:lifecycle-compiler:2.5.1")

/* Room */
implementation("androidx.room:room-ktx:2.4.3")
Expand All @@ -117,6 +117,8 @@ dependencies {
/* Network */
implementation("com.apollographql.apollo:apollo-runtime:2.3.1")

implementation("com.airbnb.android:lottie:5.2.0")

implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="n">
android:usesCleartextTraffic="true">

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
Expand Down
Loading

0 comments on commit 6b20927

Please sign in to comment.