@@ -5,6 +5,7 @@ import 'dart:async';
55import 'package:bloc/bloc.dart' ;
66import 'package:core/core.dart' ;
77import 'package:data_repository/data_repository.dart' ;
8+ import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart' ;
89import 'package:equatable/equatable.dart' ;
910import 'package:flutter_news_app_mobile_client_full_source_code/ads/inline_ad_cache_service.dart' ;
1011import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart' ;
@@ -30,14 +31,14 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
3031 required DataRepository <Source > sourceRepository,
3132 required DataRepository <Country > countryRepository,
3233 required AppBloc appBloc,
33- required FeedDecoratorService feedDecoratorService ,
34+ required AdService adService ,
3435 required InlineAdCacheService inlineAdCacheService,
3536 }) : _headlinesRepository = headlinesRepository,
3637 _topicRepository = topicRepository,
3738 _sourceRepository = sourceRepository,
3839 _countryRepository = countryRepository,
3940 _appBloc = appBloc,
40- _feedDecoratorService = feedDecoratorService ,
41+ _adService = adService ,
4142 _inlineAdCacheService = inlineAdCacheService,
4243 super (const EntityDetailsState ()) {
4344 on < EntityDetailsLoadRequested > (_onEntityDetailsLoadRequested);
@@ -54,8 +55,7 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
5455 final DataRepository <Source > _sourceRepository;
5556 final DataRepository <Country > _countryRepository;
5657 final AppBloc _appBloc;
57- final FeedDecoratorService _feedDecoratorService;
58- // ignore: unused_field
58+ final AdService _adService;
5959 final InlineAdCacheService _inlineAdCacheService;
6060
6161 static const _headlinesLimit = 10 ;
@@ -71,6 +71,9 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
7171 state.copyWith (status: EntityDetailsStatus .loading, clearEntity: true ),
7272 );
7373
74+ // On a full load, clear the ad cache for this entity to ensure fresh ads.
75+ _inlineAdCacheService.clearAdsForContext (contextKey: event.entityId);
76+
7477 try {
7578 // 1. Determine/Fetch Entity
7679 FeedItem entityToLoad;
@@ -122,15 +125,14 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
122125 //
123126 // This method injects stateless `AdPlaceholder` markers into the feed.
124127 // The full ad loading and lifecycle is managed by the UI layer.
125- // See `FeedDecoratorService` for a detailed explanation.
126- final processedFeedItems = await _feedDecoratorService
127- .injectAdPlaceholders (
128- feedItems: headlineResponse.items,
129- user: currentUser,
130- adConfig: remoteConfig.adConfig,
131- imageStyle: _appBloc.state.headlineImageStyle,
132- adThemeStyle: event.adThemeStyle,
133- );
128+ // See `AdService` for a detailed explanation.
129+ final processedFeedItems = await _adService.injectAdPlaceholders (
130+ feedItems: headlineResponse.items,
131+ user: currentUser,
132+ adConfig: remoteConfig.adConfig,
133+ imageStyle: _appBloc.state.headlineImageStyle,
134+ adThemeStyle: event.adThemeStyle,
135+ );
134136
135137 // 3. Determine isFollowing status from AppBloc's user preferences
136138 var isCurrentlyFollowing = false ;
@@ -297,7 +299,7 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
297299 // This method injects stateless `AdPlaceholder` markers into the feed.
298300 // The full ad loading and lifecycle is managed by the UI layer.
299301 // See `FeedDecoratorService` for a detailed explanation.
300- final newProcessedFeedItems = await _feedDecoratorService .injectAdPlaceholders (
302+ final newProcessedFeedItems = await _adService .injectAdPlaceholders (
301303 feedItems: headlineResponse.items,
302304 user: currentUser,
303305 adConfig: remoteConfig.adConfig,
0 commit comments