Improve message list visuals
This commit is contained in:
parent
c43a93d574
commit
c368fb6fe5
3 changed files with 71 additions and 42 deletions
|
@ -72,6 +72,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
box.delete(_lastUpdateKey);
|
box.delete(_lastUpdateKey);
|
||||||
await refreshFriendsListWithErrorHandler();
|
await refreshFriendsListWithErrorHandler();
|
||||||
await _refreshUnreads();
|
await _refreshUnreads();
|
||||||
|
_unreadSafeguard = Timer.periodic(_unreadSafeguardDuration, (timer) => _refreshUnreads());
|
||||||
});
|
});
|
||||||
_startWebsocket();
|
_startWebsocket();
|
||||||
_notifyOnlineTimer = Timer.periodic(const Duration(seconds: 60), (timer) async {
|
_notifyOnlineTimer = Timer.periodic(const Duration(seconds: 60), (timer) async {
|
||||||
|
@ -85,6 +86,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_autoRefresh?.cancel();
|
_autoRefresh?.cancel();
|
||||||
_notifyOnlineTimer?.cancel();
|
_notifyOnlineTimer?.cancel();
|
||||||
|
_unreadSafeguard?.cancel();
|
||||||
_wsChannel?.close();
|
_wsChannel?.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
@ -217,12 +219,10 @@ class MessagingClient extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _refreshUnreads() async {
|
Future<void> _refreshUnreads() async {
|
||||||
_unreadSafeguard?.cancel();
|
|
||||||
try {
|
try {
|
||||||
final unreadMessages = await MessageApi.getUserMessages(_apiClient, unreadOnly: true);
|
final unreadMessages = await MessageApi.getUserMessages(_apiClient, unreadOnly: true);
|
||||||
updateAllUnreads(unreadMessages.toList());
|
updateAllUnreads(unreadMessages.toList());
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
_unreadSafeguard = Timer(_unreadSafeguardDuration, _refreshUnreads);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _sortFriendsCache() {
|
void _sortFriendsCache() {
|
||||||
|
|
|
@ -252,6 +252,7 @@ class _FriendsListState extends State<FriendsList> {
|
||||||
friends.sort((a, b) => a.username.length.compareTo(b.username.length));
|
friends.sort((a, b) => a.username.length.compareTo(b.username.length));
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
itemCount: friends.length,
|
itemCount: friends.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final friend = friends[index];
|
final friend = friends[index];
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:contacts_plus_plus/auxiliary.dart';
|
|
||||||
import 'package:contacts_plus_plus/clients/audio_cache_client.dart';
|
import 'package:contacts_plus_plus/clients/audio_cache_client.dart';
|
||||||
import 'package:contacts_plus_plus/clients/messaging_client.dart';
|
import 'package:contacts_plus_plus/clients/messaging_client.dart';
|
||||||
import 'package:contacts_plus_plus/models/friend.dart';
|
import 'package:contacts_plus_plus/models/friend.dart';
|
||||||
|
@ -24,6 +23,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
final ScrollController _sessionListScrollController = ScrollController();
|
final ScrollController _sessionListScrollController = ScrollController();
|
||||||
|
|
||||||
bool _showSessionListScrollChevron = false;
|
bool _showSessionListScrollChevron = false;
|
||||||
|
bool _sessionListOpen = false;
|
||||||
|
|
||||||
double get _shevronOpacity => _showSessionListScrollChevron ? 1.0 : 0.0;
|
double get _shevronOpacity => _showSessionListScrollChevron ? 1.0 : 0.0;
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sessions = widget.friend.userStatus.activeSessions;
|
final sessions = widget.friend.userStatus.activeSessions;
|
||||||
|
@ -81,12 +80,39 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
bottom: sessions.isNotEmpty && _sessionListOpen ? null : PreferredSize(
|
||||||
|
preferredSize: const Size.fromHeight(1),
|
||||||
|
child: Container(
|
||||||
|
height: 1,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
if (sessions.isNotEmpty) AnimatedRotation(
|
||||||
|
turns: _sessionListOpen ? -1/4 : 1/4,
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_sessionListOpen = !_sessionListOpen;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.chevron_right),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4,)
|
||||||
|
],
|
||||||
scrolledUnderElevation: 0.0,
|
scrolledUnderElevation: 0.0,
|
||||||
backgroundColor: appBarColor,
|
backgroundColor: appBarColor,
|
||||||
|
surfaceTintColor: Colors.transparent,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
if (sessions.isNotEmpty) Container(
|
if (sessions.isNotEmpty) AnimatedSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
transitionBuilder: (child, animation) => SizeTransition(sizeFactor: animation, axis: Axis.vertical, child: child),
|
||||||
|
child: sessions.isEmpty || !_sessionListOpen ? null : Container(
|
||||||
constraints: const BoxConstraints(maxHeight: 64),
|
constraints: const BoxConstraints(maxHeight: 64),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: appBarColor,
|
color: appBarColor,
|
||||||
|
@ -127,6 +153,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
@ -176,6 +203,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
create: (BuildContext context) => AudioCacheClient(),
|
create: (BuildContext context) => AudioCacheClient(),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
reverse: true,
|
reverse: true,
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
itemCount: cache.messages.length,
|
itemCount: cache.messages.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final entry = cache.messages[index];
|
final entry = cache.messages[index];
|
||||||
|
|
Loading…
Reference in a new issue