Browse Source

【广告组件】AdUnitManager新增删除AdUnit

liuxiaolong 2 years ago
parent
commit
4fffbd53e1

+ 1 - 1
lib_ad_core/build.gradle

@@ -2,7 +2,7 @@ plugins {
     id 'com.android.library'
     id 'org.jetbrains.kotlin.android'
 }
-def version = '1.0.0'
+def version = '1.0.1'
 def releaseTime() {
     return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
 }

+ 11 - 0
lib_ad_core/src/main/java/com/composition/android/lib/ad/AdUnitConfigManager.kt

@@ -93,5 +93,16 @@ class AdUnitConfigManager {
         return hasUnAvailableAdUnit.not()
     }
 
+    fun removeAdUnit(adSlotName: String) : Boolean {
+        val needRemoveBean = adUnitLists.find {
+            it.adSlotName.equals(adSlotName)
+        }
+        return adUnitLists.remove(needRemoveBean)
+    }
+
+    fun getAllAdUnits() : List<AdUnitBean>{
+        return adUnitLists
+    }
+
 
 }

+ 19 - 0
lib_ad_core/src/main/java/com/composition/android/lib/ad/impl/Api.kt

@@ -116,6 +116,9 @@ internal class Api {
         return ad
     }
 
+    /**
+     * 根据广告位名称获取缓存的广告
+     */
     fun getCacheAd(adSlotName: String) : AdResult.Success? {
         val ad = cacheList.find {
             it.adBean.adSlotName.equals(adSlotName)
@@ -126,6 +129,22 @@ internal class Api {
         return ad
     }
 
+    /**
+     * 根据广告位名称,移除缓存池中对应的广告缓存
+     * @param adSlotName 广告位名称
+     */
+    fun removeCacheAdByAdSlot(adSlotName: String) : Boolean{
+        val ad = cacheList.find {
+            it.adBean.adSlotName.equals(adSlotName)
+        }
+        return if (ad != null) {
+            return cacheList.remove(ad)
+        }else{
+            false
+        }
+
+    }
+
 
     private fun getAdLoader(adUnitBean: AdUnitBean): AdLoader {
         return AdLoaderFactory.getAdLoader(adUnitBean)