cache
This commit is contained in:
@@ -560,8 +560,6 @@ class _EditProxiesView extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _EditProxiesViewState extends ConsumerState<_EditProxiesView>
|
class _EditProxiesViewState extends ConsumerState<_EditProxiesView>
|
||||||
with UniqueKeyStateMixin {
|
with UniqueKeyStateMixin {
|
||||||
bool _isComputing = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -579,9 +577,6 @@ class _EditProxiesViewState extends ConsumerState<_EditProxiesView>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleRemove(String proxyName) {
|
void _handleRemove(String proxyName) {
|
||||||
if (_isComputing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ref.read(itemsProvider(key).notifier).update((state) {
|
ref.read(itemsProvider(key).notifier).update((state) {
|
||||||
final newSet = Set.from(state);
|
final newSet = Set.from(state);
|
||||||
newSet.add(proxyName);
|
newSet.add(proxyName);
|
||||||
@@ -593,7 +588,6 @@ class _EditProxiesViewState extends ConsumerState<_EditProxiesView>
|
|||||||
debouncer.call(
|
debouncer.call(
|
||||||
'EditProxiesViewState_handleRealRemove',
|
'EditProxiesViewState_handleRealRemove',
|
||||||
() {
|
() {
|
||||||
_isComputing = true;
|
|
||||||
if (!ref.context.mounted) {
|
if (!ref.context.mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -604,7 +598,6 @@ class _EditProxiesViewState extends ConsumerState<_EditProxiesView>
|
|||||||
return state.copyWith(proxies: newProxies);
|
return state.copyWith(proxies: newProxies);
|
||||||
});
|
});
|
||||||
ref.read(itemsProvider(key).notifier).update((state) => <dynamic>{});
|
ref.read(itemsProvider(key).notifier).update((state) => <dynamic>{});
|
||||||
_isComputing = false;
|
|
||||||
},
|
},
|
||||||
duration: Duration(milliseconds: 1000),
|
duration: Duration(milliseconds: 1000),
|
||||||
);
|
);
|
||||||
@@ -787,21 +780,50 @@ class _AddProxiesView extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
||||||
with UniqueKeyStateMixin {
|
with UniqueKeyStateMixin {
|
||||||
void _handleAdd(String name) {
|
@override
|
||||||
final dismissItem = ref.read(itemProvider(key));
|
void initState() {
|
||||||
if (dismissItem != null) {
|
super.initState();
|
||||||
return;
|
ref.listenManual(itemsProvider('${key}_groups'), (prev, next) {
|
||||||
}
|
if (!SetEquality().equals(prev, next)) {
|
||||||
ref.read(itemProvider(key).notifier).value = name;
|
_handleRealAdd('groups');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ref.listenManual(itemsProvider('${key}_proxies'), (prev, next) {
|
||||||
|
if (!SetEquality().equals(prev, next)) {
|
||||||
|
_handleRealAdd('proxies');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleRealAdd(String name) {
|
void _handleAdd(String name, String scene) {
|
||||||
ref
|
final realKey = '${key}_$scene';
|
||||||
.read(proxyGroupProvider.notifier)
|
ref.read(itemsProvider(realKey).notifier).update((state) {
|
||||||
.update(
|
final newSet = Set.from(state);
|
||||||
(state) => state.copyWith(proxies: [...state.proxies ?? [], name]),
|
newSet.add(name);
|
||||||
);
|
return newSet;
|
||||||
ref.read(itemProvider(key).notifier).value = null;
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleRealAdd(String scene) {
|
||||||
|
debouncer.call(
|
||||||
|
'AddProxiesViewState_handleRealAdd_$scene',
|
||||||
|
() {
|
||||||
|
if (!ref.context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final realKey = '${key}_$scene';
|
||||||
|
final dismissItems = ref.read(itemsProvider(realKey));
|
||||||
|
ref.read(proxyGroupProvider.notifier).update((state) {
|
||||||
|
return state.copyWith(
|
||||||
|
proxies: [...state.proxies ?? [], ...dismissItems],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
ref
|
||||||
|
.read(itemsProvider(realKey).notifier)
|
||||||
|
.update((state) => <dynamic>{});
|
||||||
|
},
|
||||||
|
duration: Duration(milliseconds: 1000),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildItem({
|
Widget _buildItem({
|
||||||
@@ -810,12 +832,10 @@ class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
|||||||
required ItemPosition position,
|
required ItemPosition position,
|
||||||
required bool dismiss,
|
required bool dismiss,
|
||||||
required VoidCallback onAdd,
|
required VoidCallback onAdd,
|
||||||
required VoidCallback onDismissed,
|
|
||||||
}) {
|
}) {
|
||||||
return ExternalDismissible(
|
return ExternalDismissible(
|
||||||
key: ValueKey(title),
|
key: ValueKey(title),
|
||||||
dismiss: dismiss,
|
dismiss: dismiss,
|
||||||
onDismissed: onDismissed,
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||||
child: ItemPositionProvider(
|
child: ItemPositionProvider(
|
||||||
@@ -839,10 +859,11 @@ class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final dismissItem = ref.watch(itemProvider(key));
|
|
||||||
final isBottomSheet =
|
final isBottomSheet =
|
||||||
SheetProvider.of(context)?.type == SheetType.bottomSheet;
|
SheetProvider.of(context)?.type == SheetType.bottomSheet;
|
||||||
final profileId = ProfileIdProvider.of(context)!.profileId;
|
final profileId = ProfileIdProvider.of(context)!.profileId;
|
||||||
|
final dismissGroups = ref.watch(itemsProvider('${key}_groups'));
|
||||||
|
final dismissProxies = ref.watch(itemsProvider('${key}_proxies'));
|
||||||
final allProxiesAndProxyGroups = ref.watch(
|
final allProxiesAndProxyGroups = ref.watch(
|
||||||
clashConfigProvider(profileId).select(
|
clashConfigProvider(profileId).select(
|
||||||
(state) =>
|
(state) =>
|
||||||
@@ -851,17 +872,19 @@ class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
|||||||
);
|
);
|
||||||
final allProxies = allProxiesAndProxyGroups.a;
|
final allProxies = allProxiesAndProxyGroups.a;
|
||||||
final allProxyGroups = allProxiesAndProxyGroups.b;
|
final allProxyGroups = allProxiesAndProxyGroups.b;
|
||||||
final proxyNames = ref.watch(
|
final excludeProxyNames = ref.watch(
|
||||||
proxyGroupProvider.select((state) {
|
proxyGroupProvider.select((state) {
|
||||||
return [...?state.proxies, state.name];
|
return [...?state.proxies, state.name];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
final proxies = allProxies
|
|
||||||
.where((item) => !proxyNames.contains(item.name))
|
|
||||||
.toList();
|
|
||||||
final proxyGroups = allProxyGroups
|
final proxyGroups = allProxyGroups
|
||||||
.where((item) => !proxyNames.contains(item.name))
|
.where((item) => !excludeProxyNames.contains(item.name))
|
||||||
.toList();
|
.toList();
|
||||||
|
final proxies = allProxies
|
||||||
|
.where((item) => !excludeProxyNames.contains(item.name))
|
||||||
|
.toList();
|
||||||
|
final groupNames = proxyGroups.map((item) => item.name).toList();
|
||||||
|
final proxyNames = proxies.map((item) => item.name).toList();
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: isBottomSheet
|
height: isBottomSheet
|
||||||
? appController.viewSize.height * 0.80
|
? appController.viewSize.height * 0.80
|
||||||
@@ -886,20 +909,18 @@ class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
|||||||
SliverList(
|
SliverList(
|
||||||
delegate: SliverChildBuilderDelegate((_, index) {
|
delegate: SliverChildBuilderDelegate((_, index) {
|
||||||
final proxyGroup = proxyGroups[index];
|
final proxyGroup = proxyGroups[index];
|
||||||
final position = ItemPosition.get(
|
final position = ItemPosition.calculateVisualPosition(
|
||||||
index,
|
index,
|
||||||
proxyGroups.length,
|
groupNames,
|
||||||
|
dismissGroups,
|
||||||
);
|
);
|
||||||
return _buildItem(
|
return _buildItem(
|
||||||
title: proxyGroup.name,
|
title: proxyGroup.name,
|
||||||
subtitle: proxyGroup.type.value,
|
subtitle: proxyGroup.type.value,
|
||||||
position: position,
|
position: position,
|
||||||
dismiss: dismissItem == proxyGroup.name,
|
dismiss: dismissGroups.contains(proxyGroup.name),
|
||||||
onAdd: () {
|
onAdd: () {
|
||||||
_handleAdd(proxyGroup.name);
|
_handleAdd(proxyGroup.name, 'groups');
|
||||||
},
|
|
||||||
onDismissed: () {
|
|
||||||
_handleRealAdd(proxyGroup.name);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}, childCount: proxyGroups.length),
|
}, childCount: proxyGroups.length),
|
||||||
@@ -916,20 +937,18 @@ class _AddProxiesViewState extends ConsumerState<_AddProxiesView>
|
|||||||
SliverList(
|
SliverList(
|
||||||
delegate: SliverChildBuilderDelegate((_, index) {
|
delegate: SliverChildBuilderDelegate((_, index) {
|
||||||
final proxy = proxies[index];
|
final proxy = proxies[index];
|
||||||
final position = ItemPosition.get(
|
final position = ItemPosition.calculateVisualPosition(
|
||||||
index,
|
index,
|
||||||
proxies.length,
|
proxyNames,
|
||||||
|
dismissProxies,
|
||||||
);
|
);
|
||||||
return _buildItem(
|
return _buildItem(
|
||||||
title: proxy.name,
|
title: proxy.name,
|
||||||
subtitle: proxy.type,
|
subtitle: proxy.type,
|
||||||
position: position,
|
position: position,
|
||||||
dismiss: dismissItem == proxy.name,
|
dismiss: dismissProxies.contains(proxy.name),
|
||||||
onAdd: () {
|
onAdd: () {
|
||||||
_handleAdd(proxy.name);
|
_handleAdd(proxy.name, 'proxies');
|
||||||
},
|
|
||||||
onDismissed: () {
|
|
||||||
_handleRealAdd(proxy.name);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}, childCount: proxies.length),
|
}, childCount: proxies.length),
|
||||||
|
|||||||
Reference in New Issue
Block a user