feat: Show progress bar and sync status

This commit is contained in:
Christian Pauly 2021-06-22 15:46:52 +02:00
parent bddbcdf7bc
commit 972538b624
4 changed files with 36 additions and 20 deletions

View File

@ -1114,6 +1114,11 @@
"type": "text",
"placeholders": {}
},
"synchronizingPleaseWait": "Synchronizing… Please wait.",
"@synchronizingPleaseWait": {
"type": "text",
"placeholders": {}
},
"loadMore": "Load more…",
"@loadMore": {
"type": "text",

View File

@ -19,7 +19,7 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
_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<ConnectionStatusHeader> {
@override
Widget build(BuildContext context) {
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
(_) => setState(
_onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen(
(status) => setState(
() {
if (status.status == SyncStatus.finished) {
_lastSyncReceived = DateTime.now();
_error = null;
},
),
);
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
(error) => setState(
() {
_lastSyncReceived = DateTime(0);
_error = error;
}
_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<ConnectionStatusHeader> {
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<ConnectionStatusHeader> {
);
}
}
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;
}
}
}

View File

@ -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:

View File

@ -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: