From 792f3578b982daa8ac56ef0adafff6ef01ff36e4 Mon Sep 17 00:00:00 2001 From: Bruno D'Luka Date: Mon, 14 Aug 2023 16:10:29 -0300 Subject: [PATCH] fix: if event is downloaded, use the download path --- .../desktop/timeline_sidebar.dart | 4 ++-- .../events_timeline/events_playback.dart | 17 ++++++++++++++--- .../mobile/timeline_device_view.dart | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/widgets/events_timeline/desktop/timeline_sidebar.dart b/lib/widgets/events_timeline/desktop/timeline_sidebar.dart index 3f8baeb3..b1475e2b 100644 --- a/lib/widgets/events_timeline/desktop/timeline_sidebar.dart +++ b/lib/widgets/events_timeline/desktop/timeline_sidebar.dart @@ -146,7 +146,7 @@ class _TimelineSidebarState extends State { widget.timeline.add([ state.realDevices.entries .firstWhere((e) => e.key == device) - .buildTimelineTile(), + .buildTimelineTile(context), ]); } } @@ -202,7 +202,7 @@ class _TimelineSidebarState extends State { widget.timeline.add([ state.realDevices.entries .firstWhere((e) => e.key == device) - .buildTimelineTile(), + .buildTimelineTile(context), ]); } setState(() {}); diff --git a/lib/widgets/events_timeline/events_playback.dart b/lib/widgets/events_timeline/events_playback.dart index d2addd49..42414f66 100644 --- a/lib/widgets/events_timeline/events_playback.dart +++ b/lib/widgets/events_timeline/events_playback.dart @@ -17,9 +17,12 @@ * along with this program. If not, see . */ +import 'dart:io'; + import 'package:bluecherry_client/api/api.dart'; import 'package:bluecherry_client/models/device.dart'; import 'package:bluecherry_client/models/event.dart'; +import 'package:bluecherry_client/providers/downloads_provider.dart'; import 'package:bluecherry_client/providers/home_provider.dart'; import 'package:bluecherry_client/providers/server_provider.dart'; import 'package:bluecherry_client/utils/constants.dart'; @@ -172,7 +175,7 @@ class _EventsPlaybackState extends State { final parsedTiles = devices.entries .where((e) => e.value.isNotEmpty) - .map((e) => e.buildTimelineTile()); + .map((e) => e.buildTimelineTile(context)); home.notLoading(UnityLoadingReason.fetchingEventsPlayback); @@ -253,7 +256,7 @@ class _EventsPlaybackState extends State { } extension DevicesMapExtension on MapEntry> { - TimelineTile buildTimelineTile() { + TimelineTile buildTimelineTile(BuildContext context) { final device = key; final events = value; debugPrint('Loaded ${events.length} events for $device'); @@ -261,10 +264,18 @@ extension DevicesMapExtension on MapEntry> { return TimelineTile( device: device, events: events.map((event) { + final downloads = context.read(); + final mediaUrl = downloads.isEventDownloaded(event.id) + ? Uri.file( + downloads.getDownloadedPathForEvent(event.id), + windows: Platform.isWindows, + ).toString() + : event.mediaURL!.toString(); + return TimelineEvent( startTime: event.published, duration: event.duration, - videoUrl: event.mediaURL!.toString(), + videoUrl: mediaUrl, event: event, ); }).toList(), diff --git a/lib/widgets/events_timeline/mobile/timeline_device_view.dart b/lib/widgets/events_timeline/mobile/timeline_device_view.dart index 1a157018..d5d9b2e9 100644 --- a/lib/widgets/events_timeline/mobile/timeline_device_view.dart +++ b/lib/widgets/events_timeline/mobile/timeline_device_view.dart @@ -316,7 +316,7 @@ class _TimelineDeviceViewState extends State { } return UnityVideoView( - heroTag: currentEvent!.event.mediaURL, + heroTag: currentEvent!.videoUrl, player: tile.videoController, paneBuilder: !kDebugMode ? null