Skip to content

Commit b184edd

Browse files
committed
refactor(settings): remove headline image style setting
- Remove SettingsHeadlineImageStyleChanged event handler - Remove related code from _persistSettings method - Add comments explaining ad cache clearing process - Reorder ad cache clearing and settings persistence for theming changes
1 parent f7cbaaf commit b184edd

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

lib/settings/bloc/settings_bloc.dart

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
3636
_onAppFontSizeChanged,
3737
transformer: sequential(),
3838
);
39-
on<SettingsHeadlineImageStyleChanged>(
40-
_onHeadlineImageStyleChanged,
41-
transformer: sequential(),
42-
);
4339
on<SettingsAppFontTypeChanged>(
4440
_onAppFontTypeChanged,
4541
transformer: sequential(),
@@ -168,9 +164,11 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
168164
),
169165
);
170166
emit(state.copyWith(userAppSettings: updatedSettings, clearError: true));
171-
await _persistSettings(updatedSettings, emit);
172-
// Clear ad cache when theme accent changes to ensure new ads are styled correctly.
167+
// When the theme's accent color changes, ads must be reloaded to reflect
168+
// the new styling. Clearing the cache ensures that any visible or
169+
// soon-to-be-visible ads are fetched again with the updated theme.
173170
AdCacheService().clearAllAds();
171+
await _persistSettings(updatedSettings, emit);
174172
}
175173

176174
Future<void> _onAppFontSizeChanged(
@@ -188,24 +186,6 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
188186
await _persistSettings(updatedSettings, emit);
189187
}
190188

191-
Future<void> _onHeadlineImageStyleChanged(
192-
SettingsHeadlineImageStyleChanged event,
193-
Emitter<SettingsState> emit,
194-
) async {
195-
if (state.userAppSettings == null) return;
196-
197-
final updatedSettings = state.userAppSettings!.copyWith(
198-
feedPreferences: state.userAppSettings!.feedPreferences.copyWith(
199-
headlineImageStyle: event.imageStyle,
200-
),
201-
);
202-
emit(state.copyWith(userAppSettings: updatedSettings, clearError: true));
203-
await _persistSettings(updatedSettings, emit);
204-
// Clear ad cache when headline image style changes to ensure new ads are
205-
// loaded with the correct template type (small/medium).
206-
AdCacheService().clearAllAds();
207-
}
208-
209189
Future<void> _onAppFontTypeChanged(
210190
SettingsAppFontTypeChanged event,
211191
Emitter<SettingsState> emit,
@@ -248,6 +228,11 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
248228
),
249229
);
250230
emit(state.copyWith(userAppSettings: updatedSettings, clearError: true));
231+
// The headline image style directly influences which native ad template
232+
// (small or medium) is requested. To ensure the correct ad format is
233+
// displayed, the cache must be cleared, forcing a new ad load with the
234+
// appropriate template.
235+
AdCacheService().clearAllAds();
251236
await _persistSettings(updatedSettings, emit);
252237
}
253238

0 commit comments

Comments
 (0)