diff --git a/sdk/src/com/appnexus/opensdk/VisibilityDetector.java b/sdk/src/com/appnexus/opensdk/VisibilityDetector.java index d94f0f16..060531da 100644 --- a/sdk/src/com/appnexus/opensdk/VisibilityDetector.java +++ b/sdk/src/com/appnexus/opensdk/VisibilityDetector.java @@ -67,7 +67,7 @@ private boolean remove(List> list, View reference) for (Iterator> iterator = list.iterator(); iterator.hasNext(); ) { WeakReference weakRef = iterator.next(); if (weakRef.get() == reference) { - if (!(reference instanceof BannerAdView)) { + if (reference != null && !(reference instanceof BannerAdView)) { reference.setTag(R.string.native_view_tag, null); } iterator.remove(); diff --git a/sdk/src/com/appnexus/opensdk/utils/ImageService.java b/sdk/src/com/appnexus/opensdk/utils/ImageService.java index b0fd4c6a..738112dd 100644 --- a/sdk/src/com/appnexus/opensdk/utils/ImageService.java +++ b/sdk/src/com/appnexus/opensdk/utils/ImageService.java @@ -74,7 +74,8 @@ public void execute() { return; } if (imageUrlMap != null && !imageUrlMap.isEmpty()) { - for (Map.Entry pairs : imageUrlMap.entrySet()) { + HashMap imageUrlMapCopy = new HashMap<>(imageUrlMap); + for (Map.Entry pairs : imageUrlMapCopy.entrySet()) { ImageDownloader downloader = new ImageDownloader(imageReceiver, (String) pairs.getKey(), (String) pairs.getValue(), this); Clog.d(Clog.baseLogTag, "Downloading " + pairs.getKey() + " from url: " + pairs.getValue()); downloader.execute(); diff --git a/tests/AppNexusSDKTestApp/app/src/androidTest/java/appnexus/com/appnexussdktestapp/util/Utility.kt b/tests/AppNexusSDKTestApp/app/src/androidTest/java/appnexus/com/appnexussdktestapp/util/Utility.kt index 03a907d2..05812d70 100644 --- a/tests/AppNexusSDKTestApp/app/src/androidTest/java/appnexus/com/appnexussdktestapp/util/Utility.kt +++ b/tests/AppNexusSDKTestApp/app/src/androidTest/java/appnexus/com/appnexussdktestapp/util/Utility.kt @@ -5,7 +5,7 @@ import android.os.Handler import android.os.Looper import android.util.Log import android.view.View -import java.lang.ref.WeakReference +import org.junit.Assert class Utility { companion object { @@ -14,21 +14,26 @@ class Utility { Handler(Looper.getMainLooper()).post({ val vDetector = Class.forName("com.appnexus.opensdk.VisibilityDetector") - val create = vDetector.getDeclaredMethod("create", WeakReference::class.java) - create.isAccessible = true - val weakReference = WeakReference(View(context)) - val vDetInst = create.invoke(null, weakReference) + val getInstance = vDetector.getDeclaredMethod("getInstance") + + getInstance.isAccessible = true + val viewReference = View(context) + val vDetInst = getInstance.invoke(null) - val destroy = vDetector.getDeclaredMethod("destroy", WeakReference::class.java) + val addVisibilityListener = vDetector.getDeclaredMethod("addVisibilityListener", View::class.java) + addVisibilityListener.isAccessible = true + addVisibilityListener.invoke(vDetInst, viewReference) + + val destroy = vDetector.getDeclaredMethod("destroy", View::class.java) destroy.isAccessible = true - destroy.invoke(vDetInst, weakReference) + destroy.invoke(vDetInst, viewReference) - val declaredField = vDetector.getDeclaredField("viewListenerMap") + val declaredField = vDetector.getDeclaredField("viewList") declaredField.isAccessible = true - var map = declaredField.get(vDetInst) as HashMap - Log.e("VISIBILITY", " Size: ${checkZero} ${map.size}"); + var list = declaredField.get(vDetInst) as List + Log.e("VISIBILITY", " Size: ${checkZero} ${list.size}"); - junit.framework.Assert.assertTrue(map.size == checkZero) + Assert.assertEquals(checkZero, list.size) }) } diff --git a/tests/AppNexusSDKTestApp/app/src/main/java/appnexus/com/appnexussdktestapp/MARLoadAndDisplayActivity.kt b/tests/AppNexusSDKTestApp/app/src/main/java/appnexus/com/appnexussdktestapp/MARLoadAndDisplayActivity.kt index a2682c92..0eec6f22 100644 --- a/tests/AppNexusSDKTestApp/app/src/main/java/appnexus/com/appnexussdktestapp/MARLoadAndDisplayActivity.kt +++ b/tests/AppNexusSDKTestApp/app/src/main/java/appnexus/com/appnexussdktestapp/MARLoadAndDisplayActivity.kt @@ -179,7 +179,7 @@ class MARLoadAndDisplayActivity : Activity() { idlingResource.decrement() } - override fun onAdFailed(errorcode: ResultCode, adResponseInfo: ANAdResponseInfo) { + override fun onAdFailed(errorcode: ResultCode, adResponseInfo: ANAdResponseInfo?) { msg += "Native Ad Failed:$errorcode\n" toast() if (!idlingResource.isIdleNow) @@ -313,7 +313,9 @@ class MARLoadAndDisplayActivity : Activity() { onLazyAdLoaded = true arrayListAd.add(adView) if (displayAd) - recyclerListAdView.adapter!!.notifyDataSetChanged() + Handler(Looper.getMainLooper()).post({ + recyclerListAdView.adapter!!.notifyDataSetChanged() + }) if (!idlingResource.isIdleNow) idlingResource.decrement() }