Skip to content

Commit

Permalink
Merge pull request #13 from CCExtractor/master
Browse files Browse the repository at this point in the history
implemented sort by size, implemented sort by time_stamp_added
  • Loading branch information
Erarshad authored Jul 7, 2021
2 parents 8861094 + 705ebab commit 4fc259b
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 42 deletions.
Binary file modified android/.gradle/6.7/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified android/.gradle/6.7/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified android/.gradle/6.7/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified android/.gradle/6.7/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified android/.gradle/6.7/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified android/.gradle/6.7/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified android/.gradle/6.7/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified android/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=C:\\Users\\Arshad\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.versionName=0.1.0
flutter.versionCode=2
101 changes: 91 additions & 10 deletions lib/components/bottom_sheet/sorter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class _sorterState extends State<sorter> {
padding: EdgeInsets.only(top: 3.0),
child: Text("Sort as",
style: TextStyle(
color: !theme_controller.is_it_dark()?Colors.black:Colors.white,
color: !theme_controller.is_it_dark()
? Colors.black
: Colors.white,
fontSize: theme.bottom_sheet_heading_font_size,
fontFamily: theme.font_family))),
Divider(
Expand All @@ -46,42 +48,121 @@ class _sorterState extends State<sorter> {
endIndent: 55.0,
),
ListTile(

title: Text(
'Non-Reversed',
'Sort by non-reverse order',
style: TextStyle(
color: sort_helper.non_reverse_order?theme.base_color:(!theme_controller.is_it_dark()?Colors.black:Colors.white),
color: sort_helper.non_reverse_order
? theme.base_color
: (!theme_controller.is_it_dark()
? Colors.black
: Colors.white),
fontSize: theme.alert_box_font_size,
fontFamily: theme.font_family),
),
leading: Icon(Icons.arrow_upward, color: sort_helper.non_reverse_order?theme.base_color:Colors.black),
leading: Icon(Icons.arrow_upward,
color: sort_helper.non_reverse_order
? theme.base_color
: Colors.black),
onTap: () {
if (this.mounted) {
setState(() {
sort_helper.reverse_order = false;
sort_helper.non_reverse_order = true;
sort_helper.by_size_order = false;
sort_helper.by_date_time = false;
});
}
rebuilt_list();
Navigator.of(context).pop();
},
),
ListTile(

title: Text(
'Reversed',
'Sort by reverse order',
style: TextStyle(
color: sort_helper.reverse_order?theme.base_color:(!theme_controller.is_it_dark()?Colors.black:Colors.white),
color: sort_helper.reverse_order
? theme.base_color
: (!theme_controller.is_it_dark()
? Colors.black
: Colors.white),
fontSize: theme.alert_box_font_size,
fontFamily: theme.font_family),
),
leading: Icon(Icons.arrow_downward_rounded,
color: sort_helper.reverse_order?theme.base_color:Colors.black,),
leading: Icon(
Icons.arrow_downward_rounded,
color: sort_helper.reverse_order
? theme.base_color
: Colors.black,
),
onTap: () {
if (this.mounted) {
setState(() {
sort_helper.reverse_order = true;
sort_helper.non_reverse_order = false;
sort_helper.by_size_order = false;
sort_helper.by_date_time = false;
});
}
rebuilt_list();

Navigator.of(context).pop();
}),
ListTile(
title: Text(
'Sort by size',
style: TextStyle(
color: sort_helper.by_size_order
? theme.base_color
: (!theme_controller.is_it_dark()
? Colors.black
: Colors.white),
fontSize: theme.alert_box_font_size,
fontFamily: theme.font_family),
),
leading: Icon(
Icons.sd_storage_outlined,
color: sort_helper.by_size_order
? theme.base_color
: Colors.black,
),
onTap: () {
if (this.mounted) {
setState(() {
sort_helper.reverse_order = false;
sort_helper.non_reverse_order = false;
sort_helper.by_size_order = true;
sort_helper.by_date_time = false;
});
}
rebuilt_list();

Navigator.of(context).pop();
}),
ListTile(
title: Text(
'Sort by date and time added',
style: TextStyle(
color: sort_helper.by_date_time
? theme.base_color
: (!theme_controller.is_it_dark()
? Colors.black
: Colors.white),
fontSize: theme.alert_box_font_size,
fontFamily: theme.font_family),
),
leading: Icon(
Icons.watch,
color: sort_helper.by_date_time
? theme.base_color
: Colors.black,
),
onTap: () {
if (this.mounted) {
setState(() {
sort_helper.reverse_order = false;
sort_helper.non_reverse_order = false;
sort_helper.by_size_order = false;
sort_helper.by_date_time = true;
});
}
rebuilt_list();
Expand Down
45 changes: 22 additions & 23 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _dashboardState extends State<dashboard> {
String seed_pass,
String qr_auth) async {
cookie = await apis.authentication_to_deluge(url, password, has_deluge_pass,
is_reverse_proxied, seed_username, seed_pass, qr_auth,context);
is_reverse_proxied, seed_username, seed_pass, qr_auth, context);
}

@override
Expand All @@ -117,7 +117,7 @@ class _dashboardState extends State<dashboard> {
if (this.mounted) {
setState(() {
torrent = apis.get_torrent_list(cookie, url, is_reverse_proxied,
seed_username, seed_pass, qr_auth,context);
seed_username, seed_pass, qr_auth, context);

// setting state for ui changes realtime
});
Expand Down Expand Up @@ -160,7 +160,7 @@ class _dashboardState extends State<dashboard> {
if (this.mounted) {
setState(() {
torrent = apis.get_torrent_list(cookie, url, is_reverse_proxied,
seed_username, seed_pass, qr_auth,context);
seed_username, seed_pass, qr_auth, context);

// setting state for ui changes realtime
});
Expand Down Expand Up @@ -328,8 +328,7 @@ class _dashboardState extends State<dashboard> {
selx_acc.username,
selx_acc.password,
selx_acc.via_qr,
context
);
context);
}
non_delayed_torrent_fetch(
selx_acc.deluge_url,
Expand Down Expand Up @@ -363,8 +362,7 @@ class _dashboardState extends State<dashboard> {
selx_acc.username,
selx_acc.password,
selx_acc.via_qr,
context
);
context);
}
non_delayed_torrent_fetch(
selx_acc.deluge_url,
Expand Down Expand Up @@ -484,8 +482,7 @@ class _dashboardState extends State<dashboard> {
selx_acc.username,
selx_acc.password,
selx_acc.via_qr,
context
);
context);
}
non_delayed_torrent_fetch(
selx_acc.deluge_url,
Expand Down Expand Up @@ -524,8 +521,7 @@ class _dashboardState extends State<dashboard> {
selx_acc.username,
selx_acc.password,
selx_acc.via_qr,
context
);
context);
}
non_delayed_torrent_fetch(
selx_acc.deluge_url,
Expand Down Expand Up @@ -593,8 +589,12 @@ class _dashboardState extends State<dashboard> {
Map<String, dynamic> sort(Map<String, dynamic> map) {
if (sort_helper.non_reverse_order) {
return map;
} else {
} else if (sort_helper.reverse_order) {
return sort_helper.sort(map);
} else if (sort_helper.by_size_order) {
return sort_helper.sort_by_size(map);
} else if (sort_helper.by_date_time) {
return sort_helper.sort_by_date_time(map);
}
}

Expand All @@ -618,7 +618,6 @@ class _dashboardState extends State<dashboard> {
} else {
states.set_theme_mode(1);
}

},
),
],
Expand Down Expand Up @@ -752,16 +751,16 @@ class _dashboardState extends State<dashboard> {
return Center(child: loader());
} else if (snapshot.data == null ||
snapshot.data['result'] == null) {
return error(retry:(){
non_delayed_torrent_fetch(
selx_acc.deluge_url,
selx_acc.deluge_pwrd,
cookie,
selx_acc.has_deluge_pwrd,
selx_acc.is_reverse_proxied,
selx_acc.username,
selx_acc.password,
selx_acc.via_qr);
return error(retry: () {
non_delayed_torrent_fetch(
selx_acc.deluge_url,
selx_acc.deluge_pwrd,
cookie,
selx_acc.has_deluge_pwrd,
selx_acc.is_reverse_proxied,
selx_acc.username,
selx_acc.password,
selx_acc.via_qr);
});
} else {
return Expanded(
Expand Down
6 changes: 5 additions & 1 deletion lib/screens/multi_dash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,12 @@ class multi_accountState extends State<multi_account> {
Map<multtorrent, dynamic> sort(Map<multtorrent, dynamic> map) {
if (sort_helper.non_reverse_order) {
return map;
} else {
} else if (sort_helper.reverse_order) {
return sort_helper.sort_for_multi(map);
} else if (sort_helper.by_size_order) {
return sort_helper.sort_by_size_for_multi(map);
} else if (sort_helper.by_date_time) {
return sort_helper.sort_by_date_time_for_multi(map);
}
}
//----------------------------------------------------------------------
Expand Down
83 changes: 78 additions & 5 deletions lib/string/sorter.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,93 @@
import 'package:deluge_client/core/all_acc.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class sort_helper {
static bool reverse_order = false;
static bool non_reverse_order = true;
static Map<String, dynamic> sort(Map<String, dynamic> map) {

static bool by_size_order = false;
static bool by_date_time = false;
static Map<String, dynamic> sort(Map<String, dynamic> map) {
return Map.fromEntries(map.entries.toList().reversed);
}
static Map<multtorrent, dynamic> sort_for_multi(Map<multtorrent, dynamic>map) {


static Map<multtorrent, dynamic> sort_for_multi(
Map<multtorrent, dynamic> map) {
return Map.fromEntries(map.entries.toList().reversed);
}


static Map<String, dynamic> sort_by_size(Map<String, dynamic> map) {
List<map_as_list_view> mid_list = new List<map_as_list_view>();
map.entries.forEach((e) =>
mid_list.add(map_as_list_view(hash: e.key, properties: e.value)));
mid_list.sort((a, b) => (a.properties['total_size'] ~/ 1000000)
.compareTo(b.properties['total_size'] ~/ 1000000));
Map<String, dynamic> output_map = new Map<String, dynamic>();
mid_list.forEach((val) => output_map[val.hash] = val.properties);

return output_map;
}

static Map<multtorrent, dynamic> sort_by_size_for_multi(
Map<multtorrent, dynamic> map) {
List<map_as_list_view_for_multi> mid_list =
new List<map_as_list_view_for_multi>();
map.entries.forEach((e) => mid_list
.add(map_as_list_view_for_multi(identity: e.key, properties: e.value)));
mid_list.sort((a, b) => (a.properties['total_size'] ~/ 1000000)
.compareTo(b.properties['total_size'] ~/ 1000000));
Map<multtorrent, dynamic> output_map = new Map<multtorrent, dynamic>();
mid_list.forEach((val) => output_map[val.identity] = val.properties);

return output_map;
}

//-----------date and time comparision
static Map<String, dynamic> sort_by_date_time(Map<String, dynamic> map) {
final format = new DateFormat('dd-MM-yyyy hh:mm a');
final eta = new DateFormat('hh:mm');
List<map_as_list_view> mid_list = new List<map_as_list_view>();
map.entries.forEach((e) =>
mid_list.add(map_as_list_view(hash: e.key, properties: e.value)));
mid_list.sort((a, b) => (format.format(DateTime.fromMillisecondsSinceEpoch(
a.properties['time_added'] * 1000)))
.compareTo(format.format(DateTime.fromMillisecondsSinceEpoch(
b.properties['time_added'] * 1000))));
Map<String, dynamic> output_map = new Map<String, dynamic>();
mid_list.forEach((val) => output_map[val.hash] = val.properties);

return output_map;
}
//-for multi
static Map<multtorrent, dynamic> sort_by_date_time_for_multi(
Map<multtorrent, dynamic> map) {
final format = new DateFormat('dd-MM-yyyy hh:mm a');
final eta = new DateFormat('hh:mm');

List<map_as_list_view_for_multi> mid_list =
new List<map_as_list_view_for_multi>();
map.entries.forEach((e) => mid_list
.add(map_as_list_view_for_multi(identity: e.key, properties: e.value)));
mid_list.sort((a, b) => (format.format(DateTime.fromMillisecondsSinceEpoch(
a.properties['time_added'] * 1000)))
.compareTo(format.format(DateTime.fromMillisecondsSinceEpoch(
b.properties['time_added'] * 1000))));
Map<multtorrent, dynamic> output_map = new Map<multtorrent, dynamic>();
mid_list.forEach((val) => output_map[val.identity] = val.properties);

return output_map;
}

}

class map_as_list_view {
String hash;
Map<String, dynamic> properties;
map_as_list_view({this.hash, this.properties});
}

class map_as_list_view_for_multi {
multtorrent identity;
Map<String, dynamic> properties;
map_as_list_view_for_multi({this.identity, this.properties});
}
Loading

0 comments on commit 4fc259b

Please sign in to comment.