feat: Display progress for downloading content
This commit is contained in:
parent
57a5e1c96f
commit
969f1deb48
3 changed files with 46 additions and 4 deletions
|
|
@ -47,6 +47,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
static const double buttonSize = 36;
|
||||
|
||||
AudioPlayerStatus status = AudioPlayerStatus.notDownloaded;
|
||||
double? _downloadProgress;
|
||||
|
||||
late final MatrixState matrix;
|
||||
List<int>? _waveform;
|
||||
|
|
@ -149,7 +150,20 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
|
||||
setState(() => status = AudioPlayerStatus.downloading);
|
||||
try {
|
||||
matrixFile = await widget.event.downloadAndDecryptAttachment();
|
||||
final fileSize = widget.event.content
|
||||
.tryGetMap<String, dynamic>('info')
|
||||
?.tryGet<int>('size');
|
||||
matrixFile = await widget.event.downloadAndDecryptAttachment(
|
||||
onDownloadProgress: fileSize != null && fileSize > 0
|
||||
? (progress) {
|
||||
final progressPercentage = progress / fileSize;
|
||||
setState(() {
|
||||
_downloadProgress =
|
||||
progressPercentage < 1 ? progressPercentage : null;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
);
|
||||
|
||||
if (!kIsWeb) {
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
|
|
@ -320,6 +334,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
? CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: widget.color,
|
||||
value: _downloadProgress,
|
||||
)
|
||||
: InkWell(
|
||||
borderRadius: BorderRadius.circular(64),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
ChewieController? _chewieController;
|
||||
VideoPlayerController? _videoPlayerController;
|
||||
|
||||
double? _downloadProgress;
|
||||
|
||||
// The video_player package only doesn't support Windows and Linux.
|
||||
final _supportsVideoPlayer =
|
||||
!PlatformInfos.isWindows && !PlatformInfos.isLinux;
|
||||
|
|
@ -43,7 +45,20 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
}
|
||||
|
||||
try {
|
||||
final videoFile = await widget.event.downloadAndDecryptAttachment();
|
||||
final fileSize = widget.event.content
|
||||
.tryGetMap<String, dynamic>('info')
|
||||
?.tryGet<int>('size');
|
||||
final videoFile = await widget.event.downloadAndDecryptAttachment(
|
||||
onDownloadProgress: fileSize == null
|
||||
? null
|
||||
: (progress) {
|
||||
final progressPercentage = progress / fileSize;
|
||||
setState(() {
|
||||
_downloadProgress =
|
||||
progressPercentage < 1 ? progressPercentage : null;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Dispose the controllers if we already have them.
|
||||
_disposeControllers();
|
||||
|
|
@ -165,7 +180,11 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
),
|
||||
),
|
||||
),
|
||||
const Center(child: CircularProgressIndicator.adaptive()),
|
||||
Center(
|
||||
child: CircularProgressIndicator.adaptive(
|
||||
value: _downloadProgress,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,15 @@ extension LocalizedBody on Event {
|
|||
Future<async.Result<MatrixFile?>> _getFile(BuildContext context) =>
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: downloadAndDecryptAttachment,
|
||||
futureWithProgress: (onProgress) {
|
||||
final fileSize =
|
||||
infoMap['size'] is int ? infoMap['size'] as int : null;
|
||||
return downloadAndDecryptAttachment(
|
||||
onDownloadProgress: fileSize == null
|
||||
? null
|
||||
: (bytes) => onProgress(bytes / fileSize),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
void saveFile(BuildContext context) async {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue