-
Notifications
You must be signed in to change notification settings - Fork 200
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
Adapter for Maio SDK v2.0.0 #529
Changes from 1 commit
f5c6313
73dfac7
dcd8c94
2632892
6f65666
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,18 +35,24 @@ | |
import java.lang.annotation.RetentionPolicy; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import jp.maio.sdk.android.FailNotificationReason; | ||
import jp.maio.sdk.android.MaioAds; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Remove empty line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have fixed it, as you suggested. |
||
import jp.maio.sdk.android.mediation.admob.adapter.MaioAdsManager; | ||
import jp.maio.sdk.android.v2.errorcode.ErrorCode; | ||
import jp.maio.sdk.android.v2.request.MaioRequest; | ||
import jp.maio.sdk.android.v2.rewarddata.RewardData; | ||
import jp.maio.sdk.android.v2.rewarded.IRewardedLoadCallback; | ||
import jp.maio.sdk.android.v2.rewarded.IRewardedShowCallback; | ||
import jp.maio.sdk.android.v2.rewarded.Rewarded; | ||
|
||
public class MaioMediationAdapter extends Adapter | ||
implements MediationRewardedAd, MaioAdsManagerListener { | ||
public class MaioMediationAdapter extends Adapter implements MediationRewardedAd { | ||
|
||
public static final String TAG = MaioMediationAdapter.class.getSimpleName(); | ||
|
||
protected String mediaID; | ||
protected String zoneID; | ||
|
||
private Rewarded maioRewarded; | ||
|
||
private MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback> adLoadCallback; | ||
private MediationRewardedAdCallback rewardedAdCallback; | ||
|
||
|
@@ -71,30 +77,25 @@ public class MaioMediationAdapter extends Adapter | |
} | ||
|
||
@NonNull | ||
public static AdError getAdError(@NonNull FailNotificationReason reason) { | ||
// Error '99' to indicate that the error is new and has not been supported by the adapter yet. | ||
int code = 99; | ||
switch (reason) { | ||
case AD_STOCK_OUT: | ||
code = 0; | ||
break; | ||
case NETWORK_NOT_READY: | ||
code = 1; | ||
break; | ||
case RESPONSE: | ||
code = 2; | ||
break; | ||
case NETWORK: | ||
code = 3; | ||
break; | ||
case UNKNOWN: | ||
code = 4; | ||
break; | ||
case VIDEO: | ||
code = 5; | ||
break; | ||
} | ||
return new AdError(code, "Failed to request ad from Maio: " + reason, MAIO_SDK_ERROR_DOMAIN); | ||
public static AdError getAdError(int reason) { | ||
// 0: unknown | ||
// 10100: noNetwork | ||
// 10200: networkTimeout | ||
// 10300: abortedDownload | ||
// 10400: invalidResponse | ||
// 10500: zoneNotFound | ||
// 10600: unavailableZone | ||
// 10700: noFill | ||
// 10800: nullArgMaioRequest | ||
// 10900: diskSpaceNotEnough | ||
// 11000: unsupportedOsVer | ||
// 20100: expired | ||
// 20200: notReadyYet | ||
// 20300: alreadyShown | ||
// 20400: failedPlayback | ||
// 20500: nullArgViewContext | ||
return new AdError(reason, | ||
"Failed to request ad from Maio: " + ErrorCode.Companion.fromInt(reason).toString(), MAIO_SDK_ERROR_DOMAIN); | ||
} | ||
|
||
/** | ||
|
@@ -112,7 +113,6 @@ public static AdError getAdError(@NonNull FailNotificationReason reason) { | |
*/ | ||
public static final int ERROR_REQUIRES_ACTIVITY_CONTEXT = 103; | ||
|
||
|
||
/** | ||
* {@link Adapter} implementation | ||
*/ | ||
|
@@ -139,7 +139,7 @@ public VersionInfo getVersionInfo() { | |
@NonNull | ||
@Override | ||
public VersionInfo getSDKVersionInfo() { | ||
String versionString = MaioAds.getSdkVersion(); | ||
String versionString = MaioAdsManager.getSdkVersion().toString(); | ||
String[] splits = versionString.split("\\."); | ||
|
||
if (splits.length >= 3) { | ||
|
@@ -193,15 +193,7 @@ public void initialize(@NonNull Context context, | |
Log.w(TAG, logMessage); | ||
} | ||
|
||
MaioAdsManager.getManager(mediaID) | ||
.initialize( | ||
(Activity) context, | ||
new MaioAdsManager.InitializationListener() { | ||
@Override | ||
public void onMaioInitialized() { | ||
initializationCompleteCallback.onInitializationSucceeded(); | ||
} | ||
}); | ||
initializationCompleteCallback.onInitializationSucceeded(); | ||
} | ||
|
||
@Override | ||
|
@@ -239,101 +231,72 @@ public void loadRewardedAd( | |
return; | ||
} | ||
|
||
MaioAds.setAdTestMode(mediationRewardedAdConfiguration.isTestRequest()); | ||
MaioAdsManager.getManager(mediaID) | ||
.initialize( | ||
(Activity) context, | ||
new MaioAdsManager.InitializationListener() { | ||
@Override | ||
public void onMaioInitialized() { | ||
MaioAdsManager.getManager(mediaID).loadAd(zoneID, MaioMediationAdapter.this); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void showAd(@NonNull Context context) { | ||
MaioAdsManager.getManager(mediaID).showAd(zoneID, MaioMediationAdapter.this); | ||
} | ||
|
||
// region MaioAdsManagerListener implementation | ||
@Override | ||
public void onInitialized() { | ||
// Not called. | ||
// MaioAdsManager calls MaioAdsManager.InitializationListener.onMaioInitialized() instead. | ||
} | ||
|
||
@Override | ||
public void onChangedCanShow(String zoneId, boolean isAvailable) { | ||
if (adLoadCallback != null && isAvailable) { | ||
rewardedAdCallback = adLoadCallback.onSuccess(MaioMediationAdapter.this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailed(FailNotificationReason reason, String zoneId) { | ||
AdError error = MaioMediationAdapter.getAdError(reason); | ||
Log.w(TAG, error.getMessage()); | ||
if (adLoadCallback != null) { | ||
adLoadCallback.onFailure(error); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdFailedToLoad(@NonNull AdError error) { | ||
Log.w(TAG, error.getMessage()); | ||
if (adLoadCallback != null) { | ||
adLoadCallback.onFailure(error); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAdFailedToShow(@NonNull AdError error) { | ||
Log.w(TAG, error.getMessage()); | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdFailedToShow(error); | ||
} | ||
} | ||
|
||
@Override | ||
public void onOpenAd(String zoneId) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdOpened(); | ||
rewardedAdCallback.reportAdImpression(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onStartedAd(String zoneId) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onVideoStart(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClickedAd(String zoneId) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.reportAdClicked(); | ||
} | ||
} | ||
this.maioRewarded = Rewarded.loadAd(new MaioRequest(zoneID, | ||
mediationRewardedAdConfiguration.isTestRequest(), ""), context, new IRewardedLoadCallback() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the third parameter of the MaioRequest constructor is an empty string, can you add the name of the parameter in the constructor call to give more clarity? Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have fixed it, as you suggested. |
||
@Override | ||
public void loaded(@NonNull Rewarded rewarded) { | ||
if (adLoadCallback != null) { | ||
rewardedAdCallback = adLoadCallback.onSuccess(MaioMediationAdapter.this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFinishedAd(int playtime, boolean skipped, int duration, String zoneId) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onVideoComplete(); | ||
if (!skipped) { | ||
rewardedAdCallback.onUserEarnedReward(new MaioReward()); | ||
@Override | ||
public void failed(@NonNull Rewarded rewarded, int errorCode) { | ||
AdError error = getAdError(errorCode); | ||
Log.w(TAG, error.getMessage()); | ||
if (adLoadCallback != null) { | ||
adLoadCallback.onFailure(error); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onClosedAd(String zoneId) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdClosed(); | ||
public void showAd(@NonNull Context context) { | ||
if (this.maioRewarded != null) { | ||
this.maioRewarded.show(context, new IRewardedShowCallback() { | ||
@Override | ||
public void opened(@NonNull Rewarded rewarded) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdOpened(); | ||
rewardedAdCallback.onVideoStart(); | ||
rewardedAdCallback.reportAdImpression(); | ||
} | ||
} | ||
|
||
@Override | ||
public void closed(@NonNull Rewarded rewarded) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdClosed(); | ||
rewardedAdCallback.onVideoComplete(); | ||
} | ||
} | ||
|
||
@Override | ||
public void clicked(@NonNull Rewarded rewarded) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.reportAdClicked(); | ||
} | ||
} | ||
|
||
@Override | ||
public void rewarded(@NonNull Rewarded rewarded, @NonNull RewardData rewardData) { | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onUserEarnedReward(new MaioReward()); | ||
} | ||
} | ||
|
||
@Override | ||
public void failed(@NonNull Rewarded rewarded, int errorCode) { | ||
AdError error = MaioMediationAdapter.getAdError(errorCode); | ||
Log.w(TAG, error.getMessage()); | ||
if (rewardedAdCallback != null) { | ||
rewardedAdCallback.onAdFailedToShow(error); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
// endregion | ||
|
||
/** | ||
* A {@link RewardItem} used to map maio rewards to Google's rewarded video ads rewards. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update the
versionCode
below to2000000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed it, as you suggested.
In addition, the SDK version has been updated to 2.0.3.