Skip to content

Commit 9df1464

Browse files
committed
fix(app_configuration): enforce premium users never see interstitial ads
- Disable and safeguard interstitial ad frequency settings for premium users - Automatically set frequency to 0 when premium user tab is selected - Add listener to tab controller for real-time updates
1 parent c48795d commit 9df1464

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

lib/app_configuration/widgets/interstitial_ad_settings_form.dart

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,39 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
4242
vsync: this,
4343
);
4444
_initializeControllers();
45+
_tabController.addListener(_onTabChanged);
46+
}
47+
48+
void _onTabChanged() {
49+
if (_tabController.indexIsChanging) return;
50+
51+
final selectedRole = AppUserRole.values[_tabController.index];
52+
if (selectedRole == AppUserRole.premiumUser) {
53+
final adConfig = widget.remoteConfig.adConfig;
54+
final interstitialAdConfig = adConfig.interstitialAdConfiguration;
55+
56+
// If the value for premium is not 0, update the config.
57+
// This enforces the business rule that premium users do not see ads.
58+
if (interstitialAdConfig.feedInterstitialAdFrequencyConfig
59+
.premiumUserTransitionsBeforeShowingInterstitialAds !=
60+
0) {
61+
final updatedFrequencyConfig = interstitialAdConfig
62+
.feedInterstitialAdFrequencyConfig
63+
.copyWith(
64+
premiumUserTransitionsBeforeShowingInterstitialAds: 0,
65+
);
66+
final updatedInterstitialAdConfig = interstitialAdConfig.copyWith(
67+
feedInterstitialAdFrequencyConfig: updatedFrequencyConfig,
68+
);
69+
widget.onConfigChanged(
70+
widget.remoteConfig.copyWith(
71+
adConfig: adConfig.copyWith(
72+
interstitialAdConfiguration: updatedInterstitialAdConfig,
73+
),
74+
),
75+
);
76+
}
77+
}
4578
}
4679

4780
@override
@@ -96,7 +129,9 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
96129

97130
@override
98131
void dispose() {
99-
_tabController.dispose();
132+
_tabController
133+
..removeListener(_onTabChanged)
134+
..dispose();
100135
for (final controller
101136
in _transitionsBeforeShowingInterstitialAdsControllers.values) {
102137
controller.dispose();
@@ -190,6 +225,9 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
190225
AppUserRole role,
191226
InterstitialAdConfiguration config,
192227
) {
228+
// Premium users do not see ads, so their settings are disabled.
229+
final isEnabled = role != AppUserRole.premiumUser;
230+
193231
return Column(
194232
children: [
195233
AppConfigIntField(
@@ -211,6 +249,7 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
211249
);
212250
},
213251
controller: _transitionsBeforeShowingInterstitialAdsControllers[role],
252+
enabled: isEnabled,
214253
),
215254
],
216255
);
@@ -255,8 +294,10 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
255294
standardUserTransitionsBeforeShowingInterstitialAds: value,
256295
);
257296
case AppUserRole.premiumUser:
297+
// Premium users should not see ads, so their frequency is always 0.
298+
// The UI field is disabled, but this is a safeguard.
258299
newFrequencyConfig = currentFrequencyConfig.copyWith(
259-
premiumUserTransitionsBeforeShowingInterstitialAds: value,
300+
premiumUserTransitionsBeforeShowingInterstitialAds: 0,
260301
);
261302
}
262303

0 commit comments

Comments
 (0)