From 0d118f2161af822a7e3d868e8cc7a0092331117f Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:30:18 +0200 Subject: [PATCH] fix: Fix task being identified as a quick share --- .../ActiveSharesSheet.dart | 3 +-- .../locations_overview_screen_widgets/TaskTile.dart | 3 +-- lib/services/task_service/task.dart | 13 +++++++++---- lib/services/task_service/task_service.dart | 11 ++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/screens/locations_overview_screen_widgets/ActiveSharesSheet.dart b/lib/screens/locations_overview_screen_widgets/ActiveSharesSheet.dart index 0acf0f80..a5bcdbc8 100644 --- a/lib/screens/locations_overview_screen_widgets/ActiveSharesSheet.dart +++ b/lib/screens/locations_overview_screen_widgets/ActiveSharesSheet.dart @@ -160,8 +160,7 @@ class _ActiveSharesSheetState extends State Iterable get quickShareTasks { final taskService = context.read(); - return taskService.tasks - .where((task) => task.deleteAfterRun && task.timers.length <= 1); + return taskService.tasks.where((task) => task.isQuickShare); } Future getAreSomeTasksRunning() async { diff --git a/lib/screens/locations_overview_screen_widgets/TaskTile.dart b/lib/screens/locations_overview_screen_widgets/TaskTile.dart index 111d4d6c..9ebf0395 100644 --- a/lib/screens/locations_overview_screen_widgets/TaskTile.dart +++ b/lib/screens/locations_overview_screen_widgets/TaskTile.dart @@ -76,8 +76,7 @@ class _TaskTileState extends State with TaskLinkGenerationMixin { return PlatformListTile( title: Text(widget.task.name), - subtitle: widget.task.timers.length == 1 && - widget.task.timers[0] is DurationTimer && + subtitle: widget.task.isFiniteQuickShare && (widget.task.timers[0] as DurationTimer).startDate != null ? Text( formatStartDate( diff --git a/lib/services/task_service/task.dart b/lib/services/task_service/task.dart index 2539ac6b..c5b911e0 100644 --- a/lib/services/task_service/task.dart +++ b/lib/services/task_service/task.dart @@ -137,10 +137,8 @@ class Task extends ChangeNotifier with LocationBase { ); } - TaskCryptography get cryptography => TaskCryptography( - this, - _encryptionPassword, - ); + TaskCryptography get cryptography => + TaskCryptography(this, _encryptionPassword); TaskPublisher get publisher => TaskPublisher(this); @@ -372,6 +370,13 @@ class Task extends ChangeNotifier with LocationBase { limit: limit, ); + bool get isQuickShare => isInfiniteQuickShare || isFiniteQuickShare; + + bool get isInfiniteQuickShare => deleteAfterRun && timers.isEmpty; + + bool get isFiniteQuickShare => + deleteAfterRun && timers.length == 1 && timers[0] is DurationTimer; + @override void dispose() { _encryptionPassword.destroy(); diff --git a/lib/services/task_service/task_service.dart b/lib/services/task_service/task_service.dart index 548b3b9e..68eda81e 100644 --- a/lib/services/task_service/task_service.dart +++ b/lib/services/task_service/task_service.dart @@ -50,7 +50,7 @@ class TaskService extends ChangeNotifier { // await all `toJson` functions final data = await Future.wait>( _tasks.map( - (task) => task.toJSON(), + (task) => task.toJSON(), ), ); @@ -102,13 +102,14 @@ class TaskService extends ChangeNotifier { for (final task in tasks) { final isRunning = await task.isRunning(); final shouldRun = await task.shouldRunNow(); - final isQuickShare = task.deleteAfterRun && - task.timers.length == 1 && - task.timers[0] is DurationTimer; - if (isQuickShare) { + if (task.isInfiniteQuickShare) { + // Infinite quick shares are completely user controlled. + // Nothing to do here. + } else if (task.isFiniteQuickShare) { final durationTimer = task.timers[0] as DurationTimer; + // Time is over, remove task. if (durationTimer.startDate != null && !shouldRun) { FlutterLogs.logInfo(LOG_TAG, "Task Service", "Removing task.");