mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#150 new: net view sort
This commit is contained in:
@@ -21,22 +21,23 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
|||||||
|
|
||||||
BigInt get _timeDiff => BigInt.from(now[0].time - pre[0].time);
|
BigInt get _timeDiff => BigInt.from(now[0].time - pre[0].time);
|
||||||
|
|
||||||
double _speedIn(int i) => (now[i].bytesIn - pre[i].bytesIn) / _timeDiff;
|
double speedInBytes(int i) => (now[i].bytesIn - pre[i].bytesIn) / _timeDiff;
|
||||||
double _speedOut(int i) => (now[i].bytesOut - pre[i].bytesOut) / _timeDiff;
|
double speedOutBytes(int i) =>
|
||||||
BigInt _sizeIn(int i) => now[i].bytesIn;
|
(now[i].bytesOut - pre[i].bytesOut) / _timeDiff;
|
||||||
BigInt _sizeOut(int i) => now[i].bytesOut;
|
BigInt sizeInBytes(int i) => now[i].bytesIn;
|
||||||
|
BigInt sizeOutBytes(int i) => now[i].bytesOut;
|
||||||
|
|
||||||
String speedIn({String? device, bool all = false}) {
|
String speedIn({String? device, bool all = false}) {
|
||||||
if (pre[0].device == '' || now[0].device == '') return '0kb/s';
|
if (pre[0].device == '' || now[0].device == '') return '0kb/s';
|
||||||
if (all) {
|
if (all) {
|
||||||
var speed = 0.0;
|
var speed = 0.0;
|
||||||
for (var i = 0; i < now.length; i++) {
|
for (var i = 0; i < now.length; i++) {
|
||||||
speed += _speedIn(i);
|
speed += speedInBytes(i);
|
||||||
}
|
}
|
||||||
return buildStandardOutput(speed);
|
return buildStandardOutput(speed);
|
||||||
}
|
}
|
||||||
final idx = deviceIdx(device);
|
final idx = deviceIdx(device);
|
||||||
return buildStandardOutput(_speedIn(idx));
|
return buildStandardOutput(speedInBytes(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
String sizeIn({String? device, bool all = false}) {
|
String sizeIn({String? device, bool all = false}) {
|
||||||
@@ -44,12 +45,12 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
|||||||
if (all) {
|
if (all) {
|
||||||
var size = BigInt.from(0);
|
var size = BigInt.from(0);
|
||||||
for (var i = 0; i < now.length; i++) {
|
for (var i = 0; i < now.length; i++) {
|
||||||
size += _sizeIn(i);
|
size += sizeInBytes(i);
|
||||||
}
|
}
|
||||||
return size.convertBytes;
|
return size.convertBytes;
|
||||||
}
|
}
|
||||||
final idx = deviceIdx(device);
|
final idx = deviceIdx(device);
|
||||||
return _sizeIn(idx).convertBytes;
|
return sizeInBytes(idx).convertBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
String speedOut({String? device, bool all = false}) {
|
String speedOut({String? device, bool all = false}) {
|
||||||
@@ -57,12 +58,12 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
|||||||
if (all) {
|
if (all) {
|
||||||
var speed = 0.0;
|
var speed = 0.0;
|
||||||
for (var i = 0; i < now.length; i++) {
|
for (var i = 0; i < now.length; i++) {
|
||||||
speed += _speedOut(i);
|
speed += speedOutBytes(i);
|
||||||
}
|
}
|
||||||
return buildStandardOutput(speed);
|
return buildStandardOutput(speed);
|
||||||
}
|
}
|
||||||
final idx = deviceIdx(device);
|
final idx = deviceIdx(device);
|
||||||
return buildStandardOutput(_speedOut(idx));
|
return buildStandardOutput(speedOutBytes(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
String sizeOut({String? device, bool all = false}) {
|
String sizeOut({String? device, bool all = false}) {
|
||||||
@@ -70,12 +71,12 @@ class NetSpeed extends TimeSeq<NetSpeedPart> {
|
|||||||
if (all) {
|
if (all) {
|
||||||
var size = BigInt.from(0);
|
var size = BigInt.from(0);
|
||||||
for (var i = 0; i < now.length; i++) {
|
for (var i = 0; i < now.length; i++) {
|
||||||
size += _sizeOut(i);
|
size += sizeOutBytes(i);
|
||||||
}
|
}
|
||||||
return size.convertBytes;
|
return size.convertBytes;
|
||||||
}
|
}
|
||||||
final idx = deviceIdx(device);
|
final idx = deviceIdx(device);
|
||||||
return _sizeOut(idx).convertBytes;
|
return sizeOutBytes(idx).convertBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int deviceIdx(String? device) {
|
int deviceIdx(String? device) {
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:toolbox/core/extension/context/common.dart';
|
import 'package:toolbox/core/extension/context/common.dart';
|
||||||
import 'package:toolbox/core/extension/order.dart';
|
import 'package:toolbox/core/extension/order.dart';
|
||||||
import 'package:toolbox/data/model/server/cpu.dart';
|
import 'package:toolbox/data/model/server/cpu.dart';
|
||||||
|
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||||
import 'package:toolbox/data/model/server/system.dart';
|
import 'package:toolbox/data/model/server/system.dart';
|
||||||
import 'package:toolbox/data/res/store.dart';
|
import 'package:toolbox/data/res/store.dart';
|
||||||
import 'package:toolbox/view/widget/server_func_btns.dart';
|
import 'package:toolbox/view/widget/server_func_btns.dart';
|
||||||
|
import 'package:toolbox/view/widget/value_notifier.dart';
|
||||||
|
|
||||||
import '../../../core/extension/numx.dart';
|
import '../../../core/extension/numx.dart';
|
||||||
import '../../../core/route.dart';
|
import '../../../core/route.dart';
|
||||||
import '../../../data/model/server/net_speed.dart';
|
|
||||||
import '../../../data/model/server/server.dart';
|
import '../../../data/model/server/server.dart';
|
||||||
import '../../../data/model/server/server_status.dart';
|
import '../../../data/model/server/server_status.dart';
|
||||||
import '../../../data/provider/server.dart';
|
import '../../../data/provider/server.dart';
|
||||||
@@ -51,6 +52,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final _netSortType = ValueNotifier(_NetSortType.device);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
@@ -350,43 +353,80 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNetView(ServerStatus ss) {
|
Widget _buildNetView(ServerStatus ss) {
|
||||||
final ns = ss.netSpeed;
|
|
||||||
final children = <Widget>[
|
|
||||||
_buildNetSpeedTop(),
|
|
||||||
const Divider(
|
|
||||||
height: 7,
|
|
||||||
)
|
|
||||||
];
|
|
||||||
if (ns.devices.isEmpty) {
|
|
||||||
children.add(Center(
|
|
||||||
child: Text(
|
|
||||||
_s.noInterface,
|
|
||||||
style: const TextStyle(color: Colors.grey, fontSize: 13),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return RoundRectCard(
|
return RoundRectCard(
|
||||||
Padding(
|
Padding(
|
||||||
padding: UIs.roundRectCardPadding,
|
padding: UIs.roundRectCardPadding,
|
||||||
child: Column(
|
child: ValueBuilder(
|
||||||
children: children,
|
listenable: _netSortType,
|
||||||
|
build: () {
|
||||||
|
final ns = ss.netSpeed;
|
||||||
|
final children = <Widget>[
|
||||||
|
_buildNetSpeedTop(),
|
||||||
|
const Divider(
|
||||||
|
height: 7,
|
||||||
|
)
|
||||||
|
];
|
||||||
|
if (ns.devices.isEmpty) {
|
||||||
|
children.add(Center(
|
||||||
|
child: Text(
|
||||||
|
_s.noInterface,
|
||||||
|
style: const TextStyle(color: Colors.grey, fontSize: 13),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
final devices = ns.devices;
|
||||||
|
devices.sort(_netSortType.value.getSortFunc(ns));
|
||||||
|
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
children: children,
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNetSpeedTop() {
|
Widget _buildNetSpeedTop() {
|
||||||
return const Padding(
|
const icon = Icon(Icons.arrow_downward, size: 17);
|
||||||
padding: EdgeInsets.only(bottom: 3),
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 3),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.device_hub, size: 17),
|
GestureDetector(
|
||||||
Icon(Icons.arrow_downward, size: 17),
|
child: _netSortType.value.isDevice
|
||||||
Icon(Icons.arrow_upward, size: 17),
|
? const Row(
|
||||||
|
children: [
|
||||||
|
Text('Iface'),
|
||||||
|
icon,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const Text('Iface'),
|
||||||
|
onTap: () => _netSortType.value = _NetSortType.device,
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
child: _netSortType.value.isIn
|
||||||
|
? const Row(
|
||||||
|
children: [
|
||||||
|
Text('Recv'),
|
||||||
|
icon,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const Text('Recv'),
|
||||||
|
onTap: () => _netSortType.value = _NetSortType.recv,
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
child: _netSortType.value.isOut
|
||||||
|
? const Row(
|
||||||
|
children: [
|
||||||
|
Text('Trans'),
|
||||||
|
icon,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const Text('Trans'),
|
||||||
|
onTap: () => _netSortType.value = _NetSortType.trans,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -489,3 +529,29 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum _NetSortType {
|
||||||
|
device,
|
||||||
|
trans,
|
||||||
|
recv,
|
||||||
|
;
|
||||||
|
|
||||||
|
bool get isDevice => this == _NetSortType.device;
|
||||||
|
bool get isIn => this == _NetSortType.recv;
|
||||||
|
bool get isOut => this == _NetSortType.trans;
|
||||||
|
|
||||||
|
int Function(String, String) getSortFunc(NetSpeed ns) {
|
||||||
|
switch (this) {
|
||||||
|
case _NetSortType.device:
|
||||||
|
return (b, a) => a.compareTo(b);
|
||||||
|
case _NetSortType.recv:
|
||||||
|
return (b, a) => ns
|
||||||
|
.speedInBytes(ns.deviceIdx(a))
|
||||||
|
.compareTo(ns.speedInBytes(ns.deviceIdx(b)));
|
||||||
|
case _NetSortType.trans:
|
||||||
|
return (b, a) => ns
|
||||||
|
.speedOutBytes(ns.deviceIdx(a))
|
||||||
|
.compareTo(ns.speedOutBytes(ns.deviceIdx(b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user