Skip to content

Commit

Permalink
fix some small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
amitamrutiya committed Sep 16, 2023
1 parent 701ee63 commit 9f01103
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
39 changes: 27 additions & 12 deletions lib/Api/event_handler_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'package:battery_plus/battery_plus.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -96,6 +97,7 @@ class EventHandlerApi {
newTorrentMap,
strict: true,
);

//Updating data in provider
BlocProvider.of<HomeScreenBloc>(context, listen: false)
.add(SetTorrentListJsonEvent(newTorrentListJson: newTorrentListJson));
Expand All @@ -119,7 +121,7 @@ class EventHandlerApi {

if (torrentList.length > int.parse(torrentLength) ||
torrentList.length < int.parse(torrentLength)) {
filterDataRephrasor(torrentList, context);
await filterDataRephrasor(torrentList, context);
}

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

final PowerManagementBloc powerManagementBloc =
BlocProvider.of<PowerManagementBloc>(context, listen: false);

//Exit screen on all download finished
if (powerManagementBloc.state.shutDownWhenFinishDownload &&
isAllDownloadFinished(context)) {
Expand All @@ -138,7 +141,15 @@ class EventHandlerApi {
//Turn off wifi on all download finished
if (powerManagementBloc.state.shutDownWifi &&
isAllDownloadFinished(context)) {
turnOffWiFi(powerManagementBloc.state.shutDownWifi);
await turnOffWiFi(powerManagementBloc.state.shutDownWifi);
}

//Stop all download on wifi disconnect
if (powerManagementBloc.state.wifiOnlyDownload) {
final connectivityResult = await Connectivity().checkConnectivity();
if (connectivityResult != ConnectivityResult.wifi) {
await stopAllDownload(context);
}
}

// Stop all download on low battery
Expand All @@ -148,14 +159,7 @@ class EventHandlerApi {
powerManagementBloc.state.batteryLimitLevel > 0 ? true : false;
if (isBatteryLimitSet &&
currentBatteryLevel <= powerManagementBloc.state.batteryLimitLevel) {
BlocProvider.of<HomeScreenBloc>(context, listen: false)
.state
.torrentList
.forEach((element) {
if (element.status.contains('downloading')) {
TorrentApi.stopTorrent(hashes: [element.hash], context: context);
}
});
await stopAllDownload(context);
}
}

Expand Down Expand Up @@ -286,6 +290,17 @@ bool isAllDownloadFinished(BuildContext context) {
);
}

void turnOffWiFi(bool wifiStatus) async {
WiFiForIoTPlugin.setEnabled(!wifiStatus);
Future<void> turnOffWiFi(bool wifiStatus) async {
await WiFiForIoTPlugin.setEnabled(!wifiStatus);
}

Future<void> stopAllDownload(BuildContext context) async {
BlocProvider.of<HomeScreenBloc>(context, listen: false)
.state
.torrentList
.forEach((element) async {
if (element.status.contains('downloading')) {
await TorrentApi.stopTorrent(hashes: [element.hash], context: context);
}
});
}
3 changes: 2 additions & 1 deletion lib/Blocs/language_bloc/language_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class LanguageBloc extends Bloc<LanguageEvent, LanguageState> {
Future<Locale?> getPreviousLang() async {
try {
final prefs = await SharedPreferences.getInstance();
if (prefs.getString('languageCode') != 'null')
if (prefs.containsKey('languageCode') &&
prefs.getString('languageCode') != 'null')
return Locale(prefs.getString('languageCode')!);
else {
return null;
Expand Down
7 changes: 4 additions & 3 deletions lib/Blocs/theme_bloc/theme_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
Future<void> getPreviousTheme() async {
try {
final prefs = await SharedPreferences.getInstance();
final storedThemeMode = prefs.getString('themeMode');

themeMode = _convertStringToThemeMode(storedThemeMode);
if (prefs.containsKey('themeMode')) {
final storedThemeMode = prefs.getString('themeMode');
themeMode = _convertStringToThemeMode(storedThemeMode);
}
} catch (error) {
print('Error retrieving theme mode from SharedPreferences: $error');
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Pages/home_screen/widgets/rss_feed_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
FeedsApi
.listAllFeedsAndRules(
context: context);
clearFeedsFields();

if (isUpdateFeedSelected) {
UpdateFeedApi.updateFeed(
type: "feed",
Expand All @@ -758,6 +758,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
context:
context);
}
clearFeedsFields();
});
}
} else {
Expand Down

0 comments on commit 9f01103

Please sign in to comment.