chore: Follow up add backbutton support

This commit is contained in:
Christian Pauly 2022-09-11 10:22:05 +02:00
parent ed2eddd601
commit dc0f067b0a
3 changed files with 163 additions and 127 deletions

View File

@ -2942,5 +2942,12 @@
"enterRoom": "Enter room", "enterRoom": "Enter room",
"@enterRoom": {}, "@enterRoom": {},
"allSpaces": "All spaces", "allSpaces": "All spaces",
"@allSpaces": {} "@allSpaces": {},
"numChats": "{number} chats",
"@numChats": {
"type": "number",
"placeholders": {
"number": {}
}
}
} }

View File

@ -56,8 +56,20 @@ class ChatListView extends StatelessWidget {
return VWidgetGuard( return VWidgetGuard(
onSystemPop: (redirector) async { onSystemPop: (redirector) async {
final selMode = controller.selectMode; final selMode = controller.selectMode;
if (selMode != SelectMode.normal) controller.cancelAction(); if (selMode != SelectMode.normal) {
if (selMode == SelectMode.select) redirector.stopRedirection(); controller.cancelAction();
redirector.stopRedirection();
return;
}
if (controller.activeFilter !=
(AppConfig.separateChatTypes
? ActiveFilter.messages
: ActiveFilter.allChats)) {
controller
.onDestinationSelected(AppConfig.separateChatTypes ? 1 : 0);
redirector.stopRedirection();
return;
}
}, },
child: Row( child: Row(
children: [ children: [

View File

@ -148,20 +148,24 @@ class _SpaceViewState extends State<SpaceView> {
return ListView.builder( return ListView.builder(
itemCount: rootSpaces.length, itemCount: rootSpaces.length,
controller: widget.scrollController, controller: widget.scrollController,
itemBuilder: (context, i) => ListTile( itemBuilder: (context, i) => Material(
leading: Avatar( color: Theme.of(context).backgroundColor,
mxContent: rootSpaces[i].avatar, child: ListTile(
name: rootSpaces[i].displayname, leading: Avatar(
mxContent: rootSpaces[i].avatar,
name: rootSpaces[i].displayname,
),
title: Text(
rootSpaces[i].displayname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(L10n.of(context)!
.numChats(rootSpaces[i].spaceChildren.length.toString())),
onTap: () => widget.controller.setActiveSpace(rootSpaces[i].id),
onLongPress: () => _onSpaceChildContextMenu(null, rootSpaces[i]),
trailing: const Icon(Icons.chevron_right_outlined),
), ),
title: Text(
rootSpaces[i].displayname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text('${rootSpaces[i].spaceChildren.length} Chats'),
onTap: () => widget.controller.setActiveSpace(rootSpaces[i].id),
onLongPress: () => _onSpaceChildContextMenu(null, rootSpaces[i]),
trailing: const Icon(Icons.chevron_right_outlined),
), ),
); );
} }
@ -193,122 +197,135 @@ class _SpaceViewState extends State<SpaceView> {
.any((child) => child.roomId == activeSpaceId)); .any((child) => child.roomId == activeSpaceId));
final spaceChildren = response.rooms; final spaceChildren = response.rooms;
final canLoadMore = response.nextBatch != null; final canLoadMore = response.nextBatch != null;
return ListView.builder( return VWidgetGuard(
itemCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0), onSystemPop: (redirector) async {
controller: widget.scrollController, if (parentSpace != null) {
itemBuilder: (context, i) { widget.controller.setActiveSpace(parentSpace.id);
if (i == 0) { redirector.stopRedirection();
return ListTile( return;
leading: BackButton( }
onPressed: () => },
widget.controller.setActiveSpace(parentSpace?.id), child: ListView.builder(
), itemCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0),
title: Text(parentSpace == null controller: widget.scrollController,
? L10n.of(context)!.allSpaces itemBuilder: (context, i) {
: parentSpace.displayname), if (i == 0) {
trailing: IconButton( return ListTile(
icon: snapshot.connectionState != ConnectionState.done leading: BackButton(
? const CircularProgressIndicator.adaptive() onPressed: () =>
: const Icon(Icons.refresh_outlined), widget.controller.setActiveSpace(parentSpace?.id),
onPressed:
snapshot.connectionState != ConnectionState.done
? null
: _refresh,
),
);
}
i--;
if (canLoadMore && i == spaceChildren.length) {
return ListTile(
title: Text(L10n.of(context)!.loadMore),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: () {
prevBatch = response.nextBatch;
_refresh();
},
);
}
final spaceChild = spaceChildren[i];
final room = client.getRoomById(spaceChild.roomId);
if (room != null && !room.isSpace) {
return ChatListItem(
room,
onLongPress: () =>
_onSpaceChildContextMenu(spaceChild, room),
activeChat: widget.controller.activeChat == room.id,
);
}
final isSpace = spaceChild.roomType == 'm.space';
final topic =
spaceChild.topic?.isEmpty ?? true ? null : spaceChild.topic;
if (spaceChild.roomId == activeSpaceId) {
return SearchTitle(
title:
spaceChild.name ?? spaceChild.canonicalAlias ?? 'Space',
icon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Avatar(
size: 24,
mxContent: spaceChild.avatarUrl,
name: spaceChild.name,
fontSize: 9,
), ),
title: Text(parentSpace == null
? L10n.of(context)!.allSpaces
: parentSpace.displayname),
trailing: IconButton(
icon: snapshot.connectionState != ConnectionState.done
? const CircularProgressIndicator.adaptive()
: const Icon(Icons.refresh_outlined),
onPressed:
snapshot.connectionState != ConnectionState.done
? null
: _refresh,
),
);
}
i--;
if (canLoadMore && i == spaceChildren.length) {
return ListTile(
title: Text(L10n.of(context)!.loadMore),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: () {
prevBatch = response.nextBatch;
_refresh();
},
);
}
final spaceChild = spaceChildren[i];
final room = client.getRoomById(spaceChild.roomId);
if (room != null && !room.isSpace) {
return ChatListItem(
room,
onLongPress: () =>
_onSpaceChildContextMenu(spaceChild, room),
activeChat: widget.controller.activeChat == room.id,
);
}
final isSpace = spaceChild.roomType == 'm.space';
final topic = spaceChild.topic?.isEmpty ?? true
? null
: spaceChild.topic;
if (spaceChild.roomId == activeSpaceId) {
return SearchTitle(
title: spaceChild.name ??
spaceChild.canonicalAlias ??
'Space',
icon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Avatar(
size: 24,
mxContent: spaceChild.avatarUrl,
name: spaceChild.name,
fontSize: 9,
),
),
color: Theme.of(context)
.colorScheme
.secondaryContainer
.withAlpha(128),
trailing: const Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Icon(Icons.edit_outlined),
),
onTap: () => _onJoinSpaceChild(spaceChild),
);
}
return ListTile(
leading: Avatar(
mxContent: spaceChild.avatarUrl,
name: spaceChild.name,
), ),
color: Theme.of(context) title: Row(
.colorScheme children: [
.secondaryContainer Expanded(
.withAlpha(128), child: Text(
trailing: const Padding( spaceChild.name ??
padding: EdgeInsets.symmetric(horizontal: 16.0), spaceChild.canonicalAlias ??
child: Icon(Icons.edit_outlined), L10n.of(context)!.chat,
maxLines: 1,
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
if (!isSpace) ...[
const Icon(
Icons.people_outline,
size: 16,
),
const SizedBox(width: 4),
Text(
spaceChild.numJoinedMembers.toString(),
style: const TextStyle(fontSize: 14),
),
],
],
), ),
onTap: () => _onJoinSpaceChild(spaceChild), onTap: () => _onJoinSpaceChild(spaceChild),
onLongPress: () =>
_onSpaceChildContextMenu(spaceChild, room),
subtitle: Text(
topic ??
(isSpace
? L10n.of(context)!.enterSpace
: L10n.of(context)!.enterRoom),
maxLines: 1,
style: TextStyle(
color: Theme.of(context).colorScheme.onBackground),
),
trailing: isSpace
? const Icon(Icons.chevron_right_outlined)
: null,
); );
} }),
return ListTile( );
leading: Avatar(
mxContent: spaceChild.avatarUrl,
name: spaceChild.name,
),
title: Row(
children: [
Expanded(
child: Text(
spaceChild.name ??
spaceChild.canonicalAlias ??
L10n.of(context)!.chat,
maxLines: 1,
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
if (!isSpace) ...[
const Icon(
Icons.people_outline,
size: 16,
),
const SizedBox(width: 4),
Text(
spaceChild.numJoinedMembers.toString(),
style: const TextStyle(fontSize: 14),
),
],
],
),
onTap: () => _onJoinSpaceChild(spaceChild),
onLongPress: () => _onSpaceChildContextMenu(spaceChild, room),
subtitle: Text(
topic ??
(isSpace
? L10n.of(context)!.enterSpace
: L10n.of(context)!.enterRoom),
maxLines: 1,
style: TextStyle(
color: Theme.of(context).colorScheme.onBackground),
),
trailing:
isSpace ? const Icon(Icons.chevron_right_outlined) : null,
);
});
}); });
} }
} }