Merge branch 'krille/loading-bar' into 'main'

feat: nicer loading bar

See merge request famedly/fluffychat!577
This commit is contained in:
Krille Fear 2021-11-23 18:53:37 +00:00
commit 199c4f95c4
2 changed files with 21 additions and 20 deletions

View File

@ -182,7 +182,6 @@ class ChatListView extends StatelessWidget {
.displayname), .displayname),
), ),
body: Column(children: [ body: Column(children: [
const ConnectionStatusHeader(),
AnimatedContainer( AnimatedContainer(
height: controller.showChatBackupBanner ? 54 : 0, height: controller.showChatBackupBanner ? 54 : 0,
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
@ -219,10 +218,15 @@ class ChatListView extends StatelessWidget {
child: const Icon(CupertinoIcons.chat_bubble), child: const Icon(CupertinoIcons.chat_bubble),
) )
: null, : null,
bottomNavigationBar: controller.spaces.isEmpty || bottomNavigationBar: Column(
controller.selectedRoomIds.isNotEmpty mainAxisSize: MainAxisSize.min,
? null children: [
: SpacesBottomBar(controller), const ConnectionStatusHeader(),
if (controller.spaces.isNotEmpty &&
controller.selectedRoomIds.isEmpty)
SpacesBottomBar(controller),
],
),
), ),
); );
}); });

View File

@ -19,19 +19,14 @@ class ConnectionStatusHeader extends StatefulWidget {
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> { class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
StreamSubscription? _onSyncSub; StreamSubscription? _onSyncSub;
StreamSubscription? _onSyncErrorSub; static bool _anySyncReceived = false;
bool get _connected =>
DateTime.now().millisecondsSinceEpoch -
_lastSyncReceived.millisecondsSinceEpoch <
(Matrix.of(context).client.sendMessageTimeoutSeconds + 2) * 1000;
static DateTime _lastSyncReceived = DateTime(0);
SyncStatusUpdate _status = SyncStatusUpdate _status =
const SyncStatusUpdate(SyncStatus.waitingForResponse); const SyncStatusUpdate(SyncStatus.waitingForResponse);
@override @override
void dispose() { void dispose() {
_onSyncSub?.cancel(); _onSyncSub?.cancel();
_onSyncErrorSub?.cancel();
super.dispose(); super.dispose();
} }
@ -40,22 +35,24 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
_onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen( _onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen(
(status) => setState( (status) => setState(
() { () {
if ((status.status == SyncStatus.processing &&
Matrix.of(context).client.prevBatch != null) ||
status.status == SyncStatus.finished) {
_lastSyncReceived = DateTime.now();
}
_status = status; _status = status;
if (status.status == SyncStatus.finished) {
_anySyncReceived = true;
}
}, },
), ),
); );
final hide = _anySyncReceived &&
_status.status != SyncStatus.error &&
Matrix.of(context).client.prevBatch != null;
return AnimatedContainer( return AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
curve: Curves.bounceInOut, curve: Curves.bounceInOut,
height: _connected ? 0 : 36, height: hide ? 0 : 36,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surface), decoration: BoxDecoration(color: Theme.of(context).secondaryHeaderColor),
padding: const EdgeInsets.symmetric(horizontal: 12), padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -65,7 +62,7 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
height: 24, height: 24,
child: CircularProgressIndicator.adaptive( child: CircularProgressIndicator.adaptive(
strokeWidth: 2, strokeWidth: 2,
value: _connected ? 1.0 : _status.progress, value: hide ? 1.0 : _status.progress,
), ),
), ),
const SizedBox(width: 12), const SizedBox(width: 12),