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

Adapter for Maio SDK v2.0.0 #529

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions ThirdPartyAdapters/maio/maio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ext {
// String property to store the proper name of the mediation network adapter.
adapterName = "maio"
// String property to store version name.
stringVersion = "1.1.16.3"
stringVersion = "2.0.0.0"
Copy link
Collaborator

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 to 2000000

Copy link
Contributor Author

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.

// String property to store group id.
stringGroupId = "com.google.ads.mediation"
// Jacoco version to generate code coverage data
Expand Down Expand Up @@ -114,7 +114,7 @@ task jacocoTestReport(type: JacocoReport,
}

dependencies {
implementation 'com.maio:android-sdk:1.1.16'
implementation 'com.maio:android-sdk-v2:2.0.0'
implementation 'androidx.annotation:annotation:1.5.0'
implementation 'com.google.android.gms:play-services-ads:23.0.0'

Expand Down
4 changes: 2 additions & 2 deletions ThirdPartyAdapters/maio/maio/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

<application>
<activity
android:name="jp.maio.sdk.android.AdFullscreenActivity"
android:name="jp.maio.sdk.android.v2.AdActivity"
android:configChanges="orientation|screenLayout|screenSize"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

<activity
android:name="jp.maio.sdk.android.HtmlBasedAdActivity"
android:name="jp.maio.sdk.android.v2.PlayableActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</application>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove empty line

Copy link
Contributor Author

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.

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;

Expand All @@ -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);
}

/**
Expand All @@ -112,7 +113,6 @@ public static AdError getAdError(@NonNull FailNotificationReason reason) {
*/
public static final int ERROR_REQUIRES_ACTIVITY_CONTEXT = 103;


/**
* {@link Adapter} implementation
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 ClassName(/*paramName=/* "")

Copy link
Contributor Author

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.

@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.
Expand Down
Loading
Loading