Skip to content

Commit b0514b1

Browse files
committed
feat(ad-config): remove auto-disable ads for premium users
- Remove _tabController.addListener(_onTabChanged) and related logic - Remove automatic setting of transitions to 0 for premium users - Remove isEnabled check from _buildInterstitialRoleSpecificFields - Update switch label to "Visible to [Role]" - Remove.enabled parameter from TextFormField
1 parent 36aa7b6 commit b0514b1

File tree

1 file changed

+47
-91
lines changed

1 file changed

+47
-91
lines changed

lib/app_configuration/widgets/interstitial_ad_settings_form.dart

Lines changed: 47 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
3535
/// Controllers for transitions before showing interstitial ads, mapped by user role.
3636
/// These are used to manage text input for each role's interstitial ad frequency.
3737
late final Map<AppUserRole, TextEditingController>
38-
_transitionsBeforeShowingInterstitialAdsControllers;
38+
_transitionsBeforeShowingInterstitialAdsControllers;
3939

4040
@override
4141
void initState() {
@@ -45,7 +45,8 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
4545
vsync: this,
4646
);
4747
_initializeControllers();
48-
_tabController.addListener(_onTabChanged);
48+
// Removed _tabController.addListener(_onTabChanged); as automatic disabling
49+
// for premium users is no longer required.
4950
}
5051

5152
/// Initializes text editing controllers for each user role based on current
@@ -55,19 +56,17 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
5556
widget.remoteConfig.adConfig.interstitialAdConfiguration;
5657
_transitionsBeforeShowingInterstitialAdsControllers = {
5758
for (final role in AppUserRole.values)
58-
role:
59-
TextEditingController(
60-
text: _getTransitionsBeforeInterstitial(
61-
interstitialConfig,
62-
role,
63-
).toString(),
64-
)
65-
..selection = TextSelection.collapsed(
66-
offset: _getTransitionsBeforeInterstitial(
67-
interstitialConfig,
68-
role,
69-
).toString().length,
70-
),
59+
role: TextEditingController(
60+
text: _getTransitionsBeforeInterstitial(
61+
interstitialConfig,
62+
role,
63+
).toString(),
64+
)..selection = TextSelection.collapsed(
65+
offset: _getTransitionsBeforeInterstitial(
66+
interstitialConfig,
67+
role,
68+
).toString().length,
69+
),
7170
};
7271
}
7372

@@ -87,51 +86,13 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
8786
newInterstitialValue;
8887
_transitionsBeforeShowingInterstitialAdsControllers[role]?.selection =
8988
TextSelection.collapsed(
90-
offset: newInterstitialValue.length,
91-
);
92-
}
93-
}
94-
}
95-
96-
/// Listener for tab changes to enforce business rules, specifically for
97-
/// premium users who should not see ads.
98-
void _onTabChanged() {
99-
if (_tabController.indexIsChanging) return;
100-
101-
final selectedRole = AppUserRole.values[_tabController.index];
102-
if (selectedRole == AppUserRole.premiumUser) {
103-
final adConfig = widget.remoteConfig.adConfig;
104-
final interstitialAdConfig = adConfig.interstitialAdConfiguration;
105-
106-
// If the value for premium is not 0, update the config.
107-
// This enforces the business rule that premium users do not see ads.
108-
final premiumRoleConfig =
109-
interstitialAdConfig.visibleTo[AppUserRole.premiumUser];
110-
if (premiumRoleConfig != null &&
111-
premiumRoleConfig.transitionsBeforeShowingInterstitialAds != 0) {
112-
final updatedVisibleTo =
113-
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
114-
interstitialAdConfig.visibleTo,
115-
)
116-
..[AppUserRole.premiumUser] = const InterstitialAdFrequencyConfig(
117-
transitionsBeforeShowingInterstitialAds: 0,
118-
);
119-
120-
final updatedInterstitialAdConfig = interstitialAdConfig.copyWith(
121-
visibleTo: updatedVisibleTo,
122-
);
123-
124-
widget.onConfigChanged(
125-
widget.remoteConfig.copyWith(
126-
adConfig: adConfig.copyWith(
127-
interstitialAdConfiguration: updatedInterstitialAdConfig,
128-
),
129-
),
89+
offset: newInterstitialValue.length,
13090
);
13191
}
13292
}
13393
}
13494

95+
13596
@override
13697
void didUpdateWidget(covariant InterstitialAdSettingsForm oldWidget) {
13798
super.didUpdateWidget(oldWidget);
@@ -144,8 +105,7 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
144105
@override
145106
void dispose() {
146107
_tabController
147-
..removeListener(_onTabChanged)
148-
..dispose();
108+
.dispose();
149109
for (final controller
150110
in _transitionsBeforeShowingInterstitialAdsControllers.values) {
151111
controller.dispose();
@@ -236,48 +196,44 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
236196
/// Builds role-specific configuration fields for interstitial ad frequency.
237197
///
238198
/// This widget displays an input field for `transitionsBeforeShowingInterstitialAds`
239-
/// for a given [AppUserRole]. Premium users have this field disabled
240-
/// as they should not see ads.
199+
/// for a given [AppUserRole].
241200
Widget _buildInterstitialRoleSpecificFields(
242201
BuildContext context,
243202
AppLocalizations l10n,
244203
AppUserRole role,
245204
InterstitialAdConfiguration config,
246205
) {
247206
final roleConfig = config.visibleTo[role];
248-
final isEnabled = role != AppUserRole.premiumUser;
207+
// Removed isEnabled check as premium users can now be manually configured.
249208

250209
return Column(
251210
children: [
252211
SwitchListTile(
253-
// Changed from CheckboxListTile to SwitchListTile for consistency
254-
title: Text(l10n.enableInArticleAdsForRoleLabel(role.l10n(context))),
255-
value: roleConfig != null && isEnabled,
256-
onChanged: isEnabled
257-
? (value) {
258-
final newVisibleTo =
259-
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
260-
config.visibleTo,
261-
);
262-
if (value) {
263-
// Default value when enabling for a role
264-
newVisibleTo[role] = const InterstitialAdFrequencyConfig(
265-
transitionsBeforeShowingInterstitialAds: 5,
266-
);
267-
} else {
268-
newVisibleTo.remove(role);
269-
}
270-
widget.onConfigChanged(
271-
widget.remoteConfig.copyWith(
272-
adConfig: widget.remoteConfig.adConfig.copyWith(
273-
interstitialAdConfiguration: config.copyWith(
274-
visibleTo: newVisibleTo,
275-
),
276-
),
277-
),
278-
);
279-
}
280-
: null,
212+
title: Text(l10n.visibleToRoleLabel(role.l10n(context))),
213+
value: roleConfig != null, // Value is true if roleConfig exists
214+
onChanged: (value) {
215+
final newVisibleTo =
216+
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
217+
config.visibleTo,
218+
);
219+
if (value) {
220+
// Default value when enabling for a role
221+
newVisibleTo[role] = const InterstitialAdFrequencyConfig(
222+
transitionsBeforeShowingInterstitialAds: 5,
223+
);
224+
} else {
225+
newVisibleTo.remove(role);
226+
}
227+
widget.onConfigChanged(
228+
widget.remoteConfig.copyWith(
229+
adConfig: widget.remoteConfig.adConfig.copyWith(
230+
interstitialAdConfiguration: config.copyWith(
231+
visibleTo: newVisibleTo,
232+
),
233+
),
234+
),
235+
);
236+
},
281237
),
282238
if (roleConfig != null)
283239
Padding(
@@ -295,8 +251,8 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
295251
);
296252
final newVisibleTo =
297253
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
298-
config.visibleTo,
299-
)..[role] = newRoleConfig;
254+
config.visibleTo,
255+
)..[role] = newRoleConfig;
300256
widget.onConfigChanged(
301257
widget.remoteConfig.copyWith(
302258
adConfig: widget.remoteConfig.adConfig.copyWith(
@@ -309,7 +265,7 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
309265
},
310266
controller:
311267
_transitionsBeforeShowingInterstitialAdsControllers[role],
312-
enabled: isEnabled,
268+
// Removed enabled: isEnabled
313269
),
314270
),
315271
],

0 commit comments

Comments
 (0)