Merge branch 'krille/redesign-multiaccount-spaces' into 'main'
feat: Redesign multiaccounts and spaces See merge request famedly/fluffychat!547onboarding
commit
c6b1225549
@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'chat_list.dart';
|
||||
|
||||
class ClientChooserButton extends StatelessWidget {
|
||||
final ChatListController controller;
|
||||
const ClientChooserButton(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
List<PopupMenuEntry<Object>> _bundleMenuItems(BuildContext context) {
|
||||
final matrix = Matrix.of(context);
|
||||
final bundles = matrix.accountBundles.keys.toList()
|
||||
..sort((a, b) => a.isValidMatrixId == b.isValidMatrixId
|
||||
? 0
|
||||
: a.isValidMatrixId && !b.isValidMatrixId
|
||||
? -1
|
||||
: 1);
|
||||
return <PopupMenuEntry<Object>>[
|
||||
for (final bundle in bundles) ...[
|
||||
if (matrix.accountBundles[bundle].length != 1 ||
|
||||
matrix.accountBundles[bundle].single.userID != bundle)
|
||||
PopupMenuItem(
|
||||
value: null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
bundle,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).textTheme.subtitle1.color,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
],
|
||||
),
|
||||
),
|
||||
...matrix.accountBundles[bundle]
|
||||
.map(
|
||||
(client) => PopupMenuItem(
|
||||
value: client,
|
||||
child: FutureBuilder<Profile>(
|
||||
future: client.ownProfile,
|
||||
builder: (context, snapshot) => Row(
|
||||
children: [
|
||||
Avatar(
|
||||
snapshot.data?.avatarUrl,
|
||||
snapshot.data?.displayName ?? client.userID.localpart,
|
||||
size: 28,
|
||||
fontSize: 12,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
snapshot.data?.displayName ?? client.userID.localpart,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
onPressed: () => controller.editBundlesForAccount(
|
||||
client.userID, bundle),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final matrix = Matrix.of(context);
|
||||
return Center(
|
||||
child: FutureBuilder<Profile>(
|
||||
future: matrix.client.ownProfile,
|
||||
builder: (context, snapshot) => PopupMenuButton<Object>(
|
||||
child: Avatar(
|
||||
snapshot.data?.avatarUrl,
|
||||
snapshot.data?.displayName ?? matrix.client.userID.localpart,
|
||||
size: 28,
|
||||
fontSize: 12,
|
||||
),
|
||||
onSelected: (Object object) {
|
||||
if (object is Client) {
|
||||
controller.setActiveClient(object);
|
||||
} else if (object is String) {
|
||||
controller.setActiveBundle(object);
|
||||
}
|
||||
},
|
||||
itemBuilder: _bundleMenuItems,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
|
||||
class SpacesBottomBar extends StatelessWidget {
|
||||
final ChatListController controller;
|
||||
const SpacesBottomBar(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final currentIndex = controller.activeSpaceId == null
|
||||
? 0
|
||||
: controller.spaces
|
||||
.indexWhere((space) => controller.activeSpaceId == space.id) +
|
||||
1;
|
||||
return BottomNavigationBar(
|
||||
currentIndex: currentIndex,
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
landscapeLayout: BottomNavigationBarLandscapeLayout.spread,
|
||||
onTap: (i) => controller.setActiveSpaceId(
|
||||
context,
|
||||
i == 0 ? null : controller.spaces[i - 1].id,
|
||||
),
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
icon: const Icon(CupertinoIcons.chat_bubble_2),
|
||||
label: L10n.of(context).allChats,
|
||||
),
|
||||
...controller.spaces
|
||||
.map((space) => BottomNavigationBarItem(
|
||||
icon: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () => controller.setActiveSpaceId(
|
||||
context,
|
||||
space.id,
|
||||
),
|
||||
onLongPress: () => controller.editSpace(context, space.id),
|
||||
child: Avatar(
|
||||
space.avatar,
|
||||
space.displayname,
|
||||
size: 24,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
label: space.displayname,
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue