Skip to content

Commit

Permalink
Merge pull request #17 from CCExtractor/develop
Browse files Browse the repository at this point in the history
Completed speed limit section
  • Loading branch information
pratikbaid3 authored Jul 30, 2021
2 parents 5b1a1ef + b786484 commit 8829f48
Show file tree
Hide file tree
Showing 9 changed files with 1,121 additions and 607 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Flutter CI

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

Expand Down
42 changes: 42 additions & 0 deletions lib/Api/client_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flood_mobile/Model/client_settings_model.dart';
import 'package:flood_mobile/Provider/api_provider.dart';
import 'package:flood_mobile/Provider/client_provider.dart';
import 'package:flood_mobile/Provider/user_detail_provider.dart';
import 'package:flood_mobile/Services/transfer_speed_manager.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -76,4 +77,45 @@ class ClientApi {
print(e.toString());
}
}

static Future<void> setSpeedLimit(
{@required BuildContext context,
@required String downSpeed,
@required String upSpeed}) async {
try {
String url = Provider.of<ApiProvider>(context, listen: false).baseUrl +
ApiProvider.setClientSettingsUrl;
print('---SET SPEED LIMIT SETTINGS---');
print(url);
Response response;
Dio dio = new Dio();
//Headers
dio.options.headers['Accept'] = "application/json";
dio.options.headers['Content-Type'] = "application/json";
dio.options.headers['Connection'] = "keep-alive";
dio.options.headers['Cookie'] =
Provider.of<UserDetailProvider>(context, listen: false).token;
Map<String, dynamic> mp = Map();
mp['throttleGlobalDownSpeed'] =
TransferSpeedManager.speedToValMap[downSpeed];
mp['throttleGlobalUpSpeed'] = TransferSpeedManager.speedToValMap[upSpeed];
String rawBody = json.encode(mp);
print(rawBody);
response = await dio.patch(
url,
data: rawBody,
);
if (response.statusCode == 200) {
print(response);
print('--SPEED LIMIT CHANGED--');
// *Getting the client settings again
getClientSettings(context);
} else {
print('Error');
}
} catch (e) {
print('--ERROR--');
print(e.toString());
}
}
}
26 changes: 18 additions & 8 deletions lib/Api/torrent_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ class TorrentApi {
}

static Future<void> addTorrentMagnet(
{String magnetUrl, String destination, BuildContext context}) async {
{String magnetUrl,
String destination,
BuildContext context,
bool isBasePath,
bool isCompleted,
bool isSequential}) async {
try {
String url = Provider.of<ApiProvider>(context, listen: false).baseUrl +
ApiProvider.addTorrentMagnet;
Expand All @@ -124,9 +129,9 @@ class TorrentApi {
Map<String, dynamic> mp = Map();
mp['urls'] = [magnetUrl];
mp['destination'] = destination;
mp['isBasePath'] = false;
mp['isCompleted'] = false;
mp['isSequential'] = false;
mp['isBasePath'] = isBasePath;
mp['isCompleted'] = isCompleted;
mp['isSequential'] = isSequential;
mp['start'] = true;
mp['tags'] = [];
String rawBody = json.encode(mp);
Expand All @@ -144,7 +149,12 @@ class TorrentApi {
}

static Future<void> addTorrentFile(
{String base64, String destination, BuildContext context}) async {
{String base64,
String destination,
BuildContext context,
bool isBasePath,
bool isSequential,
bool isCompleted}) async {
try {
String url = Provider.of<ApiProvider>(context, listen: false).baseUrl +
ApiProvider.addTorrentFile;
Expand All @@ -161,9 +171,9 @@ class TorrentApi {
Map<String, dynamic> mp = Map();
mp['files'] = [base64];
mp['destination'] = destination;
mp['isBasePath'] = false;
mp['isCompleted'] = false;
mp['isSequential'] = false;
mp['isBasePath'] = isBasePath;
mp['isCompleted'] = isCompleted;
mp['isSequential'] = isSequential;
mp['start'] = true;
mp['tags'] = [];
String rawBody = json.encode(mp);
Expand Down
68 changes: 67 additions & 1 deletion lib/Components/add_torrent_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class AddTorrentSheet extends StatefulWidget {
class _AddTorrentSheetState extends State<AddTorrentSheet> {
bool isFileSelected = false;
bool isMagnetSelected = false;
bool useAdBasePath = false;
bool completed = false;
bool sequentialDownload = false;

TextEditingController directoryController;
TextEditingController magnetUrlController;
TextEditingController magnetUrlController = new TextEditingController();
String torrentPath;
final _formKey = GlobalKey<FormState>();
String base64;
Expand Down Expand Up @@ -109,6 +113,62 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
},
)
: Container(),
(isMagnetSelected)
? SizedBox(
height: 20,
)
: Container(),
CheckboxListTile(
activeColor: AppColor.greenAccentColor,
tileColor: AppColor.secondaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
title: Text(
'Use as Base Path',
style: TextStyle(fontSize: 14),
),
value: useAdBasePath,
onChanged: (value) {
setState(() {
useAdBasePath = value;
});
},
),
CheckboxListTile(
activeColor: AppColor.greenAccentColor,
tileColor: AppColor.secondaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
title: Text(
'Sequential Download',
style: TextStyle(fontSize: 14),
),
value: sequentialDownload,
onChanged: (value) {
setState(() {
sequentialDownload = value;
});
},
),
CheckboxListTile(
activeColor: AppColor.greenAccentColor,
tileColor: AppColor.secondaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
title: Text(
'Completed',
style: TextStyle(fontSize: 14),
),
value: completed,
onChanged: (value) {
setState(() {
completed = value;
});
},
),
SizedBox(
height: 15,
),
Expand Down Expand Up @@ -187,13 +247,19 @@ class _AddTorrentSheetState extends State<AddTorrentSheet> {
TorrentApi.addTorrentMagnet(
magnetUrl: magnetUrlController.text,
destination: directoryController.text,
isBasePath: useAdBasePath,
isSequential: sequentialDownload,
isCompleted: completed,
context: context);
Navigator.pop(context);
} else {
//The file has been chosen
TorrentApi.addTorrentFile(
base64: base64,
destination: directoryController.text,
isBasePath: useAdBasePath,
isSequential: sequentialDownload,
isCompleted: completed,
context: context);
Navigator.pop(context);
}
Expand Down
1 change: 0 additions & 1 deletion lib/Pages/about_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flood_mobile/Constants/app_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';

class AboutScreen extends StatefulWidget {
@override
Expand Down
19 changes: 12 additions & 7 deletions lib/Pages/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flood_mobile/Provider/user_detail_provider.dart';
import 'package:flood_mobile/Route/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:flutter_svg/svg.dart';
import 'package:hidden_drawer_menu/controllers/simple_hidden_drawer_controller.dart';
import 'package:hidden_drawer_menu/simple_hidden_drawer/simple_hidden_drawer.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -137,6 +138,17 @@ class _MenuState extends State<Menu> {
),
],
),
Padding(
padding: EdgeInsets.only(left: 18.0, top: 20, bottom: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SvgPicture.network(
'https://img.shields.io/github/v/release/CCExtractor/Flood_Mobile?include_prereleases',
),
],
),
),
SizedBox(
height: hp * 0.01,
),
Expand All @@ -154,13 +166,6 @@ class _MenuState extends State<Menu> {
controller.toggle();
},
title: 'Settings'),
NavDrawerListTile(
icon: Icons.speed,
onTap: () {
controller.position = 2;
controller.toggle();
},
title: 'Speed Limits'),
NavDrawerListTile(
icon: Icons.exit_to_app,
onTap: () async {
Expand Down
Loading

0 comments on commit 8829f48

Please sign in to comment.