Use Builder in ImaAdsLoader constructor

PiperOrigin-RevId: 334562209
This commit is contained in:
andrewlewis 2020-09-30 11:08:04 +01:00 committed by Oliver Woodman
parent 824b2a7305
commit 358d205f0f

View File

@ -142,7 +142,7 @@ public final class ImaAdsLoader
* @param context The context; * @param context The context;
*/ */
public Builder(Context context) { public Builder(Context context) {
this.context = checkNotNull(context); this.context = checkNotNull(context).getApplicationContext();
adPreloadTimeoutMs = DEFAULT_AD_PRELOAD_TIMEOUT_MS; adPreloadTimeoutMs = DEFAULT_AD_PRELOAD_TIMEOUT_MS;
vastLoadTimeoutMs = TIMEOUT_UNSET; vastLoadTimeoutMs = TIMEOUT_UNSET;
mediaLoadTimeoutMs = TIMEOUT_UNSET; mediaLoadTimeoutMs = TIMEOUT_UNSET;
@ -318,21 +318,7 @@ public final class ImaAdsLoader
*/ */
public ImaAdsLoader buildForAdTag(Uri adTagUri) { public ImaAdsLoader buildForAdTag(Uri adTagUri) {
return new ImaAdsLoader( return new ImaAdsLoader(
context, /* builder= */ this, /* adTagUri= */ adTagUri, /* adsResponse= */ null);
adTagUri,
imaSdkSettings,
/* adsResponse= */ null,
adPreloadTimeoutMs,
vastLoadTimeoutMs,
mediaLoadTimeoutMs,
mediaBitrate,
focusSkipButtonWhenAvailable,
playAdBeforeStartPosition,
adUiElements,
companionAdSlots,
adErrorListener,
adEventListener,
imaFactory);
} }
/** /**
@ -343,22 +329,7 @@ public final class ImaAdsLoader
* @return The new {@link ImaAdsLoader}. * @return The new {@link ImaAdsLoader}.
*/ */
public ImaAdsLoader buildForAdsResponse(String adsResponse) { public ImaAdsLoader buildForAdsResponse(String adsResponse) {
return new ImaAdsLoader( return new ImaAdsLoader(/* builder= */ this, /* adTagUri= */ null, adsResponse);
context,
/* adTagUri= */ null,
imaSdkSettings,
adsResponse,
adPreloadTimeoutMs,
vastLoadTimeoutMs,
mediaLoadTimeoutMs,
mediaBitrate,
focusSkipButtonWhenAvailable,
playAdBeforeStartPosition,
adUiElements,
companionAdSlots,
adErrorListener,
adEventListener,
imaFactory);
} }
} }
@ -520,56 +491,27 @@ public final class ImaAdsLoader
* more information. * more information.
*/ */
public ImaAdsLoader(Context context, Uri adTagUri) { public ImaAdsLoader(Context context, Uri adTagUri) {
this( this(new Builder(context), adTagUri, /* adsResponse= */ null);
context,
adTagUri,
/* imaSdkSettings= */ null,
/* adsResponse= */ null,
/* adPreloadTimeoutMs= */ Builder.DEFAULT_AD_PRELOAD_TIMEOUT_MS,
/* vastLoadTimeoutMs= */ TIMEOUT_UNSET,
/* mediaLoadTimeoutMs= */ TIMEOUT_UNSET,
/* mediaBitrate= */ BITRATE_UNSET,
/* focusSkipButtonWhenAvailable= */ true,
/* playAdBeforeStartPosition= */ true,
/* adUiElements= */ null,
/* companionAdSlots= */ null,
/* adErrorListener= */ null,
/* adEventListener= */ null,
/* imaFactory= */ new DefaultImaFactory());
} }
@SuppressWarnings({"nullness:argument.type.incompatible", "methodref.receiver.bound.invalid"}) @SuppressWarnings({"nullness:argument.type.incompatible", "methodref.receiver.bound.invalid"})
private ImaAdsLoader( private ImaAdsLoader(Builder builder, @Nullable Uri adTagUri, @Nullable String adsResponse) {
Context context,
@Nullable Uri adTagUri,
@Nullable ImaSdkSettings imaSdkSettings,
@Nullable String adsResponse,
long adPreloadTimeoutMs,
int vastLoadTimeoutMs,
int mediaLoadTimeoutMs,
int mediaBitrate,
boolean focusSkipButtonWhenAvailable,
boolean playAdBeforeStartPosition,
@Nullable Set<UiElement> adUiElements,
@Nullable Collection<CompanionAdSlot> companionAdSlots,
@Nullable AdErrorListener adErrorListener,
@Nullable AdEventListener adEventListener,
ImaFactory imaFactory) {
checkArgument(adTagUri != null || adsResponse != null); checkArgument(adTagUri != null || adsResponse != null);
this.context = context.getApplicationContext(); this.context = builder.context.getApplicationContext();
this.adTagUri = adTagUri; this.adTagUri = adTagUri;
this.adsResponse = adsResponse; this.adsResponse = adsResponse;
this.adPreloadTimeoutMs = adPreloadTimeoutMs; this.adPreloadTimeoutMs = builder.adPreloadTimeoutMs;
this.vastLoadTimeoutMs = vastLoadTimeoutMs; this.vastLoadTimeoutMs = builder.vastLoadTimeoutMs;
this.mediaLoadTimeoutMs = mediaLoadTimeoutMs; this.mediaLoadTimeoutMs = builder.mediaLoadTimeoutMs;
this.mediaBitrate = mediaBitrate; this.mediaBitrate = builder.mediaBitrate;
this.focusSkipButtonWhenAvailable = focusSkipButtonWhenAvailable; this.focusSkipButtonWhenAvailable = builder.focusSkipButtonWhenAvailable;
this.playAdBeforeStartPosition = playAdBeforeStartPosition; this.playAdBeforeStartPosition = builder.playAdBeforeStartPosition;
this.adUiElements = adUiElements; this.adUiElements = builder.adUiElements;
this.companionAdSlots = companionAdSlots; this.companionAdSlots = builder.companionAdSlots;
this.adErrorListener = adErrorListener; this.adErrorListener = builder.adErrorListener;
this.adEventListener = adEventListener; this.adEventListener = builder.adEventListener;
this.imaFactory = imaFactory; this.imaFactory = builder.imaFactory;
@Nullable ImaSdkSettings imaSdkSettings = builder.imaSdkSettings;
if (imaSdkSettings == null) { if (imaSdkSettings == null) {
imaSdkSettings = imaFactory.createImaSdkSettings(); imaSdkSettings = imaFactory.createImaSdkSettings();
if (DEBUG) { if (DEBUG) {