2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-01 20:14:49 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2022-09-11 11:07:04 +02:00
|
|
|
import 'package:badges/badges.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2022-03-01 20:14:49 +01:00
|
|
|
import 'package:keyboard_shortcuts/keyboard_shortcuts.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2022-08-30 20:24:36 +02:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
2023-01-03 18:00:56 +01:00
|
|
|
import 'package:fluffychat/pages/chat_list/navi_rail_item.dart';
|
2023-01-20 16:59:50 +01:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
2022-08-30 20:24:36 +02:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2022-09-11 11:07:04 +02:00
|
|
|
import 'package:fluffychat/widgets/unread_rooms_badge.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import '../../widgets/matrix.dart';
|
2022-05-01 13:03:33 +02:00
|
|
|
import 'chat_list_body.dart';
|
2022-05-21 12:09:25 +02:00
|
|
|
import 'chat_list_header.dart';
|
2022-07-24 22:09:26 +02:00
|
|
|
import 'start_chat_fab.dart';
|
2021-04-14 14:09:46 +02:00
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class ChatListView extends StatelessWidget {
|
2021-04-14 14:09:46 +02:00
|
|
|
final ChatListController controller;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const ChatListView(this.controller, {Key? key}) : super(key: key);
|
2021-04-14 14:09:46 +02:00
|
|
|
|
2022-09-11 11:07:04 +02:00
|
|
|
List<NavigationDestination> getNavigationDestinations(BuildContext context) {
|
|
|
|
final badgePosition = BadgePosition.topEnd(top: -12, end: -8);
|
|
|
|
return [
|
|
|
|
if (AppConfig.separateChatTypes) ...[
|
|
|
|
NavigationDestination(
|
|
|
|
icon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter: controller.getRoomFilterByActiveFilter(ActiveFilter.groups),
|
|
|
|
child: const Icon(Icons.groups_outlined),
|
2022-08-30 20:24:36 +02:00
|
|
|
),
|
2022-09-11 11:07:04 +02:00
|
|
|
selectedIcon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter: controller.getRoomFilterByActiveFilter(ActiveFilter.groups),
|
|
|
|
child: const Icon(Icons.groups),
|
2022-08-30 20:24:36 +02:00
|
|
|
),
|
2022-09-11 11:07:04 +02:00
|
|
|
label: L10n.of(context)!.groups,
|
|
|
|
),
|
|
|
|
NavigationDestination(
|
|
|
|
icon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter:
|
|
|
|
controller.getRoomFilterByActiveFilter(ActiveFilter.messages),
|
|
|
|
child: const Icon(Icons.chat_outlined),
|
2022-08-30 20:24:36 +02:00
|
|
|
),
|
2022-09-11 11:07:04 +02:00
|
|
|
selectedIcon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter:
|
|
|
|
controller.getRoomFilterByActiveFilter(ActiveFilter.messages),
|
|
|
|
child: const Icon(Icons.chat),
|
2022-08-30 20:24:36 +02:00
|
|
|
),
|
2022-09-11 11:07:04 +02:00
|
|
|
label: L10n.of(context)!.messages,
|
|
|
|
),
|
|
|
|
] else
|
|
|
|
NavigationDestination(
|
|
|
|
icon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter:
|
|
|
|
controller.getRoomFilterByActiveFilter(ActiveFilter.allChats),
|
|
|
|
child: const Icon(Icons.chat_outlined),
|
|
|
|
),
|
|
|
|
selectedIcon: UnreadRoomsBadge(
|
|
|
|
badgePosition: badgePosition,
|
|
|
|
filter:
|
|
|
|
controller.getRoomFilterByActiveFilter(ActiveFilter.allChats),
|
|
|
|
child: const Icon(Icons.chat),
|
|
|
|
),
|
|
|
|
label: L10n.of(context)!.chats,
|
|
|
|
),
|
|
|
|
if (controller.spaces.isNotEmpty)
|
|
|
|
const NavigationDestination(
|
|
|
|
icon: Icon(Icons.workspaces_outlined),
|
|
|
|
selectedIcon: Icon(Icons.workspaces),
|
|
|
|
label: 'Spaces',
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2022-08-30 20:24:36 +02:00
|
|
|
|
2021-04-14 14:09:46 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-10 13:21:33 +02:00
|
|
|
final client = Matrix.of(context).client;
|
2022-01-29 12:35:03 +01:00
|
|
|
return StreamBuilder<Object?>(
|
2022-04-02 16:18:36 +02:00
|
|
|
stream: Matrix.of(context).onShareContentChanged.stream,
|
|
|
|
builder: (_, __) {
|
|
|
|
final selectMode = controller.selectMode;
|
|
|
|
return VWidgetGuard(
|
|
|
|
onSystemPop: (redirector) async {
|
|
|
|
final selMode = controller.selectMode;
|
2022-09-11 10:22:05 +02:00
|
|
|
if (selMode != SelectMode.normal) {
|
|
|
|
controller.cancelAction();
|
|
|
|
redirector.stopRedirection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (controller.activeFilter !=
|
|
|
|
(AppConfig.separateChatTypes
|
|
|
|
? ActiveFilter.messages
|
|
|
|
: ActiveFilter.allChats)) {
|
|
|
|
controller
|
|
|
|
.onDestinationSelected(AppConfig.separateChatTypes ? 1 : 0);
|
|
|
|
redirector.stopRedirection();
|
|
|
|
return;
|
|
|
|
}
|
2022-04-02 16:18:36 +02:00
|
|
|
},
|
2022-12-26 16:02:45 +01:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
if (FluffyThemes.isColumnMode(context) &&
|
|
|
|
FluffyThemes.getDisplayNavigationRail(context)) ...[
|
2023-03-02 10:57:52 +01:00
|
|
|
Builder(
|
|
|
|
builder: (context) {
|
|
|
|
final allSpaces =
|
|
|
|
client.rooms.where((room) => room.isSpace);
|
|
|
|
final rootSpaces = allSpaces
|
|
|
|
.where(
|
|
|
|
(space) => !allSpaces.any(
|
|
|
|
(parentSpace) => parentSpace.spaceChildren
|
|
|
|
.any((child) => child.roomId == space.id),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList();
|
|
|
|
final destinations = getNavigationDestinations(context);
|
2022-09-10 13:21:33 +02:00
|
|
|
|
2023-03-02 10:57:52 +01:00
|
|
|
return SizedBox(
|
|
|
|
width: 64,
|
|
|
|
child: ListView.builder(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
itemCount: rootSpaces.length + destinations.length,
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
if (i < destinations.length) {
|
|
|
|
return NaviRailItem(
|
|
|
|
isSelected: i == controller.selectedIndex,
|
|
|
|
onTap: () => controller.onDestinationSelected(i),
|
|
|
|
icon: destinations[i].icon,
|
|
|
|
selectedIcon: destinations[i].selectedIcon,
|
|
|
|
toolTip: destinations[i].label,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i -= destinations.length;
|
|
|
|
final isSelected =
|
|
|
|
controller.activeFilter == ActiveFilter.spaces &&
|
|
|
|
rootSpaces[i].id == controller.activeSpaceId;
|
2023-01-03 18:00:56 +01:00
|
|
|
return NaviRailItem(
|
2023-03-02 10:57:52 +01:00
|
|
|
toolTip: rootSpaces[i].getLocalizedDisplayname(
|
2023-01-20 16:59:50 +01:00
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
),
|
2023-03-02 10:57:52 +01:00
|
|
|
isSelected: isSelected,
|
|
|
|
onTap: () =>
|
|
|
|
controller.setActiveSpace(rootSpaces[i].id),
|
|
|
|
icon: Avatar(
|
|
|
|
mxContent: rootSpaces[i].avatar,
|
|
|
|
name: rootSpaces[i].getLocalizedDisplayname(
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
),
|
|
|
|
size: 32,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-12-26 16:02:45 +01:00
|
|
|
Container(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
Expanded(
|
2022-12-25 13:08:51 +01:00
|
|
|
child: GestureDetector(
|
|
|
|
onTap: FocusManager.instance.primaryFocus?.unfocus,
|
|
|
|
excludeFromSemantics: true,
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: ChatListHeader(controller: controller),
|
|
|
|
body: ChatListViewBody(controller),
|
|
|
|
bottomNavigationBar: controller.displayNavigationBar
|
|
|
|
? NavigationBar(
|
|
|
|
height: 64,
|
|
|
|
selectedIndex: controller.selectedIndex,
|
|
|
|
onDestinationSelected:
|
|
|
|
controller.onDestinationSelected,
|
|
|
|
destinations: getNavigationDestinations(context),
|
|
|
|
)
|
|
|
|
: null,
|
2022-12-29 10:26:01 +01:00
|
|
|
floatingActionButtonLocation:
|
|
|
|
controller.filteredRooms.isEmpty
|
|
|
|
? FloatingActionButtonLocation.centerFloat
|
|
|
|
: null,
|
|
|
|
floatingActionButton: selectMode == SelectMode.normal
|
2022-12-25 13:08:51 +01:00
|
|
|
? KeyBoardShortcuts(
|
|
|
|
keysToPress: {
|
|
|
|
LogicalKeyboardKey.controlLeft,
|
|
|
|
LogicalKeyboardKey.keyN
|
|
|
|
},
|
|
|
|
onKeysPressed: () =>
|
|
|
|
VRouter.of(context).to('/newprivatechat'),
|
|
|
|
helpLabel: L10n.of(context)!.newChat,
|
|
|
|
child: StartChatFloatingActionButton(
|
2022-12-29 10:26:01 +01:00
|
|
|
controller: controller,
|
|
|
|
),
|
2022-12-25 13:08:51 +01:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
2022-12-26 16:02:45 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-04-02 16:18:36 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-04-14 14:09:46 +02:00
|
|
|
}
|
|
|
|
}
|