From 777a27c60e87dffb8817f21a9e4b181637335155 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 22 Jun 2021 15:46:52 +0200 Subject: [PATCH] feat: Show progress bar and sync status --- assets/l10n/intl_en.arb | 5 +++ lib/widgets/connection_status_header.dart | 47 ++++++++++++++--------- pubspec.lock | 2 +- pubspec.yaml | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 094405b5..01914b16 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -1114,6 +1114,11 @@ "type": "text", "placeholders": {} }, + "synchronizingPleaseWait": "Synchronizing… Please wait.", + "@synchronizingPleaseWait": { + "type": "text", + "placeholders": {} + }, "loadMore": "Load more…", "@loadMore": { "type": "text", diff --git a/lib/widgets/connection_status_header.dart b/lib/widgets/connection_status_header.dart index 36101024..c30037ae 100644 --- a/lib/widgets/connection_status_header.dart +++ b/lib/widgets/connection_status_header.dart @@ -19,7 +19,7 @@ class _ConnectionStatusHeaderState extends State { _lastSyncReceived.millisecondsSinceEpoch < 1000 * 30; static DateTime _lastSyncReceived = DateTime(0); - SdkError _error; + SyncStatusUpdate _status = SyncStatusUpdate(SyncStatus.waitingForResponse); @override void dispose() { @@ -30,25 +30,19 @@ class _ConnectionStatusHeaderState extends State { @override Widget build(BuildContext context) { - _onSyncSub ??= Matrix.of(context).client.onSync.stream.listen( - (_) => setState( + _onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen( + (status) => setState( () { - _lastSyncReceived = DateTime.now(); - _error = null; - }, - ), - ); - _onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen( - (error) => setState( - () { - _lastSyncReceived = DateTime(0); - _error = error; + if (status.status == SyncStatus.finished) { + _lastSyncReceived = DateTime.now(); + } + _status = status; }, ), ); return AnimatedContainer( - duration: Duration(milliseconds: 250), + duration: Duration(milliseconds: 200), curve: Curves.bounceInOut, height: _connected ? 0 : 36, clipBehavior: Clip.hardEdge, @@ -60,13 +54,14 @@ class _ConnectionStatusHeaderState extends State { SizedBox( width: 24, height: 24, - child: CircularProgressIndicator(strokeWidth: 2), + child: CircularProgressIndicator( + strokeWidth: 2, + value: _status.progress, + ), ), SizedBox(width: 12), Text( - _error != null - ? (_error.exception as Object).toLocalizedString(context) - : L10n.of(context).loadingPleaseWait, + _status.toLocalizedString(context), maxLines: 1, overflow: TextOverflow.ellipsis, ), @@ -75,3 +70,19 @@ class _ConnectionStatusHeaderState extends State { ); } } + +extension on SyncStatusUpdate { + String toLocalizedString(BuildContext context) { + switch (status) { + case SyncStatus.waitingForResponse: + return L10n.of(context).loadingPleaseWait; + case SyncStatus.error: + return (error.exception as Object).toLocalizedString(context); + case SyncStatus.processing: + case SyncStatus.cleaningUp: + case SyncStatus.finished: + default: + return L10n.of(context).synchronizingPleaseWait; + } + } +} diff --git a/pubspec.lock b/pubspec.lock index a78edb68..80d0987c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -589,7 +589,7 @@ packages: name: matrix url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" matrix_api_lite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5231bc59..2124f1da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: image_picker: ^0.7.4 intl: any localstorage: ^4.0.0+1 - matrix: ^0.1.3 + matrix: ^0.1.4 mime_type: ^1.0.0 moor: ^4.2.1 native_imaging: