A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.6 KiB

part of '../neon_spreed.dart';
class SpreedMainPage extends StatefulWidget {
const SpreedMainPage({
super.key,
});
@override
State<SpreedMainPage> createState() => _SpreedMainPageState();
}
class _SpreedMainPageState extends State<SpreedMainPage> {
late final SpreedBloc bloc;
@override
void initState() {
super.initState();
bloc = NeonProvider.of<SpreedBloc>(context);
bloc.errors.listen((final error) {
NeonError.showSnackbar(context, error);
});
}
@override
Widget build(final BuildContext context) => Scaffold(
resizeToAvoidBottomInset: false,
body: ResultBuilder(
stream: bloc.rooms,
builder: (final context, final rooms) {
final sorted = rooms.data?.sorted((final a, final b) => b.lastActivity.compareTo(a.lastActivity)) ?? [];
return NeonListView(
scrollKey: 'spreed-rooms',
isLoading: rooms.isLoading,
error: rooms.error,
onRefresh: bloc.refresh,
itemCount: sorted.length,
itemBuilder: (final context, final index) => _buildRoom(context, sorted[index]),
);
},
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () async {
final result = await showDialog<SpreedCreateRoomDetails>(
context: context,
builder: (final context) => const SpreedCreateRoomDialog(),
);
if (result == null) {
return;
}
bloc.createRoom(
result.type,
result.roomName,
result.invite,
);
},
),
);
Widget _buildRoom(
final BuildContext context,
final spreed.Room room,
) =>
ListTile(
title: Text(room.displayName),
subtitle: Text(
room.lastMessage.chatMessage != null
? (room.type == spreed.RoomType.changelog.value ||
(room.type == spreed.RoomType.oneToOne.value &&
room.lastMessage.chatMessage!.actorId != bloc.account.username)
? room.lastMessage.chatMessage!.message
: '${room.lastMessage.chatMessage!.actorId == bloc.account.username ? SpreedLocalizations.of(context).messageYou : room.lastMessage.chatMessage!.actorDisplayName}: ${room.lastMessage.chatMessage!.message}')
: '',
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
leading: SpreedRoomIcon(
roomType: spreed.RoomType.values[room.type],
roomName: room.name,
),
trailing: room.unreadMessages > 0
? Chip(
backgroundColor: room.unreadMention ? Theme.of(context).colorScheme.primary : null,
label: Text(
room.unreadMessages.toString(),
style: TextStyle(
color: room.unreadMention
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.primary,
),
),
)
: null,
onTap: () async {
final roomBloc = SpreedRoomBloc(
bloc.options,
bloc.account,
room,
);
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (final context) => SpreedRoomPage(
bloc: roomBloc,
),
),
);
await roomBloc.leaveRoom();
bloc.dispose();
},
);
}