clockbyte / admobadapter

It wraps your Adapter to display Admob native ads and banners in a ListView/RecyclerView data set. It based on the Yahoo fetchr project https://github.com/yahoo/fetchr
Apache License 2.0
237 stars 75 forks source link

Ads does not show up when RecyclerView.ItemDecoration is used #111

Open Shajeel-Afzal opened 6 years ago

Shajeel-Afzal commented 6 years ago

Ads in RecyclerView does work when ItemDecoration is used. It is just showing the White Space at the place of Ads. I think the problem is with the ad size maybe (Can SMART_BANNER solve the problem?)

The ads work fine when I don't add the ItemDecoration. Following is the code.

mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(numberOfColumns, (int) AppUtils.convertDpToPixel(16, getActivity()), true));

Admobadapter version or commit: 1.4.6

Android compileSdkVersion: 27

kot331107 commented 6 years ago

Try the smart banner size...

kot331107 commented 6 years ago

@Shajeel-Afzal any update on it? you should check if the item decorator's dimensions are equal/greater than banner's dimensions. You also should take into account spaces which you have set between columns, paddings from layout (xml) and the count of columns (if your banner is expected to be shown only in one of columns, I mean not full width).

Shajeel-Afzal commented 6 years ago

@kot331107 should I try .setSingleAdSize(AdSize.SMART_BANNER) in the builder?

kot331107 commented 6 years ago

@Shajeel-Afzal it depends on what you want to display to users. setSingleAdSize sets SMART BANNER size for all your ad blocks at once.

Shajeel-Afzal commented 6 years ago

Awesome. If you can point me to some detailed documentation on this then that will be great.

kot331107 commented 6 years ago

@Shajeel-Afzal what you mean? I even don't understand what do you want to display lol :)

ahmedgalal commented 6 years ago

i have the same problem, the recyclerview shows a white space at the place of the Ad while loading it, after the Ad loads it replaces the white space with the Ad or remove it in case of Ad failed to load, SMART_BANNER does not solve this problem.

kot331107 commented 6 years ago

@ahmedgalal just to be sure, it sounds like a normal behavior...This lib always shows a white placeholder while ad is loading. It is required by admob rules

to avoid accidental clicks

So I think you should show something to user instead of that white placeholder while ad is loading to make sure user totally knows that it is the reserved place for banner and to prevent his accidential clicks there (see sampleapp of this lib for instance). Otherwise they could probably block your account if your earnings will be too high :) If it doesn't show banner at all please provide your LogCat filtered by "ad"

Shajeel-Afzal commented 6 years ago

@kot331107, I am showing the Banner Ads inside RecyclerView Items. While using the ItemDecoration the ads were not loading, I guess because those were not fitting into the area. I'll check those again while calling .setSingleAdSize(AdSize.SMART_BANNER). I hope then those will work. Currently, I have used removed the Item Decoration and fixed the spacing using the margins/padding.

Here is code:

mAdapterWrapper = AdmobBannerRecyclerAdapterWrapper.builder(getActivity())
                    .setFirstAdIndex(firstAdIndex < 2 ? 2 : firstAdIndex)
                    .setNoOfDataBetweenAds(adsFrequency < 2 ? 2 : adsFrequency)
                    .setLimitOfAds(listAdsLimit <= 1 ? 3 : listAdsLimit)
                    .setTestDeviceIds(((GlobalApplication) getActivity().getApplication()).getTestDeviceIds())
                    .setAdPresets(adPresets)
                    .setAdapter(mAdapter)
                    .build();

            mLiveScoreRV.setAdapter(mAdapterWrapper);
kot331107 commented 6 years ago

@Shajeel-Afzal it seems that @ahmedgalal has a different issue...So could you update if you still have this issue?

kot331107 commented 6 years ago

@Shajeel-Afzal closing it for now. Please feel free to duplicate an issue if you'll face it again

Shajeel-Afzal commented 6 years ago

I am still facing the issue. The Ads are not loading if ItemDecoration is used. Following is the screenshot. Even the .setSingleAdSize(AdSize.SMART_BANNER) in the builder does not help. Following is the complete code:

adapterWrapper = AdmobBannerRecyclerAdapterWrapper.builder(getActivity())
                    .setFirstAdIndex(firstAdIndex < 2 ? 2 : firstAdIndex)
                    .setNoOfDataBetweenAds(adsFrequency < 2 ? 2 : adsFrequency)
                    .setLimitOfAds(listAdsLimit <= 1 ? 3 : listAdsLimit)
                    .setSingleAdSize(AdSize.SMART_BANNER)
                    .setTestDeviceIds(((GlobalApplication) getActivity().getApplication()).getTestDeviceIds())
                    .setAdPresets(adPresets)
                    .setAdapter(adapter)
                    .build();

            mRecyclerView.setAdapter(adapterWrapper);

Just removing mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(1, (int) AppUtils.convertDpToPixel(16, getActivity()), true)); starts showing the ads because it gets the full width.

Please resolve this issue @kot331107

kot331107 commented 6 years ago

@Shajeel-Afzal Provide the code for the adPresets

Shajeel-Afzal commented 6 years ago

Following is the code for creating BannerAdPreset:

 List<BannerAdPreset> adPresets = new ArrayList<>();

            if (BuildConfig.DEBUG)
                adPresets.add(new BannerAdPreset(getString(R.string.test_admob_banner_ad_id)));
            else {
                adPresets.add(new BannerAdPreset(getString(R.string.category_recyclerview_banner_ad_1)));
                adPresets.add(new BannerAdPreset(getString(R.string.category_recyclerview_banner_ad_2)));
                adPresets.add(new BannerAdPreset(getString(R.string.category_recyclerview_banner_ad_3)));               
            }
Shajeel-Afzal commented 6 years ago

I have tried adPresets.add(new BannerAdPreset(getString(R.string.test_admob_banner_ad_id), AdSize.SMART_BANNER)); as well but it also does not work.