2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
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
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2022-03-01 20:14:49 +01:00
|
|
|
import 'package:keyboard_shortcuts/keyboard_shortcuts.dart';
|
2022-04-02 16:18:36 +02:00
|
|
|
import 'package:snapping_sheet/snapping_sheet.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
import 'package:fluffychat/pages/chat_list/spaces_bottom_bar.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/connection_status_header.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';
|
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
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
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;
|
2022-05-05 09:47:12 +02:00
|
|
|
final showSpaces = controller.spacesEntries.length > 1 &&
|
|
|
|
controller.selectedRoomIds.isEmpty;
|
2022-04-02 16:18:36 +02:00
|
|
|
return VWidgetGuard(
|
|
|
|
onSystemPop: (redirector) async {
|
|
|
|
final selMode = controller.selectMode;
|
|
|
|
if (selMode != SelectMode.normal) controller.cancelAction();
|
|
|
|
if (selMode == SelectMode.select) redirector.stopRedirection();
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
2022-05-21 12:09:25 +02:00
|
|
|
appBar: ChatListHeader(controller: controller),
|
2022-04-02 16:18:36 +02:00
|
|
|
body: LayoutBuilder(
|
|
|
|
builder: (context, size) {
|
|
|
|
controller.snappingSheetContainerSize = size;
|
|
|
|
return SnappingSheet(
|
|
|
|
key: ValueKey(Matrix.of(context).client.userID.toString() +
|
|
|
|
showSpaces.toString()),
|
|
|
|
controller: controller.snappingSheetController,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
AnimatedContainer(
|
|
|
|
height: controller.showChatBackupBanner ? 54 : 0,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
curve: Curves.bounceInOut,
|
|
|
|
decoration: const BoxDecoration(),
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
child: ListTile(
|
|
|
|
leading: Image.asset(
|
|
|
|
'assets/backup.png',
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
width: 44,
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
2022-04-02 16:18:36 +02:00
|
|
|
title: Text(L10n.of(context)!.setupChatBackupNow),
|
|
|
|
trailing: const Icon(Icons.chevron_right_outlined),
|
|
|
|
onTap: controller.firstRunBootstrapAction,
|
|
|
|
),
|
|
|
|
),
|
2021-11-19 09:12:47 +01:00
|
|
|
),
|
2022-05-01 13:03:33 +02:00
|
|
|
Expanded(child: ChatListViewBody(controller)),
|
2022-04-02 16:18:36 +02:00
|
|
|
],
|
2021-11-19 09:12:47 +01:00
|
|
|
),
|
2022-04-02 16:18:36 +02:00
|
|
|
initialSnappingPosition: showSpaces
|
|
|
|
? const SnappingPosition.pixels(
|
|
|
|
positionPixels: kSpacesBottomBarHeight)
|
|
|
|
: const SnappingPosition.factor(positionFactor: 0.0),
|
|
|
|
snappingPositions: showSpaces
|
|
|
|
? const [
|
|
|
|
SnappingPosition.pixels(
|
|
|
|
positionPixels: kSpacesBottomBarHeight),
|
|
|
|
SnappingPosition.factor(positionFactor: 0.5),
|
|
|
|
SnappingPosition.factor(positionFactor: 0.9),
|
|
|
|
]
|
|
|
|
: [const SnappingPosition.factor(positionFactor: 0.0)],
|
|
|
|
sheetBelow: showSpaces
|
|
|
|
? SnappingSheetContent(
|
|
|
|
childScrollController:
|
|
|
|
controller.snappingSheetScrollContentController,
|
|
|
|
draggable: true,
|
|
|
|
child: SpacesBottomBar(controller),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
floatingActionButton: selectMode == SelectMode.normal
|
|
|
|
? Padding(
|
|
|
|
padding: showSpaces
|
|
|
|
? const EdgeInsets.only(bottom: 64.0)
|
|
|
|
: const EdgeInsets.all(0),
|
|
|
|
child: KeyBoardShortcuts(
|
2022-03-01 20:14:49 +01:00
|
|
|
child: FloatingActionButton.extended(
|
|
|
|
isExtended: controller.scrolledToTop,
|
|
|
|
onPressed: () =>
|
|
|
|
VRouter.of(context).to('/newprivatechat'),
|
|
|
|
icon: const Icon(CupertinoIcons.chat_bubble),
|
|
|
|
label: Text(L10n.of(context)!.newChat),
|
|
|
|
),
|
|
|
|
keysToPress: {
|
|
|
|
LogicalKeyboardKey.controlLeft,
|
|
|
|
LogicalKeyboardKey.keyN
|
|
|
|
},
|
|
|
|
onKeysPressed: () =>
|
2021-12-31 09:12:47 +01:00
|
|
|
VRouter.of(context).to('/newprivatechat'),
|
2022-03-01 20:14:49 +01:00
|
|
|
helpLabel: L10n.of(context)!.newChat,
|
2022-04-02 16:18:36 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2022-06-04 20:06:57 +02:00
|
|
|
bottomNavigationBar: const SafeArea(
|
|
|
|
child: ConnectionStatusHeader(),
|
|
|
|
),
|
2022-04-02 16:18:36 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-04-14 14:09:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ChatListPopupMenuItemActions {
|
|
|
|
createGroup,
|
2021-08-01 08:05:40 +02:00
|
|
|
createSpace,
|
2021-04-14 14:09:46 +02:00
|
|
|
discover,
|
|
|
|
setStatus,
|
|
|
|
inviteContact,
|
|
|
|
settings,
|
|
|
|
}
|