|
1 | 1 | import 'dart:collection';
|
2 | 2 | import 'dart:convert';
|
3 |
| -import 'dart:io'; |
4 |
| -import 'package:awesome_notifications/awesome_notifications.dart'; |
5 |
| -import 'package:battery_plus/battery_plus.dart'; |
6 |
| -import 'package:duration/duration.dart'; |
7 | 3 | import 'package:flutter/cupertino.dart';
|
8 |
| -import 'package:flutter/services.dart'; |
9 | 4 | import 'package:flutter_bloc/flutter_bloc.dart';
|
10 | 5 | import 'package:flutter_client_sse/flutter_client_sse.dart';
|
11 | 6 | import 'package:json_patch/json_patch.dart';
|
12 | 7 | import 'package:wifi_iot/wifi_iot.dart';
|
13 |
| -import 'package:flood_mobile/Api/torrent_api.dart'; |
14 | 8 | import 'package:flood_mobile/Blocs/filter_torrent_bloc/filter_torrent_bloc.dart';
|
15 | 9 | import 'package:flood_mobile/Blocs/home_screen_bloc/home_screen_bloc.dart';
|
16 |
| -import 'package:flood_mobile/Blocs/power_management_bloc/power_management_bloc.dart'; |
17 |
| -import 'package:flood_mobile/Constants/notification_keys.dart'; |
18 | 10 | import 'package:flood_mobile/Model/download_rate_model.dart';
|
19 | 11 | import 'package:flood_mobile/Model/torrent_model.dart';
|
20 | 12 | import 'package:flood_mobile/Services/file_size_helper.dart';
|
@@ -128,120 +120,6 @@ class EventHandlerApi {
|
128 | 120 | //Setting the full list of torrent
|
129 | 121 | BlocProvider.of<HomeScreenBloc>(context, listen: false)
|
130 | 122 | .add(SetTorrentListEvent(newTorrentList: torrentList));
|
131 |
| - |
132 |
| - final PowerManagementBloc powerManagementBloc = |
133 |
| - BlocProvider.of<PowerManagementBloc>(context, listen: false); |
134 |
| - //Exit screen on all download finished |
135 |
| - if (powerManagementBloc.state.shutDownWhenFinishDownload && |
136 |
| - isAllDownloadFinished(context)) { |
137 |
| - SystemChannels.platform.invokeMethod('SystemNavigator.pop'); |
138 |
| - exit(0); |
139 |
| - } |
140 |
| - |
141 |
| - //Turn off wifi on all download finished |
142 |
| - if (powerManagementBloc.state.shutDownWifi && |
143 |
| - isAllDownloadFinished(context)) { |
144 |
| - turnOffWiFi(powerManagementBloc.state.shutDownWifi); |
145 |
| - } |
146 |
| - |
147 |
| - // Stop all download on low battery |
148 |
| - Battery _battery = Battery(); |
149 |
| - int currentBatteryLevel = await _battery.batteryLevel; |
150 |
| - bool isBatteryLimitSet = |
151 |
| - powerManagementBloc.state.batteryLimitLevel > 0 ? true : false; |
152 |
| - if (isBatteryLimitSet && |
153 |
| - currentBatteryLevel <= powerManagementBloc.state.batteryLimitLevel) { |
154 |
| - BlocProvider.of<HomeScreenBloc>(context, listen: false) |
155 |
| - .state |
156 |
| - .torrentList |
157 |
| - .forEach((element) { |
158 |
| - if (element.status.contains('downloading')) { |
159 |
| - TorrentApi.stopTorrent(hashes: [element.hash], context: context); |
160 |
| - } |
161 |
| - }); |
162 |
| - } |
163 |
| - } |
164 |
| - |
165 |
| - static Future<void> showNotification(int id, BuildContext context) async { |
166 |
| - late bool displayNotification; |
167 |
| - late bool isPaused; |
168 |
| - isPaused = true; |
169 |
| - HomeScreenState homeModel = |
170 |
| - BlocProvider.of<HomeScreenBloc>(context, listen: false).state; |
171 |
| - |
172 |
| - // Skip finished torrents |
173 |
| - if (homeModel.torrentList[id].status.contains('complete')) { |
174 |
| - displayNotification = false; |
175 |
| - } else { |
176 |
| - displayNotification = true; |
177 |
| - } |
178 |
| - |
179 |
| - // Torrent not being downloaded |
180 |
| - if (homeModel.torrentList[id].status.contains('downloading')) { |
181 |
| - // Change to the 'RESUME' action |
182 |
| - isPaused = false; |
183 |
| - } |
184 |
| - |
185 |
| - // Torrent Paused |
186 |
| - else { |
187 |
| - isPaused = true; |
188 |
| - } |
189 |
| - |
190 |
| - // Create notification for unfinished downloads |
191 |
| - if (displayNotification) { |
192 |
| - AwesomeNotifications().createNotification( |
193 |
| - content: NotificationContent( |
194 |
| - id: id, |
195 |
| - actionType: ActionType.Default, |
196 |
| - channelKey: NotificationConstants.DOWNLOADS_CHANNEL_KEY, |
197 |
| - category: NotificationCategory.Progress, |
198 |
| - notificationLayout: NotificationLayout.ProgressBar, |
199 |
| - title: homeModel.torrentList[id].name, |
200 |
| - body: isPaused |
201 |
| - ? "Stopped ETA: ∞" |
202 |
| - : "Downloading ETA: " + |
203 |
| - prettyDuration( |
204 |
| - Duration( |
205 |
| - seconds: homeModel.torrentList[id].eta.toInt(), |
206 |
| - ), |
207 |
| - abbreviated: true, |
208 |
| - ), |
209 |
| - progress: homeModel.torrentList[id].percentComplete.round(), |
210 |
| - summary: isPaused ? 'Paused' : 'Downloading', |
211 |
| - locked: true, |
212 |
| - autoDismissible: false, |
213 |
| - showWhen: false, |
214 |
| - ), |
215 |
| - actionButtons: [ |
216 |
| - NotificationActionButton( |
217 |
| - key: isPaused |
218 |
| - ? NotificationConstants.RESUME_ACTION_KEY |
219 |
| - : NotificationConstants.PAUSE_ACTION_KEY, |
220 |
| - label: isPaused ? 'Resume' : 'Pause', |
221 |
| - actionType: ActionType.KeepOnTop, |
222 |
| - enabled: true, |
223 |
| - autoDismissible: false, |
224 |
| - ), |
225 |
| - ], |
226 |
| - ); |
227 |
| - } |
228 |
| - } |
229 |
| - |
230 |
| - static Future<void> showEventNotification( |
231 |
| - int id, BuildContext context) async { |
232 |
| - AwesomeNotifications().createNotification( |
233 |
| - content: NotificationContent( |
234 |
| - id: id, |
235 |
| - autoDismissible: false, |
236 |
| - channelKey: NotificationConstants.PUSH_NOTIFICATION_CHANNEL_KEY, |
237 |
| - category: NotificationCategory.Event, |
238 |
| - notificationLayout: NotificationLayout.Default, |
239 |
| - title: BlocProvider.of<HomeScreenBloc>(context, listen: false) |
240 |
| - .state |
241 |
| - .torrentList[id] |
242 |
| - .name, |
243 |
| - body: "Download Finished", |
244 |
| - )); |
245 | 123 | }
|
246 | 124 |
|
247 | 125 | static Future<void> filterDataRephrasor(
|
|
0 commit comments