@@ -49,7 +49,8 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
4949 vsync: this ,
5050 );
5151 _initializeControllers ();
52- _tabController.addListener (_onTabChanged);
52+ // Removed _tabController.addListener(_onTabChanged); as automatic disabling
53+ // for premium users is no longer required.
5354 }
5455
5556 /// Initializes text editing controllers for each user role based on current
@@ -101,42 +102,6 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
101102 }
102103 }
103104
104- /// Listener for tab changes to enforce business rules, specifically for
105- /// premium users who should not see ads.
106- void _onTabChanged () {
107- if (_tabController.indexIsChanging) return ;
108-
109- final selectedRole = AppUserRole .values[_tabController.index];
110- if (selectedRole == AppUserRole .premiumUser) {
111- final adConfig = widget.remoteConfig.adConfig;
112- final feedAdConfig = adConfig.feedAdConfiguration;
113-
114- // If the values for premium are not 0, update the config.
115- // This enforces the business rule that premium users do not see ads.
116- final premiumRoleConfig = feedAdConfig.visibleTo[AppUserRole .premiumUser];
117- if (premiumRoleConfig != null &&
118- (premiumRoleConfig.adFrequency != 0 ||
119- premiumRoleConfig.adPlacementInterval != 0 )) {
120- final updatedVisibleTo =
121- Map <AppUserRole , FeedAdFrequencyConfig >.from (feedAdConfig.visibleTo)
122- ..[AppUserRole .premiumUser] = const FeedAdFrequencyConfig (
123- adFrequency: 0 ,
124- adPlacementInterval: 0 ,
125- );
126-
127- final updatedFeedAdConfig =
128- feedAdConfig.copyWith (visibleTo: updatedVisibleTo);
129-
130- widget.onConfigChanged (
131- widget.remoteConfig.copyWith (
132- adConfig: adConfig.copyWith (
133- feedAdConfiguration: updatedFeedAdConfig,
134- ),
135- ),
136- );
137- }
138- }
139- }
140105
141106 @override
142107 void didUpdateWidget (covariant FeedAdSettingsForm oldWidget) {
@@ -149,9 +114,7 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
149114
150115 @override
151116 void dispose () {
152- _tabController
153- ..removeListener (_onTabChanged)
154- ..dispose ();
117+ _tabController.dispose ();
155118 for (final controller in _adFrequencyControllers.values) {
156119 controller.dispose ();
157120 }
@@ -294,49 +257,45 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
294257 /// Builds role-specific configuration fields for feed ad frequency.
295258 ///
296259 /// This widget displays input fields for ad frequency and placement interval
297- /// for a given [AppUserRole] . Premium users have these fields disabled
298- /// as they should not see ads.
260+ /// for a given [AppUserRole] .
299261 Widget _buildRoleSpecificFields (
300262 BuildContext context,
301263 AppLocalizations l10n,
302264 AppUserRole role,
303265 FeedAdConfiguration config,
304266 ) {
305267 final roleConfig = config.visibleTo[role];
306- final isEnabled = role != AppUserRole .premiumUser;
268+ // Removed isEnabled check as premium users can now be manually configured.
307269
308270 return Column (
309271 children: [
310272 SwitchListTile (
311- // Changed from CheckboxListTile to SwitchListTile for consistency
312- title: Text (l10n.enableInArticleAdsForRoleLabel (role.l10n (context))),
313- value: roleConfig != null && isEnabled,
314- onChanged: isEnabled
315- ? (value) {
316- final newVisibleTo =
317- Map <AppUserRole , FeedAdFrequencyConfig >.from (
318- config.visibleTo,
319- );
320- if (value) {
321- // Default values when enabling for a role
322- newVisibleTo[role] = const FeedAdFrequencyConfig (
323- adFrequency: 5 ,
324- adPlacementInterval: 3 ,
325- );
326- } else {
327- newVisibleTo.remove (role);
328- }
329- widget.onConfigChanged (
330- widget.remoteConfig.copyWith (
331- adConfig: widget.remoteConfig.adConfig.copyWith (
332- feedAdConfiguration: config.copyWith (
333- visibleTo: newVisibleTo,
334- ),
335- ),
336- ),
337- );
338- }
339- : null ,
273+ title: Text (l10n.visibleToRoleLabel (role.l10n (context))),
274+ value: roleConfig != null , // Value is true if roleConfig exists
275+ onChanged: (value) {
276+ final newVisibleTo =
277+ Map <AppUserRole , FeedAdFrequencyConfig >.from (
278+ config.visibleTo,
279+ );
280+ if (value) {
281+ // Default values when enabling for a role
282+ newVisibleTo[role] = const FeedAdFrequencyConfig (
283+ adFrequency: 5 ,
284+ adPlacementInterval: 3 ,
285+ );
286+ } else {
287+ newVisibleTo.remove (role);
288+ }
289+ widget.onConfigChanged (
290+ widget.remoteConfig.copyWith (
291+ adConfig: widget.remoteConfig.adConfig.copyWith (
292+ feedAdConfiguration: config.copyWith (
293+ visibleTo: newVisibleTo,
294+ ),
295+ ),
296+ ),
297+ );
298+ },
340299 ),
341300 if (roleConfig != null )
342301 Padding (
@@ -368,7 +327,6 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
368327 );
369328 },
370329 controller: _adFrequencyControllers[role],
371- enabled: isEnabled,
372330 ),
373331 AppConfigIntField (
374332 label: l10n.adPlacementIntervalLabel,
@@ -392,7 +350,6 @@ class _FeedAdSettingsFormState extends State<FeedAdSettingsForm>
392350 );
393351 },
394352 controller: _adPlacementIntervalControllers[role],
395- enabled: isEnabled,
396353 ),
397354 ],
398355 ),
0 commit comments