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;
|
static const double buttonSize = 36;
|
||||||
|
|
||||||
AudioPlayerStatus status = AudioPlayerStatus.notDownloaded;
|
AudioPlayerStatus status = AudioPlayerStatus.notDownloaded;
|
||||||
|
double? _downloadProgress;
|
||||||
|
|
||||||
late final MatrixState matrix;
|
late final MatrixState matrix;
|
||||||
List<int>? _waveform;
|
List<int>? _waveform;
|
||||||
|
|
@ -149,7 +150,20 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
|
|
||||||
setState(() => status = AudioPlayerStatus.downloading);
|
setState(() => status = AudioPlayerStatus.downloading);
|
||||||
try {
|
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) {
|
if (!kIsWeb) {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
|
@ -320,6 +334,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
? CircularProgressIndicator(
|
? CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
color: widget.color,
|
color: widget.color,
|
||||||
|
value: _downloadProgress,
|
||||||
)
|
)
|
||||||
: InkWell(
|
: InkWell(
|
||||||
borderRadius: BorderRadius.circular(64),
|
borderRadius: BorderRadius.circular(64),
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
ChewieController? _chewieController;
|
ChewieController? _chewieController;
|
||||||
VideoPlayerController? _videoPlayerController;
|
VideoPlayerController? _videoPlayerController;
|
||||||
|
|
||||||
|
double? _downloadProgress;
|
||||||
|
|
||||||
// The video_player package only doesn't support Windows and Linux.
|
// The video_player package only doesn't support Windows and Linux.
|
||||||
final _supportsVideoPlayer =
|
final _supportsVideoPlayer =
|
||||||
!PlatformInfos.isWindows && !PlatformInfos.isLinux;
|
!PlatformInfos.isWindows && !PlatformInfos.isLinux;
|
||||||
|
|
@ -43,7 +45,20 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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.
|
// Dispose the controllers if we already have them.
|
||||||
_disposeControllers();
|
_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) =>
|
Future<async.Result<MatrixFile?>> _getFile(BuildContext context) =>
|
||||||
showFutureLoadingDialog(
|
showFutureLoadingDialog(
|
||||||
context: context,
|
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 {
|
void saveFile(BuildContext context) async {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue