feat: Implement new search view design
This commit is contained in:
parent
31fa5bf104
commit
b33e551923
11 changed files with 634 additions and 396 deletions
115
lib/components/contacts_list.dart
Normal file
115
lib/components/contacts_list.dart
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/avatar.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../utils/client_presence_extension.dart';
|
||||
import '../utils/presence_extension.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
|
||||
class ContactsList extends StatefulWidget {
|
||||
final TextEditingController searchController;
|
||||
|
||||
const ContactsList({
|
||||
Key key,
|
||||
@required this.searchController,
|
||||
}) : super(key: key);
|
||||
@override
|
||||
_ContactsState createState() => _ContactsState();
|
||||
}
|
||||
|
||||
class _ContactsState extends State<ContactsList> {
|
||||
StreamSubscription _onSync;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_onSync?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
DateTime _lastSetState = DateTime.now();
|
||||
Timer _coolDown;
|
||||
|
||||
void _updateView() {
|
||||
_lastSetState = DateTime.now();
|
||||
setState(() => null);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = Matrix.of(context).client;
|
||||
_onSync ??= client.onSync.stream.listen((_) {
|
||||
if (DateTime.now().millisecondsSinceEpoch -
|
||||
_lastSetState.millisecondsSinceEpoch <
|
||||
1000) {
|
||||
_coolDown?.cancel();
|
||||
_coolDown = Timer(Duration(seconds: 1), _updateView);
|
||||
} else {
|
||||
_updateView();
|
||||
}
|
||||
});
|
||||
final contactList = Matrix.of(context)
|
||||
.client
|
||||
.contactList
|
||||
.where((p) => p.senderId
|
||||
.toLowerCase()
|
||||
.contains(widget.searchController.text.toLowerCase()))
|
||||
.toList();
|
||||
if (client.presences[client.userID]?.presence?.statusMsg?.isNotEmpty ??
|
||||
false) {
|
||||
contactList.insert(0, client.presences[client.userID]);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: contactList.length,
|
||||
itemBuilder: (_, i) => _ContactListTile(contact: contactList[i]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ContactListTile extends StatelessWidget {
|
||||
final Presence contact;
|
||||
|
||||
const _ContactListTile({Key key, @required this.contact}) : super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Profile>(
|
||||
future:
|
||||
Matrix.of(context).client.getProfileFromUserId(contact.senderId),
|
||||
builder: (context, snapshot) {
|
||||
final displayname =
|
||||
snapshot.data?.displayname ?? contact.senderId.localpart;
|
||||
final avatarUrl = snapshot.data?.avatarUrl;
|
||||
return ListTile(
|
||||
leading: Container(
|
||||
width: Avatar.defaultSize,
|
||||
height: Avatar.defaultSize,
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(child: Avatar(avatarUrl, displayname)),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Icon(
|
||||
Icons.circle,
|
||||
color: contact.color,
|
||||
size: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
title: Text(displayname),
|
||||
subtitle: Text(contact.getLocalizedStatusMessage(context),
|
||||
style: contact.presence.statusMsg?.isNotEmpty ?? false
|
||||
? TextStyle(
|
||||
color: Theme.of(context).accentColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
)
|
||||
: null),
|
||||
onTap: () => AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst(
|
||||
'/rooms/${Matrix.of(context).client.getDirectChatFromUserId(contact.senderId)}'),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class DefaultBottomNavigationBar extends StatelessWidget {
|
||||
final int currentIndex;
|
||||
|
||||
const DefaultBottomNavigationBar({Key key, this.currentIndex = 1})
|
||||
: super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BottomNavigationBar(
|
||||
onTap: (i) {
|
||||
if (i == currentIndex) return;
|
||||
switch (i) {
|
||||
case 0:
|
||||
AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst('/contacts');
|
||||
break;
|
||||
case 1:
|
||||
AdaptivePageLayout.of(context).pushNamedAndRemoveAllOthers('/');
|
||||
break;
|
||||
case 2:
|
||||
AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst('/discover');
|
||||
break;
|
||||
}
|
||||
},
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
selectedItemColor: Theme.of(context).accentColor,
|
||||
currentIndex: currentIndex,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
showUnselectedLabels: true,
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(currentIndex == 0 ? Icons.people : Icons.people_outlined),
|
||||
label: L10n.of(context).friends,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(currentIndex == 1
|
||||
? CupertinoIcons.chat_bubble_2_fill
|
||||
: CupertinoIcons.chat_bubble_2),
|
||||
label: L10n.of(context).messages,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(currentIndex == 2
|
||||
? CupertinoIcons.compass_fill
|
||||
: CupertinoIcons.compass),
|
||||
label: L10n.of(context).discover,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue