Skip to content

Commit 9075e9e

Browse files
committed
refactor(ads): standardize in-article ad type to banner
- Update in-article ad implementation to always use AdType.banner - Add logic to determine effective headline image style based on banner shape - Modify _loadInlineAd method to accommodate banner ad shapes - Update method signatures to include bannerAdShape parameter where applicable
1 parent 2636c96 commit 9075e9e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/ads/ad_service.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,17 @@ class AdService {
159159
Future<InlineAd?> getInArticleAd({
160160
required AdConfig adConfig,
161161
required AdThemeStyle adThemeStyle,
162+
// headlineImageStyle is not directly used for in-article ad sizing,
163+
// but kept for consistency with AdService.getFeedAd.
162164
HeadlineImageStyle? headlineImageStyle,
163165
}) async {
164166
return _loadInlineAd(
165167
adConfig: adConfig,
166-
adType: adConfig.articleAdConfiguration.defaultInArticleAdType,
168+
adType: AdType.banner, // In-article ads are now always banners
167169
adThemeStyle: adThemeStyle,
168170
feedAd: false,
169171
headlineImageStyle: headlineImageStyle,
172+
bannerAdShape: adConfig.articleAdConfiguration.bannerAdShape,
170173
);
171174
}
172175

@@ -182,6 +185,7 @@ class AdService {
182185
/// - [feedAd]: A boolean indicating if this is for a feed ad (true) or in-article ad (false).
183186
/// - [headlineImageStyle]: The user's preference for feed layout,
184187
/// which can be used to request an appropriately sized ad.
188+
/// - [bannerAdShape]: The preferred shape for banner ads, used for in-article banners.
185189
///
186190
/// Returns an [InlineAd] if an ad is successfully loaded, otherwise `null`.
187191
Future<InlineAd?> _loadInlineAd({
@@ -190,6 +194,7 @@ class AdService {
190194
required AdThemeStyle adThemeStyle,
191195
required bool feedAd,
192196
HeadlineImageStyle? headlineImageStyle,
197+
BannerAdShape? bannerAdShape,
193198
}) async {
194199
// Check if ads are globally enabled and specifically for the context (feed or article).
195200
if (!adConfig.enabled ||
@@ -249,20 +254,29 @@ class AdService {
249254
);
250255
try {
251256
InlineAd? loadedAd;
257+
// Determine the effective headlineImageStyle for the ad provider.
258+
// For in-article banner ads, bannerAdShape dictates the visual style.
259+
final effectiveHeadlineImageStyle =
260+
!feedAd && adType == AdType.banner && bannerAdShape != null
261+
? (bannerAdShape == BannerAdShape.square
262+
? HeadlineImageStyle.largeThumbnail
263+
: HeadlineImageStyle.smallThumbnail)
264+
: headlineImageStyle; // Otherwise, use the provided headlineImageStyle
265+
252266
switch (adType) {
253267
case AdType.native:
254268
loadedAd = await adProvider.loadNativeAd(
255269
adPlatformIdentifiers: platformAdIdentifiers,
256270
adId: adId,
257271
adThemeStyle: adThemeStyle,
258-
headlineImageStyle: headlineImageStyle,
272+
headlineImageStyle: effectiveHeadlineImageStyle,
259273
);
260274
case AdType.banner:
261275
loadedAd = await adProvider.loadBannerAd(
262276
adPlatformIdentifiers: platformAdIdentifiers,
263277
adId: adId,
264278
adThemeStyle: adThemeStyle,
265-
headlineImageStyle: headlineImageStyle,
279+
headlineImageStyle: effectiveHeadlineImageStyle,
266280
);
267281
case AdType.interstitial:
268282
case AdType.video:

0 commit comments

Comments
 (0)