|
1 |
| -import 'package:core/src/models/config/remote_config.dart'; |
| 1 | +import 'package:core/src/enums/ad_platform_type.dart'; |
| 2 | +import 'package:core/src/models/config/ad_platform_identifiers.dart'; |
| 3 | +import 'package:core/src/models/config/article_ad_configuration.dart'; |
| 4 | +import 'package:core/src/models/config/feed_ad_configuration.dart'; |
| 5 | +import 'package:core/src/models/config/local_ad.dart'; |
2 | 6 | import 'package:equatable/equatable.dart';
|
3 | 7 | import 'package:json_annotation/json_annotation.dart';
|
4 | 8 | import 'package:meta/meta.dart';
|
5 | 9 |
|
6 | 10 | part 'ad_config.g.dart';
|
7 | 11 |
|
8 | 12 | /// {@template ad_config}
|
9 |
| -/// Defines configuration settings related to ad injection and display, |
10 |
| -/// tiered by user role. |
11 |
| -/// |
12 |
| -/// This model is part of the overall [RemoteConfig] and is used to control |
13 |
| -/// how ads are integrated into the application's feed or other content areas |
14 |
| -/// based on the user's authentication status or subscription level. |
15 |
| -/// |
16 |
| -/// **Ad Injection Logic Explained:** |
17 |
| -/// |
18 |
| -/// - __`AdFrequency`__: This determines *how often* an ad *can* be injected relative to the number of primary content items. For example, an `adFrequency` of 5 means an ad *could* be placed after every 5 primary items. It sets the overall density of ads in the feed. |
19 |
| -/// |
20 |
| -/// - __`AdPlacementInterval`__: This sets a *minimum number of primary items* that must appear *before* the *first* ad is placed. It prevents ads from appearing right at the very beginning of the feed, ensuring the user sees some initial content first. |
21 |
| -/// |
22 |
| -/// So, `AdFrequency` controls the spacing of ads *throughout* the feed (after the initial interval), while `AdPlacementInterval` controls where the *very first* ad can appear. |
23 |
| -/// |
24 |
| -/// Think of it like this: |
25 |
| -/// |
26 |
| -/// - `AdPlacementInterval` = 3: No ads will appear in the first 3 primary items. |
27 |
| -/// - `AdFrequency` = 5: After the first 3 items, an ad *could* appear after item #5, then potentially after item #10, #15, etc. |
| 13 | +/// This is the main container for all ad-related configurations. |
28 | 14 | /// {@endtemplate}
|
29 | 15 | @immutable
|
30 | 16 | @JsonSerializable(explicitToJson: true, includeIfNull: true, checked: true)
|
31 | 17 | class AdConfig extends Equatable {
|
32 | 18 | /// {@macro ad_config}
|
33 | 19 | const AdConfig({
|
34 |
| - required this.guestAdFrequency, |
35 |
| - required this.guestAdPlacementInterval, |
36 |
| - required this.authenticatedAdFrequency, |
37 |
| - required this.authenticatedAdPlacementInterval, |
38 |
| - required this.premiumAdFrequency, |
39 |
| - required this.premiumAdPlacementInterval, |
40 |
| - required this.guestArticlesToReadBeforeShowingInterstitialAds, |
41 |
| - required this.standardUserArticlesToReadBeforeShowingInterstitialAds, |
42 |
| - required this.premiumUserArticlesToReadBeforeShowingInterstitialAds, |
| 20 | + required this.primaryAdPlatform, |
| 21 | + required this.platformAdIdentifiers, |
| 22 | + required this.localAdsCatalog, |
| 23 | + required this.feedAdConfiguration, |
| 24 | + required this.articleAdConfiguration, |
43 | 25 | });
|
44 | 26 |
|
45 |
| - /// Factory method to create an [AdConfig] instance from a JSON map. |
| 27 | + /// Creates an [AdConfig] from JSON data. |
46 | 28 | factory AdConfig.fromJson(Map<String, dynamic> json) =>
|
47 | 29 | _$AdConfigFromJson(json);
|
48 | 30 |
|
49 |
| - /// See class documentation for details on AdFrequency. |
50 |
| - final int guestAdFrequency; |
51 |
| - |
52 |
| - /// See class documentation for details on AdPlacementInterval. |
53 |
| - final int guestAdPlacementInterval; |
54 |
| - |
55 |
| - /// See class documentation for details on AdFrequency. |
56 |
| - final int authenticatedAdFrequency; |
57 |
| - |
58 |
| - /// See class documentation for details on AdPlacementInterval. |
59 |
| - final int authenticatedAdPlacementInterval; |
| 31 | + /// Converts this [AdConfig] instance to JSON data. |
| 32 | + Map<String, dynamic> toJson() => _$AdConfigToJson(this); |
60 | 33 |
|
61 |
| - /// See class documentation for details on AdFrequency. |
62 |
| - final int premiumAdFrequency; |
| 34 | + /// Global choice: AdMob or Local. |
| 35 | + final AdPlatformType primaryAdPlatform; |
63 | 36 |
|
64 |
| - /// See class documentation for details on AdPlacementInterval. |
65 |
| - final int premiumAdPlacementInterval; |
| 37 | + /// Map to store identifiers for all platforms. |
| 38 | + final Map<AdPlatformType, AdPlatformIdentifiers> platformAdIdentifiers; |
66 | 39 |
|
67 |
| - /// The number of articles a guest user needs to read before an |
68 |
| - /// interstitial ad is shown. |
69 |
| - final int guestArticlesToReadBeforeShowingInterstitialAds; |
| 40 | + /// All defined local ads by ID. |
| 41 | + final Map<String, LocalAd> localAdsCatalog; |
70 | 42 |
|
71 |
| - /// The number of articles a standard user needs to read before an |
72 |
| - /// interstitial ad is shown. |
73 |
| - final int standardUserArticlesToReadBeforeShowingInterstitialAds; |
| 43 | + /// Configuration for main feed, search feed, similar headlines feed. |
| 44 | + final FeedAdConfiguration feedAdConfiguration; |
74 | 45 |
|
75 |
| - /// The number of articles a premium user needs to read before an |
76 |
| - /// interstitial ad is shown. |
77 |
| - final int premiumUserArticlesToReadBeforeShowingInterstitialAds; |
| 46 | + /// Configuration for article page ads. |
| 47 | + final ArticleAdConfiguration articleAdConfiguration; |
78 | 48 |
|
79 |
| - /// Converts this [AdConfig] instance to a JSON map. |
80 |
| - Map<String, dynamic> toJson() => _$AdConfigToJson(this); |
| 49 | + @override |
| 50 | + List<Object> get props => [ |
| 51 | + primaryAdPlatform, |
| 52 | + platformAdIdentifiers, |
| 53 | + localAdsCatalog, |
| 54 | + feedAdConfiguration, |
| 55 | + articleAdConfiguration, |
| 56 | + ]; |
81 | 57 |
|
82 | 58 | /// Creates a copy of this [AdConfig] but with the given fields replaced
|
83 | 59 | /// with the new values.
|
84 | 60 | AdConfig copyWith({
|
85 |
| - int? guestAdFrequency, |
86 |
| - int? guestAdPlacementInterval, |
87 |
| - int? authenticatedAdFrequency, |
88 |
| - int? authenticatedAdPlacementInterval, |
89 |
| - int? premiumAdFrequency, |
90 |
| - int? premiumAdPlacementInterval, |
91 |
| - int? guestArticlesToReadBeforeShowingInterstitialAds, |
92 |
| - int? standardUserArticlesToReadBeforeShowingInterstitialAds, |
93 |
| - int? premiumUserArticlesToReadBeforeShowingInterstitialAds, |
| 61 | + AdPlatformType? primaryAdPlatform, |
| 62 | + Map<AdPlatformType, AdPlatformIdentifiers>? platformAdIdentifiers, |
| 63 | + Map<String, LocalAd>? localAdsCatalog, |
| 64 | + FeedAdConfiguration? feedAdConfiguration, |
| 65 | + ArticleAdConfiguration? articleAdConfiguration, |
94 | 66 | }) {
|
95 | 67 | return AdConfig(
|
96 |
| - guestAdFrequency: guestAdFrequency ?? this.guestAdFrequency, |
97 |
| - guestAdPlacementInterval: |
98 |
| - guestAdPlacementInterval ?? this.guestAdPlacementInterval, |
99 |
| - authenticatedAdFrequency: |
100 |
| - authenticatedAdFrequency ?? this.authenticatedAdFrequency, |
101 |
| - authenticatedAdPlacementInterval: |
102 |
| - authenticatedAdPlacementInterval ?? |
103 |
| - this.authenticatedAdPlacementInterval, |
104 |
| - premiumAdFrequency: premiumAdFrequency ?? this.premiumAdFrequency, |
105 |
| - premiumAdPlacementInterval: |
106 |
| - premiumAdPlacementInterval ?? this.premiumAdPlacementInterval, |
107 |
| - guestArticlesToReadBeforeShowingInterstitialAds: |
108 |
| - guestArticlesToReadBeforeShowingInterstitialAds ?? |
109 |
| - this.guestArticlesToReadBeforeShowingInterstitialAds, |
110 |
| - standardUserArticlesToReadBeforeShowingInterstitialAds: |
111 |
| - standardUserArticlesToReadBeforeShowingInterstitialAds ?? |
112 |
| - this.standardUserArticlesToReadBeforeShowingInterstitialAds, |
113 |
| - premiumUserArticlesToReadBeforeShowingInterstitialAds: |
114 |
| - premiumUserArticlesToReadBeforeShowingInterstitialAds ?? |
115 |
| - this.premiumUserArticlesToReadBeforeShowingInterstitialAds, |
| 68 | + primaryAdPlatform: primaryAdPlatform ?? this.primaryAdPlatform, |
| 69 | + platformAdIdentifiers: |
| 70 | + platformAdIdentifiers ?? this.platformAdIdentifiers, |
| 71 | + localAdsCatalog: localAdsCatalog ?? this.localAdsCatalog, |
| 72 | + feedAdConfiguration: feedAdConfiguration ?? this.feedAdConfiguration, |
| 73 | + articleAdConfiguration: |
| 74 | + articleAdConfiguration ?? this.articleAdConfiguration, |
116 | 75 | );
|
117 | 76 | }
|
118 |
| - |
119 |
| - @override |
120 |
| - List<Object> get props => [ |
121 |
| - guestAdFrequency, |
122 |
| - guestAdPlacementInterval, |
123 |
| - authenticatedAdFrequency, |
124 |
| - authenticatedAdPlacementInterval, |
125 |
| - premiumAdFrequency, |
126 |
| - premiumAdPlacementInterval, |
127 |
| - guestArticlesToReadBeforeShowingInterstitialAds, |
128 |
| - standardUserArticlesToReadBeforeShowingInterstitialAds, |
129 |
| - premiumUserArticlesToReadBeforeShowingInterstitialAds, |
130 |
| - ]; |
131 | 77 | }
|
0 commit comments