Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support madu rewarded #17

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -14,16 +14,16 @@
import androidx.multidex.BuildConfig;
import com.ironsource.mediationsdk.IronSource;
import com.ironsource.mediationsdk.integration.IntegrationHelper;
import com.ironsource.mediationsdk.model.Placement;
import com.ironsource.mediationsdk.utils.IronSourceUtils;
import com.unity3d.mediation.LevelPlay;
import com.unity3d.mediation.LevelPlayAdSize;
import com.unity3d.mediation.LevelPlayInitRequest;
import com.unity3d.mediation.banner.LevelPlayBannerAdView;
import com.unity3d.mediation.interstitial.LevelPlayInterstitialAd;
import com.unity3d.mediation.rewarded.LevelPlayReward;
import com.unity3d.mediation.rewarded.LevelPlayRewardedAd;

import java.util.Arrays;
import java.util.List;

public class DemoActivity extends Activity implements DemoActivityListener {

Expand All @@ -34,14 +34,17 @@ public class DemoActivity extends Activity implements DemoActivityListener {

// Replace with your ad unit ids as available in the LevelPlay dashboard
public static final String INTERSTITIAL_AD_UNIT_ID = "aeyqi3vqlv6o8sh9";
public static final String REWARDED_AD_UNIT_ID = "76yy3nay3ceui2a3";
public static final String BANNER_AD_UNIT_ID = "thnfvcsog13bhn08";

private Button rewardedVideoShowButton;
private Placement rewardedVideoPlacementInfo;
private Button rewardedLoadButton;
private Button rewardedShowButton;
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
private LevelPlayReward reward;

private Button interstitialLoadButton;
private Button interstitialShowButton;
private LevelPlayInterstitialAd interstitialAd;
private LevelPlayRewardedAd rewardedAd;
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved

private Button bannerLoadButton;
private FrameLayout bannerParentLayout;
Expand Down Expand Up @@ -82,7 +85,8 @@ protected void onDestroy() {

//region Initialization Methods
private void setupUI() {
rewardedVideoShowButton = findViewById(R.id.rewarded_video_show_button);
rewardedLoadButton = findViewById(R.id.rewarded_load_button);
rewardedShowButton = findViewById(R.id.rewarded_show_button);
interstitialLoadButton = findViewById(R.id.interstitial_load_button);
interstitialShowButton = findViewById(R.id.interstitial_show_button);
bannerLoadButton = findViewById(R.id.banner_load_button);
Expand All @@ -100,26 +104,13 @@ private void setupIronSourceSdk() {
IntegrationHelper.validateIntegration(this);
}

// Before initializing any of our legacy products (Rewarded video, Interstitial or Banner) you must set
// their listeners. Take a look at each of these listeners method and you will see that they each implement a product
// protocol. This is our way of letting you know what's going on, and if you don't set the listeners
// we will not be able to communicate with you.
// We're passing 'this' to our listeners because we want
// to be able to enable/disable buttons to match ad availability.
IronSource.setLevelPlayRewardedVideoListener(new DemoRewardedVideoAdListener(this));
// Set the impression data listener
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
IronSource.addImpressionDataListener(new DemoImpressionDataListener());

// After setting the listeners you can go ahead and initialize the SDK.
// Once the initialization callback is returned you can start loading your ads

// Init the SDK when implementing the Multiple Ad Units Interstitial and Banner API, and Rewarded using legacy APIs
List<LevelPlay.AdFormat> legacyAdFormats = Arrays.asList(LevelPlay.AdFormat.REWARDED);

// Create the init request with the appKey and init the SDK
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
LevelPlayInitRequest initRequest = new LevelPlayInitRequest.Builder(APP_KEY)
.withLegacyAdFormats(legacyAdFormats)
.build();

log("init ironSource SDK with appKey: " + APP_KEY);
log("init levelPlay SDK with appKey: " + APP_KEY);
LevelPlay.init(this, initRequest, new DemoInitializationListener(this));

// Scroll down the file to find out what happens when you tap a button...
Expand Down Expand Up @@ -202,38 +193,52 @@ public void setBannerViewVisibility(int visibility) {
}
//endregion

//region Rewarded Video Methods
public void showRewardedVideoButtonTapped(View view) {
// It is advised to make sure there is available ad before attempting to show an ad
if (IronSource.isRewardedVideoAvailable()) {
// This will present the Rewarded Video.
//region Rewarded Methods
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
public void createRewardedAd() {
rewardedAd = new LevelPlayRewardedAd(REWARDED_AD_UNIT_ID);
rewardedAd.setListener(new DemoRewardedAdListener(this));

setEnablementForButton(DemoButtonIdentifiers.LOAD_REWARDED_VIDEO_BUTTON_IDENTIFIER, true);
}

public void loadRewardedButtonTapped(View view) {
// This will load a Rewarded ad
if (rewardedAd != null) {
log("loadAd for rewarded");
rewardedAd.loadAd();
}
}

public void showRewardedButtonTapped(View view) {
// It is advised to make sure there is available ad that isn't capped before attempting to show it
if (rewardedAd != null && rewardedAd.isAdReady()) {

log("showRewardedVideo");
IronSource.showRewardedVideo();
log("showAd for rewarded");
rewardedAd.showAd(this);
} else {
// wait for the availability of rewarded video to change to true before calling show
// load a new ad before calling show
}
}

@Override
public void setPlacementInfo(Placement placementInfo) {
// Setting the rewarded video placement info, an object that contains the placement's reward name and amount
this.rewardedVideoPlacementInfo = placementInfo;
public void setReward(LevelPlayReward reward) {
// Setting the reward, an object that contains the reward name and amount
this.reward = reward;
}

@Override
public void showRewardDialog() {
// Showing a graphical indication of the reward name and amount after the user closed the rewarded video ad
if (this.rewardedVideoPlacementInfo != null) {
if (this.reward != null) {
new AlertDialog.Builder(DemoActivity.this)
.setPositiveButton("ok", (dialog, id) -> dialog.dismiss())
.setTitle(getResources().getString(R.string.rewarded_dialog_header))
.setMessage(getResources().getString(R.string.rewarded_dialog_message) + " " + this.rewardedVideoPlacementInfo.getRewardAmount() + " " + this.rewardedVideoPlacementInfo.getRewardName())
.setMessage(getResources().getString(R.string.rewarded_dialog_message) + " " + this.reward.getAmount() + " " + this.reward.getName())
.setCancelable(false)
.create()
.show();

this.rewardedVideoPlacementInfo = null;
this.reward = null;
}
}
//endregion
Expand All @@ -246,9 +251,11 @@ public void setEnablementForButton(DemoButtonIdentifiers identifier, boolean ena
Button buttonToModify = null;

switch (identifier) {
case LOAD_REWARDED_VIDEO_BUTTON_IDENTIFIER:
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
buttonToModify = rewardedLoadButton;
break;
case SHOW_REWARDED_VIDEO_BUTTON_IDENTIFIER:
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
text = enable ? getResources().getString(R.string.show) : getResources().getString(R.string.initializing);
buttonToModify = rewardedVideoShowButton;
buttonToModify = rewardedShowButton;
break;
case LOAD_INTERSTITIAL_BUTTON_IDENTIFIER:
buttonToModify = interstitialLoadButton;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.ironsource.ironsourcesdkdemo;

import com.ironsource.mediationsdk.model.Placement;
import com.unity3d.mediation.rewarded.LevelPlayReward;

interface DemoActivityListener {
void setEnablementForButton(DemoButtonIdentifiers buttonIdentifier, boolean enable);
void setBannerViewVisibility(int visibility);
void setPlacementInfo(Placement placementInfo);
void setReward(LevelPlayReward reward);
void showRewardDialog();
void createInterstitialAd();
void createBannerAd();

void createRewardedAd();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ironsource.ironsourcesdkdemo;

enum DemoButtonIdentifiers {
LOAD_REWARDED_VIDEO_BUTTON_IDENTIFIER,
SHOW_REWARDED_VIDEO_BUTTON_IDENTIFIER,
LOAD_INTERSTITIAL_BUTTON_IDENTIFIER,
SHOW_INTERSTITIAL_BUTTON_IDENTIFIER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public DemoInitializationListener(DemoActivityListener listener) {
this.listener = listener;
}


/**
triggered when the initialization is completed successfully. After you receive this indication, ads can be loaded
@param configuration The configuration
*/
@Override
public void onInitSuccess(LevelPlayConfiguration configuration) {
public void onInitSuccess(@NonNull LevelPlayConfiguration configuration) {
logCallbackName(TAG, "");
this.listener.createRewardedAd();
this.listener.createInterstitialAd();
this.listener.createBannerAd();
}
Expand All @@ -34,7 +34,6 @@ the configuration was not retrieved successfully and ads cannot be loaded. It is
@Override
public void onInitFailed(@NonNull LevelPlayInitError error) {
logCallbackName(TAG, "error = " + error);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.ironsource.ironsourcesdkdemo;

import static com.ironsource.ironsourcesdkdemo.DemoActivity.logCallbackName;

import androidx.annotation.NonNull;
import com.unity3d.mediation.LevelPlayAdError;
import com.unity3d.mediation.LevelPlayAdInfo;
import com.unity3d.mediation.rewarded.LevelPlayReward;
import com.unity3d.mediation.rewarded.LevelPlayRewardedAdListener;

public class DemoRewardedAdListener implements LevelPlayRewardedAdListener {
private final String TAG = DemoRewardedAdListener.class.getSimpleName();
private final DemoActivityListener listener;

public DemoRewardedAdListener(DemoActivityListener listener) {
this.listener = listener;
}

/**
Called after a rewarded ad has been loaded
@param adInfo The info of the ad
*/
@Override
public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {
logCallbackName(TAG, "adInfo = " + adInfo);
this.listener.setEnablementForButton(DemoButtonIdentifiers.SHOW_REWARDED_VIDEO_BUTTON_IDENTIFIER, true);
}

/**
Called after a rewarded ad has attempted to load but failed
@param error The reason for the error
*/
@Override
public void onAdLoadFailed(@NonNull LevelPlayAdError error) {
logCallbackName(TAG, "error = " + error);
this.listener.setEnablementForButton(DemoButtonIdentifiers.SHOW_REWARDED_VIDEO_BUTTON_IDENTIFIER, false);
}

/**
Called after a rewarded ad has been displayed
This is the indication for impression
@param adInfo The info of the ad
*/
@Override
public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {
logCallbackName(TAG, "adInfo = " + adInfo);
this.listener.setEnablementForButton(DemoButtonIdentifiers.SHOW_REWARDED_VIDEO_BUTTON_IDENTIFIER, false);
}

/**
Called after a rewarded ad has attempted to display but failed.
@param error The reason for the error.
@param adInfo The info of the ad.
*/
@Override
public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {
logCallbackName(TAG, "error = " + error + " | adInfo = " + adInfo);
}

/**
Called after a rewarded ad has been closed.
@param adInfo The info of the ad.
*/
@Override
public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {
logCallbackName(TAG, "adInfo = " + adInfo);
this.listener.showRewardDialog();
}

/**
Called after a rewarded ad has been clicked.
@param adInfo The info of the ad.
*/
@Override
public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
logCallbackName(TAG, "adInfo = " + adInfo);
}

/**
Called after a rewarded video has been viewed completely and the user is eligible for a reward.
@param reward The reward info.
@param adInfo The info of the ad.
*/
@Override
public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) {
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
logCallbackName(TAG, "reward = " + reward + " | adInfo = " + adInfo);
this.listener.setReward(reward);
}

/**
Called after the ad info is updated. Available when another rewarded ad has loaded, and includes a higher CPM/Rate
@param adInfo The info of the ad
*/
@Override
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {
ArielBarsheshetIS marked this conversation as resolved.
Show resolved Hide resolved
logCallbackName(TAG, "adInfo = " + adInfo);
}
}

This file was deleted.

Loading