Skip to content

Commit

Permalink
refactor: public method docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTeqBlaze committed Oct 17, 2024
1 parent 43ca68a commit 5aea3a8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,46 @@ public class RewardedAdUnit extends BaseInterstitialAdUnit {

private static final String TAG = RewardedAdUnit.class.getSimpleName();

/**
* Handler that is responsible for requesting, displaying and destroying of
* primary ad (e.g. GAM). Also it tracks impression and sets listener.
*/
private final RewardedEventHandler eventHandler;

/**
* Interstitial ad units events listener (like onAdLoaded, onAdFailed...)
*/
@Nullable
private RewardedAdUnitListener userListener;

/**
* Listener that must be applied to InterstitialEventHandler.
* It is responsible for onAdServerWin or onPrebidSdkWin.
*/
private final RewardedVideoEventListener eventListener = createRewardedListener();

/**
* Constructor that creates the instance with a {@link StandaloneRewardedVideoEventHandler}
* for integration without any primary ad server.
*
* @param context Android context
* @param configId configuration id for on Prebid Server
*/
public RewardedAdUnit(
Context context,
String configId
) {
this(context, configId, new StandaloneRewardedVideoEventHandler());
}

/**
* Constructor that initializes a RewardedAdUnit with a custom event handler.
* It supports GAM integration (use {@code GamRewardedEventHandler})
*
* @param context the Android context
* @param configId the configuration id on Prebid Server
* @param eventHandler the event handler for primary ad server responsible for managing rewarded ad
*/
public RewardedAdUnit(
Context context,
String configId,
Expand All @@ -61,13 +96,9 @@ public RewardedAdUnit(
init(adUnitConfiguration);
}

public RewardedAdUnit(
Context context,
String configId
) {
this(context, configId, new StandaloneRewardedVideoEventHandler());
}

/**
* Executes ad loading if no request is running.
*/
@Override
public void loadAd() {
super.loadAd();
Expand All @@ -76,6 +107,9 @@ public void loadAd() {
rewardManager.setRewardListener(controllerListener::onUserEarnedReward);
}

/**
* Cleans up resources when destroyed. It has to be called if the ad unit is no longer needed.
*/
@Override
public void destroy() {
super.destroy();
Expand All @@ -85,6 +119,9 @@ public void destroy() {
}
}

/**
* Sets the listener for the rewarded ad events.
*/
public void setRewardedAdUnitListener(@Nullable RewardedAdUnitListener userListener) {
this.userListener = userListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public interface RewardedAdUnitListener {
/**
* Executed when user receives reward.
*
* @param rewardedAdUnit view of the corresponding event. Contains reward instance inside. Prebid reward is always null.
* @param rewardedAdUnit the rewarded ad unit
* @param reward the reward object. It can be null if it is not set in the ad server.
*/
void onUserEarnedReward(RewardedAdUnit rewardedAdUnit, @Nullable Reward reward);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public class GamRewardedEventHandler implements RewardedEventHandler, GamAdEvent
private boolean isExpectingAppEvent;
private boolean didNotifiedBidWin;

/**
* Default constructor.
*
* @param activity Android activity
* @param gamAdUnitId the GAM ad unit id for the rewarded ad unit
*/
public GamRewardedEventHandler(
Activity activity,
String gamAdUnitId
Expand Down

0 comments on commit 5aea3a8

Please sign in to comment.