From 60e822cf12ea8fd8727883b88316df9690eaa581 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 6 Jul 2022 12:14:40 -0700 Subject: [PATCH] Android + Time out Resume Logic so files can be requested again --- lib/models/filedownloadprogress.dart | 2 ++ lib/models/profile.dart | 17 ++++++++++++++++- lib/views/messageview.dart | 6 ++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/models/filedownloadprogress.dart b/lib/models/filedownloadprogress.dart index 0a4394af..9212f379 100644 --- a/lib/models/filedownloadprogress.dart +++ b/lib/models/filedownloadprogress.dart @@ -7,8 +7,10 @@ class FileDownloadProgress { String? downloadedTo; DateTime? timeStart; DateTime? timeEnd; + DateTime? requested; FileDownloadProgress(this.chunksTotal, this.timeStart); + double progress() { return 1.0 * chunksDownloaded / chunksTotal; } diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 9f53286a..f67179cc 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -291,12 +291,27 @@ class ProfileInfoState extends ChangeNotifier { } bool downloadInterrupted(String fileKey) { - return this._downloads.containsKey(fileKey) && this._downloads[fileKey]!.interrupted; + if (this._downloads.containsKey(fileKey)) { + if (this._downloads[fileKey]!.interrupted) { + return true; + } + + if (this._downloads[fileKey]!.requested != null) { + if (DateTime.now().difference(this._downloads[fileKey]!.requested!) > Duration(minutes: 1)) { + this._downloads[fileKey]!.requested = null; + this._downloads[fileKey]!.interrupted = true; + return true; + } + } + } + + return false; } void downloadMarkResumed(String fileKey) { if (this._downloads.containsKey(fileKey)) { this._downloads[fileKey]!.interrupted = false; + this._downloads[fileKey]!.requested = DateTime.now(); notifyListeners(); } } diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index b4991b55..dc711bf9 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -99,8 +99,10 @@ class _MessageViewState extends State { var showFileSharing = Provider.of(context).isExperimentEnabled(FileSharingExperiment); var appBarButtons = []; - appBarButtons.add( - IconButton(splashRadius: Material.defaultSplashRadius / 2, icon: Icon(Icons.folder_shared), tooltip: AppLocalizations.of(context)!.conversationSettings, onPressed: _pushFileSharingSettings)); + if (showFileSharing) { + appBarButtons.add(IconButton( + splashRadius: Material.defaultSplashRadius / 2, icon: Icon(Icons.folder_shared), tooltip: AppLocalizations.of(context)!.conversationSettings, onPressed: _pushFileSharingSettings)); + } if (Provider.of(context).isOnline()) { if (showFileSharing) {