From b0cabcbdca2db6043a9466ed153a72dbfa0e002b Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Fri, 27 Oct 2023 14:04:08 +0300 Subject: [PATCH] Rename `CacheAdModel` to `CachedAd` --- monetisation/admob/api/admob.api | 36 +++++++++---------- .../monetisation/admob/formats/AdCache.kt | 20 +++++------ .../monetisation/admob/formats/AppOpenAd.kt | 7 ++-- .../formats/{CacheAdModel.kt => CachedAd.kt} | 12 +++---- .../admob/formats/InterstitialAd.kt | 4 +-- .../monetisation/admob/formats/RewardedAd.kt | 4 +-- .../admob/formats/RewardedInterstitialAd.kt | 4 +-- 7 files changed, 43 insertions(+), 44 deletions(-) rename monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/{CacheAdModel.kt => CachedAd.kt} (93%) diff --git a/monetisation/admob/api/admob.api b/monetisation/admob/api/admob.api index 2a13f27a..73602f94 100644 --- a/monetisation/admob/api/admob.api +++ b/monetisation/admob/api/admob.api @@ -90,8 +90,8 @@ public abstract class dev/teogor/ceres/monetisation/admob/formats/Ad : dev/teogo public final class dev/teogor/ceres/monetisation/admob/formats/AdCache { public static final field $stable I public static final field INSTANCE Ldev/teogor/ceres/monetisation/admob/formats/AdCache; - public final fun cacheAd (Ljava/lang/String;Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel;)V - public final fun getAd (Ljava/lang/String;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel; + public final fun cacheAd (Ljava/lang/String;Ldev/teogor/ceres/monetisation/admob/formats/CachedAd;)V + public final fun getAd (Ljava/lang/String;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd; public final fun getAdCount (Ljava/lang/String;)I public final fun getAds (Ljava/lang/String;I)Ljava/util/List; public final fun removeAd (Ljava/lang/String;)V @@ -240,19 +240,19 @@ public abstract class dev/teogor/ceres/monetisation/admob/formats/BannerAd : dev public fun useCache ()Z } -public abstract class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public abstract class dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public synthetic fun (JLkotlin/jvm/internal/DefaultConstructorMarker;)V public fun getLoadTime ()J } -public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$AppOpen : dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public final class dev/teogor/ceres/monetisation/admob/formats/CachedAd$AppOpen : dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public fun (Lcom/google/android/gms/ads/appopen/AppOpenAd;J)V public final fun component1 ()Lcom/google/android/gms/ads/appopen/AppOpenAd; public final fun component2 ()J - public final fun copy (Lcom/google/android/gms/ads/appopen/AppOpenAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$AppOpen; - public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$AppOpen;Lcom/google/android/gms/ads/appopen/AppOpenAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$AppOpen; + public final fun copy (Lcom/google/android/gms/ads/appopen/AppOpenAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$AppOpen; + public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$AppOpen;Lcom/google/android/gms/ads/appopen/AppOpenAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$AppOpen; public fun equals (Ljava/lang/Object;)Z public final fun getAd ()Lcom/google/android/gms/ads/appopen/AppOpenAd; public fun getLoadTime ()J @@ -260,13 +260,13 @@ public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$AppO public fun toString ()Ljava/lang/String; } -public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Interstitial : dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public final class dev/teogor/ceres/monetisation/admob/formats/CachedAd$Interstitial : dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public fun (Lcom/google/android/gms/ads/interstitial/InterstitialAd;J)V public final fun component1 ()Lcom/google/android/gms/ads/interstitial/InterstitialAd; public final fun component2 ()J - public final fun copy (Lcom/google/android/gms/ads/interstitial/InterstitialAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Interstitial; - public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Interstitial;Lcom/google/android/gms/ads/interstitial/InterstitialAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Interstitial; + public final fun copy (Lcom/google/android/gms/ads/interstitial/InterstitialAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Interstitial; + public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Interstitial;Lcom/google/android/gms/ads/interstitial/InterstitialAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Interstitial; public fun equals (Ljava/lang/Object;)Z public final fun getAd ()Lcom/google/android/gms/ads/interstitial/InterstitialAd; public fun getLoadTime ()J @@ -274,13 +274,13 @@ public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Inte public fun toString ()Ljava/lang/String; } -public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Native : dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public final class dev/teogor/ceres/monetisation/admob/formats/CachedAd$Native : dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public fun (Lcom/google/android/gms/ads/nativead/NativeAd;J)V public final fun component1 ()Lcom/google/android/gms/ads/nativead/NativeAd; public final fun component2 ()J - public final fun copy (Lcom/google/android/gms/ads/nativead/NativeAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Native; - public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Native;Lcom/google/android/gms/ads/nativead/NativeAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Native; + public final fun copy (Lcom/google/android/gms/ads/nativead/NativeAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Native; + public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Native;Lcom/google/android/gms/ads/nativead/NativeAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Native; public fun equals (Ljava/lang/Object;)Z public final fun getAd ()Lcom/google/android/gms/ads/nativead/NativeAd; public fun getLoadTime ()J @@ -288,13 +288,13 @@ public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Nati public fun toString ()Ljava/lang/String; } -public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Rewarded : dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public final class dev/teogor/ceres/monetisation/admob/formats/CachedAd$Rewarded : dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public fun (Lcom/google/android/gms/ads/rewarded/RewardedAd;J)V public final fun component1 ()Lcom/google/android/gms/ads/rewarded/RewardedAd; public final fun component2 ()J - public final fun copy (Lcom/google/android/gms/ads/rewarded/RewardedAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Rewarded; - public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Rewarded;Lcom/google/android/gms/ads/rewarded/RewardedAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Rewarded; + public final fun copy (Lcom/google/android/gms/ads/rewarded/RewardedAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Rewarded; + public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Rewarded;Lcom/google/android/gms/ads/rewarded/RewardedAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$Rewarded; public fun equals (Ljava/lang/Object;)Z public final fun getAd ()Lcom/google/android/gms/ads/rewarded/RewardedAd; public fun getLoadTime ()J @@ -302,13 +302,13 @@ public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$Rewa public fun toString ()Ljava/lang/String; } -public final class dev/teogor/ceres/monetisation/admob/formats/CacheAdModel$RewardedInterstitial : dev/teogor/ceres/monetisation/admob/formats/CacheAdModel { +public final class dev/teogor/ceres/monetisation/admob/formats/CachedAd$RewardedInterstitial : dev/teogor/ceres/monetisation/admob/formats/CachedAd { public static final field $stable I public fun (Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd;J)V public final fun component1 ()Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd; public final fun component2 ()J - public final fun copy (Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$RewardedInterstitial; - public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$RewardedInterstitial;Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CacheAdModel$RewardedInterstitial; + public final fun copy (Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd;J)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$RewardedInterstitial; + public static synthetic fun copy$default (Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$RewardedInterstitial;Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd;JILjava/lang/Object;)Ldev/teogor/ceres/monetisation/admob/formats/CachedAd$RewardedInterstitial; public fun equals (Ljava/lang/Object;)Z public final fun getAd ()Lcom/google/android/gms/ads/rewardedinterstitial/RewardedInterstitialAd; public fun getLoadTime ()J diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AdCache.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AdCache.kt index 9afc69cd..d4e7e78b 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AdCache.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AdCache.kt @@ -17,11 +17,11 @@ package dev.teogor.ceres.monetisation.admob.formats object AdCache { - private val adCache: MutableMap> = mutableMapOf() + private val cachedAds: MutableMap> = mutableMapOf() @Synchronized - fun cacheAd(adId: String, ad: CacheAdModel) { - adCache.getOrPut(adId) { + fun cacheAd(adId: String, ad: CachedAd) { + cachedAds.getOrPut(adId) { mutableListOf() }.apply { add(ad) @@ -29,27 +29,27 @@ object AdCache { } @Synchronized - fun getAd(adId: String): CacheAdModel? { - return adCache[adId]?.firstOrNull() + fun getAd(adId: String): CachedAd? { + return cachedAds[adId]?.firstOrNull() } @Synchronized - fun getAds(adId: String, count: Int): List { - return adCache[adId]?.take(count) ?: emptyList() + fun getAds(adId: String, count: Int): List { + return cachedAds[adId]?.take(count) ?: emptyList() } @Synchronized fun removeAd(adId: String) { - adCache[adId]?.let { adList -> + cachedAds[adId]?.let { adList -> if (adList.isNotEmpty()) { adList.removeAt(0) } if (adList.isEmpty()) { - adCache.remove(adId) + cachedAds.remove(adId) } } } @Synchronized - fun getAdCount(adId: String) = adCache[adId]?.size ?: 0 + fun getAdCount(adId: String) = cachedAds[adId]?.size ?: 0 } diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AppOpenAd.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AppOpenAd.kt index b1724c58..5d01d1a5 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AppOpenAd.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/AppOpenAd.kt @@ -53,7 +53,7 @@ abstract class AppOpenAd : Ad() { log("onAdLoaded.") AdCache.cacheAd( adId = id, - ad = CacheAdModel.AppOpen(ad, Date().time), + ad = CachedAd.AppOpen(ad, Date().time), ) onListener(AdEvent.AdLoaded) } @@ -92,12 +92,11 @@ abstract class AppOpenAd : Ad() { return } - val appOpenAd = (ad as CacheAdModel.AppOpen).ad + val appOpenAd = (ad as CachedAd.AppOpen).ad + if (!wasLoadTimeLessThanNHoursAgo(ad.loadTime, 4)) { reloadExpiredAd() return - } else { - log("App open ad is still valid; no need to reload.") } if (isShowing) { diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CacheAdModel.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CachedAd.kt similarity index 93% rename from monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CacheAdModel.kt rename to monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CachedAd.kt index c619297c..20873338 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CacheAdModel.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/CachedAd.kt @@ -27,7 +27,7 @@ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd * * @property loadTime The time when the ad was loaded. */ -sealed class CacheAdModel( +sealed class CachedAd( open val loadTime: Long, ) { /** @@ -39,7 +39,7 @@ sealed class CacheAdModel( data class AppOpen( val ad: AppOpenAd, override val loadTime: Long, - ) : CacheAdModel(loadTime) + ) : CachedAd(loadTime) /** * Data class representing a cached Interstitial ad. @@ -50,7 +50,7 @@ sealed class CacheAdModel( data class Interstitial( val ad: InterstitialAd, override val loadTime: Long, - ) : CacheAdModel(loadTime) + ) : CachedAd(loadTime) /** * Data class representing a cached Rewarded Interstitial ad. @@ -61,7 +61,7 @@ sealed class CacheAdModel( data class RewardedInterstitial( val ad: RewardedInterstitialAd, override val loadTime: Long, - ) : CacheAdModel(loadTime) + ) : CachedAd(loadTime) /** * Data class representing a cached Rewarded ad. @@ -72,7 +72,7 @@ sealed class CacheAdModel( data class Rewarded( val ad: RewardedAd, override val loadTime: Long, - ) : CacheAdModel(loadTime) + ) : CachedAd(loadTime) /** * Data class representing a cached Native ad. @@ -83,5 +83,5 @@ sealed class CacheAdModel( data class Native( val ad: NativeAd, override val loadTime: Long, - ) : CacheAdModel(loadTime) + ) : CachedAd(loadTime) } diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/InterstitialAd.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/InterstitialAd.kt index 40ec47fc..f5ed6485 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/InterstitialAd.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/InterstitialAd.kt @@ -58,7 +58,7 @@ abstract class InterstitialAd( log("Ad was loaded.") AdCache.cacheAd( adId = id, - ad = CacheAdModel.Interstitial(ad, Date().time), + ad = CachedAd.Interstitial(ad, Date().time), ) onListener(AdEvent.AdLoaded) } @@ -84,7 +84,7 @@ abstract class InterstitialAd( load() return } - val interstitialAd = (ad as CacheAdModel.Interstitial).ad + val interstitialAd = (ad as CachedAd.Interstitial).ad if (isShowing) { log("The interstitial ad is already showing.") return diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedAd.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedAd.kt index b96b9d12..ea86eeb3 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedAd.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedAd.kt @@ -58,7 +58,7 @@ abstract class RewardedAd( log("Ad was loaded.") AdCache.cacheAd( adId = id, - ad = CacheAdModel.Rewarded(ad, Date().time), + ad = CachedAd.Rewarded(ad, Date().time), ) onListener(AdEvent.AdLoaded) } @@ -84,7 +84,7 @@ abstract class RewardedAd( load() return } - val rewardedAd = (ad as CacheAdModel.Rewarded).ad + val rewardedAd = (ad as CachedAd.Rewarded).ad if (isShowing) { log("The rewarded interstitial ad is already showing.") return diff --git a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedInterstitialAd.kt b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedInterstitialAd.kt index 76c291a3..3decc4fa 100644 --- a/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedInterstitialAd.kt +++ b/monetisation/admob/src/main/kotlin/dev/teogor/ceres/monetisation/admob/formats/RewardedInterstitialAd.kt @@ -58,7 +58,7 @@ abstract class RewardedInterstitialAd( log("Ad was loaded.") AdCache.cacheAd( adId = id, - ad = CacheAdModel.RewardedInterstitial(ad, Date().time), + ad = CachedAd.RewardedInterstitial(ad, Date().time), ) onListener(AdEvent.AdLoaded) } @@ -84,7 +84,7 @@ abstract class RewardedInterstitialAd( load() return } - val rewardedInterstitialAd = (ad as CacheAdModel.RewardedInterstitial).ad + val rewardedInterstitialAd = (ad as CachedAd.RewardedInterstitial).ad if (isShowing) { log("The rewarded interstitial ad is already showing.") return