Skip to content

Commit

Permalink
TW-1561: refactor: create checkFileInDownloadsInApp method
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Apr 1, 2024
1 parent 5175e2a commit 56055c3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/pages/chat/events/message_download_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@ class _MessageDownloadContentState extends State<MessageDownloadContent>

void checkDownloadFileState() async {
checkFileExistInMemory();
final filePath = await StorageDirectoryUtils.instance.getFilePathInAppDownloads(
eventId: widget.event.eventId,
fileName: widget.event.filename,
);
final file = File(filePath);
if (await file.exists() &&
await file.length() == widget.event.getFileSize()) {
downloadFileStateNotifier.value = DownloadedPresentationState(
filePath: filePath,
);
return;
}
await checkFileInDownloadsInApp();

_trySetupDownloadingStreamSubcription();
if (streamSubscription != null) {
Expand All @@ -80,6 +69,22 @@ class _MessageDownloadContentState extends State<MessageDownloadContent>
}
}

Future<void> checkFileInDownloadsInApp() async {
final filePath =
await StorageDirectoryUtils.instance.getFilePathInAppDownloads(
eventId: widget.event.eventId,
fileName: widget.event.filename,
);
final file = File(filePath);
if (await file.exists() &&
await file.length() == widget.event.getFileSize()) {
downloadFileStateNotifier.value = DownloadedPresentationState(
filePath: filePath,
);
return;
}
}

void _trySetupDownloadingStreamSubcription() {
streamSubscription = downloadManager
.getDownloadStateStream(widget.event.eventId)
Expand Down

0 comments on commit 56055c3

Please sign in to comment.