From dff04bd0d00a29a8dbff53108f5012c29448d5fe Mon Sep 17 00:00:00 2001 From: Dmitrii Feshchenko Date: Thu, 12 Sep 2024 17:09:30 +0200 Subject: [PATCH 1/5] Improve Android bridge --- .../Android/AndroidAppodealClient.cs | 424 ++++++++---------- .../Android/AndroidAppodealHelper.cs | 75 ++++ .../Android/AndroidAppodealHelper.cs.meta | 11 + .../Android/AndroidPlayStoreInAppPurchase.cs | 28 +- .../AndroidPlayStoreInAppPurchaseBuilder.cs | 45 +- Runtime/Platforms/Android/AssemblyInfo.cs | 4 + .../Callbacks/AppodealAdRevenueCallback.cs | 20 +- .../Callbacks/AppodealBannerCallbacks.cs | 4 +- .../AppodealInitializationCallback.cs | 18 +- .../AppodealInterstitialCallbacks.cs | 4 +- .../Callbacks/AppodealMrecCallbacks.cs | 4 +- .../AppodealRewardedVideoCallbacks.cs | 4 +- .../InAppPurchaseValidationCallbacks.cs | 21 +- Runtime/Platforms/Android/Constants.meta | 8 + .../Constants/AndroidConstants.JavaAdType.cs | 15 + .../AndroidConstants.JavaAdType.cs.meta | 11 + .../AndroidConstants.JavaClassName.cs | 25 ++ .../AndroidConstants.JavaClassName.cs.meta | 11 + .../AndroidConstants.JavaFieldName.cs | 19 + .../AndroidConstants.JavaFieldName.cs.meta | 11 + .../AndroidConstants.JavaInterfaceName.cs | 18 + ...AndroidConstants.JavaInterfaceName.cs.meta | 11 + ...droidConstants.JavaMethodName.AdRevenue.cs | 22 + ...Constants.JavaMethodName.AdRevenue.cs.meta | 11 + ...ndroidConstants.JavaMethodName.Appodeal.cs | 58 +++ ...dConstants.JavaMethodName.Appodeal.cs.meta | 11 + ...tants.JavaMethodName.AppodealBannerView.cs | 19 + ....JavaMethodName.AppodealBannerView.cs.meta | 11 + ...Constants.JavaMethodName.AppodealReward.cs | 16 + ...ants.JavaMethodName.AppodealReward.cs.meta | 11 + ...dConstants.JavaMethodName.InAppPurchase.cs | 28 ++ ...tants.JavaMethodName.InAppPurchase.cs.meta | 11 + ...nts.JavaMethodName.InAppPurchaseBuilder.cs | 26 ++ ...avaMethodName.InAppPurchaseBuilder.cs.meta | 11 + .../AndroidConstants.JavaShowStyle.cs | 17 + .../AndroidConstants.JavaShowStyle.cs.meta | 11 + .../Android/Constants/AndroidConstants.cs | 12 + .../Constants/AndroidConstants.cs.meta | 11 + 38 files changed, 778 insertions(+), 299 deletions(-) create mode 100644 Runtime/Platforms/Android/AndroidAppodealHelper.cs create mode 100644 Runtime/Platforms/Android/AndroidAppodealHelper.cs.meta create mode 100644 Runtime/Platforms/Android/Constants.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs.meta create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.cs create mode 100644 Runtime/Platforms/Android/Constants/AndroidConstants.cs.meta diff --git a/Runtime/Platforms/Android/AndroidAppodealClient.cs b/Runtime/Platforms/Android/AndroidAppodealClient.cs index 3c1697a..1508328 100644 --- a/Runtime/Platforms/Android/AndroidAppodealClient.cs +++ b/Runtime/Platforms/Android/AndroidAppodealClient.cs @@ -10,418 +10,384 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "UnusedType.Global")] internal class AndroidAppodealClient : IAppodealAdsClient { - private const int AppodealAdTypeInterstitial = 3; - private const int AppodealAdTypeBanner = 4; - private const int AppodealAdTypeRewardedVideo = 128; - private const int AppodealAdTypeMrec = 256; + private AndroidJavaClass _appodealJavaClass; - private const int AppodealShowStyleInterstitial = 3; - private const int AppodealShowStyleRewardedVideo = 128; - private const int AppodealShowStyleBannerBottom = 8; - private const int AppodealShowStyleBannerTop = 16; - private const int AppodealShowStyleBannerLeft = 1024; - private const int AppodealShowStyleBannerRight = 2048; + private AndroidJavaObject _unityActivityJavaObject; + private AndroidJavaObject _appodealBannerJavaObject; - private AndroidJavaClass _appodealClass; - - private AndroidJavaObject _activity; - private AndroidJavaObject _appodealBannerInstance; - - private static int NativeYAxisPosForUnityViewPos(int viewPos) - { - return viewPos switch - { - AppodealViewPosition.VerticalBottom => AppodealShowStyleBannerBottom, - AppodealViewPosition.VerticalTop => AppodealShowStyleBannerTop, - _ => viewPos - }; - } - - private static int NativeAdTypesForType(int adTypes) + private AndroidJavaClass AppodealJavaClass { - int nativeAdTypes = 0; - - if ((adTypes & AppodealAdType.Interstitial) > 0) - { - nativeAdTypes |= AppodealAdTypeInterstitial; - } - - if ((adTypes & AppodealAdType.Banner) > 0) + get { - nativeAdTypes |= AppodealAdTypeBanner; - } + if (_appodealJavaClass != null) return _appodealJavaClass; - if ((adTypes & AppodealAdType.Mrec) > 0) - { - nativeAdTypes |= AppodealAdTypeMrec; - } + try + { + _appodealJavaClass = new AndroidJavaClass(AndroidConstants.JavaClassName.Appodeal); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); + _appodealJavaClass = null; + } - if ((adTypes & AppodealAdType.RewardedVideo) > 0) - { - nativeAdTypes |= AppodealAdTypeRewardedVideo; + return _appodealJavaClass; } - - return nativeAdTypes; } - private static int NativeShowStyleForType(int adTypes) + private AndroidJavaObject UnityActivityJavaObject { - if ((adTypes & AppodealShowStyle.Interstitial) > 0) - { - return AppodealShowStyleInterstitial; - } - - if ((adTypes & AppodealShowStyle.BannerTop) > 0) + get { - return AppodealShowStyleBannerTop; - } + if (_unityActivityJavaObject != null) return _unityActivityJavaObject; - if ((adTypes & AppodealShowStyle.BannerBottom) > 0) - { - return AppodealShowStyleBannerBottom; - } - - if ((adTypes & AppodealShowStyle.BannerLeft) > 0) - { - return AppodealShowStyleBannerLeft; - } + try + { + using var unityPlayerJavaClass = new AndroidJavaClass(AndroidConstants.JavaClassName.UnityPlayer); + _unityActivityJavaObject = unityPlayerJavaClass.GetStatic(AndroidConstants.JavaFieldName.UnityPlayerCurrentActivity); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); + _unityActivityJavaObject = null; + } - if ((adTypes & AppodealShowStyle.BannerRight) > 0) - { - return AppodealShowStyleBannerRight; + return _unityActivityJavaObject; } - - if ((adTypes & AppodealShowStyle.RewardedVideo) > 0) - { - return AppodealShowStyleRewardedVideo; - } - - return 0; } - private static AppodealInitializationCallback GetInitCallback(IAppodealInitializationListener listener) + private AndroidJavaObject AppodealBannerJavaObject { - AppodealCallbacks.Sdk.Instance.SdkEventsImpl.InitListener = listener; - return new AppodealInitializationCallback(AppodealCallbacks.Sdk.Instance.SdkEventsImpl); - } + get + { + if (_appodealBannerJavaObject != null) return _appodealBannerJavaObject; - private static InAppPurchaseValidationCallbacks GetPurchaseCallback(IInAppPurchaseValidationListener listener) - { - AppodealCallbacks.InAppPurchase.Instance.PurchaseEventsImpl.Listener = listener; - return new InAppPurchaseValidationCallbacks(AppodealCallbacks.InAppPurchase.Instance.PurchaseEventsImpl); - } + try + { + using var appodealBannerViewJavaClass = new AndroidJavaClass(AndroidConstants.JavaClassName.AppodealBannerView); + _appodealBannerJavaObject = appodealBannerViewJavaClass.CallStatic(AndroidConstants.JavaMethodName.AppodealBannerView.GetInstance); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); + _appodealBannerJavaObject = null; + } - private AndroidJavaClass GetAppodealClass() - { - return _appodealClass ??= new AndroidJavaClass("com.appodeal.ads.Appodeal"); + return _appodealBannerJavaObject; + } } - private AndroidJavaObject GetAppodealBannerInstance() + public void Initialize(string appKey, int adTypes, IAppodealInitializationListener listener) { - if (_appodealBannerInstance != null) return _appodealBannerInstance; - using var appodealBannerViewJavaClass = new AndroidJavaClass("com.appodeal.ads.AppodealUnityBannerView"); - return _appodealBannerInstance = appodealBannerViewJavaClass.CallStatic("getInstance"); - } + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; - private AndroidJavaObject GetActivity() - { - if (_activity != null) return _activity; - using var unityPlayerJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); - return _activity = unityPlayerJavaClass.GetStatic("currentActivity"); - } + AppodealCallbacks.Sdk.Instance.SdkEventsImpl.InitListener = listener; - private void SetCallbacks() - { - GetAppodealClass().CallStatic("setMrecCallbacks", new AppodealMrecCallbacks(AppodealCallbacks.Mrec.Instance.MrecAdEventsImpl)); - GetAppodealClass().CallStatic("setBannerCallbacks", new AppodealBannerCallbacks(AppodealCallbacks.Banner.Instance.BannerAdEventsImpl)); - GetAppodealClass().CallStatic("setInterstitialCallbacks", new AppodealInterstitialCallbacks(AppodealCallbacks.Interstitial.Instance.InterstitialAdEventsImpl)); - GetAppodealClass().CallStatic("setRewardedVideoCallbacks", new AppodealRewardedVideoCallbacks(AppodealCallbacks.RewardedVideo.Instance.RewardedVideoAdEventsImpl)); - GetAppodealClass().CallStatic("setAdRevenueCallbacks", new AppodealAdRevenueCallback(AppodealCallbacks.AdRevenue.Instance.AdRevenueEventsImpl)); - } + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetFramework, AndroidConstants.FrameworkName, $"{AppodealVersions.GetPluginVersion()}-upm", AppodealVersions.GetUnityVersion()); - public void Initialize(string appKey, int adTypes, IAppodealInitializationListener listener) - { - SetCallbacks(); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetMrecCallbacks, new AppodealMrecCallbacks(AppodealCallbacks.Mrec.Instance.MrecAdEventsImpl)); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetBannerCallbacks, new AppodealBannerCallbacks(AppodealCallbacks.Banner.Instance.BannerAdEventsImpl)); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetInterstitialCallbacks, new AppodealInterstitialCallbacks(AppodealCallbacks.Interstitial.Instance.InterstitialAdEventsImpl)); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetRewardedVideoCallbacks, new AppodealRewardedVideoCallbacks(AppodealCallbacks.RewardedVideo.Instance.RewardedVideoAdEventsImpl)); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetAdRevenueCallbacks, new AppodealAdRevenueCallback(AppodealCallbacks.AdRevenue.Instance.AdRevenueEventsImpl)); - GetAppodealClass().CallStatic("setFramework", "unity", $"{AppodealVersions.GetPluginVersion()}-upm", AppodealVersions.GetUnityVersion()); - GetAppodealClass().CallStatic("initialize", GetActivity(), appKey, NativeAdTypesForType(adTypes), GetInitCallback(listener)); + int javaAdTypes = AndroidAppodealHelper.GetJavaAdTypes(adTypes); + var initCallback = new AppodealInitializationCallback(AppodealCallbacks.Sdk.Instance.SdkEventsImpl); + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Initialize, UnityActivityJavaObject, appKey, javaAdTypes, initCallback); } public bool IsInitialized(int adType) { - return GetAppodealClass().CallStatic("isInitialized", NativeAdTypesForType(adType)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.IsInitialized, AndroidAppodealHelper.GetJavaAdTypes(adType)) ?? false; } - public bool Show(int adTypes) + public bool Show(int showStyle) { - return GetAppodealClass().CallStatic("show", GetActivity(), NativeShowStyleForType(adTypes)); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return false; + return AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Show, UnityActivityJavaObject, AndroidAppodealHelper.GetJavaShowStyle(showStyle)); } - public bool Show(int adTypes, string placement) + public bool Show(int showStyle, string placement) { - return GetAppodealClass().CallStatic("show", GetActivity(), NativeShowStyleForType(adTypes), placement); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return false; + return AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Show, UnityActivityJavaObject, AndroidAppodealHelper.GetJavaShowStyle(showStyle), placement); } public bool ShowBannerView(int yAxis, int xAxis, string placement) { - return GetAppodealBannerInstance().Call("showBannerView", GetActivity(), xAxis, NativeYAxisPosForUnityViewPos(yAxis), placement); + if (AppodealBannerJavaObject == null || UnityActivityJavaObject == null) return false; + return AppodealBannerJavaObject.Call(AndroidConstants.JavaMethodName.AppodealBannerView.ShowBannerView, UnityActivityJavaObject, xAxis, AndroidAppodealHelper.GetJavaYAxisPosition(yAxis), placement); } public bool ShowMrecView(int yAxis, int xAxis, string placement) { - return GetAppodealBannerInstance().Call("showMrecView", GetActivity(), xAxis, NativeYAxisPosForUnityViewPos(yAxis), placement); + if (AppodealBannerJavaObject == null || UnityActivityJavaObject == null) return false; + return AppodealBannerJavaObject.Call(AndroidConstants.JavaMethodName.AppodealBannerView.ShowMrecView, UnityActivityJavaObject, xAxis, AndroidAppodealHelper.GetJavaYAxisPosition(yAxis), placement); } public bool IsLoaded(int adTypes) { - return GetAppodealClass().CallStatic("isLoaded", NativeAdTypesForType(adTypes)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.IsLoaded, AndroidAppodealHelper.GetJavaAdTypes(adTypes)) ?? false; } public void Cache(int adTypes) { - GetAppodealClass().CallStatic("cache", GetActivity(), NativeAdTypesForType(adTypes)); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Cache, UnityActivityJavaObject, AndroidAppodealHelper.GetJavaAdTypes(adTypes)); } public void Hide(int adTypes) { - GetAppodealClass().CallStatic("hide", GetActivity(), NativeAdTypesForType(adTypes)); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Hide, UnityActivityJavaObject, AndroidAppodealHelper.GetJavaAdTypes(adTypes)); } public void HideBannerView() { - GetAppodealBannerInstance().Call("hideBannerView", GetActivity()); + if (AppodealBannerJavaObject == null || UnityActivityJavaObject == null) return; + AppodealBannerJavaObject.Call(AndroidConstants.JavaMethodName.AppodealBannerView.HideBannerView, UnityActivityJavaObject); } public void HideMrecView() { - GetAppodealBannerInstance().Call("hideMrecView", GetActivity()); + if (AppodealBannerJavaObject == null || UnityActivityJavaObject == null) return; + AppodealBannerJavaObject.Call(AndroidConstants.JavaMethodName.AppodealBannerView.HideMrecView, UnityActivityJavaObject); } public bool IsPrecache(int adTypes) { - return GetAppodealClass().CallStatic("isPrecache", NativeAdTypesForType(adTypes)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.IsPrecache, AndroidAppodealHelper.GetJavaAdTypes(adTypes)) ?? false; } - public void SetAutoCache(int adTypes, bool autoCache) + public void SetAutoCache(int adTypes, bool isEnabled) { - GetAppodealClass().CallStatic("setAutoCache", NativeAdTypesForType(adTypes), autoCache); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetAutoCache, AndroidAppodealHelper.GetJavaAdTypes(adTypes), isEnabled); } - public void SetSmartBanners(bool value) + public void SetSmartBanners(bool areEnabled) { - GetAppodealClass().CallStatic("setSmartBanners", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetSmartBanners, areEnabled); } public bool IsSmartBannersEnabled() { - return GetAppodealClass().CallStatic("isSmartBannersEnabled"); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.IsSmartBannersEnabled) ?? false; } - public void SetBannerAnimation(bool value) + public void SetBannerAnimation(bool isEnabled) { - GetAppodealClass().CallStatic("setBannerAnimation", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetBannerAnimation, isEnabled); } - public void SetTabletBanners(bool value) + public void SetTabletBanners(bool areEnabled) { - GetAppodealClass().CallStatic("set728x90Banners", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetTabletBanners, areEnabled); } public void SetBannerRotation(int leftBannerRotation, int rightBannerRotation) { - GetAppodealClass().CallStatic("setBannerRotation", leftBannerRotation, rightBannerRotation); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetBannerRotation, leftBannerRotation, rightBannerRotation); } - public void SetTesting(bool test) + public void SetTesting(bool isEnabled) { - GetAppodealClass().CallStatic("setTesting", test); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetTesting, isEnabled); } - public void SetLogLevel(AppodealLogLevel logging) + public void SetLogLevel(AppodealLogLevel logLevel) { - using var logLevel = new AndroidJavaClass("com.appodeal.ads.utils.Log$LogLevel"); - switch (logging) + string javaLogLevelEnumValueName = logLevel switch { - case AppodealLogLevel.None: - { - GetAppodealClass().CallStatic("setLogLevel", logLevel.CallStatic("valueOf", "none")); - break; - } - case AppodealLogLevel.Debug: - { - GetAppodealClass().CallStatic("setLogLevel", logLevel.CallStatic("valueOf", "debug")); - break; - } - case AppodealLogLevel.Verbose: - { - GetAppodealClass().CallStatic("setLogLevel", logLevel.CallStatic("valueOf", "verbose")); - break; - } - default: - throw new ArgumentOutOfRangeException(nameof(logging), logging, null); + AppodealLogLevel.Debug => AndroidConstants.JavaFieldName.AppodealLogLevelDebug, + AppodealLogLevel.Verbose => AndroidConstants.JavaFieldName.AppodealLogLevelVerbose, + _ => AndroidConstants.JavaFieldName.AppodealLogLevelNone + }; + + try + { + using var logLevelJavaClass = new AndroidJavaClass(AndroidConstants.JavaClassName.AppodealLogLevel); + var logLevelJavaObject = logLevelJavaClass.CallStatic("valueOf", javaLogLevelEnumValueName); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetLogLevel, logLevelJavaObject); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); } } - public void SetChildDirectedTreatment(bool value) + public void SetChildDirectedTreatment(bool isEnabled) { - GetAppodealClass().CallStatic("setChildDirectedTreatment", Helper.GetJavaObject(value)); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetChildDirectedTreatment, AndroidAppodealHelper.GetJavaObject(isEnabled)); } public void DisableNetwork(string network) { - GetAppodealClass().CallStatic("disableNetwork", network); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.DisableNetwork, network); } public void DisableNetwork(string network, int adTypes) { - GetAppodealClass().CallStatic("disableNetwork", network, NativeAdTypesForType(adTypes)); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.DisableNetwork, network, AndroidAppodealHelper.GetJavaAdTypes(adTypes)); } - public void SetTriggerOnLoadedOnPrecache(int adTypes, bool onLoadedTriggerBoth) + public void SetTriggerOnLoadedOnPrecache(int adTypes, bool shouldTriggerOnLoadedOnPrecache) { - GetAppodealClass().CallStatic("setTriggerOnLoadedOnPrecache", NativeAdTypesForType(adTypes), onLoadedTriggerBoth); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetTriggerOnLoadedOnPrecache, AndroidAppodealHelper.GetJavaAdTypes(adTypes), shouldTriggerOnLoadedOnPrecache); } - public void MuteVideosIfCallsMuted(bool value) + public void MuteVideosIfCallsMuted(bool shouldMute) { - GetAppodealClass().CallStatic("muteVideosIfCallsMuted", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.MuteVideosIfCallsMuted, shouldMute); } public void ShowTestScreen() { - GetAppodealClass().CallStatic("startTestActivity", GetActivity()); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.StartTestActivity, UnityActivityJavaObject); } public string GetVersion() { - return GetAppodealClass().CallStatic("getVersion"); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetVersion) ?? String.Empty; } public long GetSegmentId() { - return GetAppodealClass().CallStatic("getSegmentId"); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetSegmentId) ?? -1; } public bool CanShow(int adTypes) { - return GetAppodealClass().CallStatic("canShow", NativeAdTypesForType(adTypes)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.CanShow, AndroidAppodealHelper.GetJavaAdTypes(adTypes)) ?? false; } public bool CanShow(int adTypes, string placement) { - return GetAppodealClass().CallStatic("canShow", NativeAdTypesForType(adTypes), placement); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.CanShow, AndroidAppodealHelper.GetJavaAdTypes(adTypes), placement) ?? false; } public void SetCustomFilter(string name, bool value) { - GetAppodealClass().CallStatic("setCustomFilter", name, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetCustomFilter, name, value); } public void SetCustomFilter(string name, int value) { - GetAppodealClass().CallStatic("setCustomFilter", name, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetCustomFilter, name, value); } public void SetCustomFilter(string name, double value) { - GetAppodealClass().CallStatic("setCustomFilter", name, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetCustomFilter, name, value); } public void SetCustomFilter(string name, string value) { - GetAppodealClass().CallStatic("setCustomFilter", name, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetCustomFilter, name, value); } public void ResetCustomFilter(string name) { - GetAppodealClass().CallStatic("setCustomFilter", name, null); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetCustomFilter, name, null); } public void SetExtraData(string key, bool value) { - GetAppodealClass().CallStatic("setExtraData", key, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetExtraData, key, value); } public void SetExtraData(string key, int value) { - GetAppodealClass().CallStatic("setExtraData", key, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetExtraData, key, value); } public void SetExtraData(string key, double value) { - GetAppodealClass().CallStatic("setExtraData", key, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetExtraData, key, value); } public void SetExtraData(string key, string value) { - GetAppodealClass().CallStatic("setExtraData", key, value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetExtraData, key, value); } public void ResetExtraData(string key) { - GetAppodealClass().CallStatic("setExtraData", key, null); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetExtraData, key, null); } public void TrackInAppPurchase(double amount, string currency) { - GetAppodealClass().CallStatic("trackInAppPurchase", GetActivity(), amount, currency); + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.TrackInAppPurchase, UnityActivityJavaObject, amount, currency); } public List GetNetworks(int adTypes) { - using var networks = GetAppodealClass().CallStatic("getNetworks", NativeAdTypesForType(adTypes)); - int countOfNetworks = networks.Call("size"); var networksList = new List(); - for(int i = 0; i < countOfNetworks; i++) + + using var networks = AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetNetworks, AndroidAppodealHelper.GetJavaAdTypes(adTypes)); + if (networks == null) return networksList; + + try + { + int countOfNetworks = networks.Call("size"); + for(int i = 0; i < countOfNetworks; i++) + { + networksList.Add(networks.Call("get", i)); + } + } + catch (Exception e) { - networksList.Add(networks.Call("get", i)); + AndroidAppodealHelper.LogIntegrationError(e.Message); } + return networksList; } public AppodealReward GetReward(string placement) { using var reward = String.IsNullOrEmpty(placement) - ? GetAppodealClass().CallStatic("getReward") - : GetAppodealClass().CallStatic("getReward", placement); + ? AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetReward) + : AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetReward, placement); return new AppodealReward { - Amount = reward.Call("getAmount"), - Currency = reward.Call("getCurrency") + Amount = reward?.Call(AndroidConstants.JavaMethodName.AppodealReward.GetAmount) ?? -1, + Currency = reward?.Call(AndroidConstants.JavaMethodName.AppodealReward.GetCurrency) ?? String.Empty }; } public double GetPredictedEcpm(int adType) { - return GetAppodealClass().CallStatic("getPredictedEcpm", NativeAdTypesForType(adType)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetPredictedEcpm, AndroidAppodealHelper.GetJavaAdTypes(adType)) ?? -1; } public double GetPredictedEcpmForPlacement(int adType, string placement) { return String.IsNullOrEmpty(placement) - ? GetAppodealClass().CallStatic("getPredictedEcpmByPlacement", NativeAdTypesForType(adType)) - : GetAppodealClass().CallStatic("getPredictedEcpmByPlacement", NativeAdTypesForType(adType), placement); + ? AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetPredictedEcpmByPlacement, AndroidAppodealHelper.GetJavaAdTypes(adType)) ?? -1 + : AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetPredictedEcpmByPlacement, AndroidAppodealHelper.GetJavaAdTypes(adType), placement) ?? -1; } public void Destroy(int adTypes) { - GetAppodealClass().CallStatic("destroy", NativeAdTypesForType(adTypes)); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.Destroy, AndroidAppodealHelper.GetJavaAdTypes(adTypes)); } public void SetUserId(string id) { - GetAppodealClass().CallStatic("setUserId", id); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetUserId, id); } public string GetUserId() { - return GetAppodealClass().CallStatic("getUserId"); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.GetUserId) ?? String.Empty; } public void SetInterstitialCallbacks(IInterstitialAdListener listener) @@ -449,83 +415,69 @@ public void SetAdRevenueCallback(IAdRevenueListener listener) AppodealCallbacks.AdRevenue.Instance.AdRevenueEventsImpl.Listener = listener; } - public void setSharedAdsInstanceAcrossActivities(bool value) + public void setSharedAdsInstanceAcrossActivities(bool isEnabled) { - GetAppodealClass().CallStatic("setSharedAdsInstanceAcrossActivities", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetSharedAdsInstanceAcrossActivities, isEnabled); } - public void SetUseSafeArea(bool value) + public void SetUseSafeArea(bool shouldUseSafeArea) { - GetAppodealClass().CallStatic("setUseSafeArea", value); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.SetUseSafeArea, shouldUseSafeArea); } public bool IsAutoCacheEnabled(int adType) { - return GetAppodealClass().CallStatic("isAutoCacheEnabled", NativeAdTypesForType(adType)); + return AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.IsAutoCacheEnabled, AndroidAppodealHelper.GetJavaAdTypes(adType)) ?? false; } public void LogEvent(string eventName, Dictionary eventParams) { if (eventParams == null) { - GetAppodealClass().CallStatic("logEvent", eventName, null); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.LogEvent, eventName, null); + return; } - else - { - var paramsFiltered = new Dictionary(); - eventParams.Keys.Where(key => eventParams[key] is int || eventParams[key] is double || eventParams[key] is string) - .ToList().ForEach(key => paramsFiltered.Add(key, eventParams[key])); + var paramsFiltered = new Dictionary(); - using var map = new AndroidJavaObject("java.util.HashMap"); + eventParams.Keys.Where(key => eventParams[key] is int || eventParams[key] is double || eventParams[key] is string) + .ToList().ForEach(key => paramsFiltered.Add(key, eventParams[key])); + try + { + using var map = new AndroidJavaObject(AndroidConstants.JavaClassName.HashMap); foreach (var entry in paramsFiltered) { - map.Call("put", entry.Key, Helper.GetJavaObject(entry.Value)); + map.Call("put", entry.Key, AndroidAppodealHelper.GetJavaObject(entry.Value)); } - GetAppodealClass().CallStatic("logEvent", eventName, map); + AppodealJavaClass?.CallStatic(AndroidConstants.JavaMethodName.Appodeal.LogEvent, eventName, map); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); } } public void ValidatePlayStoreInAppPurchase(IPlayStoreInAppPurchase purchase, IInAppPurchaseValidationListener listener) { - var androidPurchase = purchase.NativeInAppPurchase as AndroidPlayStoreInAppPurchase; - if (androidPurchase == null) return; - GetAppodealClass().CallStatic("validateInAppPurchase", GetActivity(), androidPurchase.GetInAppPurchase(), GetPurchaseCallback(listener)); - } + if (AppodealJavaClass == null || UnityActivityJavaObject == null) return; + if (purchase.NativeInAppPurchase is not AndroidPlayStoreInAppPurchase androidPurchase) return; - public void SetLocationTracking(bool value) - { - Debug.Log("Not supported on Android platform"); + AppodealCallbacks.InAppPurchase.Instance.PurchaseEventsImpl.Listener = listener; + var purchaseCallback = new InAppPurchaseValidationCallbacks(AppodealCallbacks.InAppPurchase.Instance.PurchaseEventsImpl); + + AppodealJavaClass.CallStatic(AndroidConstants.JavaMethodName.Appodeal.ValidateInAppPurchase, UnityActivityJavaObject, androidPurchase.GetInAppPurchase(), purchaseCallback); } - public void ValidateAppStoreInAppPurchase(IAppStoreInAppPurchase purchase, IInAppPurchaseValidationListener listener) + public void SetLocationTracking(bool isEnabled) { - Debug.Log("Not supported on Android platform"); + AndroidAppodealHelper.LogMethodNotSupported(); } - } - internal static class Helper - { - public static object GetJavaObject(object value) + public void ValidateAppStoreInAppPurchase(IAppStoreInAppPurchase purchase, IInAppPurchaseValidationListener listener) { - if (value is not bool && value is not char && value is not int && value is not long && value is not float && value is not double && value is not string) - { - Debug.LogError($"[Appodeal Unity Plugin] Conversion of {value.GetType()} type to java is not implemented"); - } - - return value switch - { - bool => new AndroidJavaObject("java.lang.Boolean", value), - char => new AndroidJavaObject("java.lang.Character", value), - int => new AndroidJavaObject("java.lang.Integer", value), - long => new AndroidJavaObject("java.lang.Long", value), - float => new AndroidJavaObject("java.lang.Float", value), - double => new AndroidJavaObject("java.lang.Double", value), - string => value, - _ => null - }; + AndroidAppodealHelper.LogMethodNotSupported(); } } } diff --git a/Runtime/Platforms/Android/AndroidAppodealHelper.cs b/Runtime/Platforms/Android/AndroidAppodealHelper.cs new file mode 100644 index 0000000..ac94e45 --- /dev/null +++ b/Runtime/Platforms/Android/AndroidAppodealHelper.cs @@ -0,0 +1,75 @@ +// ReSharper Disable CheckNamespace + +using System.Runtime.CompilerServices; +using UnityEngine; +using AppodealStack.Monetization.Common; + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static class AndroidAppodealHelper + { + public static int GetJavaAdTypes(int adTypes) + { + int javaAdTypes = 0; + + if ((adTypes & AppodealAdType.Interstitial) > 0) javaAdTypes |= AndroidConstants.JavaAdType.Interstitial; + if ((adTypes & AppodealAdType.Banner) > 0) javaAdTypes |= AndroidConstants.JavaAdType.Banner; + if ((adTypes & AppodealAdType.RewardedVideo) > 0) javaAdTypes |= AndroidConstants.JavaAdType.RewardedVideo; + if ((adTypes & AppodealAdType.Mrec) > 0) javaAdTypes |= AndroidConstants.JavaAdType.Mrec; + + return javaAdTypes; + } + + public static int GetJavaShowStyle(int showStyle) + { + if ((showStyle & AppodealShowStyle.Interstitial) > 0) return AndroidConstants.JavaShowStyle.Interstitial; + if ((showStyle & AppodealShowStyle.BannerBottom) > 0) return AndroidConstants.JavaShowStyle.BannerBottom; + if ((showStyle & AppodealShowStyle.BannerTop) > 0) return AndroidConstants.JavaShowStyle.BannerTop; + if ((showStyle & AppodealShowStyle.BannerLeft) > 0) return AndroidConstants.JavaShowStyle.BannerLeft; + if ((showStyle & AppodealShowStyle.BannerRight) > 0) return AndroidConstants.JavaShowStyle.BannerRight; + if ((showStyle & AppodealShowStyle.RewardedVideo) > 0) return AndroidConstants.JavaShowStyle.RewardedVideo; + + return 0; + } + + public static int GetJavaYAxisPosition(int viewPosition) + { + return viewPosition switch + { + AppodealViewPosition.VerticalBottom => AndroidConstants.JavaShowStyle.BannerBottom, + AppodealViewPosition.VerticalTop => AndroidConstants.JavaShowStyle.BannerTop, + _ => viewPosition + }; + } + + public static object GetJavaObject(object value) + { + if (value is not bool && value is not char && value is not int && value is not long && value is not float && value is not double && value is not string) + { + Debug.LogError($"[Appodeal Unity Plugin] Conversion of {value.GetType()} type to java is not implemented"); + } + + return value switch + { + bool => new AndroidJavaObject(AndroidConstants.JavaClassName.Boolean, value), + char => new AndroidJavaObject(AndroidConstants.JavaClassName.Character, value), + int => new AndroidJavaObject(AndroidConstants.JavaClassName.Integer, value), + long => new AndroidJavaObject(AndroidConstants.JavaClassName.Long, value), + float => new AndroidJavaObject(AndroidConstants.JavaClassName.Float, value), + double => new AndroidJavaObject(AndroidConstants.JavaClassName.Double, value), + string => value, + _ => null + }; + } + + public static void LogMethodNotSupported([CallerMemberName] string methodName = "") + { + Debug.LogWarning($"{AndroidConstants.MethodNotSupportedMessage} {methodName}()"); + } + + public static void LogIntegrationError(string message) + { + Debug.LogError($"{AndroidConstants.IntegrationErrorMessage} {message}"); + } + } +} diff --git a/Runtime/Platforms/Android/AndroidAppodealHelper.cs.meta b/Runtime/Platforms/Android/AndroidAppodealHelper.cs.meta new file mode 100644 index 0000000..9f393ff --- /dev/null +++ b/Runtime/Platforms/Android/AndroidAppodealHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51b441bf34d8c4a04b29e73e06042778 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchase.cs b/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchase.cs index 8098fde..3dbf2b2 100644 --- a/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchase.cs +++ b/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchase.cs @@ -25,69 +25,69 @@ public AndroidJavaObject GetInAppPurchase() public PlayStorePurchaseType GetPurchaseType() { - string type = GetInAppPurchase().Call("getType").Call("toString"); + string type = GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPurchaseType).Call("toString"); return type switch { - "Subs" => PlayStorePurchaseType.Subs, - "InApp" => PlayStorePurchaseType.InApp, + AndroidConstants.JavaFieldName.AppodealPlayStorePurchaseTypeSubs => PlayStorePurchaseType.Subs, + AndroidConstants.JavaFieldName.AppodealPlayStorePurchaseTypeInApp => PlayStorePurchaseType.InApp, _ => throw new ArgumentOutOfRangeException(nameof(PlayStorePurchaseType), type, null) }; } public string GetPublicKey() { - return GetInAppPurchase().Call("getPublicKey"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPublicKey); } public string GetSignature() { - return GetInAppPurchase().Call("getSignature"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetSignature); } public string GetPurchaseData() { - return GetInAppPurchase().Call("getPurchaseData"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPurchaseData); } public string GetPrice() { - return GetInAppPurchase().Call("getPrice"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPrice); } public string GetCurrency() { - return GetInAppPurchase().Call("getCurrency"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetCurrency); } public string GetSku() { - return GetInAppPurchase().Call("getSku"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetSku); } public string GetOrderId() { - return GetInAppPurchase().Call("getOrderId"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetOrderId); } public string GetPurchaseToken() { - return GetInAppPurchase().Call("getPurchaseToken"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPurchaseToken); } public long GetPurchaseTimestamp() { - return GetInAppPurchase().Call("getPurchaseTimestamp"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetPurchaseTimestamp); } public string GetAdditionalParameters() { - return GetInAppPurchase().Call("getAdditionalParameters").Call("toString"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetAdditionalParameters).Call("toString"); } public string GetDeveloperPayload() { - return GetInAppPurchase().Call("getDeveloperPayload"); + return GetInAppPurchase().Call(AndroidConstants.JavaMethodName.InAppPurchase.GetDeveloperPayload); } } } diff --git a/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchaseBuilder.cs b/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchaseBuilder.cs index 56819f4..996022e 100644 --- a/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchaseBuilder.cs +++ b/Runtime/Platforms/Android/AndroidPlayStoreInAppPurchaseBuilder.cs @@ -16,11 +16,11 @@ internal class AndroidPlayStoreInAppPurchaseBuilder : IPlayStoreInAppPurchaseBui internal AndroidPlayStoreInAppPurchaseBuilder(PlayStorePurchaseType purchaseType) { - using var inAppPurchaseJavaClass = new AndroidJavaClass("com.appodeal.ads.inapp.InAppPurchase"); + using var inAppPurchaseJavaClass = new AndroidJavaClass(AndroidConstants.JavaClassName.AppodealInAppPurchase); _inAppPurchaseBuilder = purchaseType switch { - PlayStorePurchaseType.Subs => inAppPurchaseJavaClass.CallStatic("newSubscriptionBuilder"), - PlayStorePurchaseType.InApp => inAppPurchaseJavaClass.CallStatic("newInAppBuilder"), + PlayStorePurchaseType.Subs => inAppPurchaseJavaClass.CallStatic(AndroidConstants.JavaMethodName.InAppPurchase.NewSubscriptionBuilder), + PlayStorePurchaseType.InApp => inAppPurchaseJavaClass.CallStatic(AndroidConstants.JavaMethodName.InAppPurchase.NewInAppBuilder), _ => throw new ArgumentOutOfRangeException(nameof(purchaseType), purchaseType, null) }; } @@ -32,69 +32,76 @@ private AndroidJavaObject GetBuilder() public IPlayStoreInAppPurchase Build() { - _inAppPurchase = GetBuilder().Call("build"); + _inAppPurchase = GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.Build); return new AndroidPlayStoreInAppPurchase(_inAppPurchase); } public void WithPublicKey(string publicKey) { - GetBuilder().Call("withPublicKey", publicKey); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithPublicKey, publicKey); } public void WithSignature(string signature) { - GetBuilder().Call("withSignature", signature); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithSignature, signature); } public void WithPurchaseData(string purchaseData) { - GetBuilder().Call("withPurchaseData", purchaseData); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithPurchaseData, purchaseData); } public void WithPrice(string price) { - GetBuilder().Call("withPrice", price); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithPrice, price); } public void WithCurrency(string currency) { - GetBuilder().Call("withCurrency", currency); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithCurrency, currency); } public void WithSku(string sku) { - GetBuilder().Call("withSku", sku); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithSku, sku); } public void WithOrderId(string orderId) { - GetBuilder().Call("withOrderId", orderId); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithOrderId, orderId); } public void WithDeveloperPayload(string developerPayload) { - GetBuilder().Call("withDeveloperPayload", developerPayload); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithDeveloperPayload, developerPayload); } public void WithPurchaseToken(string purchaseToken) { - GetBuilder().Call("withPurchaseToken", purchaseToken); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithPurchaseToken, purchaseToken); } public void WithPurchaseTimestamp(long purchaseTimestamp) { - GetBuilder().Call("withPurchaseTimestamp", purchaseTimestamp); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithPurchaseTimestamp, purchaseTimestamp); } public void WithAdditionalParameters(Dictionary additionalParameters) { - using var map = new AndroidJavaObject("java.util.HashMap"); - foreach (var entry in additionalParameters) + try { - map.Call("put", entry.Key, entry.Value); - } + using var map = new AndroidJavaObject(AndroidConstants.JavaClassName.HashMap); + foreach (var entry in additionalParameters) + { + map.Call("put", entry.Key, entry.Value); + } - GetBuilder().Call("withAdditionalParams", map); + GetBuilder().Call(AndroidConstants.JavaMethodName.InAppPurchaseBuilder.WithAdditionalParams, map); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); + } } } } diff --git a/Runtime/Platforms/Android/AssemblyInfo.cs b/Runtime/Platforms/Android/AssemblyInfo.cs index f5f7647..34c13e8 100644 --- a/Runtime/Platforms/Android/AssemblyInfo.cs +++ b/Runtime/Platforms/Android/AssemblyInfo.cs @@ -1,3 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("AppodealStack.Monetization.Platforms")] + +#if APPODEAL_DEV_TESTS +[assembly: InternalsVisibleTo("AppodealStack.Monetization.Platforms.Android.Tests")] +#endif diff --git a/Runtime/Platforms/Android/Callbacks/AppodealAdRevenueCallback.cs b/Runtime/Platforms/Android/Callbacks/AppodealAdRevenueCallback.cs index e8bf1e6..d491c31 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealAdRevenueCallback.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealAdRevenueCallback.cs @@ -8,14 +8,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealAdRevenueCallback : AndroidJavaProxy { private readonly IAdRevenueListener _listener; - internal AppodealAdRevenueCallback(IAdRevenueListener listener) : base("com.appodeal.ads.revenue.AdRevenueCallbacks") + internal AppodealAdRevenueCallback(IAdRevenueListener listener) : base(AndroidConstants.JavaInterfaceName.AdRevenueCallback) { _listener = listener; } @@ -31,14 +31,14 @@ private void onAdRevenueReceive(AndroidJavaObject ad) var adRevenue = new AppodealAdRevenue { - AdType = ad.Call("getAdTypeString"), - NetworkName = ad.Call("getNetworkName"), - AdUnitName = ad.Call("getAdUnitName"), - DemandSource = ad.Call("getDemandSource"), - Placement = ad.Call("getPlacement"), - Revenue = ad.Call("getRevenue"), - Currency = ad.Call("getCurrency"), - RevenuePrecision = ad.Call("getRevenuePrecision") + AdType = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetAdTypeString), + NetworkName = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetNetworkName), + AdUnitName = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetAdUnitName), + DemandSource = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetDemandSource), + Placement = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetPlacement), + Revenue = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetRevenue), + Currency = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetCurrency), + RevenuePrecision = ad.Call(AndroidConstants.JavaMethodName.AdRevenue.GetRevenuePrecision) }; UnityMainThreadDispatcher.Post(_ => _listener?.OnAdRevenueReceived(adRevenue)); diff --git a/Runtime/Platforms/Android/Callbacks/AppodealBannerCallbacks.cs b/Runtime/Platforms/Android/Callbacks/AppodealBannerCallbacks.cs index 7cf0ebf..d9e2a07 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealBannerCallbacks.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealBannerCallbacks.cs @@ -8,14 +8,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealBannerCallbacks : AndroidJavaProxy { private readonly IBannerAdListener _listener; - internal AppodealBannerCallbacks(IBannerAdListener listener) : base("com.appodeal.ads.BannerCallbacks") + internal AppodealBannerCallbacks(IBannerAdListener listener) : base(AndroidConstants.JavaInterfaceName.BannerCallbacks) { _listener = listener; } diff --git a/Runtime/Platforms/Android/Callbacks/AppodealInitializationCallback.cs b/Runtime/Platforms/Android/Callbacks/AppodealInitializationCallback.cs index d6ee6e8..a7a98a6 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealInitializationCallback.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealInitializationCallback.cs @@ -1,5 +1,6 @@ // ReSharper Disable CheckNamespace +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using UnityEngine; @@ -9,14 +10,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealInitializationCallback : AndroidJavaProxy { private readonly IAppodealInitializationListener _listener; - internal AppodealInitializationCallback(IAppodealInitializationListener listener) : base("com.appodeal.ads.initializing.ApdInitializationCallback") + internal AppodealInitializationCallback(IAppodealInitializationListener listener) : base(AndroidConstants.JavaInterfaceName.InitializationCallback) { _listener = listener; } @@ -32,10 +33,17 @@ private void onInitializationFinished(AndroidJavaObject errors) var errorsList = new List(); - int countOfErrors = errors.Call("size"); - for (int i = 0; i < countOfErrors; i++) + try { - errorsList.Add(errors.Call("get", i).Call("toString")); + int countOfErrors = errors.Call("size"); + for (int i = 0; i < countOfErrors; i++) + { + errorsList.Add(errors.Call("get", i).Call("toString")); + } + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); } UnityMainThreadDispatcher.Post(_ => _listener?.OnInitializationFinished(errorsList)); diff --git a/Runtime/Platforms/Android/Callbacks/AppodealInterstitialCallbacks.cs b/Runtime/Platforms/Android/Callbacks/AppodealInterstitialCallbacks.cs index cadb00c..5f60cf6 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealInterstitialCallbacks.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealInterstitialCallbacks.cs @@ -8,14 +8,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealInterstitialCallbacks : AndroidJavaProxy { private readonly IInterstitialAdListener _listener; - internal AppodealInterstitialCallbacks(IInterstitialAdListener listener) : base("com.appodeal.ads.InterstitialCallbacks") + internal AppodealInterstitialCallbacks(IInterstitialAdListener listener) : base(AndroidConstants.JavaInterfaceName.InterstitialCallbacks) { _listener = listener; } diff --git a/Runtime/Platforms/Android/Callbacks/AppodealMrecCallbacks.cs b/Runtime/Platforms/Android/Callbacks/AppodealMrecCallbacks.cs index 95a4919..9bddc75 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealMrecCallbacks.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealMrecCallbacks.cs @@ -8,14 +8,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealMrecCallbacks : AndroidJavaProxy { private readonly IMrecAdListener _listener; - internal AppodealMrecCallbacks(IMrecAdListener listener) : base("com.appodeal.ads.MrecCallbacks") + internal AppodealMrecCallbacks(IMrecAdListener listener) : base(AndroidConstants.JavaInterfaceName.MrecCallbacks) { _listener = listener; } diff --git a/Runtime/Platforms/Android/Callbacks/AppodealRewardedVideoCallbacks.cs b/Runtime/Platforms/Android/Callbacks/AppodealRewardedVideoCallbacks.cs index 298e3d8..fe1b113 100644 --- a/Runtime/Platforms/Android/Callbacks/AppodealRewardedVideoCallbacks.cs +++ b/Runtime/Platforms/Android/Callbacks/AppodealRewardedVideoCallbacks.cs @@ -8,14 +8,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class AppodealRewardedVideoCallbacks : AndroidJavaProxy { private readonly IRewardedVideoAdListener _listener; - internal AppodealRewardedVideoCallbacks(IRewardedVideoAdListener listener) : base("com.appodeal.ads.RewardedVideoCallbacks") + internal AppodealRewardedVideoCallbacks(IRewardedVideoAdListener listener) : base(AndroidConstants.JavaInterfaceName.RewardedVideoCallbacks) { _listener = listener; } diff --git a/Runtime/Platforms/Android/Callbacks/InAppPurchaseValidationCallbacks.cs b/Runtime/Platforms/Android/Callbacks/InAppPurchaseValidationCallbacks.cs index 2ba4220..bd288f6 100644 --- a/Runtime/Platforms/Android/Callbacks/InAppPurchaseValidationCallbacks.cs +++ b/Runtime/Platforms/Android/Callbacks/InAppPurchaseValidationCallbacks.cs @@ -10,14 +10,14 @@ namespace AppodealStack.Monetization.Platforms.Android { /// - /// Android implementation of the interface. + /// Android implementation of the interface. /// [SuppressMessage("ReSharper", "InconsistentNaming")] internal class InAppPurchaseValidationCallbacks : AndroidJavaProxy { private readonly IInAppPurchaseValidationListener _listener; - internal InAppPurchaseValidationCallbacks(IInAppPurchaseValidationListener listener) : base("com.appodeal.ads.inapp.InAppPurchaseValidateCallback") + internal InAppPurchaseValidationCallbacks(IInAppPurchaseValidationListener listener) : base(AndroidConstants.JavaInterfaceName.InAppPurchaseCallbacks) { _listener = listener; } @@ -54,13 +54,20 @@ private static string CreateResponse(AndroidJavaObject purchase, AndroidJavaObje string responseError = "\"Errors\":["; if (errors != null) { - var errorsList = new List(); - int countOfErrors = errors.Call("size"); - for (int i = 0; i < countOfErrors; i++) + try { - errorsList.Add($"\"{errors.Call("get", i).Call("toString")}\""); + var errorsList = new List(); + int countOfErrors = errors.Call("size"); + for (int i = 0; i < countOfErrors; i++) + { + errorsList.Add($"\"{errors.Call("get", i).Call("toString")}\""); + } + responseError += String.Join(",", errorsList); + } + catch (Exception e) + { + AndroidAppodealHelper.LogIntegrationError(e.Message); } - responseError += String.Join(",", errorsList); } responseError += ']'; diff --git a/Runtime/Platforms/Android/Constants.meta b/Runtime/Platforms/Android/Constants.meta new file mode 100644 index 0000000..5ffc001 --- /dev/null +++ b/Runtime/Platforms/Android/Constants.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 56e01f299639244dfa2a90d88de6ecf4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs new file mode 100644 index 0000000..0ed4871 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs @@ -0,0 +1,15 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static class JavaAdType + { + public const int Interstitial = 3; + public const int Banner = 4; + public const int RewardedVideo = 128; + public const int Mrec = 256; + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs.meta new file mode 100644 index 0000000..9dd5bef --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaAdType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f25844940dde54d56bcd5f09bfd7bd17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs new file mode 100644 index 0000000..73fab52 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs @@ -0,0 +1,25 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static class JavaClassName + { + public const string Appodeal = "com.appodeal.ads.Appodeal"; + public const string AppodealBannerView = "com.appodeal.ads.AppodealUnityBannerView"; + public const string AppodealInAppPurchase = "com.appodeal.ads.inapp.InAppPurchase"; + public const string AppodealLogLevel = "com.appodeal.ads.utils.Log$LogLevel"; + + public const string UnityPlayer = "com.unity3d.player.UnityPlayer"; + + public const string Boolean = "java.lang.Boolean"; + public const string Character = "java.lang.Character"; + public const string Double = "java.lang.Double"; + public const string Float = "java.lang.Float"; + public const string HashMap = "java.util.HashMap"; + public const string Integer = "java.lang.Integer"; + public const string Long = "java.lang.Long"; + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs.meta new file mode 100644 index 0000000..e9b244f --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaClassName.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b3e8c03b5860477f96a928e623bfe0c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs new file mode 100644 index 0000000..5d2fef2 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs @@ -0,0 +1,19 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static class JavaFieldName + { + public const string AppodealLogLevelDebug = "debug"; + public const string AppodealLogLevelNone = "none"; + public const string AppodealLogLevelVerbose = "verbose"; + + public const string AppodealPlayStorePurchaseTypeInApp = "InApp"; + public const string AppodealPlayStorePurchaseTypeSubs = "Subs"; + + public const string UnityPlayerCurrentActivity = "currentActivity"; + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs.meta new file mode 100644 index 0000000..504f4a3 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaFieldName.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d4bb77ca69be5464bb8a34537a2d066a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs new file mode 100644 index 0000000..438148e --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs @@ -0,0 +1,18 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static class JavaInterfaceName + { + public const string AdRevenueCallback = "com.appodeal.ads.revenue.AdRevenueCallbacks"; + public const string BannerCallbacks = "com.appodeal.ads.BannerCallbacks"; + public const string InitializationCallback = "com.appodeal.ads.initializing.ApdInitializationCallback"; + public const string InterstitialCallbacks = "com.appodeal.ads.InterstitialCallbacks"; + public const string MrecCallbacks = "com.appodeal.ads.MrecCallbacks"; + public const string RewardedVideoCallbacks = "com.appodeal.ads.RewardedVideoCallbacks"; + public const string InAppPurchaseCallbacks = "com.appodeal.ads.inapp.InAppPurchaseValidateCallback"; + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs.meta new file mode 100644 index 0000000..6beb1ec --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaInterfaceName.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c09dcbbe79674450eb95b2f353de730b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs new file mode 100644 index 0000000..6d05561 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs @@ -0,0 +1,22 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class AdRevenue + { + public const string GetAdTypeString = "getAdTypeString"; + public const string GetAdUnitName = "getAdUnitName"; + public const string GetCurrency = "getCurrency"; + public const string GetDemandSource = "getDemandSource"; + public const string GetNetworkName = "getNetworkName"; + public const string GetPlacement = "getPlacement"; + public const string GetRevenue = "getRevenue"; + public const string GetRevenuePrecision = "getRevenuePrecision"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs.meta new file mode 100644 index 0000000..c823386 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AdRevenue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c99f59306770c49c6b0a57382d881435 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs new file mode 100644 index 0000000..4db1547 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs @@ -0,0 +1,58 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class Appodeal + { + public const string Cache = "cache"; + public const string CanShow = "canShow"; + public const string Destroy = "destroy"; + public const string DisableNetwork = "disableNetwork"; + public const string GetNetworks = "getNetworks"; + public const string GetPredictedEcpm = "getPredictedEcpm"; + public const string GetPredictedEcpmByPlacement = "getPredictedEcpmByPlacement"; + public const string GetReward = "getReward"; + public const string GetSegmentId = "getSegmentId"; + public const string GetUserId = "getUserId"; + public const string GetVersion = "getVersion"; + public const string Hide = "hide"; + public const string Initialize = "initialize"; + public const string IsAutoCacheEnabled = "isAutoCacheEnabled"; + public const string IsInitialized = "isInitialized"; + public const string IsLoaded = "isLoaded"; + public const string IsPrecache = "isPrecache"; + public const string IsSmartBannersEnabled = "isSmartBannersEnabled"; + public const string LogEvent = "logEvent"; + public const string MuteVideosIfCallsMuted = "muteVideosIfCallsMuted"; + public const string SetAdRevenueCallbacks = "setAdRevenueCallbacks"; + public const string SetAutoCache = "setAutoCache"; + public const string SetBannerAnimation = "setBannerAnimation"; + public const string SetBannerCallbacks = "setBannerCallbacks"; + public const string SetBannerRotation = "setBannerRotation"; + public const string SetChildDirectedTreatment = "setChildDirectedTreatment"; + public const string SetCustomFilter = "setCustomFilter"; + public const string SetExtraData = "setExtraData"; + public const string SetFramework = "setFramework"; + public const string SetInterstitialCallbacks = "setInterstitialCallbacks"; + public const string SetLogLevel = "setLogLevel"; + public const string SetMrecCallbacks = "setMrecCallbacks"; + public const string SetRewardedVideoCallbacks = "setRewardedVideoCallbacks"; + public const string SetSharedAdsInstanceAcrossActivities = "setSharedAdsInstanceAcrossActivities"; + public const string SetSmartBanners = "setSmartBanners"; + public const string SetTabletBanners = "set728x90Banners"; + public const string SetTesting = "setTesting"; + public const string SetTriggerOnLoadedOnPrecache = "setTriggerOnLoadedOnPrecache"; + public const string SetUseSafeArea = "setUseSafeArea"; + public const string SetUserId = "setUserId"; + public const string Show = "show"; + public const string StartTestActivity = "startTestActivity"; + public const string TrackInAppPurchase = "trackInAppPurchase"; + public const string ValidateInAppPurchase = "validateInAppPurchase"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs.meta new file mode 100644 index 0000000..2337bea --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.Appodeal.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f130d98ae00ea4aa5adda7578c2f4ca1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs new file mode 100644 index 0000000..a925dde --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs @@ -0,0 +1,19 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class AppodealBannerView + { + public const string GetInstance = "getInstance"; + public const string HideBannerView = "hideBannerView"; + public const string HideMrecView = "hideMrecView"; + public const string ShowBannerView = "showBannerView"; + public const string ShowMrecView = "showMrecView"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs.meta new file mode 100644 index 0000000..a34c9bb --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealBannerView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 309630e1ac50841ae88d6f712f2e20b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs new file mode 100644 index 0000000..bc07867 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs @@ -0,0 +1,16 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class AppodealReward + { + public const string GetAmount = "getAmount"; + public const string GetCurrency = "getCurrency"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs.meta new file mode 100644 index 0000000..b87cf34 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.AppodealReward.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc35f14468e5a413ab0090850ebe6a72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs new file mode 100644 index 0000000..88075fc --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs @@ -0,0 +1,28 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class InAppPurchase + { + public const string GetAdditionalParameters = "getAdditionalParameters"; + public const string GetCurrency = "getCurrency"; + public const string GetDeveloperPayload = "getDeveloperPayload"; + public const string GetOrderId = "getOrderId"; + public const string GetPrice = "getPrice"; + public const string GetPublicKey = "getPublicKey"; + public const string GetPurchaseData = "getPurchaseData"; + public const string GetPurchaseTimestamp = "getPurchaseTimestamp"; + public const string GetPurchaseToken = "getPurchaseToken"; + public const string GetPurchaseType = "getType"; + public const string GetSignature = "getSignature"; + public const string GetSku = "getSku"; + public const string NewInAppBuilder = "newInAppBuilder"; + public const string NewSubscriptionBuilder = "newSubscriptionBuilder"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs.meta new file mode 100644 index 0000000..1d0dd83 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5fdc0210dfbd54d2fa17c641fb18bea9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs new file mode 100644 index 0000000..35887bd --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs @@ -0,0 +1,26 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static partial class JavaMethodName + { + internal static class InAppPurchaseBuilder + { + public const string Build = "build"; + public const string WithAdditionalParams = "withAdditionalParams"; + public const string WithCurrency = "withCurrency"; + public const string WithDeveloperPayload = "withDeveloperPayload"; + public const string WithOrderId = "withOrderId"; + public const string WithPrice = "withPrice"; + public const string WithPublicKey = "withPublicKey"; + public const string WithPurchaseData = "withPurchaseData"; + public const string WithPurchaseTimestamp = "withPurchaseTimestamp"; + public const string WithPurchaseToken = "withPurchaseToken"; + public const string WithSignature = "withSignature"; + public const string WithSku = "withSku"; + } + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs.meta new file mode 100644 index 0000000..adaced2 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaMethodName.InAppPurchaseBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07c044021843c4434833e81b858bc7a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs new file mode 100644 index 0000000..c5db86d --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs @@ -0,0 +1,17 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + internal static class JavaShowStyle + { + public const int Interstitial = 3; + public const int BannerBottom = 8; + public const int BannerTop = 16; + public const int RewardedVideo = 128; + public const int BannerLeft = 1024; + public const int BannerRight = 2048; + } + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs.meta new file mode 100644 index 0000000..ec8effb --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.JavaShowStyle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1da898d4af18b4b888d96517af5c38d6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.cs b/Runtime/Platforms/Android/Constants/AndroidConstants.cs new file mode 100644 index 0000000..839d801 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.cs @@ -0,0 +1,12 @@ +// ReSharper Disable CheckNamespace + +namespace AppodealStack.Monetization.Platforms.Android +{ + internal static partial class AndroidConstants + { + public const string FrameworkName = "unity"; + + public const string IntegrationErrorMessage = "[Appodeal Unity Plugin] Operation is not possible due to incorrect integration:"; + public const string MethodNotSupportedMessage = "[Appodeal Unity Plugin] Method is not supported on Android platform -"; + } +} diff --git a/Runtime/Platforms/Android/Constants/AndroidConstants.cs.meta b/Runtime/Platforms/Android/Constants/AndroidConstants.cs.meta new file mode 100644 index 0000000..af62333 --- /dev/null +++ b/Runtime/Platforms/Android/Constants/AndroidConstants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db58f58a468cf4c3c86502dabf783284 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 939cee8863813616dccce4c86705ef45abacfe5b Mon Sep 17 00:00:00 2001 From: Dmitrii Feshchenko Date: Thu, 12 Sep 2024 17:13:59 +0200 Subject: [PATCH 2/5] Update DM assembly for compatibility with tests --- Editor/DependencyManager/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/DependencyManager/AssemblyInfo.cs b/Editor/DependencyManager/AssemblyInfo.cs index 736d799..8f1ab69 100644 --- a/Editor/DependencyManager/AssemblyInfo.cs +++ b/Editor/DependencyManager/AssemblyInfo.cs @@ -1,5 +1,5 @@ -#if APPODEAL_DEV +#if APPODEAL_DEV_TESTS using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("AppodealInc.Mediation.Tests")] +[assembly: InternalsVisibleTo("AppodealInc.Mediation.DependencyManager.Editor.Tests")] #endif From 2a4109b59749251146ff8739b3736fc8c7b50f5a Mon Sep 17 00:00:00 2001 From: Dmitrii Feshchenko Date: Thu, 12 Sep 2024 17:32:07 +0200 Subject: [PATCH 3/5] Update Android SDK dependencies --- .../AppodealDependencies.txt | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/Editor/DependencyManager/DefaultDependencies/AppodealDependencies.txt b/Editor/DependencyManager/DefaultDependencies/AppodealDependencies.txt index f9a92cc..549d7a1 100644 --- a/Editor/DependencyManager/DefaultDependencies/AppodealDependencies.txt +++ b/Editor/DependencyManager/DefaultDependencies/AppodealDependencies.txt @@ -68,52 +68,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + From 3c23fd5dc40361467b14d98be663369a60accbd3 Mon Sep 17 00:00:00 2001 From: Dmitrii Feshchenko Date: Thu, 12 Sep 2024 17:32:25 +0200 Subject: [PATCH 4/5] Bump plugin version --- Runtime/Common/AppodealVersions.cs | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Common/AppodealVersions.cs b/Runtime/Common/AppodealVersions.cs index f90ee13..53d075f 100644 --- a/Runtime/Common/AppodealVersions.cs +++ b/Runtime/Common/AppodealVersions.cs @@ -12,7 +12,7 @@ namespace AppodealStack.Monetization.Common [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class AppodealVersions { - private const string AppodealPluginVersion = "3.4.0-alpha.1"; + private const string AppodealPluginVersion = "3.4.0-alpha.2"; /// /// Gets the current version of the Appodeal Unity Plugin. diff --git a/package.json b/package.json index c95f6b7..aa5e69d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.appodeal.mediation", - "version": "3.4.0-alpha.1", + "version": "3.4.0-alpha.2", "displayName": "Appodeal", "description": "Monetize more with less hassle. Our one ad mediation SDK includes it all: 70+ ad demand sources, all ad formats, in-app bidding algorithm, full-controls, a/b testing plus much more.", "documentationUrl": "https://docs.appodeal.com/unity/get-started", From bc03f49f3ae133abdddabaa3b9b7addaed2ee5c4 Mon Sep 17 00:00:00 2001 From: Dmitrii Feshchenko Date: Thu, 12 Sep 2024 17:32:35 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fe1f3..e088295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ *The full changelog can always be obtained at [Appodeal website](https://docs.appodeal.com/unity/changelog).* +### 3.4.0-alpha.2 (September 13, 2024) + ++ Updated Appodeal Android SDK to v3.4.0-alpha.2 ++ Improved Android bridge + ### 3.4.0-alpha.1 (September 06, 2024) + Updated Appodeal Android SDK to v3.4.0-alpha.1