Skip to content

Commit b89f61b

Browse files
committed
refactor(headlines-feed): remove ads and simplify headline handling
- Remove InterstitialAdManager and related ad code - Extract headline tap handling logic to a separate class - Simplify item spacing in the feed - Update imports and remove unused code
1 parent fb83f37 commit b89f61b

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars
3-
41
import 'package:core/core.dart';
52
import 'package:flutter/material.dart';
63
import 'package:flutter_bloc/flutter_bloc.dart';
7-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/interstitial_ad_manager.dart';
84
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_placeholder.dart';
95
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
106
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/feed_ad_loader_widget.dart';
@@ -237,23 +233,6 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
237233
);
238234
}
239235

240-
Future<void> onHeadlineTap(Headline headline) async {
241-
// Await for the ad to be shown and dismissed.
242-
await context
243-
.read<InterstitialAdManager>()
244-
.onPotentialAdTrigger();
245-
246-
// Check if the widget is still in the tree before navigating.
247-
if (!context.mounted) return;
248-
249-
// Proceed with navigation after the ad is closed.
250-
await context.pushNamed(
251-
Routes.articleDetailsName,
252-
pathParameters: {'id': headline.id},
253-
extra: headline,
254-
);
255-
}
256-
257236
return RefreshIndicator(
258237
onRefresh: () async {
259238
context.read<HeadlinesFeedBloc>().add(
@@ -272,15 +251,16 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
272251
? state.feedItems.length + 1
273252
: state.feedItems.length,
274253
separatorBuilder: (context, index) {
275-
if (index < state.feedItems.length - 1) {
276-
final currentItem = state.feedItems[index];
277-
final nextItem = state.feedItems[index + 1];
278-
// Adjust spacing around any decorator or ad
279-
if (currentItem is! Headline || nextItem is! Headline) {
280-
return const SizedBox(height: AppSpacing.md);
281-
}
254+
if (index >= state.feedItems.length - 1) {
255+
return const SizedBox.shrink();
256+
}
257+
final currentItem = state.feedItems[index];
258+
final nextItem = state.feedItems[index + 1];
259+
260+
if (currentItem is! Headline || nextItem is! Headline) {
261+
return const SizedBox(height: AppSpacing.md);
282262
}
283-
return const SizedBox(height: AppSpacing.lg);
263+
return const SizedBox(height: AppSpacing.sm);
284264
},
285265
itemBuilder: (context, index) {
286266
if (index >= state.feedItems.length) {
@@ -305,17 +285,29 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
305285
case HeadlineImageStyle.hidden:
306286
tile = HeadlineTileTextOnly(
307287
headline: item,
308-
onHeadlineTap: () => onHeadlineTap(item),
288+
onHeadlineTap: () =>
289+
HeadlineTapHandler.handleHeadlineTap(
290+
context,
291+
item,
292+
),
309293
);
310294
case HeadlineImageStyle.smallThumbnail:
311295
tile = HeadlineTileImageStart(
312296
headline: item,
313-
onHeadlineTap: () => onHeadlineTap(item),
297+
onHeadlineTap: () =>
298+
HeadlineTapHandler.handleHeadlineTap(
299+
context,
300+
item,
301+
),
314302
);
315303
case HeadlineImageStyle.largeThumbnail:
316304
tile = HeadlineTileImageTop(
317305
headline: item,
318-
onHeadlineTap: () => onHeadlineTap(item),
306+
onHeadlineTap: () =>
307+
HeadlineTapHandler.handleHeadlineTap(
308+
context,
309+
item,
310+
),
319311
);
320312
}
321313
return tile;

0 commit comments

Comments
 (0)