Created
December 24, 2016 17:06
-
-
Save YuriHeupa/926bae29c1b687b0725c5680380f0780 to your computer and use it in GitHub Desktop.
Example of an ads adapter allowing to hide ads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AdmobAdapter extends AbstractWrapAdapter<AdItem> { | |
private static final int SPAN = 10; | |
private boolean mShowAds = true; | |
public AdmobAdapter() { | |
super(Collections.singletonList(new AdItem())); | |
} | |
@Override | |
public boolean shouldInsertItemAtPosition(int position) { | |
return mShowAds && ((position + 1) % SPAN) == 0; | |
} | |
@Override | |
public int itemInsertedBeforeCount(int position) { | |
if(!mShowAds) return 0; | |
return position/SPAN; | |
} | |
@Override | |
public AdItem getItem(int position) { | |
if (shouldInsertItemAtPosition(position)) { | |
return getItems().get(0); | |
} | |
return null; | |
} | |
public void setShowAds(boolean show) { | |
mShowAds = show; | |
notifyDataSetChanged(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment