💄 Optimize task overlay

This commit is contained in:
2026-01-11 13:22:13 +08:00
parent 88c4d648d5
commit 826238a374
2 changed files with 41 additions and 57 deletions

View File

@@ -1587,5 +1587,10 @@
"fediversePostDescribe": "Post from the Fediverse Network", "fediversePostDescribe": "Post from the Fediverse Network",
"settingsShowFediverseContent": "Show Fediverse Content", "settingsShowFediverseContent": "Show Fediverse Content",
"universalSearch": "Universal Search", "universalSearch": "Universal Search",
"universalSearchDescription": "Search content across the Solar Network and the fediverse network." "universalSearchDescription": "Search content across the Solar Network and the fediverse network.",
"tasks": "Tasks",
"tasksCount": {
"one": "{} task",
"other": "{} tasks"
}
} }

View File

@@ -74,9 +74,9 @@ class TaskOverlay extends HookConsumerWidget {
final isDesktop = isWideScreen(context); final isDesktop = isWideScreen(context);
// Auto-compact timer for mobile when expanded // Auto-compact timer for mobile when not expanded
useEffect(() { useEffect(() {
if (!isDesktop && !isCompactLocal.value) { if (!isDesktop && !isCompactLocal.value && !isExpandedLocal.value) {
// Start timer to auto-compact after 5 seconds // Start timer to auto-compact after 5 seconds
autoCompactTimer.value?.cancel(); autoCompactTimer.value?.cancel();
autoCompactTimer.value = Timer(const Duration(seconds: 5), () { autoCompactTimer.value = Timer(const Duration(seconds: 5), () {
@@ -87,7 +87,7 @@ class TaskOverlay extends HookConsumerWidget {
autoCompactTimer.value = null; autoCompactTimer.value = null;
} }
return null; return null;
}, [isCompactLocal.value, isDesktop]); }, [isCompactLocal.value, isExpandedLocal.value, isDesktop]);
final isVisible = final isVisible =
(isVisibleOverride.value ?? activeTasks.isNotEmpty) && (isVisibleOverride.value ?? activeTasks.isNotEmpty) &&
!pendingHide.value; !pendingHide.value;
@@ -438,58 +438,47 @@ class _TaskOverlayContent extends HookConsumerWidget {
color: Colors.transparent, color: Colors.transparent,
child: CustomScrollView( child: CustomScrollView(
slivers: [ slivers: [
// Clear completed tasks button SliverToBoxAdapter(
if (_hasCompletedTasks(activeTasks)) child: ListTile(
SliverToBoxAdapter( dense: true,
child: ListTile( contentPadding: const EdgeInsets.only(
dense: true, left: 18,
title: const Text( right: 16,
'clearCompleted',
).tr(),
leading: Icon(
Symbols.clear_all,
size: 18,
color: Theme.of(
context,
).colorScheme.onSurfaceVariant,
),
onTap: () {
taskNotifier.clearCompletedTasks();
onExpansionChanged?.call(false);
},
tileColor: Theme.of(
context,
).colorScheme.surfaceContainerHighest,
), ),
), title: const Text(
'clearCompleted',
// Clear all tasks button ).tr(),
if (activeTasks.any( leading: Icon(
(task) => Symbols.clear_all,
task.status != size: 18,
DriveTaskStatus.completed, color: Theme.of(
)) context,
SliverToBoxAdapter( ).colorScheme.onSurfaceVariant,
child: ListTile( ),
dense: true, onTap: () {
title: const Text('Clear All'), taskNotifier.clearCompletedTasks();
leading: Icon( onExpansionChanged?.call(false);
Symbols.clear_all, },
trailing: IconButton(
tooltip: 'clearAll'.tr(),
icon: Icon(
Symbols.close,
size: 18, size: 18,
color: Theme.of( color: Theme.of(
context, context,
).colorScheme.error, ).colorScheme.error,
), ),
onTap: () { padding: EdgeInsets.zero,
onPressed: () {
taskNotifier.clearAllTasks(); taskNotifier.clearAllTasks();
onExpansionChanged?.call(false); onExpansionChanged?.call(false);
}, },
tileColor: Theme.of(
context,
).colorScheme.surfaceContainerHighest,
), ),
tileColor: Theme.of(
context,
).colorScheme.surfaceContainerHighest,
), ),
),
// Task list // Task list
SliverList( SliverList(
@@ -618,7 +607,7 @@ class _TaskOverlayContent extends HookConsumerWidget {
} }
String _getOverallStatusText(List<DriveTask> tasks) { String _getOverallStatusText(List<DriveTask> tasks) {
if (tasks.isEmpty) return '0 tasks'; if (tasks.isEmpty) return 'tasks'.plural(0);
final hasDownload = tasks.any((task) => task.type == 'FileDownload'); final hasDownload = tasks.any((task) => task.type == 'FileDownload');
final hasInProgress = tasks.any( final hasInProgress = tasks.any(
@@ -656,20 +645,10 @@ class _TaskOverlayContent extends HookConsumerWidget {
} else if (hasCompleted) { } else if (hasCompleted) {
return '${tasks.length} ${'completed'.tr()}'; return '${tasks.length} ${'completed'.tr()}';
} else { } else {
return '${tasks.length} ${'tasks'.tr()}'; return 'tasks'.plural(tasks.length);
} }
} }
bool _hasCompletedTasks(List<DriveTask> tasks) {
return tasks.any(
(task) =>
task.status == DriveTaskStatus.completed ||
task.status == DriveTaskStatus.failed ||
task.status == DriveTaskStatus.cancelled ||
task.status == DriveTaskStatus.expired,
);
}
double _getCompactWidth(List<DriveTask> tasks) { double _getCompactWidth(List<DriveTask> tasks) {
// Base width for icon and padding // Base width for icon and padding
double width = 16 + 12 + 12; // icon size + padding + spacing double width = 16 + 12 + 12; // icon size + padding + spacing