Change proxies page
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/domain/failures.dart';
|
||||
import 'package:hiddify/features/common/common.dart';
|
||||
@@ -10,7 +9,6 @@ import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
// TODO: rewrite, bugs with scroll
|
||||
class ProxiesPage extends HookConsumerWidget with PresLogger {
|
||||
const ProxiesPage({super.key});
|
||||
|
||||
@@ -18,9 +16,8 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
final notifier = ref.watch(proxiesNotifierProvider.notifier);
|
||||
final asyncProxies = ref.watch(proxiesNotifierProvider);
|
||||
final proxies = asyncProxies.asData?.value ?? [];
|
||||
final notifier = ref.watch(proxiesNotifierProvider.notifier);
|
||||
final delays = ref.watch(proxiesDelayNotifierProvider);
|
||||
|
||||
final selectActiveProxyMutation = useMutation(
|
||||
@@ -28,14 +25,9 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
||||
CustomToast.error(t.presentError(error)).show(context),
|
||||
);
|
||||
|
||||
final tabController = useTabController(
|
||||
initialLength: proxies.length,
|
||||
keys: [proxies.length],
|
||||
);
|
||||
|
||||
switch (asyncProxies) {
|
||||
case AsyncData(value: final proxies):
|
||||
if (proxies.isEmpty) {
|
||||
case AsyncData(value: final groups):
|
||||
if (groups.isEmpty) {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
@@ -55,101 +47,93 @@ class ProxiesPage extends HookConsumerWidget with PresLogger {
|
||||
);
|
||||
}
|
||||
|
||||
final tabs = [
|
||||
for (final groupWithProxies in proxies)
|
||||
Tab(
|
||||
child: Text(
|
||||
groupWithProxies.group.name.toUpperCase(),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).appBarTheme.foregroundColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
];
|
||||
final select = groups.first;
|
||||
|
||||
final tabViews = [
|
||||
for (final groupWithProxies in proxies)
|
||||
SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return CustomScrollView(
|
||||
key: PageStorageKey<String>(
|
||||
groupWithProxies.group.name,
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
NestedTabAppBar(
|
||||
title: Text(t.proxies.pageTitle.titleCase),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (_) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
onTap: ref
|
||||
.read(proxiesDelayNotifierProvider.notifier)
|
||||
.cancelDelayTest,
|
||||
child: Text(
|
||||
t.proxies.cancelTestButtonText.sentenceCase,
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
SliverLayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.crossAxisExtent;
|
||||
if (!PlatformUtils.isDesktop && width < 648) {
|
||||
return SliverList.builder(
|
||||
itemBuilder: (_, index) {
|
||||
final proxy = select.proxies[index];
|
||||
return ProxyTile(
|
||||
proxy,
|
||||
selected: select.group.now == proxy.name,
|
||||
delay: delays[proxy.name],
|
||||
onSelect: () async {
|
||||
if (selectActiveProxyMutation.state.isInProgress) {
|
||||
return;
|
||||
}
|
||||
selectActiveProxyMutation.setFuture(
|
||||
notifier.changeProxy(
|
||||
select.group.name,
|
||||
proxy.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: select.proxies.length,
|
||||
);
|
||||
}
|
||||
|
||||
return SliverGrid.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: (width / 268).floor(),
|
||||
mainAxisExtent: 68,
|
||||
),
|
||||
slivers: <Widget>[
|
||||
SliverList.builder(
|
||||
itemBuilder: (_, index) {
|
||||
final proxy = groupWithProxies.proxies[index];
|
||||
return ProxyTile(
|
||||
proxy,
|
||||
selected: groupWithProxies.group.now == proxy.name,
|
||||
delay: delays[proxy.name],
|
||||
onSelect: () async {
|
||||
if (selectActiveProxyMutation
|
||||
.state.isInProgress) {
|
||||
return;
|
||||
}
|
||||
selectActiveProxyMutation.setFuture(
|
||||
notifier.changeProxy(
|
||||
groupWithProxies.group.name,
|
||||
proxy.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, index) {
|
||||
final proxy = select.proxies[index];
|
||||
return ProxyTile(
|
||||
proxy,
|
||||
selected: select.group.now == proxy.name,
|
||||
delay: delays[proxy.name],
|
||||
onSelect: () async {
|
||||
if (selectActiveProxyMutation.state.isInProgress) {
|
||||
return;
|
||||
}
|
||||
selectActiveProxyMutation.setFuture(
|
||||
notifier.changeProxy(
|
||||
select.group.name,
|
||||
proxy.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: groupWithProxies.proxies.length,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
itemCount: select.proxies.length,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return <Widget>[
|
||||
NestedTabAppBar(
|
||||
title: Text(t.proxies.pageTitle.titleCase),
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (_) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
onTap: ref
|
||||
.read(proxiesDelayNotifierProvider.notifier)
|
||||
.cancelDelayTest,
|
||||
child: Text(
|
||||
t.proxies.cancelTestButtonText.sentenceCase,
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
],
|
||||
bottom: TabBar(
|
||||
controller: tabController,
|
||||
isScrollable: true,
|
||||
tabs: tabs,
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
body: TabBarView(
|
||||
controller: tabController,
|
||||
children: tabViews,
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () async =>
|
||||
// TODO: improve
|
||||
ref.read(proxiesDelayNotifierProvider.notifier).testDelay(
|
||||
proxies[tabController.index].proxies.map((e) => e.name),
|
||||
select.proxies.map((e) => e.name),
|
||||
),
|
||||
tooltip: t.proxies.delayTestTooltip.titleCase,
|
||||
child: const Icon(Icons.bolt),
|
||||
|
||||
Reference in New Issue
Block a user