Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into flood2
Browse files Browse the repository at this point in the history
  • Loading branch information
andoriyaprashant committed Sep 20, 2023
2 parents 934aef5 + de1befe commit 64858b2
Show file tree
Hide file tree
Showing 41 changed files with 498 additions and 218 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Flutter CI

on:
push:
branches: [ master , develop ]
branches: [master, develop]
pull_request:
branches: [ master , develop ]
branches: [master, develop]

jobs:
build:
Expand All @@ -14,10 +14,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
java-version: "12.x"
- uses: subosito/flutter-action@v1
with:
flutter-version: '3.10.5'
flutter-version: "3.13.1"
- run: flutter pub get
- run: flutter gen-l10n --arb-dir=lib/l10n/arb
- run: flutter analyze
Expand Down
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
2 changes: 2 additions & 0 deletions lib/Blocs/user_interface_bloc/user_interface_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UserInterfaceBloc extends Bloc<UserInterfaceEvent, UserInterfaceState> {
Emitter<UserInterfaceState> emit,
) {
UserInterfaceModel model = UserInterfaceModel(
showProgressBar: event.model.showProgressBar,
showDateAdded: event.model.showDateAdded,
showDateCreated: event.model.showDateCreated,
showRatio: event.model.showRatio,
Expand All @@ -43,6 +44,7 @@ class UserInterfaceBloc extends Bloc<UserInterfaceEvent, UserInterfaceState> {
showInitialSeeding: event.model.showInitialSeeding,
showSequentialDownload: event.model.showSequentialDownload,
showDownloadTorrent: event.model.showDownloadTorrent,
tagPreferenceButtonValue: event.model.tagPreferenceButtonValue,
);

saveUserInterfaceModel(model);
Expand Down
2 changes: 2 additions & 0 deletions lib/Blocs/user_interface_bloc/user_interface_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class UserInterfaceState extends Equatable {

factory UserInterfaceState.initial() => UserInterfaceState(
model: UserInterfaceModel(
showProgressBar: true,
showDateAdded: true,
showDateCreated: true,
showRatio: false,
Expand All @@ -33,6 +34,7 @@ class UserInterfaceState extends Equatable {
showInitialSeeding: false,
showSequentialDownload: false,
showDownloadTorrent: false,
tagPreferenceButtonValue: TagPreferenceButtonValue.multiSelection,
),
);

Expand Down
20 changes: 19 additions & 1 deletion lib/Model/user_interface_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:equatable/equatable.dart';

enum TagPreferenceButtonValue { singleSelection, multiSelection }

class UserInterfaceModel extends Equatable {
final bool showProgressBar;
final bool showDateAdded;
final bool showDateCreated;
final bool showRatio;
Expand All @@ -25,8 +28,10 @@ class UserInterfaceModel extends Equatable {
final bool showInitialSeeding;
final bool showSequentialDownload;
final bool showDownloadTorrent;
final TagPreferenceButtonValue tagPreferenceButtonValue;

const UserInterfaceModel({
required this.showProgressBar,
required this.showDateAdded,
required this.showDateCreated,
required this.showRatio,
Expand All @@ -51,10 +56,12 @@ class UserInterfaceModel extends Equatable {
required this.showInitialSeeding,
required this.showSequentialDownload,
required this.showDownloadTorrent,
required this.tagPreferenceButtonValue,
});

factory UserInterfaceModel.fromJson(Map<String, dynamic> json) {
return UserInterfaceModel(
showProgressBar: json['showProgressBar'] as bool,
showDateAdded: json['showDateAdded'] as bool,
showDateCreated: json['showDateCreated'] as bool,
showRatio: json['showRatio'] as bool,
Expand All @@ -79,11 +86,16 @@ class UserInterfaceModel extends Equatable {
showInitialSeeding: json['showInitialSeeding'] as bool,
showSequentialDownload: json['showSequentialDownload'] as bool,
showDownloadTorrent: json['showDownloadTorrent'] as bool,
tagPreferenceButtonValue:
json['tagPreferenceButtonValue'] == 'singleSelection'
? TagPreferenceButtonValue.singleSelection
: TagPreferenceButtonValue.multiSelection,
);
}

Map<String, dynamic> toJson() {
return {
'showProgressBar': showProgressBar,
'showDateAdded': showDateAdded,
'showDateCreated': showDateCreated,
'showRatio': showRatio,
Expand All @@ -108,11 +120,16 @@ class UserInterfaceModel extends Equatable {
'showInitialSeeding': showInitialSeeding,
'showSequentialDownload': showSequentialDownload,
'showDownloadTorrent': showDownloadTorrent,
'tagPreferenceButtonValue':
tagPreferenceButtonValue == TagPreferenceButtonValue.singleSelection
? 'singleSelection'
: 'multiSelection',
};
}

@override
List<Object?> get props => [
showProgressBar,
showDateAdded,
showDateCreated,
showRatio,
Expand All @@ -136,6 +153,7 @@ class UserInterfaceModel extends Equatable {
showPriority,
showInitialSeeding,
showSequentialDownload,
showDownloadTorrent
showDownloadTorrent,
tagPreferenceButtonValue,
];
}
22 changes: 13 additions & 9 deletions 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 Expand Up @@ -1011,20 +1012,23 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
Padding(
padding:
const EdgeInsets
.only(
.only(
top: 20),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Padding(
padding: const EdgeInsets
padding:
const EdgeInsets
.only(
right: 20,
left: 20,
bottom:
5),
right:
20,
left:
20,
bottom:
5),
child: Text(
l10n.selected_magnet_link,
style: TextStyle(
Expand All @@ -1043,7 +1047,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
),
Padding(
padding: const EdgeInsets
.only(
.only(
left:
20.0,
right:
Expand Down Expand Up @@ -1384,7 +1388,7 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
? Padding(
padding:
const EdgeInsets
.only(
.only(
top: 8.0),
child: Container(
height: 1,
Expand Down
23 changes: 20 additions & 3 deletions lib/Pages/login_screen/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _LoginScreenState extends State<LoginScreen> {
TextEditingController usernameController = new TextEditingController();
TextEditingController passwordController = new TextEditingController();
TextEditingController urlController =
new TextEditingController(text: 'http://localhost:3000');
new TextEditingController(text: 'https://yourserver.xirvik.com');
final _formKey = GlobalKey<FormState>();
late int themeIndex;

Expand Down Expand Up @@ -100,7 +100,7 @@ class _LoginScreenState extends State<LoginScreen> {
labelText: l10n.login_screen_url,
prefixIcon: Icons.link,
themeIndex: themeIndex,
trailingIconButton: Align(
trailingIconButton1: Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: () {
Expand All @@ -120,6 +120,23 @@ class _LoginScreenState extends State<LoginScreen> {
),
),
),
trailingIconButton2: Align(
alignment: Alignment.centerRight,
child: Tooltip(
triggerMode: TooltipTriggerMode.tap,
message:
"URL for your Flood instance (local, seedbox...).",
showDuration: Duration(seconds: 3),
child: Icon(
Icons.info_outline,
color: ThemeBloc.theme(themeIndex)
.textTheme
.bodyLarge!
.color!,
size: 20,
),
),
),
),
SizedBox(
height: hp * 0.01,
Expand All @@ -141,7 +158,7 @@ class _LoginScreenState extends State<LoginScreen> {
prefixIcon: Icons.lock_outline,
themeIndex: themeIndex,
obscureText: showPass,
trailingIconButton: Align(
trailingIconButton1: Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: () {
Expand Down
14 changes: 11 additions & 3 deletions lib/Pages/login_screen/widgets/login_screen_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ class LoginScreenTextField extends StatelessWidget {
final String labelText;
final IconData prefixIcon;
final bool obscureText;
final Widget? trailingIconButton;
final Widget? trailingIconButton1;
final Widget? trailingIconButton2;
final int themeIndex;

const LoginScreenTextField({
required this.controller,
required this.labelText,
required this.prefixIcon,
required this.themeIndex,
this.trailingIconButton,
this.trailingIconButton1,
this.trailingIconButton2,
this.obscureText = false,
Key? key,
}) : super(key: key);
Expand Down Expand Up @@ -73,7 +75,13 @@ class LoginScreenTextField extends StatelessWidget {
),
),
),
trailingIconButton ?? Container()
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
trailingIconButton1 ?? Container(),
trailingIconButton2 ?? Container(),
],
)
],
),
);
Expand Down
Loading

0 comments on commit 64858b2

Please sign in to comment.