Skip to content

Commit 1e7b898

Browse files
committed
add new fields in home screen and sse bloc file
1 parent 58897aa commit 1e7b898

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

lib/Blocs/home_screen_bloc/home_screen_bloc.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:bloc/bloc.dart';
24
import 'package:equatable/equatable.dart';
35
import 'package:flood_mobile/Model/feeds_content_model.dart';
@@ -20,6 +22,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
2022
on<SetTorrentListJsonEvent>(_setTorrentListJson);
2123
on<SetFeedsAndRulesListJsonEvent>(_setFeedsAndRulesListJson);
2224
on<UpdateTorrentListEvent>(_updateTorrentList);
25+
on<UpdateNotificationCancelEvent>(_updateNotificationCancel);
2326
}
2427

2528
// Handle the SetUnreadNotifications event
@@ -81,4 +84,10 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
8184
UpdateTorrentListEvent event, Emitter<HomeScreenState> emit) {
8285
emit(state.copyWith(torrentListJson: event.newTorrentListJson));
8386
}
87+
88+
// Handle the UpdateNotificationCancel event
89+
FutureOr<void> _updateNotificationCancel(
90+
UpdateNotificationCancelEvent event, Emitter<HomeScreenState> emit) {
91+
emit(state.copyWith(notificationCancel: event.newNotificationCancel));
92+
}
8493
}

lib/Blocs/home_screen_bloc/home_screen_event.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,12 @@ class UpdateTorrentListEvent extends HomeScreenEvent {
9090
@override
9191
List<Object> get props => [newTorrentListJson];
9292
}
93+
94+
class UpdateNotificationCancelEvent extends HomeScreenEvent {
95+
final Map<String, bool> newNotificationCancel;
96+
97+
UpdateNotificationCancelEvent({required this.newNotificationCancel});
98+
99+
@override
100+
List<Object> get props => [newNotificationCancel];
101+
}

lib/Blocs/home_screen_bloc/home_screen_state.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class HomeScreenState extends Equatable {
1313
final List<FeedsContentsModel> rssFeedsContentsList;
1414
String upSpeed;
1515
String downSpeed;
16+
final Map<String, bool> notificationCancel;
1617

1718
HomeScreenState({
1819
required this.torrentList,
@@ -25,6 +26,7 @@ class HomeScreenState extends Equatable {
2526
required this.rssFeedsContentsList,
2627
required this.upSpeed,
2728
required this.downSpeed,
29+
required this.notificationCancel,
2830
});
2931

3032
HomeScreenState copyWith({
@@ -38,19 +40,20 @@ class HomeScreenState extends Equatable {
3840
List<FeedsContentsModel>? rssFeedsContentsList,
3941
String? upSpeed,
4042
String? downSpeed,
43+
Map<String, bool>? notificationCancel,
4144
}) {
4245
return HomeScreenState(
43-
torrentList: torrentList ?? this.torrentList,
44-
torrentListJson: torrentListJson ?? this.torrentListJson,
45-
unreadNotifications: unreadNotifications ?? this.unreadNotifications,
46-
notificationModel: notificationModel ?? this.notificationModel,
47-
rssFeedsListJson: rssFeedsListJson ?? this.rssFeedsListJson,
48-
rssFeedsList: rssFeedsList ?? this.rssFeedsList,
49-
rssRulesList: rssRulesList ?? this.rssRulesList,
50-
rssFeedsContentsList: rssFeedsContentsList ?? this.rssFeedsContentsList,
51-
upSpeed: upSpeed ?? this.upSpeed,
52-
downSpeed: downSpeed ?? this.downSpeed,
53-
);
46+
torrentList: torrentList ?? this.torrentList,
47+
torrentListJson: torrentListJson ?? this.torrentListJson,
48+
unreadNotifications: unreadNotifications ?? this.unreadNotifications,
49+
notificationModel: notificationModel ?? this.notificationModel,
50+
rssFeedsListJson: rssFeedsListJson ?? this.rssFeedsListJson,
51+
rssFeedsList: rssFeedsList ?? this.rssFeedsList,
52+
rssRulesList: rssRulesList ?? this.rssRulesList,
53+
rssFeedsContentsList: rssFeedsContentsList ?? this.rssFeedsContentsList,
54+
upSpeed: upSpeed ?? this.upSpeed,
55+
downSpeed: downSpeed ?? this.downSpeed,
56+
notificationCancel: notificationCancel ?? this.notificationCancel);
5457
}
5558

5659
@override
@@ -65,6 +68,7 @@ class HomeScreenState extends Equatable {
6568
rssFeedsContentsList,
6669
upSpeed,
6770
downSpeed,
71+
notificationCancel,
6872
];
6973
}
7074

@@ -82,6 +86,7 @@ class HomeScreenInitial extends HomeScreenState {
8286
rssFeedsContentsList: [],
8387
upSpeed: '0 KB/s',
8488
downSpeed: '0 KB/s',
89+
notificationCancel: {},
8590
);
8691

8792
@override

lib/Blocs/sse_bloc/sse_bloc.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,20 @@ class SSEBloc extends Bloc<SSEEvent, SSEState> {
5656
.torrentList
5757
.length;
5858
i++) {
59-
EventHandlerApi.showNotification(i, event.context);
59+
createTorrentDownloadNotification(i, event.context);
6060
}
6161
break;
6262
case Events.TORRENT_LIST_DIFF_CHANGE:
63+
var homeScreenBloc =
64+
BlocProvider.of<HomeScreenBloc>(event.context, listen: false)
65+
.state;
6366
EventHandlerApi.updateFullTorrentList(
6467
model: listenEvent, context: event.context);
6568
await Future.delayed(Duration.zero);
66-
for (int i = 0;
67-
i <
68-
BlocProvider.of<HomeScreenBloc>(event.context,
69-
listen: false)
70-
.state
71-
.torrentList
72-
.length;
73-
i++) {
74-
EventHandlerApi.showNotification(i, event.context);
69+
for (int i = 0; i < homeScreenBloc.torrentList.length; i++) {
70+
if (!homeScreenBloc.notificationCancel
71+
.containsKey(homeScreenBloc.torrentList[i].hash))
72+
await createTorrentDownloadNotification(i, event.context);
7573
}
7674
break;
7775
case Events.NOTIFICATION_COUNT_CHANGE:
@@ -91,7 +89,14 @@ class SSEBloc extends Bloc<SSEEvent, SSEState> {
9189
.torrentList[j]
9290
.status
9391
.contains('complete')) {
94-
EventHandlerApi.showEventNotification(j, event.context);
92+
createDownloadFinishedNotification(j, event.context);
93+
} else if (BlocProvider.of<HomeScreenBloc>(event.context,
94+
listen: false)
95+
.state
96+
.torrentList[j]
97+
.status
98+
.contains('error')) {
99+
createDownloadErrorNotification(j, event.context);
95100
}
96101
}
97102
break;

0 commit comments

Comments
 (0)