Skip to content

Commit e921b87

Browse files
committed
Fixed some bugs in the newly implemented feature.
1 parent d2fff62 commit e921b87

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

lib/Notifications/notification_controller.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,32 @@ class NotificationController {
3535
await TorrentApi.startTorrent(
3636
hashes: [homeModel.state.torrentList[receivedAction.id!].hash],
3737
context: NavigationService.navigatorKey.currentContext!);
38-
} else if (actionKey == NotificationConstants.CANCEL_ACTION_KEY) {
38+
}
39+
40+
// Cancel downloads
41+
else if (actionKey == NotificationConstants.CANCEL_ACTION_KEY) {
3942
BlocProvider.of<HomeScreenBloc>(
4043
NavigationService.navigatorKey.currentContext!,
4144
listen: false)
42-
.add(
43-
UpdateNotificationCancelEvent(
44-
newNotificationCancel: {
45-
homeModel.state.torrentList[receivedAction.id!].hash: true
46-
},
47-
),
48-
);
49-
} else if (actionKey == NotificationConstants.STOP_ACTION_KEY) {
45+
.state
46+
.notificationCancel
47+
.putIfAbsent(
48+
homeModel.state.torrentList[receivedAction.id!].hash, () => true);
49+
}
50+
51+
// Stop downloads
52+
else if (actionKey == NotificationConstants.STOP_ACTION_KEY) {
5053
await TorrentApi.stopTorrent(
5154
hashes: [homeModel.state.torrentList[receivedAction.id!].hash],
5255
context: NavigationService.navigatorKey.currentContext!);
56+
5357
BlocProvider.of<HomeScreenBloc>(
5458
NavigationService.navigatorKey.currentContext!,
5559
listen: false)
56-
.add(
57-
UpdateNotificationCancelEvent(
58-
newNotificationCancel: {
59-
homeModel.state.torrentList[receivedAction.id!].hash: true
60-
},
61-
),
62-
);
60+
.state
61+
.notificationCancel
62+
.putIfAbsent(
63+
homeModel.state.torrentList[receivedAction.id!].hash, () => true);
6364
}
6465
}
6566
}

lib/Pages/torrent_screen/services/filtered_torrent_list.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import 'package:flood_mobile/Blocs/filter_torrent_bloc/filter_torrent_bloc.dart'
22
import 'package:flood_mobile/Blocs/home_screen_bloc/home_screen_bloc.dart';
33
import 'package:flood_mobile/Blocs/sort_by_torrent_bloc/sort_by_torrent_bloc.dart';
44
import 'package:flood_mobile/Model/torrent_model.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_bloc/flutter_bloc.dart';
57

68
bool isFilteredTorrent(
79
TorrentModel torrentModel, FilterTorrentState stateFilterBloc) {
@@ -58,7 +60,8 @@ int countDisplayTorrent(HomeScreenState model, FilterTorrentState filterModel) {
5860

5961
List<TorrentModel> sortTorrents(
6062
{required List<TorrentModel> torrents,
61-
required SortByTorrentState sortState}) {
63+
required SortByTorrentState sortState,
64+
required BuildContext context}) {
6265
switch (sortState.sortByStatus) {
6366
case SortByValue.name:
6467
torrents.sort((a, b) {
@@ -171,5 +174,7 @@ List<TorrentModel> sortTorrents(
171174
default:
172175
throw Exception('Unsupported sort criteria');
173176
}
177+
BlocProvider.of<HomeScreenBloc>(context)
178+
.add(SetTorrentListEvent(newTorrentList: torrents));
174179
return torrents;
175180
}

lib/Pages/torrent_screen/torrent_screen.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ class _TorrentScreenState extends State<TorrentScreen> {
5151
builder: (context, sortByState) {
5252
List<TorrentModel> torrentList = sortTorrents(
5353
torrents: state.torrentList,
54-
sortState:
55-
BlocProvider.of<SortByTorrentBloc>(context)
56-
.state,
54+
sortState: sortByState,
55+
context: context,
5756
);
5857
return BlocBuilder<SpeedGraphBloc, SpeedGraphState>(
5958
builder: (context, graphSstate) {

0 commit comments

Comments
 (0)