-
Notifications
You must be signed in to change notification settings - Fork 0
APS Updates #89
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
base: main
Are you sure you want to change the base?
APS Updates #89
Changes from all commits
8ed284d
f9fcbeb
6e6b26c
a205cab
503504a
a2b3d33
9837574
d9741a8
b11fc8e
1af208b
6c84a82
c094b71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,4 +442,4 @@ extension DispatchGroup { | |
return pairIds | ||
} | ||
} | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,9 @@ public void InitializeNativeSDK() { | |
_aps = new AndroidJavaClass(AndroidApsPackage); | ||
_aps.CallStatic("initialize", _currentActivity, _appID); | ||
foreach (var slot in _slotData) { | ||
var (w, h) = AdTypeToDim(slot.AdUnitType); | ||
if (slot.AdUnitType == AdUnitType.Rewarded) { | ||
var (w, h) = AdTypeToDim(slot.APSAdUnitType); | ||
if (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo || | ||
slot.APSAdUnitType == APSAdUnitType.RewardedVideo) { | ||
_aps.CallStatic<bool>("addApsSlot", slot.SlotId, w, h, true); | ||
continue; | ||
} | ||
|
@@ -46,39 +47,77 @@ public void InitializeNativeSDK() { | |
adRegistration.CallStatic("enableTesting", true); | ||
} | ||
|
||
private static Tuple<int, int> AdTypeToDim(AdUnitType type) { | ||
private static Tuple<int, int> AdTypeToDim(APSAdUnitType type) { | ||
switch (type) { | ||
case AdUnitType.Undefined: | ||
return new Tuple<int, int>(0, 0); | ||
case AdUnitType.Banner: | ||
case APSAdUnitType.Display320X50: | ||
return new Tuple<int, int>(320, 50); | ||
case AdUnitType.Interstitial: | ||
case APSAdUnitType.Display300X250: | ||
return new Tuple<int, int>(300, 250); | ||
case APSAdUnitType.Display728X90: | ||
return new Tuple<int, int>(728, 90); | ||
case APSAdUnitType.InterstitialDisplay: | ||
return new Tuple<int, int>(320, 480); | ||
case APSAdUnitType.InterstitialVideo: | ||
return new Tuple<int, int>(320, 480); | ||
case AdUnitType.Rewarded: | ||
case APSAdUnitType.RewardedVideo: | ||
return new Tuple<int, int>(Screen.width, Screen.height); | ||
default: | ||
return new Tuple<int, int>(0, 0); | ||
} | ||
} | ||
|
||
|
||
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) { | ||
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) { | ||
var found = false; | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
// ReSharper disable once LoopCanBeConvertedToQuery | ||
for (var i = 0; i < _slotData.Length; i++) { | ||
if (_slotData[i].AdUnitType != type) continue; | ||
found = true; | ||
break; | ||
var interstitialVideo = false; | ||
foreach (ApsSlotData slot in _slotData){ | ||
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. The previous for loop implementation for matching slots was fine since it was only checking a single condition but as the complexity has grown, this pattern becomes much harder to maintain as it is currently lacking adequate testing and will be prone to future error. Is it possible to replace this with the .Net Find function? |
||
if (type == AdUnitType.Banner) | ||
{ | ||
if (width == 320 && height == 50 && slot.APSAdUnitType == APSAdUnitType.Display320X50) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
if (width == 300 && height == 250 && slot.APSAdUnitType == APSAdUnitType.Display300X250) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
if (width == 728 && height == 90 && slot.APSAdUnitType == APSAdUnitType.Display728X90) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (type == AdUnitType.Interstitial) | ||
{ | ||
if (slot.APSAdUnitType == APSAdUnitType.InterstitialDisplay || | ||
slot.APSAdUnitType == APSAdUnitType.InterstitialVideo) | ||
{ | ||
found = true; | ||
interstitialVideo = (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo); | ||
break; | ||
} | ||
} | ||
if (type == AdUnitType.Rewarded) | ||
{ | ||
if (slot.APSAdUnitType == APSAdUnitType.RewardedVideo) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!found) { | ||
Debug.unityLogger.LogError("Nimbus", | ||
"APS NOT FOUND"); | ||
return null; | ||
} | ||
|
||
var (w, h) = AdTypeToDim(type); | ||
if (type == AdUnitType.Rewarded) { | ||
|
||
var w = width; | ||
var h = height; | ||
if (interstitialVideo || type == AdUnitType.Rewarded) { | ||
w = 0; | ||
h = 0; | ||
isFullScreen = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,9 @@ public void InitializeNativeSDK() { | |
_initializeAPSRequestHelper(_appID, TimeoutInSeconds, _enableTestMode); | ||
|
||
foreach (var slot in _slotData) { | ||
var (w, h) = AdTypeToDim(slot.AdUnitType); | ||
if (slot.AdUnitType == AdUnitType.Rewarded) { | ||
var (w, h) = AdTypeToDim(slot.APSAdUnitType); | ||
if (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo || | ||
slot.APSAdUnitType == APSAdUnitType.RewardedVideo) { | ||
_addAPSSlot(slot.SlotId, w, h, true); | ||
continue; | ||
} | ||
|
@@ -50,39 +51,74 @@ public void InitializeNativeSDK() { | |
} | ||
} | ||
|
||
private static Tuple<int, int> AdTypeToDim(AdUnitType type) { | ||
private static Tuple<int, int> AdTypeToDim(APSAdUnitType type) { | ||
switch (type) { | ||
case AdUnitType.Undefined: | ||
return new Tuple<int, int>(0, 0); | ||
case AdUnitType.Banner: | ||
case APSAdUnitType.Display320X50: | ||
return new Tuple<int, int>(320, 50); | ||
case AdUnitType.Interstitial: | ||
case APSAdUnitType.Display300X250: | ||
return new Tuple<int, int>(300, 250); | ||
case APSAdUnitType.Display728X90: | ||
return new Tuple<int, int>(728, 90); | ||
case APSAdUnitType.InterstitialDisplay: | ||
return new Tuple<int, int>(320, 480); | ||
case AdUnitType.Rewarded: | ||
case APSAdUnitType.InterstitialVideo: | ||
return new Tuple<int, int>(Screen.width, Screen.height); | ||
case APSAdUnitType.RewardedVideo: | ||
return new Tuple<int, int>(Screen.width, Screen.height); | ||
default: | ||
return new Tuple<int, int>(0, 0); | ||
} | ||
} | ||
|
||
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) { | ||
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) { | ||
var found = false; | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
// ReSharper disable once LoopCanBeConvertedToQuery | ||
for (var i = 0; i < _slotData.Length; i++) { | ||
if (_slotData[i].AdUnitType != type) continue; | ||
found = true; | ||
break; | ||
var interstitialVideo = false; | ||
foreach (ApsSlotData slot in _slotData){ | ||
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. This looks to be duplicated from the Android code, is it possible to use a single method for retrieving the slot that can be used by both platforms? |
||
if (type == AdUnitType.Banner) | ||
{ | ||
if (width == 320 && height == 50 && slot.APSAdUnitType == APSAdUnitType.Display320X50) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
if (width == 300 && height == 250 && slot.APSAdUnitType == APSAdUnitType.Display300X250) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
if (width == 728 && height == 90 && slot.APSAdUnitType == APSAdUnitType.Display728X90) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (type == AdUnitType.Interstitial) | ||
{ | ||
if (slot.APSAdUnitType == APSAdUnitType.InterstitialDisplay || | ||
slot.APSAdUnitType == APSAdUnitType.InterstitialVideo) | ||
{ | ||
found = true; | ||
interstitialVideo = (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo); | ||
break; | ||
} | ||
} | ||
if (type == AdUnitType.Rewarded) | ||
{ | ||
if (slot.APSAdUnitType == APSAdUnitType.RewardedVideo) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!found) { | ||
return null; | ||
} | ||
|
||
|
||
var (w, h) = AdTypeToDim(type); | ||
// ReSharper disable once InvertIf | ||
if (type == AdUnitType.Rewarded) { | ||
var w = width; | ||
var h = height; | ||
if (interstitialVideo || type == AdUnitType.Rewarded) { | ||
w = 0; | ||
h = 0; | ||
isFullScreen = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Nimbus.Internal.Interceptor.ThirdPartyDemand { | ||
[Serializable] | ||
public class ApsSlotData { | ||
public string SlotId; | ||
public AdUnitType AdUnitType; | ||
public APSAdUnitType APSAdUnitType; | ||
} | ||
public enum APSAdUnitType : byte { | ||
Display320X50 = 0, | ||
Display300X250 = 1, | ||
Display728X90 = 2, | ||
InterstitialDisplay = 3, | ||
InterstitialVideo = 4, | ||
RewardedVideo = 5 | ||
} | ||
} |
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.
If you were to store the width and height of the ad on the
ApsAdSlot
you could remove this function and reference those values directly.