Skip to content

Commit a8df4b8

Browse files
authored
Merge pull request #77 from flutter-news-app-full-source-code/sync-app-settings-ads-section-with-the-core-ads-config
Sync app settings ads section with the core ads config
2 parents d891c48 + 75a77b1 commit a8df4b8

File tree

11 files changed

+129
-47
lines changed

11 files changed

+129
-47
lines changed

lib/app_configuration/widgets/ad_platform_config_form.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,16 @@ class _AdPlatformConfigFormState extends State<AdPlatformConfigForm> {
245245
),
246246
),
247247
segments: AdPlatformType.values
248+
.where(
249+
(type) =>
250+
type !=
251+
AdPlatformType
252+
.demo, // Ignore demo ad platform for dashboard
253+
)
248254
.map(
249-
(platform) => ButtonSegment<AdPlatformType>(
250-
value: platform,
251-
label: Text(platform.l10n(context)),
255+
(type) => ButtonSegment<AdPlatformType>(
256+
value: type,
257+
label: Text(type.l10n(context)),
252258
),
253259
)
254260
.toList(),

lib/app_configuration/widgets/article_ad_settings_form.dart

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
4-
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/ad_type_l10n.dart';
4+
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/banner_ad_shape_l10n.dart';
55
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/in_article_ad_slot_type_l10n.dart';
66
import 'package:ui_kit/ui_kit.dart';
77

@@ -64,51 +64,47 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
6464
),
6565
const SizedBox(height: AppSpacing.lg),
6666
ExpansionTile(
67-
title: Text(l10n.defaultInArticleAdTypeSelectionTitle),
67+
title: Text(l10n.bannerAdShapeSelectionTitle),
6868
childrenPadding: const EdgeInsetsDirectional.only(
69-
start: AppSpacing.lg, // Adjusted padding for hierarchy
69+
start: AppSpacing.lg,
7070
top: AppSpacing.md,
7171
bottom: AppSpacing.md,
7272
),
73-
expandedCrossAxisAlignment:
74-
CrossAxisAlignment.start, // Align content to start
73+
expandedCrossAxisAlignment: CrossAxisAlignment.start,
7574
children: [
7675
Text(
77-
l10n.defaultInArticleAdTypeSelectionDescription,
76+
l10n.bannerAdShapeSelectionDescription,
7877
style: Theme.of(context).textTheme.bodySmall?.copyWith(
7978
color: Theme.of(
8079
context,
8180
).colorScheme.onSurface.withOpacity(0.7),
8281
),
83-
textAlign: TextAlign.start, // Ensure text aligns to start
82+
textAlign: TextAlign.start,
8483
),
8584
const SizedBox(height: AppSpacing.lg),
8685
Align(
8786
alignment: AlignmentDirectional.centerStart,
88-
child: SegmentedButton<AdType>(
87+
child: SegmentedButton<BannerAdShape>(
8988
style: SegmentedButton.styleFrom(
9089
shape: const RoundedRectangleBorder(
9190
borderRadius: BorderRadius.zero,
9291
),
9392
),
94-
segments: AdType.values
95-
.where(
96-
(type) => type == AdType.native || type == AdType.banner,
97-
)
93+
segments: BannerAdShape.values
9894
.map(
99-
(type) => ButtonSegment<AdType>(
95+
(type) => ButtonSegment<BannerAdShape>(
10096
value: type,
10197
label: Text(type.l10n(context)),
10298
),
10399
)
104100
.toList(),
105-
selected: {articleAdConfig.defaultInArticleAdType},
101+
selected: {articleAdConfig.bannerAdShape},
106102
onSelectionChanged: (newSelection) {
107103
widget.onConfigChanged(
108104
widget.remoteConfig.copyWith(
109105
adConfig: adConfig.copyWith(
110106
articleAdConfiguration: articleAdConfig.copyWith(
111-
defaultInArticleAdType: newSelection.first,
107+
bannerAdShape: newSelection.first,
112108
),
113109
),
114110
),
@@ -122,12 +118,11 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
122118
ExpansionTile(
123119
title: Text(l10n.inArticleAdSlotPlacementsTitle),
124120
childrenPadding: const EdgeInsetsDirectional.only(
125-
start: AppSpacing.lg, // Adjusted padding for hierarchy
121+
start: AppSpacing.lg,
126122
top: AppSpacing.md,
127123
bottom: AppSpacing.md,
128124
),
129-
expandedCrossAxisAlignment:
130-
CrossAxisAlignment.start, // Align content to start
125+
expandedCrossAxisAlignment: CrossAxisAlignment.start,
131126
children: [
132127
Text(
133128
l10n.inArticleAdSlotPlacementsDescription,
@@ -136,7 +131,7 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
136131
context,
137132
).colorScheme.onSurface.withOpacity(0.7),
138133
),
139-
textAlign: TextAlign.start, // Ensure text aligns to start
134+
textAlign: TextAlign.start,
140135
),
141136
const SizedBox(height: AppSpacing.lg),
142137
...articleAdConfig.inArticleAdSlotConfigurations.map(

lib/l10n/app_localizations.dart

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,12 +2084,6 @@ abstract class AppLocalizations {
20842084
/// **'The unit ID for banner ads within articles.'**
20852085
String get inArticleBannerAdIdDescription;
20862086

2087-
/// Localized name for InArticleAdSlotType.belowMainArticleImage
2088-
///
2089-
/// In en, this message translates to:
2090-
/// **'Below the main image of the article'**
2091-
String get inArticleAdSlotTypeBelowMainArticleImage;
2092-
20932087
/// Localized name for InArticleAdSlotType.aboveArticleContinueReadingButton
20942088
///
20952089
/// In en, this message translates to:
@@ -2407,6 +2401,30 @@ abstract class AppLocalizations {
24072401
/// In en, this message translates to:
24082402
/// **'Video'**
24092403
String get videoAdType;
2404+
2405+
/// Title for the Banner Ad Shape Selection section
2406+
///
2407+
/// In en, this message translates to:
2408+
/// **'Banner Ad Shape'**
2409+
String get bannerAdShapeSelectionTitle;
2410+
2411+
/// Description for the Banner Ad Shape Selection section
2412+
///
2413+
/// In en, this message translates to:
2414+
/// **'Select the preferred visual shape for banner ads displayed in articles.'**
2415+
String get bannerAdShapeSelectionDescription;
2416+
2417+
/// Label for the Square banner ad shape option
2418+
///
2419+
/// In en, this message translates to:
2420+
/// **'Square'**
2421+
String get bannerAdShapeSquare;
2422+
2423+
/// Label for the Rectangle banner ad shape option
2424+
///
2425+
/// In en, this message translates to:
2426+
/// **'Rectangle'**
2427+
String get bannerAdShapeRectangle;
24102428
}
24112429

24122430
class _AppLocalizationsDelegate

lib/l10n/app_localizations_ar.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,10 +1108,6 @@ class AppLocalizationsAr extends AppLocalizations {
11081108
String get inArticleBannerAdIdDescription =>
11091109
'معرف وحدة إعلانات البانر داخل المقالات.';
11101110

1111-
@override
1112-
String get inArticleAdSlotTypeBelowMainArticleImage =>
1113-
'أسفل الصورة الرئيسية للمقال';
1114-
11151111
@override
11161112
String get inArticleAdSlotTypeAboveArticleContinueReadingButton =>
11171113
'فوق زر \'متابعة القراءة\'';
@@ -1287,4 +1283,17 @@ class AppLocalizationsAr extends AppLocalizations {
12871283

12881284
@override
12891285
String get videoAdType => 'فيديو';
1286+
1287+
@override
1288+
String get bannerAdShapeSelectionTitle => 'شكل إعلان البانر';
1289+
1290+
@override
1291+
String get bannerAdShapeSelectionDescription =>
1292+
'اختر الشكل المرئي المفضل لإعلانات البانر المعروضة في المقالات.';
1293+
1294+
@override
1295+
String get bannerAdShapeSquare => 'مربع';
1296+
1297+
@override
1298+
String get bannerAdShapeRectangle => 'مستطيل';
12901299
}

lib/l10n/app_localizations_en.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,6 @@ class AppLocalizationsEn extends AppLocalizations {
11071107
String get inArticleBannerAdIdDescription =>
11081108
'The unit ID for banner ads within articles.';
11091109

1110-
@override
1111-
String get inArticleAdSlotTypeBelowMainArticleImage =>
1112-
'Below the main image of the article';
1113-
11141110
@override
11151111
String get inArticleAdSlotTypeAboveArticleContinueReadingButton =>
11161112
'Above the \'Continue Reading\' button';
@@ -1289,4 +1285,17 @@ class AppLocalizationsEn extends AppLocalizations {
12891285

12901286
@override
12911287
String get videoAdType => 'Video';
1288+
1289+
@override
1290+
String get bannerAdShapeSelectionTitle => 'Banner Ad Shape';
1291+
1292+
@override
1293+
String get bannerAdShapeSelectionDescription =>
1294+
'Select the preferred visual shape for banner ads displayed in articles.';
1295+
1296+
@override
1297+
String get bannerAdShapeSquare => 'Square';
1298+
1299+
@override
1300+
String get bannerAdShapeRectangle => 'Rectangle';
12921301
}

lib/l10n/arb/app_ar.arb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,10 +1386,6 @@
13861386
"@inArticleBannerAdIdDescription": {
13871387
"description": "وصف حقل إدخال معرف إعلان البانر داخل المقال"
13881388
},
1389-
"inArticleAdSlotTypeBelowMainArticleImage": "أسفل الصورة الرئيسية للمقال",
1390-
"@inArticleAdSlotTypeBelowMainArticleImage": {
1391-
"description": "الاسم المترجم لـ InArticleAdSlotType.belowMainArticleImage"
1392-
},
13931389
"inArticleAdSlotTypeAboveArticleContinueReadingButton": "فوق زر 'متابعة القراءة'",
13941390
"@inArticleAdSlotTypeAboveArticleContinueReadingButton": {
13951391
"description": "الاسم المترجم لـ InArticleAdSlotType.aboveArticleContinueReadingButton"
@@ -1613,5 +1609,21 @@
16131609
"videoAdType": "فيديو",
16141610
"@videoAdType": {
16151611
"description": "تسمية نوع إعلان الفيديو."
1612+
},
1613+
"bannerAdShapeSelectionTitle": "شكل إعلان البانر",
1614+
"@bannerAdShapeSelectionTitle": {
1615+
"description": "Title for the Banner Ad Shape Selection section"
1616+
},
1617+
"bannerAdShapeSelectionDescription": "اختر الشكل المرئي المفضل لإعلانات البانر المعروضة في المقالات.",
1618+
"@bannerAdShapeSelectionDescription": {
1619+
"description": "Description for the Banner Ad Shape Selection section"
1620+
},
1621+
"bannerAdShapeSquare": "مربع",
1622+
"@bannerAdShapeSquare": {
1623+
"description": "Label for the Square banner ad shape option"
1624+
},
1625+
"bannerAdShapeRectangle": "مستطيل",
1626+
"@bannerAdShapeRectangle": {
1627+
"description": "Label for the Rectangle banner ad shape option"
16161628
}
16171629
}

lib/l10n/arb/app_en.arb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,6 @@
13821382
"@inArticleBannerAdIdDescription": {
13831383
"description": "Description for the In-Article Banner Ad ID input field"
13841384
},
1385-
"inArticleAdSlotTypeBelowMainArticleImage": "Below the main image of the article",
1386-
"@inArticleAdSlotTypeBelowMainArticleImage": {
1387-
"description": "Localized name for InArticleAdSlotType.belowMainArticleImage"
1388-
},
13891385
"inArticleAdSlotTypeAboveArticleContinueReadingButton": "Above the 'Continue Reading' button",
13901386
"@inArticleAdSlotTypeAboveArticleContinueReadingButton": {
13911387
"description": "Localized name for InArticleAdSlotType.aboveArticleContinueReadingButton"
@@ -1609,5 +1605,21 @@
16091605
"videoAdType": "Video",
16101606
"@videoAdType": {
16111607
"description": "Label for Video Ad Type."
1608+
},
1609+
"bannerAdShapeSelectionTitle": "Banner Ad Shape",
1610+
"@bannerAdShapeSelectionTitle": {
1611+
"description": "Title for the Banner Ad Shape Selection section"
1612+
},
1613+
"bannerAdShapeSelectionDescription": "Select the preferred visual shape for banner ads displayed in articles.",
1614+
"@bannerAdShapeSelectionDescription": {
1615+
"description": "Description for the Banner Ad Shape Selection section"
1616+
},
1617+
"bannerAdShapeSquare": "Square",
1618+
"@bannerAdShapeSquare": {
1619+
"description": "Label for the Square banner ad shape option"
1620+
},
1621+
"bannerAdShapeRectangle": "Rectangle",
1622+
"@bannerAdShapeRectangle": {
1623+
"description": "Label for the Rectangle banner ad shape option"
16121624
}
16131625
}

lib/shared/extensions/ad_platform_type_l10n.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ extension AdPlatformTypeL10n on AdPlatformType {
1212
return l10n.adPlatformTypeAdmob;
1313
case AdPlatformType.local:
1414
return l10n.adPlatformTypeLocal;
15+
case AdPlatformType.demo:
16+
throw UnimplementedError(
17+
'Demo ad platform type is not intended for dashboard usage, rather for mobile client, demo env specific usecase.',
18+
);
1519
}
1620
}
1721
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:core/core.dart';
2+
import 'package:flutter/widgets.dart';
3+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
4+
5+
/// {@template banner_ad_shape_l10n}
6+
/// Extension on [BannerAdShape] to provide localized string representations.
7+
/// {@endtemplate}
8+
extension BannerAdShapeL10n on BannerAdShape {
9+
/// Returns the localized name for a [BannerAdShape].
10+
String l10n(BuildContext context) {
11+
final l10n = context.l10n;
12+
switch (this) {
13+
case BannerAdShape.square:
14+
return l10n.bannerAdShapeSquare;
15+
case BannerAdShape.rectangle:
16+
return l10n.bannerAdShapeRectangle;
17+
}
18+
}
19+
}

lib/shared/extensions/in_article_ad_slot_type_l10n.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ extension InArticleAdSlotTypeL10n on InArticleAdSlotType {
1010
String l10n(BuildContext context) {
1111
final l10n = context.l10n;
1212
switch (this) {
13-
case InArticleAdSlotType.belowMainArticleImage:
14-
return l10n.inArticleAdSlotTypeBelowMainArticleImage;
1513
case InArticleAdSlotType.aboveArticleContinueReadingButton:
1614
return l10n.inArticleAdSlotTypeAboveArticleContinueReadingButton;
1715
case InArticleAdSlotType.belowArticleContinueReadingButton:

0 commit comments

Comments
 (0)