Skip to content

Instantly share code, notes, and snippets.

@YuriHeupa
Created December 24, 2016 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuriHeupa/926bae29c1b687b0725c5680380f0780 to your computer and use it in GitHub Desktop.
Save YuriHeupa/926bae29c1b687b0725c5680380f0780 to your computer and use it in GitHub Desktop.
Example of an ads adapter allowing to hide ads.
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