Files
umbrix/lib/features/proxy/active/active_proxy_footer.dart

177 lines
6.2 KiB
Dart
Raw Normal View History

2024-02-09 12:02:52 +03:30
import 'package:dartx/dartx.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/widget/animated_visibility.dart';
2024-02-11 00:29:09 +03:30
import 'package:hiddify/core/widget/shimmer_skeleton.dart';
2024-02-09 12:02:52 +03:30
import 'package:hiddify/features/proxy/active/active_proxy_notifier.dart';
2024-02-11 00:29:09 +03:30
import 'package:hiddify/features/proxy/active/ip_widget.dart';
2024-02-17 14:49:44 +03:30
import 'package:hiddify/features/proxy/model/proxy_failure.dart';
2024-02-09 12:02:52 +03:30
import 'package:hiddify/features/stats/notifier/stats_notifier.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ActiveProxyFooter extends HookConsumerWidget {
const ActiveProxyFooter({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
2024-02-13 16:59:35 +03:30
final activeProxy = ref.watch(activeProxyNotifierProvider);
final ipInfo = ref.watch(ipInfoNotifierProvider);
2024-02-09 12:02:52 +03:30
return AnimatedVisibility(
axis: Axis.vertical,
2024-02-13 16:59:35 +03:30
visible: activeProxy is AsyncData,
child: switch (activeProxy) {
AsyncData(value: final proxy) => Padding(
2024-02-09 12:02:52 +03:30
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_InfoProp(
2024-02-11 00:29:09 +03:30
icon: FluentIcons.arrow_routing_20_regular,
2024-02-13 16:59:35 +03:30
text: proxy.selectedName.isNotNullOrBlank
? proxy.selectedName!
: proxy.name,
2024-02-13 18:49:58 +03:30
semanticLabel: t.proxies.activeProxySemanticLabel,
2024-02-09 12:02:52 +03:30
),
const Gap(8),
2024-02-13 16:59:35 +03:30
switch (ipInfo) {
AsyncData(value: final info) => Row(
2024-02-11 00:29:09 +03:30
children: [
2024-02-13 16:59:35 +03:30
IPCountryFlag(countryCode: info.countryCode),
2024-02-11 00:29:09 +03:30
const Gap(8),
IPText(
2024-02-13 16:59:35 +03:30
ip: info.ip,
2024-02-11 00:29:09 +03:30
onLongPress: () async {
ref
2024-02-13 16:59:35 +03:30
.read(ipInfoNotifierProvider.notifier)
.refresh();
2024-02-11 00:29:09 +03:30
},
),
],
2024-02-09 12:02:52 +03:30
),
2024-02-17 14:49:44 +03:30
AsyncError(error: final UnknownIp _) => Row(
children: [
const Icon(FluentIcons.arrow_sync_20_regular),
const Gap(8),
UnknownIPText(
text: t.proxies.checkIp,
onTap: () async {
ref
.read(ipInfoNotifierProvider.notifier)
.refresh();
},
),
],
),
2024-02-17 12:32:11 +03:30
AsyncError() => Row(
children: [
const Icon(FluentIcons.error_circle_20_regular),
const Gap(8),
2024-02-17 14:49:44 +03:30
UnknownIPText(
text: t.proxies.unknownIp,
onTap: () async {
2024-02-17 12:32:11 +03:30
ref
.read(ipInfoNotifierProvider.notifier)
.refresh();
},
),
],
2024-02-09 12:02:52 +03:30
),
2024-02-11 00:29:09 +03:30
_ => const Row(
children: [
Icon(FluentIcons.question_circle_20_regular),
Gap(8),
Flexible(
child: ShimmerSkeleton(
height: 16,
widthFactor: 1,
),
),
],
2024-02-09 12:02:52 +03:30
),
},
],
),
),
2024-02-12 18:39:51 +03:30
const _StatsColumn(),
2024-02-09 12:02:52 +03:30
],
),
),
_ => const SizedBox(),
},
);
}
}
2024-02-12 18:39:51 +03:30
class _StatsColumn extends HookConsumerWidget {
const _StatsColumn();
@override
Widget build(BuildContext context, WidgetRef ref) {
2024-02-13 18:49:58 +03:30
final t = ref.watch(translationsProvider);
2024-02-12 18:39:51 +03:30
final stats = ref.watch(statsNotifierProvider).value;
return Directionality(
textDirection: TextDirection.values[
(Directionality.of(context).index + 1) % TextDirection.values.length],
child: Flexible(
child: Column(
children: [
_InfoProp(
icon: FluentIcons.arrow_bidirectional_up_down_20_regular,
text: (stats?.downlinkTotal ?? 0).size(),
2024-02-13 18:49:58 +03:30
semanticLabel: t.proxies.statsSemantics.totalTransferred,
2024-02-12 18:39:51 +03:30
),
const Gap(8),
_InfoProp(
icon: FluentIcons.arrow_download_20_regular,
text: (stats?.downlink ?? 0).speed(),
2024-02-13 18:49:58 +03:30
semanticLabel: t.proxies.statsSemantics.speed,
2024-02-12 18:39:51 +03:30
),
],
),
),
);
}
}
2024-02-09 12:02:52 +03:30
class _InfoProp extends StatelessWidget {
2024-02-11 00:29:09 +03:30
const _InfoProp({
required this.icon,
required this.text,
2024-02-13 18:49:58 +03:30
this.semanticLabel,
2024-02-11 00:29:09 +03:30
});
2024-02-09 12:02:52 +03:30
2024-02-11 00:29:09 +03:30
final IconData icon;
final String text;
2024-02-13 18:49:58 +03:30
final String? semanticLabel;
2024-02-09 12:02:52 +03:30
@override
Widget build(BuildContext context) {
2024-02-13 18:49:58 +03:30
return Semantics(
label: semanticLabel,
child: Row(
children: [
Icon(icon),
const Gap(8),
Flexible(
child: Text(
text,
style: Theme.of(context).textTheme.labelMedium,
overflow: TextOverflow.ellipsis,
),
2024-02-11 00:29:09 +03:30
),
2024-02-13 18:49:58 +03:30
],
),
2024-02-09 12:02:52 +03:30
);
}
}