From f9922f4c8cbf74864b1d2b9125579b61e86a6b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Bonaf=C3=A9?= <99195905+github-lucas-bon@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:07:21 +0200 Subject: [PATCH] Layout params fix (#232) * wip * wip * wip * wip * wip --- .../component/GenericRecyclerViewAdapter.kt | 2 +- .../PluginRendererScrollViewFragment.kt | 11 +-- ...StandaloneIntegrationScrollViewFragment.kt | 20 ++-- .../inread/InReadGridRecyclerViewFragment.kt | 6 +- .../format/inread/InReadScrollViewFragment.kt | 91 +++++++++---------- .../adapter/SimpleRecyclerViewAdapter.kt | 23 ++--- .../inread/extensions/ViewExtensions.kt | 18 ++++ .../adapter/AdMobRecyclerViewAdapter.kt | 14 +-- .../adapter/AppLovinRecyclerViewAdapter.kt | 12 +-- .../admob/AdMobGridRecyclerViewFragment.kt | 5 +- .../admob/AdMobRecyclerViewFragment.kt | 5 +- .../admob/AdMobScrollViewFragment.kt | 12 +-- .../AppLovinGridRecyclerViewFragment.kt | 7 +- .../applovin/AppLovinRecyclerViewFragment.kt | 5 +- .../applovin/AppLovinScrollViewFragment.kt | 12 +-- .../SmartNativeGridRecyclerViewFragment.kt | 4 + .../smart/SmartNativeRecyclerViewFragment.kt | 4 + .../smart/SmartRecyclerViewFragment.kt | 3 +- .../smart/SmartScrollViewFragment.kt | 2 +- .../res/layout/fragment_inread_scrollview.xml | 2 +- 20 files changed, 133 insertions(+), 125 deletions(-) create mode 100644 TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/extensions/ViewExtensions.kt diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/component/GenericRecyclerViewAdapter.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/component/GenericRecyclerViewAdapter.kt index 52c8e77..6b2d190 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/component/GenericRecyclerViewAdapter.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/component/GenericRecyclerViewAdapter.kt @@ -15,7 +15,7 @@ open class GenericRecyclerViewAdapter(private val mTitle: String) : RecyclerView 0 -> RecyclerItemType.TYPE_SCROLL_DOWN.value 1 -> RecyclerItemType.TYPE_ARTICLE_TITLE.value 2 -> RecyclerItemType.TYPE_ARTICLE_REAL_LINES.value - 6 -> RecyclerItemType.TYPE_TEADS.value + 4 -> RecyclerItemType.TYPE_TEADS.value else -> RecyclerItemType.TYPE_ARTICLE_FAKE_LINES.value } } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/PluginRendererScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/PluginRendererScrollViewFragment.kt index 5fce19c..e8ab525 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/PluginRendererScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/PluginRendererScrollViewFragment.kt @@ -20,6 +20,7 @@ import tv.teads.sdk.TeadsMediationSettings import tv.teads.teadssdkdemo.R import tv.teads.teadssdkdemo.data.CreativeSize import tv.teads.teadssdkdemo.databinding.FragmentInreadScrollviewBinding +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer import tv.teads.teadssdkdemo.format.mediation.identifier.PrebidIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment @@ -69,12 +70,8 @@ class PluginRendererScrollViewFragment : BaseFragment() { bannerView?.setPluginEventListener(object : TeadsPBMEventListener{ override fun onAdRatioUpdate(adRatio: AdRatio) { Log.d("TeadsPBMEventListener", "onAdRatioUpdate") - - bannerView?.let { - val adViewParams = binding.adSlotView.layoutParams - adViewParams.height = adRatio.calculateHeight(it.measuredWidth) - binding.adSlotView.layoutParams = adViewParams - } + // Resize + binding.adSlotContainer.resizeAdContainer(adRatio) } override fun onAdCollapsedFromFullscreen() { @@ -114,7 +111,7 @@ class PluginRendererScrollViewFragment : BaseFragment() { }) // 8. Add the ad view to its container - bannerView?.let { binding.adSlotView.addView(it) } + bannerView?.let { binding.adSlotContainer.addView(it) } // 9. Load the ad bannerView?.loadAd() diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/StandaloneIntegrationScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/StandaloneIntegrationScrollViewFragment.kt index 9498db4..f19dc11 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/StandaloneIntegrationScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/headerbidding/prebid/StandaloneIntegrationScrollViewFragment.kt @@ -18,6 +18,7 @@ import tv.teads.sdk.VideoPlaybackListener import tv.teads.sdk.renderer.InReadAdView import tv.teads.teadssdkdemo.R import tv.teads.teadssdkdemo.databinding.FragmentInreadScrollviewBinding +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer import tv.teads.teadssdkdemo.utils.BaseFragment /** @@ -62,24 +63,21 @@ class StandaloneIntegrationScrollViewFragment : BaseFragment() { requestSettings, object : InReadAdViewListener { override fun onAdReceived(ad: InReadAdView, adRatio: AdRatio) { - val layoutParams = ad.layoutParams - binding.adSlotView.addView(ad) - layoutParams.height = adRatio.calculateHeight(binding.adSlotView.measuredWidth) - binding.adSlotView.layoutParams = layoutParams - + // Clean and init inReadAdView + inReadAdView?.clean() inReadAdView = ad + // Add ad to the container and resize + binding.adSlotContainer.addView(ad) + binding.adSlotContainer.resizeAdContainer(adRatio) } override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { - binding.adSlotView.addView(trackerView) + binding.adSlotContainer.addView(trackerView) } override fun onAdRatioUpdate(adRatio: AdRatio) { - inReadAdView?.let { inReadAdView -> - val layoutParams = inReadAdView.layoutParams - layoutParams.height = adRatio.calculateHeight(binding.adSlotView.measuredWidth) - binding.adSlotView.layoutParams = layoutParams - } + // Resize + binding.adSlotContainer.resizeAdContainer(adRatio) } override fun onAdClicked() {} diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadGridRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadGridRecyclerViewFragment.kt index 49af1e1..93f90b3 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadGridRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadGridRecyclerViewFragment.kt @@ -9,7 +9,11 @@ import androidx.recyclerview.widget.RecyclerView import tv.teads.teadssdkdemo.databinding.FragmentRecyclerviewBinding import tv.teads.teadssdkdemo.format.inread.adapter.SimpleRecyclerViewAdapter import tv.teads.teadssdkdemo.utils.BaseFragment - +/** + * + * inRead format within a RecyclerView + * + */ class InReadGridRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding private lateinit var adapter: SimpleRecyclerViewAdapter diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadScrollViewFragment.kt index dfd4a9b..4d5160c 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/InReadScrollViewFragment.kt @@ -17,6 +17,7 @@ import tv.teads.sdk.VideoPlaybackListener import tv.teads.sdk.renderer.InReadAdView import tv.teads.teadssdkdemo.R import tv.teads.teadssdkdemo.databinding.FragmentInreadScrollviewBinding +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer import tv.teads.teadssdkdemo.utils.BaseFragment /** @@ -41,61 +42,59 @@ class InReadScrollViewFragment : BaseFragment() { // 1. Setup the settings val placementSettings = AdPlacementSettings.Builder() - .enableDebug() - .build() + .enableDebug() + .build() // 2. Create the InReadAdPlacement adPlacement = TeadsSDK.createInReadPlacement(requireActivity(), pid, placementSettings) // 3. Request the ad and listen its events val requestSettings = AdRequestSettings.Builder() - .pageSlotUrl("http://teads.com") - .build() + .pageSlotUrl("http://teads.com") + .build() adPlacement.requestAd(requestSettings, - object : InReadAdViewListener { - override fun onAdReceived(ad: InReadAdView, adRatio: AdRatio) { - val layoutParams = ad.layoutParams - binding.adSlotView.addView(ad) - layoutParams.height = adRatio.calculateHeight(binding.adSlotView.measuredWidth) - binding.adSlotView.layoutParams = layoutParams - - inReadAdView = ad - } - - override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { - binding.adSlotView.addView(trackerView) - } - - override fun onAdRatioUpdate(adRatio: AdRatio) { - inReadAdView?.let { inReadAdView -> - val layoutParams = inReadAdView.layoutParams - layoutParams.height = adRatio.calculateHeight(binding.adSlotView.measuredWidth) - binding.adSlotView.layoutParams = layoutParams - } - } - - override fun onAdClicked() {} - override fun onAdClosed() {} - override fun onAdError(code: Int, description: String) {} - override fun onAdImpression() {} - override fun onAdExpandedToFullscreen() {} - override fun onAdCollapsedFromFullscreen() {} - override fun onFailToReceiveAd(failReason: String) {} - }, - object : VideoPlaybackListener { - override fun onVideoComplete() { - Log.d("PlaybackEvent", "complete") - } - - override fun onVideoPause() { - Log.d("PlaybackEvent", "pause") - } - - override fun onVideoPlay() { - Log.d("PlaybackEvent", "play") - } + object : InReadAdViewListener { + override fun onAdReceived(ad: InReadAdView, adRatio: AdRatio) { + // Clean and init inReadAdView + inReadAdView?.clean() + inReadAdView = ad + // Add ad to the container and resize + binding.adSlotContainer.addView(ad) + binding.adSlotContainer.resizeAdContainer(adRatio) + } + + override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { + // Resize ad container + binding.adSlotContainer.addView(trackerView) + } + + override fun onAdRatioUpdate(adRatio: AdRatio) { + // Resize the ad container + binding.adSlotContainer.resizeAdContainer(adRatio) + } + override fun onAdClicked() {} + override fun onAdClosed() {} + override fun onAdError(code: Int, description: String) {} + override fun onAdImpression() {} + override fun onAdExpandedToFullscreen() {} + override fun onAdCollapsedFromFullscreen() {} + override fun onFailToReceiveAd(failReason: String) {} + }, + object : VideoPlaybackListener { + override fun onVideoComplete() { + Log.d("PlaybackEvent", "complete") } + + override fun onVideoPause() { + Log.d("PlaybackEvent", "pause") + } + + override fun onVideoPlay() { + Log.d("PlaybackEvent", "play") + } + + } ) } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/adapter/SimpleRecyclerViewAdapter.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/adapter/SimpleRecyclerViewAdapter.kt index 8f50a70..4a76535 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/adapter/SimpleRecyclerViewAdapter.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/adapter/SimpleRecyclerViewAdapter.kt @@ -8,6 +8,7 @@ import tv.teads.sdk.* import tv.teads.sdk.renderer.InReadAdView import tv.teads.teadssdkdemo.component.GenericRecyclerViewAdapter import tv.teads.teadssdkdemo.data.RecyclerItemType +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer /** * Simple RecyclerView adapter @@ -41,30 +42,24 @@ class SimpleRecyclerViewAdapter(private val context: Context?, pid: Int, title: override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { when (holder.itemViewType) { RecyclerItemType.TYPE_TEADS.value -> { - val adViewContainer = holder.itemView as FrameLayout - var inReadAdView: InReadAdView? = null + val adSlotContainer = holder.itemView as FrameLayout + adSlotContainer.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) // 3. Request the ad and register to the listener in it adPlacement.requestAd(requestSettings, object : InReadAdViewListener { override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { - adViewContainer.addView(trackerView) + adSlotContainer.addView(trackerView) } override fun onAdReceived(ad: InReadAdView, adRatio: AdRatio) { - val layoutParams = ad.layoutParams - adViewContainer.addView(ad, 0) - layoutParams.height = adRatio.calculateHeight(adViewContainer.measuredWidth) - adViewContainer.layoutParams = layoutParams - - inReadAdView = ad + // Add ad to the container and resize + adSlotContainer.resizeAdContainer(adRatio) + adSlotContainer.addView(ad, 0) } override fun onAdRatioUpdate(adRatio: AdRatio) { - inReadAdView?.let { inReadAdView -> - val layoutParams = inReadAdView.layoutParams - layoutParams.height = adRatio.calculateHeight(adViewContainer.measuredWidth) - adViewContainer.layoutParams = layoutParams - } + // Resize + adSlotContainer.resizeAdContainer(adRatio) } override fun onAdClicked() {} diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/extensions/ViewExtensions.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/extensions/ViewExtensions.kt new file mode 100644 index 0000000..d975d18 --- /dev/null +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/inread/extensions/ViewExtensions.kt @@ -0,0 +1,18 @@ +package tv.teads.teadssdkdemo.format.inread.extensions + +import android.view.View +import tv.teads.sdk.AdRatio + +/** + * Resize the ad container to the correct height + * @param adRatio the ratio of the ad + * + * adRatio.calculateHeight(adSlotContainer.measuredWidth) calculates the height of the ad container + * measuredWidth parameter must to be from the ad container/view group encapsulating the ad view + */ +fun View.resizeAdContainer(adRatio: AdRatio) { + val adSlotContainer = this + val adSlotContainerParams = adSlotContainer.layoutParams + adSlotContainerParams.height = adRatio.calculateHeight(adSlotContainer.measuredWidth) + adSlotContainer.layoutParams = adSlotContainerParams +} \ No newline at end of file diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AdMobRecyclerViewAdapter.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AdMobRecyclerViewAdapter.kt index af05826..255ac49 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AdMobRecyclerViewAdapter.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AdMobRecyclerViewAdapter.kt @@ -16,19 +16,20 @@ import tv.teads.sdk.utils.userConsent.TCFVersion import tv.teads.teadssdkdemo.component.GenericRecyclerViewAdapter import tv.teads.teadssdkdemo.data.RecyclerItemType import tv.teads.teadssdkdemo.data.SessionDataSource +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer /** * Simple RecyclerView adapter */ -class AdMobRecyclerViewAdapter(admobBannerId: String, context: Context?, title: String) +class AdMobRecyclerViewAdapter(admobBannerId: String, context: Context, title: String) : GenericRecyclerViewAdapter(title) { - private val adView: AdView = AdView(context!!) + private val adView: AdView = AdView(context) private val mListener: TeadsAdapterListener init { // 1. Initialize AdMob & Teads Helper - MobileAds.initialize(context!!) + MobileAds.initialize(context) TeadsHelper.initialize() // 2. Setup the AdMob view @@ -67,12 +68,7 @@ class AdMobRecyclerViewAdapter(admobBannerId: String, context: Context?, title: adView.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener { override fun onGlobalLayout() { adView.viewTreeObserver.removeOnGlobalLayoutListener(this) - val params: ViewGroup.LayoutParams = adView.layoutParams - - // Here the width is MATCH_PARENT - params.height = adRatio.calculateHeight(adView.measuredWidth) - - adView.layoutParams = params + adView.resizeAdContainer(adRatio) } }) } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AppLovinRecyclerViewAdapter.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AppLovinRecyclerViewAdapter.kt index 16efe25..f86eead 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AppLovinRecyclerViewAdapter.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/adapter/AppLovinRecyclerViewAdapter.kt @@ -19,14 +19,15 @@ import tv.teads.sdk.utils.userConsent.TCFVersion import tv.teads.teadssdkdemo.component.GenericRecyclerViewAdapter import tv.teads.teadssdkdemo.data.RecyclerItemType import tv.teads.teadssdkdemo.data.SessionDataSource +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer /** * Simple RecyclerView adapter */ -class AppLovinRecyclerViewAdapter(appLovinUnitId: String, context: Context?, title: String) +class AppLovinRecyclerViewAdapter(appLovinUnitId: String, context: Context, title: String) : GenericRecyclerViewAdapter(title) { - private val adView: MaxAdView = MaxAdView(appLovinUnitId, MaxAdFormat.MREC, context!!) + private val adView: MaxAdView = MaxAdView(appLovinUnitId, MaxAdFormat.MREC, context) private val mListener: TeadsAdapterListener init { @@ -65,12 +66,7 @@ class AppLovinRecyclerViewAdapter(appLovinUnitId: String, context: Context?, tit adView.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener { override fun onGlobalLayout() { adView.viewTreeObserver.removeOnGlobalLayoutListener(this) - val params: ViewGroup.LayoutParams = adView.layoutParams - - // Here the width is MATCH_PARENT - params.height = adRatio.calculateHeight(adView.measuredWidth) - - adView.layoutParams = params + adView.resizeAdContainer(adRatio) } }) } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobGridRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobGridRecyclerViewFragment.kt index 002700a..bad179e 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobGridRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobGridRecyclerViewFragment.kt @@ -12,7 +12,8 @@ import tv.teads.teadssdkdemo.format.mediation.identifier.AdMobIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment /** - * Display inRead as Banner within a RecyclerView using AdMob Mediation. + * inRead format within a RecyclerView + * */ class AdMobGridRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding @@ -32,7 +33,7 @@ class AdMobGridRecyclerViewFragment : BaseFragment() { val adUnit = AdMobIdentifier.getAdUnitFromPid(pid) - recyclerView.adapter = AdMobRecyclerViewAdapter(adUnit, context, getTitle()) + recyclerView.adapter = AdMobRecyclerViewAdapter(adUnit, requireContext(), getTitle()) } override fun getTitle(): String = "InRead AdMob RecyclerView Grid" diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobRecyclerViewFragment.kt index 1435218..c48bc8c 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobRecyclerViewFragment.kt @@ -12,7 +12,8 @@ import tv.teads.teadssdkdemo.format.mediation.identifier.AdMobIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment /** - * Display inRead as Banner within a RecyclerView using AdMob Mediation. + * inRead format within a RecyclerView + * */ class AdMobRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding @@ -32,7 +33,7 @@ class AdMobRecyclerViewFragment : BaseFragment() { val adUnit = AdMobIdentifier.getAdUnitFromPid(pid) - recyclerView.adapter = AdMobRecyclerViewAdapter(adUnit, context, getTitle()) + recyclerView.adapter = AdMobRecyclerViewAdapter(adUnit, requireContext(), getTitle()) } override fun getTitle(): String = "InRead AdMob RecyclerView" diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobScrollViewFragment.kt index 6774412..d4c4783 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/admob/AdMobScrollViewFragment.kt @@ -17,6 +17,7 @@ import tv.teads.sdk.utils.userConsent.TCFVersion import tv.teads.teadssdkdemo.R import tv.teads.teadssdkdemo.data.SessionDataSource import tv.teads.teadssdkdemo.databinding.FragmentInreadScrollviewBinding +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer import tv.teads.teadssdkdemo.format.mediation.identifier.AdMobIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment @@ -44,7 +45,7 @@ class AdMobScrollViewFragment : BaseFragment() { val adView = AdView(view.context) adView.adUnitId = AdMobIdentifier.getAdUnitFromPid(pid) adView.setAdSize(AdSize.MEDIUM_RECTANGLE) - binding.adSlotView.addView(adView, 0) + binding.adSlotContainer.addView(adView, 0) // 3. Attach listener (will include Teads events) adView.adListener = object : AdListener() { @@ -63,16 +64,11 @@ class AdMobScrollViewFragment : BaseFragment() { */ mListener = object : TeadsAdapterListener { override fun onRatioUpdated(adRatio: AdRatio) { - val params: ViewGroup.LayoutParams = adView.layoutParams - - // Here the width is MATCH_PARENT - params.height = adRatio.calculateHeight(adView.measuredWidth) - - adView.layoutParams = params + binding.adSlotContainer.resizeAdContainer(adRatio) } override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { - binding.adSlotView.addView(trackerView) + binding.adSlotContainer.addView(trackerView) } } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinGridRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinGridRecyclerViewFragment.kt index d588666..3bc9696 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinGridRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinGridRecyclerViewFragment.kt @@ -7,12 +7,13 @@ import android.view.ViewGroup import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import tv.teads.teadssdkdemo.databinding.FragmentRecyclerviewBinding -import tv.teads.teadssdkdemo.format.mediation.adapter.AdMobRecyclerViewAdapter +import tv.teads.teadssdkdemo.format.mediation.adapter.AppLovinRecyclerViewAdapter import tv.teads.teadssdkdemo.format.mediation.identifier.AppLovinIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment /** - * Display inRead as Banner within a RecyclerView using AdMob Mediation. + * inRead format within a RecyclerView + * */ class AppLovinGridRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding @@ -32,7 +33,7 @@ class AppLovinGridRecyclerViewFragment : BaseFragment() { val adUnit = AppLovinIdentifier.getAdUnitFromPid(pid) - recyclerView.adapter = AdMobRecyclerViewAdapter(adUnit, context, getTitle()) + recyclerView.adapter = AppLovinRecyclerViewAdapter(adUnit, requireContext(), getTitle()) } override fun getTitle(): String = "InRead AppLovin RecyclerView Grid" diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinRecyclerViewFragment.kt index 3477548..6841d2c 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinRecyclerViewFragment.kt @@ -12,7 +12,8 @@ import tv.teads.teadssdkdemo.format.mediation.identifier.AppLovinIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment /** - * Display inRead as Banner within a RecyclerView using AdMob Mediation. + * inRead format within a RecyclerView + * */ class AppLovinRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding @@ -31,7 +32,7 @@ class AppLovinRecyclerViewFragment : BaseFragment() { val adUnit = AppLovinIdentifier.getAdUnitFromPid(pid) - recyclerView.adapter = AppLovinRecyclerViewAdapter(adUnit, context, getTitle()) + recyclerView.adapter = AppLovinRecyclerViewAdapter(adUnit, requireContext(), getTitle()) } override fun getTitle(): String = "InRead AdMob RecyclerView" diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinScrollViewFragment.kt index 4a627de..fc64a39 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/applovin/AppLovinScrollViewFragment.kt @@ -20,6 +20,7 @@ import tv.teads.sdk.utils.userConsent.TCFVersion import tv.teads.teadssdkdemo.R import tv.teads.teadssdkdemo.data.SessionDataSource import tv.teads.teadssdkdemo.databinding.FragmentInreadScrollviewBinding +import tv.teads.teadssdkdemo.format.inread.extensions.resizeAdContainer import tv.teads.teadssdkdemo.format.mediation.identifier.AppLovinIdentifier import tv.teads.teadssdkdemo.utils.BaseFragment @@ -43,7 +44,7 @@ class AppLovinScrollViewFragment : BaseFragment() { // 2. Create MaxAdView view and add it to view hierarchy val adView = MaxAdView(AppLovinIdentifier.getAdUnitFromPid(pid), MaxAdFormat.MREC, context) - binding.adSlotView.addView(adView, 0) + binding.adSlotContainer.addView(adView, 0) // 3. Attach listener (will include Teads events) adView.setListener(object : MaxAdViewAdListener { @@ -70,16 +71,11 @@ class AppLovinScrollViewFragment : BaseFragment() { */ mListener = object : TeadsAdapterListener { override fun onRatioUpdated(adRatio: AdRatio) { - val params: ViewGroup.LayoutParams = adView.layoutParams - - // Here the width is MATCH_PARENT - params.height = adRatio.calculateHeight(adView.measuredWidth) - - adView.layoutParams = params + adView.resizeAdContainer(adRatio) } override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) { - binding.adSlotView.addView(trackerView) + binding.adSlotContainer.addView(trackerView) } } diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeGridRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeGridRecyclerViewFragment.kt index 65e8797..75748cd 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeGridRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeGridRecyclerViewFragment.kt @@ -12,6 +12,10 @@ import tv.teads.teadssdkdemo.format.mediation.adapter.SmartNativeRecyclerViewAda import tv.teads.teadssdkdemo.utils.BaseFragment import tv.teads.teadssdkdemo.utils.MarginItemDecoration +/** + * Native format within a RecyclerView + * + */ class SmartNativeGridRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeRecyclerViewFragment.kt index 0e6ac61..dd6fa22 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartNativeRecyclerViewFragment.kt @@ -12,6 +12,10 @@ import tv.teads.teadssdkdemo.format.mediation.adapter.SmartNativeRecyclerViewAda import tv.teads.teadssdkdemo.utils.BaseFragment import tv.teads.teadssdkdemo.utils.MarginItemDecoration +/** + * Native format within a RecyclerView + * + */ class SmartNativeRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartRecyclerViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartRecyclerViewFragment.kt index 4a2dc9b..4c6bab8 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartRecyclerViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartRecyclerViewFragment.kt @@ -11,7 +11,8 @@ import tv.teads.teadssdkdemo.format.mediation.adapter.SmartRecyclerViewAdapter import tv.teads.teadssdkdemo.utils.BaseFragment /** - * Display inRead as Banner within a RecyclerView using Smart Mediation. + * inRead format within a RecyclerView + * */ class SmartRecyclerViewFragment : BaseFragment() { private lateinit var binding: FragmentRecyclerviewBinding diff --git a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartScrollViewFragment.kt b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartScrollViewFragment.kt index ef1ce49..27cdd40 100644 --- a/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartScrollViewFragment.kt +++ b/TeadsSDKDemo/app/src/main/java/tv/teads/teadssdkdemo/format/mediation/smart/SmartScrollViewFragment.kt @@ -43,7 +43,7 @@ class SmartScrollViewFragment : BaseFragment() { smartAdView.loadAd(bannerPlacement) - binding.adSlotView.addView(smartAdView) + binding.adSlotContainer.addView(smartAdView) } override fun getTitle(): String = "InRead Smart ScrollView" diff --git a/TeadsSDKDemo/app/src/main/res/layout/fragment_inread_scrollview.xml b/TeadsSDKDemo/app/src/main/res/layout/fragment_inread_scrollview.xml index f07c779..231d5fa 100644 --- a/TeadsSDKDemo/app/src/main/res/layout/fragment_inread_scrollview.xml +++ b/TeadsSDKDemo/app/src/main/res/layout/fragment_inread_scrollview.xml @@ -18,7 +18,7 @@