Skip to content

Commit

Permalink
ref/refactoring_code (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
alhiwatan authored Aug 5, 2024
1 parent 28cb8c7 commit ec08d6c
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.applovin.sdk.AppLovinSdkConfiguration.ConsentFlowUserGeography;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.applovin.sdk.AppLovinSdkUtils;
import com.applovin.sdk.AppLovinUserService;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -82,9 +81,9 @@ public class AppLovinMAX
private AppLovinSdkConfiguration sdkConfiguration;

// Store these values if pub attempts to set it before initializing
private List<String> initializationAdUnitIdsToSet;
private List<String> testDeviceAdvertisingIdsToSet;
private MaxSegmentCollection.Builder segmentCollectionBuilder = MaxSegmentCollection.builder();
private List<String> initializationAdUnitIdsToSet;
private List<String> testDeviceAdvertisingIdsToSet;
private final MaxSegmentCollection.Builder segmentCollectionBuilder = MaxSegmentCollection.builder();

// Fullscreen Ad Fields
private final Map<String, MaxInterstitialAd> mInterstitials = new HashMap<>( 2 );
Expand Down Expand Up @@ -139,21 +138,14 @@ public void onDetachedFromEngine(@NonNull final FlutterPluginBinding binding)
sharedChannel.setMethodCallHandler( null );
}

private boolean isInitialized()
{
return isInitialized( null );
}

private boolean isInitialized(@Nullable final Result result)
private void isInitialized(@Nullable final Result result)
{
boolean isInitialized = isPluginInitialized && isSdkInitialized;

if ( result != null )
{
result.success( isInitialized );
}

return isInitialized;
}

private void initialize(final String pluginVersion, final String sdkKey, final Result result)
Expand Down Expand Up @@ -210,15 +202,10 @@ private Map<String, Object> getInitializationMessage()

if ( sdkConfiguration != null )
{
message.put( "consentDialogState", sdkConfiguration.getConsentDialogState().ordinal() );
message.put( "countryCode", sdkConfiguration.getCountryCode() );
message.put( "isTestModeEnabled", sdkConfiguration.isTestModeEnabled() );
message.put( "consentFlowUserGeography", getRawAppLovinConsentFlowUserGeography( sdkConfiguration.getConsentFlowUserGeography() ) );
}
else
{
message.put( "consentDialogState", AppLovinSdkConfiguration.ConsentDialogState.UNKNOWN.ordinal() );
}

return message;
}
Expand All @@ -241,24 +228,6 @@ public void showMediationDebugger()
sdk.showMediationDebugger();
}

public void showConsentDialog(final Result result)
{
if ( sdk == null )
{
logUninitializedAccessError( "showConsentDialog" );
return;
}

sdk.getUserService().showConsentDialog( getCurrentActivity(), (AppLovinUserService.OnConsentDialogDismissListener) () -> result.success( null ) );
}

public void getConsentDialogState(final Result result)
{
if ( !isInitialized() ) result.success( AppLovinSdkConfiguration.ConsentDialogState.UNKNOWN.ordinal() );

result.success( sdkConfiguration.getConsentDialogState().ordinal() );
}

public void setHasUserConsent(boolean hasUserConsent)
{
AppLovinPrivacySettings.setHasUserConsent( hasUserConsent, applicationContext );
Expand Down Expand Up @@ -299,13 +268,6 @@ public void setMuted(final boolean muted)
sdk.getSettings().setMuted( muted );
}

public boolean isMuted()
{
if ( !isPluginInitialized ) return false;

return sdk.getSettings().isMuted();
}

public void setVerboseLogging(final boolean enabled)
{
sdk.getSettings().setVerboseLogging( enabled );
Expand Down Expand Up @@ -674,7 +636,7 @@ else if ( MaxAdFormat.APP_OPEN == adFormat )
}

@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error)
public void onAdLoadFailed(@NonNull final String adUnitId, @NonNull final MaxError error)
{
if ( TextUtils.isEmpty( adUnitId ) )
{
Expand Down Expand Up @@ -767,7 +729,7 @@ else if ( MaxAdFormat.REWARDED == adFormat )
}

@Override
public void onAdDisplayFailed(final MaxAd ad, final MaxError error)
public void onAdDisplayFailed(final MaxAd ad, @NonNull final MaxError error)
{
// BMLs do not support [DISPLAY] events
final MaxAdFormat adFormat = ad.getFormat();
Expand Down Expand Up @@ -875,19 +837,19 @@ else if ( MaxAdFormat.APP_OPEN == adFormat )
}

@Override
public void onRewardedVideoCompleted(final MaxAd ad)
public void onRewardedVideoCompleted(@NonNull final MaxAd ad)
{
// This event is not forwarded
}

@Override
public void onRewardedVideoStarted(final MaxAd ad)
public void onRewardedVideoStarted(@NonNull final MaxAd ad)
{
// This event is not forwarded
}

@Override
public void onUserRewarded(final MaxAd ad, final MaxReward reward)
public void onUserRewarded(final MaxAd ad, @NonNull final MaxReward reward)
{
final MaxAdFormat adFormat = ad.getFormat();
if ( adFormat != MaxAdFormat.REWARDED )
Expand All @@ -896,8 +858,8 @@ public void onUserRewarded(final MaxAd ad, final MaxReward reward)
return;
}

final String rewardLabel = reward != null ? reward.getLabel() : "";
final int rewardAmount = reward != null ? reward.getAmount() : 0;
final String rewardLabel = reward.getLabel();
final int rewardAmount = reward.getAmount();

try
{
Expand Down Expand Up @@ -1502,23 +1464,11 @@ private void setAmazonResult(final Object result, final String adUnitId, final M
if ( adFormat == MaxAdFormat.INTERSTITIAL )
{
MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
if ( interstitial == null )
{
e( "Failed to set Amazon result - unable to find interstitial" );
return;
}

interstitial.setLocalExtraParameter( key, result );
}
else if ( adFormat == MaxAdFormat.REWARDED )
{
MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
if ( rewardedAd == null )
{
e( "Failed to set Amazon result - unable to find rewarded ad" );
return;
}

rewardedAd.setLocalExtraParameter( key, result );
}
else // MaxAdFormat.BANNER or MaxAdFormat.MREC
Expand Down Expand Up @@ -1571,7 +1521,7 @@ private AdViewSize(final int widthDp, final int heightDp)
}
}

public static AdViewSize getAdViewSize(final MaxAdFormat format)
private static AdViewSize getAdViewSize(final MaxAdFormat format)
{
if ( MaxAdFormat.LEADER == format )
{
Expand Down Expand Up @@ -1648,10 +1598,6 @@ else if ( "showMediationDebugger".equals( call.method ) )

result.success( null );
}
else if ( "getConsentDialogState".equals( call.method ) )
{
getConsentDialogState( result );
}
else if ( "setHasUserConsent".equals( call.method ) )
{
boolean hasUserConsent = call.argument( "value" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,47 +142,47 @@ public void dispose()
}

@Override
public void onAdLoaded(final MaxAd ad)
public void onAdLoaded(@NonNull final MaxAd ad)
{
sendEvent( "OnAdViewAdLoadedEvent", ad );
}

@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error)
public void onAdLoadFailed(@NonNull final String adUnitId, @NonNull final MaxError error)
{
Map params = AppLovinMAX.getInstance().getAdLoadFailedInfo( adUnitId, error );
Map<String, Object> params = AppLovinMAX.getInstance().getAdLoadFailedInfo( adUnitId, error );
AppLovinMAX.getInstance().fireCallback( "OnAdViewAdLoadFailedEvent", params, channel );
}

@Override
public void onAdClicked(final MaxAd ad)
public void onAdClicked(@NonNull final MaxAd ad)
{
sendEvent( "OnAdViewAdClickedEvent", ad );
}

@Override
public void onAdExpanded(final MaxAd ad)
public void onAdExpanded(@NonNull final MaxAd ad)
{
sendEvent( "OnAdViewAdExpandedEvent", ad );
}

@Override
public void onAdCollapsed(final MaxAd ad)
public void onAdCollapsed(@NonNull final MaxAd ad)
{
sendEvent( "OnAdViewAdCollapsedEvent", ad );
}

@Override
public void onAdDisplayed(final MaxAd ad) { }
public void onAdDisplayed(@NonNull final MaxAd ad) { }

@Override
public void onAdDisplayFailed(final MaxAd ad, final MaxError error) { }
public void onAdDisplayFailed(@NonNull final MaxAd ad, @NonNull final MaxError error) { }

@Override
public void onAdHidden(final MaxAd ad) { }
public void onAdHidden(@NonNull final MaxAd ad) { }

@Override
public void onAdRevenuePaid(final MaxAd ad)
public void onAdRevenuePaid(@NonNull final MaxAd ad)
{
sendEvent( "OnAdViewAdRevenuePaidEvent", ad );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public PlatformView create(@Nullable final Context context, final int viewId, fi
{
// Ensure plugin has been initialized
AppLovinSdk sdk = AppLovinMAX.getInstance().getSdk();
if ( sdk == null )
{
AppLovinMAX.e( "Failed to create MaxAdView widget - please ensure the AppLovin MAX plugin has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
return null;
}

Map<String, Object> params = (Map<String, Object>) args;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class AppLovinMAXNativeAdView
@Nullable
private final String customData;
@Nullable
private Map<String, Object> extraParameters;
private final Map<String, Object> extraParameters;
@Nullable
private Map<String, Object> localExtraParameters;
private final Map<String, Object> localExtraParameters;

private final FrameLayout nativeAdView;
@Nullable
Expand Down Expand Up @@ -260,7 +260,7 @@ private class NativeAdListener
extends MaxNativeAdListener
{
@Override
public void onNativeAdLoaded(@Nullable final MaxNativeAdView nativeAdView, final MaxAd ad)
public void onNativeAdLoaded(@Nullable final MaxNativeAdView nativeAdView, @NonNull final MaxAd ad)
{
AppLovinMAX.d( "Native ad loaded: " + ad );

Expand All @@ -280,13 +280,13 @@ public void onNativeAdLoaded(@Nullable final MaxNativeAdView nativeAdView, final
}

@Override
public void onNativeAdLoadFailed(final String adUnitId, final MaxError error)
public void onNativeAdLoadFailed(@NonNull final String adUnitId, @NonNull final MaxError error)
{
handleAdLoadFailed( "Failed to load native ad for Ad Unit ID " + adUnitId + " with error: " + error, error );
}

@Override
public void onNativeAdClicked(final MaxAd ad)
public void onNativeAdClicked(@NonNull final MaxAd ad)
{
sendEvent( "OnNativeAdClickedEvent", ad );
}
Expand All @@ -295,7 +295,7 @@ public void onNativeAdClicked(final MaxAd ad)
/// Ad Revenue Listener

@Override
public void onAdRevenuePaid(final MaxAd ad)
public void onAdRevenuePaid(@NonNull final MaxAd ad)
{
sendEvent( "OnNativeAdRevenuePaidEvent", ad );
}
Expand Down Expand Up @@ -509,7 +509,7 @@ private void handleAdLoadFailed(final String message, @Nullable final MaxError e

AppLovinMAX.e( message );

Map params = AppLovinMAX.getInstance().getAdLoadFailedInfo( adUnitId, error );
Map<String, Object> params = AppLovinMAX.getInstance().getAdLoadFailedInfo( adUnitId, error );
AppLovinMAX.getInstance().fireCallback( "OnNativeAdLoadFailedEvent", params, channel );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public PlatformView create(@Nullable final Context context, final int viewId, fi
{
// Ensure plugin has been initialized
AppLovinSdk sdk = AppLovinMAX.getInstance().getSdk();
if ( sdk == null )
{
AppLovinMAX.e( "Failed to create MaxNativeAdView widget - please ensure the AppLovin MAX plugin has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
return null;
}

Map<String, Object> params = (Map<String, Object>) args;

Expand Down
4 changes: 2 additions & 2 deletions applovin_max/example/lib/native_ad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class NativeAdViewState extends State<NativeAdView> {
width: double.infinity,
child: MaxNativeAdCallToActionView(
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll<Color>(Color(0xff2d545e)),
textStyle: MaterialStatePropertyAll<TextStyle>(TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
backgroundColor: WidgetStatePropertyAll<Color>(Colors.white),
textStyle: WidgetStatePropertyAll<TextStyle>(TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
),
),
),
Expand Down
21 changes: 0 additions & 21 deletions applovin_max/ios/Classes/AppLovinMAX.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,11 @@ - (void)getConfiguration:(FlutterResult)result

if ( self.sdkConfiguration )
{
message[@"consentDialogState"] = @(self.sdkConfiguration.consentDialogState);
message[@"countryCode"] = self.sdkConfiguration.countryCode;
message[@"isTestModeEnabled"] = @(self.sdkConfiguration.isTestModeEnabled);
message[@"consentFlowUserGeography"] = [self fromAppLovinConsentFlowUserGeography: self.sdkConfiguration.consentFlowUserGeography];
message[@"appTrackingStatus"] = [self fromAppLovinAppTrackingStatus: self.sdkConfiguration.appTrackingTransparencyStatus];
}
else
{
message[@"consentDialogState"] = @(ALConsentDialogStateUnknown);
}

return message;
}
Expand All @@ -222,18 +217,6 @@ - (void)showMediationDebugger
[self.sdk showMediationDebugger];
}

- (void)getConsentDialogState:(FlutterResult)result
{
if ( ![self isInitialized] )
{
result(@(ALConsentDialogStateUnknown));

return;
}

result(@(self.sdkConfiguration.consentDialogState));
}

- (void)setHasUserConsent:(BOOL)hasUserConsent
{
[ALPrivacySettings setHasUserConsent: hasUserConsent];
Expand Down Expand Up @@ -1587,10 +1570,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result

result(nil);
}
else if ( [@"getConsentDialogState" isEqualToString: call.method] )
{
[self getConsentDialogState: result];
}
else if ( [@"setHasUserConsent" isEqualToString: call.method] )
{
BOOL hasUserConsent = ((NSNumber *)call.arguments[@"value"]).boolValue;
Expand Down
Loading

0 comments on commit ec08d6c

Please sign in to comment.