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", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"synchronizingPleaseWait": "Synchronizing… Please wait.",
"@synchronizingPleaseWait": {
"type": "text",
"placeholders": {}
},
"loadMore": "Load more…", "loadMore": "Load more…",
"@loadMore": { "@loadMore": {
"type": "text", "type": "text",

View File

@ -19,7 +19,7 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
_lastSyncReceived.millisecondsSinceEpoch < _lastSyncReceived.millisecondsSinceEpoch <
1000 * 30; 1000 * 30;
static DateTime _lastSyncReceived = DateTime(0); static DateTime _lastSyncReceived = DateTime(0);
SdkError _error; SyncStatusUpdate _status = SyncStatusUpdate(SyncStatus.waitingForResponse);
@override @override
void dispose() { void dispose() {
@ -30,25 +30,19 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen( _onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen(
(_) => setState( (status) => setState(
() { () {
if (status.status == SyncStatus.finished) {
_lastSyncReceived = DateTime.now(); _lastSyncReceived = DateTime.now();
_error = null; }
}, _status = status;
),
);
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
(error) => setState(
() {
_lastSyncReceived = DateTime(0);
_error = error;
}, },
), ),
); );
return AnimatedContainer( return AnimatedContainer(
duration: Duration(milliseconds: 250), duration: Duration(milliseconds: 200),
curve: Curves.bounceInOut, curve: Curves.bounceInOut,
height: _connected ? 0 : 36, height: _connected ? 0 : 36,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
@ -60,13 +54,14 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
SizedBox( SizedBox(
width: 24, width: 24,
height: 24, height: 24,
child: CircularProgressIndicator(strokeWidth: 2), child: CircularProgressIndicator(
strokeWidth: 2,
value: _status.progress,
),
), ),
SizedBox(width: 12), SizedBox(width: 12),
Text( Text(
_error != null _status.toLocalizedString(context),
? (_error.exception as Object).toLocalizedString(context)
: L10n.of(context).loadingPleaseWait,
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, 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 name: matrix
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
matrix_api_lite: matrix_api_lite:
dependency: transitive dependency: transitive
description: description:

View File

@ -41,7 +41,7 @@ dependencies:
image_picker: ^0.7.4 image_picker: ^0.7.4
intl: any intl: any
localstorage: ^4.0.0+1 localstorage: ^4.0.0+1
matrix: ^0.1.3 matrix: ^0.1.4
mime_type: ^1.0.0 mime_type: ^1.0.0
moor: ^4.2.1 moor: ^4.2.1
native_imaging: native_imaging: