Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,23 @@ protected void setUpCloseButtonTask() {
AdUnitConfiguration config = interstitialManager.getInterstitialDisplayProperties().config;
RewardManager rewardManager = config.getRewardManager();
if (config != null && config.isRewarded()) {
RewardedExt rewardedExt = rewardManager.getRewardedExt();
int postRewardTime = rewardedExt.getClosingRules().getPostRewardTime() * 1000;
boolean autoClose = rewardedExt.getClosingRules().getAction() == RewardedClosingRules.Action.AUTO_CLOSE;

if (rewardManager.getUserRewardedAlready()) {
// The reward was already granted before this dialog (e.g. the end card) was created,
// so there is no reward event to wait for anymore. Still schedule the close button so
// it doesn't stay hidden forever, respecting close.action/postrewardtime rules.
changeCloseViewVisibility(View.GONE);
scheduleCloseButtonDisplaying(postRewardTime, autoClose);
return;
}

setBackgroundListener();
changeCloseViewVisibility(View.GONE);

RewardedExt rewardedExt = rewardManager.getRewardedExt();
int defaultRewardTime = RewardedCompletionRules.DEFAULT_BANNER_TIME_MS;
int postRewardTime = rewardedExt.getClosingRules().getPostRewardTime() * 1000;

boolean autoClose = rewardedExt.getClosingRules().getAction() == RewardedClosingRules.Action.AUTO_CLOSE;
boolean isEndCard = config.getHasEndCard();
boolean hasRewardEventUrl = getBannerEvent(rewardedExt, isEndCard) != null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ public void setUpCloseButton_userAlreadyRewarded() {
InterstitialDisplayPropertiesInternal mockProperties = mock(InterstitialDisplayPropertiesInternal.class);
when(mockInterstitialManager.getInterstitialDisplayProperties()).thenReturn(mockProperties);

RewardedCompletionRules completionRules = new RewardedCompletionRules();
RewardedClosingRules closingRules = new RewardedClosingRules(5, RewardedClosingRules.Action.AUTO_CLOSE);
RewardedExt rewardedExt = new RewardedExt(null, completionRules, closingRules);

RewardManager mockRewardManager = mock(RewardManager.class);
when(mockRewardManager.getUserRewardedAlready()).thenReturn(true);
when(mockRewardManager.getRewardedExt()).thenReturn(rewardedExt);

AdUnitConfiguration mockConfig = mock(AdUnitConfiguration.class);
when(mockConfig.isRewarded()).thenReturn(true);
Expand All @@ -132,8 +137,10 @@ public void setUpCloseButton_userAlreadyRewarded() {

spySubject.setUpCloseButtonTask();

verify(spySubject, never()).changeCloseViewVisibility(View.GONE);
verify(spySubject, never()).scheduleCloseButtonDisplaying(anyInt(), anyBoolean());
// Even though the reward was already granted before this dialog was created (e.g. the
// end card), the close button must still be scheduled so it doesn't stay hidden forever.
verify(spySubject).changeCloseViewVisibility(View.GONE);
verify(spySubject).scheduleCloseButtonDisplaying(5_000, true);
verify(spySubject, never()).scheduleRewardListener(anyInt(), anyInt(), anyBoolean());
}

Expand Down
Loading