Skip to content

Commit 9f01103

Browse files
committed
fix some small issues
1 parent 701ee63 commit 9f01103

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

lib/Api/event_handler_api.dart

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:collection';
22
import 'dart:convert';
33
import 'dart:io';
44
import 'package:battery_plus/battery_plus.dart';
5+
import 'package:connectivity_plus/connectivity_plus.dart';
56
import 'package:flutter/cupertino.dart';
67
import 'package:flutter/services.dart';
78
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -96,6 +97,7 @@ class EventHandlerApi {
9697
newTorrentMap,
9798
strict: true,
9899
);
100+
99101
//Updating data in provider
100102
BlocProvider.of<HomeScreenBloc>(context, listen: false)
101103
.add(SetTorrentListJsonEvent(newTorrentListJson: newTorrentListJson));
@@ -119,7 +121,7 @@ class EventHandlerApi {
119121

120122
if (torrentList.length > int.parse(torrentLength) ||
121123
torrentList.length < int.parse(torrentLength)) {
122-
filterDataRephrasor(torrentList, context);
124+
await filterDataRephrasor(torrentList, context);
123125
}
124126

125127
//Setting the full list of torrent
@@ -128,6 +130,7 @@ class EventHandlerApi {
128130

129131
final PowerManagementBloc powerManagementBloc =
130132
BlocProvider.of<PowerManagementBloc>(context, listen: false);
133+
131134
//Exit screen on all download finished
132135
if (powerManagementBloc.state.shutDownWhenFinishDownload &&
133136
isAllDownloadFinished(context)) {
@@ -138,7 +141,15 @@ class EventHandlerApi {
138141
//Turn off wifi on all download finished
139142
if (powerManagementBloc.state.shutDownWifi &&
140143
isAllDownloadFinished(context)) {
141-
turnOffWiFi(powerManagementBloc.state.shutDownWifi);
144+
await turnOffWiFi(powerManagementBloc.state.shutDownWifi);
145+
}
146+
147+
//Stop all download on wifi disconnect
148+
if (powerManagementBloc.state.wifiOnlyDownload) {
149+
final connectivityResult = await Connectivity().checkConnectivity();
150+
if (connectivityResult != ConnectivityResult.wifi) {
151+
await stopAllDownload(context);
152+
}
142153
}
143154

144155
// Stop all download on low battery
@@ -148,14 +159,7 @@ class EventHandlerApi {
148159
powerManagementBloc.state.batteryLimitLevel > 0 ? true : false;
149160
if (isBatteryLimitSet &&
150161
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-
});
162+
await stopAllDownload(context);
159163
}
160164
}
161165

@@ -286,6 +290,17 @@ bool isAllDownloadFinished(BuildContext context) {
286290
);
287291
}
288292

289-
void turnOffWiFi(bool wifiStatus) async {
290-
WiFiForIoTPlugin.setEnabled(!wifiStatus);
293+
Future<void> turnOffWiFi(bool wifiStatus) async {
294+
await WiFiForIoTPlugin.setEnabled(!wifiStatus);
295+
}
296+
297+
Future<void> stopAllDownload(BuildContext context) async {
298+
BlocProvider.of<HomeScreenBloc>(context, listen: false)
299+
.state
300+
.torrentList
301+
.forEach((element) async {
302+
if (element.status.contains('downloading')) {
303+
await TorrentApi.stopTorrent(hashes: [element.hash], context: context);
304+
}
305+
});
291306
}

lib/Blocs/language_bloc/language_bloc.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class LanguageBloc extends Bloc<LanguageEvent, LanguageState> {
2727
Future<Locale?> getPreviousLang() async {
2828
try {
2929
final prefs = await SharedPreferences.getInstance();
30-
if (prefs.getString('languageCode') != 'null')
30+
if (prefs.containsKey('languageCode') &&
31+
prefs.getString('languageCode') != 'null')
3132
return Locale(prefs.getString('languageCode')!);
3233
else {
3334
return null;

lib/Blocs/theme_bloc/theme_bloc.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
1919
Future<void> getPreviousTheme() async {
2020
try {
2121
final prefs = await SharedPreferences.getInstance();
22-
final storedThemeMode = prefs.getString('themeMode');
23-
24-
themeMode = _convertStringToThemeMode(storedThemeMode);
22+
if (prefs.containsKey('themeMode')) {
23+
final storedThemeMode = prefs.getString('themeMode');
24+
themeMode = _convertStringToThemeMode(storedThemeMode);
25+
}
2526
} catch (error) {
2627
print('Error retrieving theme mode from SharedPreferences: $error');
2728
}

lib/Pages/home_screen/widgets/rss_feed_home_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
737737
FeedsApi
738738
.listAllFeedsAndRules(
739739
context: context);
740-
clearFeedsFields();
740+
741741
if (isUpdateFeedSelected) {
742742
UpdateFeedApi.updateFeed(
743743
type: "feed",
@@ -758,6 +758,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
758758
context:
759759
context);
760760
}
761+
clearFeedsFields();
761762
});
762763
}
763764
} else {

0 commit comments

Comments
 (0)