Feed Type (2.0)
BuzzAd Benefit SDK: Feed
This documentation provides a guideline for integrating feed for BuzzAd Benefit.
※ Note
Please proceed with the following process only after BuzzAd Benefit SDK integration is complete.
The feed accommodates customization of the design of toolbar, ad list item and header.
Please proceed with the Advanced Usage only after implementing all of the features in Basic Usage.
Index
Basic Usage
Setting the FeedConfig
and the FeedHandler
Create the
FeedConfig
withunit_id
.Create a
FeedHandler
using the theFeedConfig
as its object.Call
startFeedActivity()
to start a feed activity.
final FeedConfig feedConfig = new FeedConfig.Builder(context, "YOUR_FEED_UNIT_ID").build();
final FeedHandler feedHandler = new FeedHandler(feedConfig);
feedHandler.startFeedActivity(this);
Recommended Usage
Checking for the Ad Status
At times, directly calling startFeedActivity()
may result in a blank screen when there are no ads available. Therefore, it is recommended to call preload()
and call onPreloaded()
to check the ad status so that feed activity can be started only when there are ads available.
feedHandler.getSize()
: The number of adsfeedHandler.getTotalReward()
: The total amount of reward available
feedHandler.preload(new FeedHandler.FeedPreloadListener() {
@Override
public void onPreloaded() {
int feedAdSize = feedHandler.getSize();
int feedTotalReward = feedHandler.getTotalReward();
}
@Override
public void onError(AdError error) {
// on load failure, error explains why the load failed
}
});
Note
The method
startFeedActivity()
must be called on the same object as the preloadedFeedHandler
.Attention : If ads are preloaded in a
FeedHandler
instance, the instance will continue to hold the same ads. Hence, even if the user leaves the activity, calling thestartFeedActivity()
with the same instance will display the same preloaded ads. By callingstartFeedActivity()
with a newFeedHandler
, new ads will be shown each time the feed activity is started.
The preload feature may not work if the
FeedHandler
is declared as a local variable since weakReference is implemented for the object to prevent memory leaks. Hence, please declare theFeedHandler
as non-local variable.
// Example of declaring FeedHandler as a local variable
private void preloadFeed() {
// The below listener may not work as FeedHandler might get deleted from the memory.
final FeedHandler feedHandler = new FeedHandler(getFeedConfig());
feedHandler.preload(new FeedHandler.FeedPreloadListener() {
@Override
public void onPreloaded() { // may not work }
@Override
public void onError(AdError error) { // may not work }
});
}
Advanced Usage
Design Customization
Important
When creating a custom class for the FeedToolbarHolder, FeedAdsAdapter, FeedHeaderViewAdapter, one of the following conditions must be followed:
Each class must not be an inner class.
If created as an inner class, it must be declared as a public static class.
If the above conditions are not met, the class cannot be found and customization will not be applied.
ToolBar Customization
The design of the toolbar at the top of the feed can be customized.
Create a class that implements
FeedToolbarHolder
.Specify the
FeedToolbarHolder
when building theFeedConfig
.
Changing the Height of the ToolBar
The height value of the layout for the customized toolbar is fixed by default. To modify the height value, add the following code below.
Customizing the Header
Customizing the header can be done to provide more information to the users.
Create a class that implements
FeedHeaderViewAdapter
.Specify the
FeedHeaderViewAdapter
when building theFeedConfig
.
Customizing the Feed Ad List View
The ad list view of the feed can be customized and callbacks for ad events can be registered.
Implement a class that inherits
AdsAdapter
.Implement
onCreateViewHolder
andonBindViewHolder
to customize the layout and the binding logic ofitemView
to display in the feed list.getCtaTextView ()
andgetRewardImageView ()
methods can be called to customize the text and reward images shown in theCtaView
. (See CtaView Customization below for more flexibility in customization)(optional) Implement necessary customizations for the state-specific callbacks for the ad. (Refer to the document for event definitions and actions).
Specify the
AdsAdapter
when building theFeedConfig
.
CtaView (Button) Customization
To implement the CtaView
differently from the default view, please proceed as follows.
※ Note
There may be times when reward is not available for an ad either because only a very short time has passed since the user has been rewarded for the same ad or because the ad did not have reward to begin with. Therefore, when configuring the ad layout, please check to see the availability of a reward to decide whether to show the reward on the UI or not (see sample code below).
Using the FeedFragment
FeedFragment
can be used to display feed differently from that of the FeedActivity
The basic usage of
FeedFragment
For
FeedFragment
,preload()
can be used by creating aFeedHandler
without callingstartFeedActivity()
.FeedFragment
accommodates the customization of AdsAdapter, with the exception of toolbar, and header is available by usingfeedConfig
.
To refresh ads in the fragment, FeedHandler needs to be created before initializing the FeedFragment.