mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 23:12:37 +01:00
Merge branch 'krille/add-connection-status-header' into 'master'
Add connection status header See merge request ChristianPauly/fluffychat-flutter!100
This commit is contained in:
commit
c1c6659ce0
44
lib/components/connection_status_header.dart
Normal file
44
lib/components/connection_status_header.dart
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'matrix.dart';
|
||||||
|
|
||||||
|
class ConnectionStatusHeader extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_ConnectionStatusHeaderState createState() => _ConnectionStatusHeaderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
||||||
|
StreamSubscription _onSyncSub;
|
||||||
|
StreamSubscription _onSyncErrorSub;
|
||||||
|
static bool _connected = false;
|
||||||
|
|
||||||
|
set connected(bool connected) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _connected = connected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_onSyncSub?.cancel();
|
||||||
|
_onSyncErrorSub?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
|
||||||
|
(_) => connected = true,
|
||||||
|
);
|
||||||
|
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
|
||||||
|
(_) => connected = false,
|
||||||
|
);
|
||||||
|
|
||||||
|
return AnimatedContainer(
|
||||||
|
duration: Duration(milliseconds: 500),
|
||||||
|
height: _connected ? 0 : 5,
|
||||||
|
child: LinearProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||||
import 'package:fluffychat/components/avatar.dart';
|
import 'package:fluffychat/components/avatar.dart';
|
||||||
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
||||||
|
import 'package:fluffychat/components/connection_status_header.dart';
|
||||||
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
|
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
|
||||||
import 'package:fluffychat/components/dialogs/recording_dialog.dart';
|
import 'package:fluffychat/components/dialogs/recording_dialog.dart';
|
||||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||||
@ -90,11 +91,11 @@ class _ChatState extends State<_Chat> {
|
|||||||
void requestHistory() async {
|
void requestHistory() async {
|
||||||
if (_canLoadMore) {
|
if (_canLoadMore) {
|
||||||
setState(() => _loadingHistory = true);
|
setState(() => _loadingHistory = true);
|
||||||
try {
|
|
||||||
await timeline.requestHistory(historyCount: _loadHistoryCount);
|
await SimpleDialogs(context).tryRequestWithErrorToast(
|
||||||
} catch (e) {
|
timeline.requestHistory(historyCount: _loadHistoryCount),
|
||||||
debugPrint('Error loading history: ' + e.toString());
|
);
|
||||||
}
|
|
||||||
if (mounted) setState(() => _loadingHistory = false);
|
if (mounted) setState(() => _loadingHistory = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,7 +453,6 @@ class _ChatState extends State<_Chat> {
|
|||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
if (_loadingHistory) LinearProgressIndicator(),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FutureBuilder<bool>(
|
child: FutureBuilder<bool>(
|
||||||
future: getTimeline(),
|
future: getTimeline(),
|
||||||
@ -486,14 +486,23 @@ class _ChatState extends State<_Chat> {
|
|||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
itemBuilder: (BuildContext context, int i) {
|
itemBuilder: (BuildContext context, int i) {
|
||||||
return i == timeline.events.length + 1
|
return i == timeline.events.length + 1
|
||||||
? _canLoadMore && !_loadingHistory
|
? _loadingHistory
|
||||||
|
? Container(
|
||||||
|
height: 50,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
: _canLoadMore
|
||||||
? FlatButton(
|
? FlatButton(
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).loadMore,
|
L10n.of(context).loadMore,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context)
|
||||||
|
.primaryColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
decoration: TextDecoration.underline,
|
decoration:
|
||||||
|
TextDecoration.underline,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: requestHistory,
|
onPressed: requestHistory,
|
||||||
@ -556,6 +565,7 @@ class _ChatState extends State<_Chat> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
ConnectionStatusHeader(),
|
||||||
AnimatedContainer(
|
AnimatedContainer(
|
||||||
duration: Duration(milliseconds: 300),
|
duration: Duration(milliseconds: 300),
|
||||||
height: replyEvent != null ? 56 : 0,
|
height: replyEvent != null ? 56 : 0,
|
||||||
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/matrix_api.dart';
|
import 'package:famedlysdk/matrix_api.dart';
|
||||||
|
import 'package:fluffychat/components/connection_status_header.dart';
|
||||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||||
import 'package:fluffychat/components/list_items/presence_list_item.dart';
|
import 'package:fluffychat/components/list_items/presence_list_item.dart';
|
||||||
import 'package:fluffychat/components/list_items/public_room_list_item.dart';
|
import 'package:fluffychat/components/list_items/public_room_list_item.dart';
|
||||||
@ -408,8 +409,13 @@ class _ChatListState extends State<ChatList> {
|
|||||||
itemCount: totalCount + 1,
|
itemCount: totalCount + 1,
|
||||||
itemBuilder: (BuildContext context, int i) {
|
itemBuilder: (BuildContext context, int i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return (directChats.isEmpty ||
|
return Column(
|
||||||
selectMode == SelectMode.share)
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ConnectionStatusHeader(),
|
||||||
|
(directChats.isEmpty ||
|
||||||
|
selectMode ==
|
||||||
|
SelectMode.share)
|
||||||
? Container()
|
? Container()
|
||||||
: PreferredSize(
|
: PreferredSize(
|
||||||
preferredSize:
|
preferredSize:
|
||||||
@ -419,14 +425,17 @@ class _ChatListState extends State<ChatList> {
|
|||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
scrollDirection:
|
scrollDirection:
|
||||||
Axis.horizontal,
|
Axis.horizontal,
|
||||||
itemCount: directChats.length,
|
itemCount:
|
||||||
itemBuilder:
|
directChats.length,
|
||||||
(BuildContext context,
|
itemBuilder: (BuildContext
|
||||||
|
context,
|
||||||
int i) =>
|
int i) =>
|
||||||
PresenceListItem(
|
PresenceListItem(
|
||||||
directChats[i]),
|
directChats[i]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
|
Loading…
Reference in New Issue
Block a user