Skip to content

Commit d2fff62

Browse files
committed
Add support for multiple languages to the notification features.
1 parent 589a216 commit d2fff62

24 files changed

+233
-25
lines changed

lib/Api/event_handler_api.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import 'dart:collection';
22
import 'dart:convert';
3+
import 'dart:io';
4+
import 'package:battery_plus/battery_plus.dart';
35
import 'package:flutter/cupertino.dart';
6+
import 'package:flutter/services.dart';
47
import 'package:flutter_bloc/flutter_bloc.dart';
58
import 'package:flutter_client_sse/flutter_client_sse.dart';
69
import 'package:json_patch/json_patch.dart';
710
import 'package:wifi_iot/wifi_iot.dart';
11+
import 'package:flood_mobile/Api/torrent_api.dart';
812
import 'package:flood_mobile/Blocs/filter_torrent_bloc/filter_torrent_bloc.dart';
913
import 'package:flood_mobile/Blocs/home_screen_bloc/home_screen_bloc.dart';
14+
import 'package:flood_mobile/Blocs/power_management_bloc/power_management_bloc.dart';
1015
import 'package:flood_mobile/Model/download_rate_model.dart';
1116
import 'package:flood_mobile/Model/torrent_model.dart';
1217
import 'package:flood_mobile/Services/file_size_helper.dart';
@@ -120,6 +125,38 @@ class EventHandlerApi {
120125
//Setting the full list of torrent
121126
BlocProvider.of<HomeScreenBloc>(context, listen: false)
122127
.add(SetTorrentListEvent(newTorrentList: torrentList));
128+
129+
final PowerManagementBloc powerManagementBloc =
130+
BlocProvider.of<PowerManagementBloc>(context, listen: false);
131+
//Exit screen on all download finished
132+
if (powerManagementBloc.state.shutDownWhenFinishDownload &&
133+
isAllDownloadFinished(context)) {
134+
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
135+
exit(0);
136+
}
137+
138+
//Turn off wifi on all download finished
139+
if (powerManagementBloc.state.shutDownWifi &&
140+
isAllDownloadFinished(context)) {
141+
turnOffWiFi(powerManagementBloc.state.shutDownWifi);
142+
}
143+
144+
// Stop all download on low battery
145+
Battery _battery = Battery();
146+
int currentBatteryLevel = await _battery.batteryLevel;
147+
bool isBatteryLimitSet =
148+
powerManagementBloc.state.batteryLimitLevel > 0 ? true : false;
149+
if (isBatteryLimitSet &&
150+
currentBatteryLevel <= powerManagementBloc.state.batteryLimitLevel) {
151+
BlocProvider.of<HomeScreenBloc>(context, listen: false)
152+
.state
153+
.torrentList
154+
.forEach((element) {
155+
if (element.status.contains('downloading')) {
156+
TorrentApi.stopTorrent(hashes: [element.hash], context: context);
157+
}
158+
});
159+
}
123160
}
124161

125162
static Future<void> filterDataRephrasor(

lib/Blocs/sse_bloc/sse_bloc.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:flood_mobile/Blocs/home_screen_bloc/home_screen_bloc.dart';
99
import 'package:flood_mobile/Blocs/user_detail_bloc/user_detail_bloc.dart';
1010
import 'package:flood_mobile/Constants/api_endpoints.dart';
1111
import 'package:flood_mobile/Constants/event_names.dart';
12+
import 'package:flood_mobile/Notifications/notification_controller.dart';
1213

1314
part 'sse_event.dart';
1415
part 'sse_state.dart';

lib/Notifications/notification_controller.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
import 'package:awesome_notifications/awesome_notifications.dart';
42
import 'package:duration/duration.dart';
53
import 'package:flutter/material.dart';
@@ -128,7 +126,9 @@ Future<void> createTorrentDownloadNotification(
128126
key: isPaused
129127
? NotificationConstants.RESUME_ACTION_KEY
130128
: NotificationConstants.PAUSE_ACTION_KEY,
131-
label: isPaused ? context.l10n.notification_resume : context.l10n.notification_pause,
129+
label: isPaused
130+
? context.l10n.notification_resume
131+
: context.l10n.notification_pause,
132132
actionType: ActionType.KeepOnTop,
133133
enabled: true,
134134
autoDismissible: false,
@@ -137,7 +137,9 @@ Future<void> createTorrentDownloadNotification(
137137
key: isPaused
138138
? NotificationConstants.CANCEL_ACTION_KEY
139139
: NotificationConstants.STOP_ACTION_KEY,
140-
label: isPaused ? context.l10n.notification_cancel : context.l10n.notification_stop,
140+
label: isPaused
141+
? context.l10n.notification_cancel
142+
: context.l10n.notification_stop,
141143
actionType: ActionType.KeepOnTop,
142144
enabled: true,
143145
autoDismissible: true,

lib/l10n/arb/app_ar.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,13 @@
313313
"sort_by_uploaded": "تم الرفع",
314314
"sort_by_upload_speed": "سرعة الرفع",
315315
"sort_by_file_size": "حجم الملف",
316-
"sort_by_percent_completed": "نسبة الانتهاء"
316+
"sort_by_percent_completed": "نسبة الانتهاء",
317+
"notification_resume": "استئناف",
318+
"notification_pause": "إيقاف مؤقت",
319+
"notification_stop": "توقف",
320+
"notification_cancel": "إلغاء",
321+
"notification_stopped": "تم الإيقاف",
322+
"notification_downloading": "جاري التنزيل",
323+
"notification_error": "خطأ في التنزيل",
324+
"notification_finished": "تم التنزيل"
317325
}

lib/l10n/arb/app_cs.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,13 @@
313313
"sort_by_uploaded": "Nahráno",
314314
"sort_by_upload_speed": "Rychlost nahrávání",
315315
"sort_by_file_size": "Velikost souboru",
316-
"sort_by_percent_completed": "Procento dokončení"
316+
"sort_by_percent_completed": "Procento dokončení",
317+
"notification_resume": "Pokračovat",
318+
"notification_pause": "Pozastavit",
319+
"notification_stop": "Zastavit",
320+
"notification_cancel": "Zrušit",
321+
"notification_stopped": "Zastaveno",
322+
"notification_downloading": "Stahování",
323+
"notification_error": "Chyba při stahování",
324+
"notification_finished": "Stahování dokončeno"
317325
}

lib/l10n/arb/app_de.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@
284284
"torrent_screen_items_heading": "Torrent-Bildschirmelemente",
285285
"torrents_set_trackers_snackbar": "Tracker erfolgreich festgelegt",
286286
"context_menu_items_heading": "Elemente im Kontextmenü",
287+
"notification_resume": "Fortsetzen",
288+
"notification_pause": "Pause",
289+
"notification_stop": "Stop",
290+
"notification_cancel": "Abbrechen",
291+
"notification_stopped": "Gestoppt",
292+
"notification_downloading": "Herunterladen",
293+
"notification_error": "Fehler beim Herunterladen",
294+
"notification_finished": "Download abgeschlossen",
287295
"wifi_only_title" : "Nur WLAN",
288296
"wifi_only_subtitle" : "Torrents werden nur herunter- und hochgeladen, wenn WLAN verbunden ist.",
289297
"shutdown_when_download_completes_title" : "Herunterfahren nach Abschluss des Downloads",

lib/l10n/arb/app_en.arb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@
326326
"shut_down_wifi_subtitle" : "This setting automatically shut down wifi when all torrents complete download.",
327327
"battery_optimization_title" : "Change battery optimization",
328328
"battery_optimization_subtitle" : "This setting is required if you want to make sure progress notification works smoothly.",
329-
"battery_low_title": "Stop downloads if battery level is low"
329+
"battery_low_title": "Stop downloads if battery level is low",
330+
331+
"notification_resume" : "Resume",
332+
"notification_pause": "Pause",
333+
"notification_stop": "Stop",
334+
"notification_cancel": "Cancel",
335+
"notification_stopped": "Stopped",
336+
"notification_downloading": "Downloading",
337+
"notification_error": "Download Error",
338+
"notification_finished": "Download Finished"
330339
}
331340

lib/l10n/arb/app_es.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,13 @@
313313
"sort_by_uploaded": "Subido",
314314
"sort_by_upload_speed": "Velocidad de carga",
315315
"sort_by_file_size": "Tamaño del archivo",
316-
"sort_by_percent_completed": "Porcentaje completado"
316+
"sort_by_percent_completed": "Porcentaje completado",
317+
"notification_resume": "Continuar",
318+
"notification_pause": "Pausa",
319+
"notification_stop": "Detener",
320+
"notification_cancel": "Cancelar",
321+
"notification_stopped": "Detenido",
322+
"notification_downloading": "Descargando",
323+
"notification_error": "Error de descarga",
324+
"notification_finished": "Descarga finalizada"
317325
}

lib/l10n/arb/app_fi.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,13 @@
313313
"sort_by_uploaded": "Ladattu palvelimelle",
314314
"sort_by_upload_speed": "Lähetysnopeus",
315315
"sort_by_file_size": "Tiedostokoko",
316-
"sort_by_percent_completed": "Suoritusprosentti"
316+
"sort_by_percent_completed": "Suoritusprosentti",
317+
"notification_resume": "Jatka",
318+
"notification_pause": "Keskeytä",
319+
"notification_stop": "Pysäytä",
320+
"notification_cancel": "Peruuta",
321+
"notification_stopped": "Pysähtynyt",
322+
"notification_downloading": "Lataaminen",
323+
"notification_error": "Latausvirhe",
324+
"notification_finished": "Lataus valmis"
317325
}

lib/l10n/arb/app_fr.arb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,13 @@
314314
"sort_by_upload_speed": "Vitesse d'envoi",
315315
"sort_by_file_size": "Taille du fichier",
316316
"sort_by_percent_completed": "Pourcentage accompli"
317-
317+
,
318+
"notification_resume": "Reprendre",
319+
"notification_pause": "Pause",
320+
"notification_stop": "Arrêter",
321+
"notification_cancel": "Annuler",
322+
"notification_stopped": "Arrêté",
323+
"notification_downloading": "Téléchargement",
324+
"notification_error": "Erreur de téléchargement",
325+
"notification_finished": "Téléchargement terminé"
318326
}

0 commit comments

Comments
 (0)