refactor: Pages folder structure

This commit is contained in:
Krille Fear 2021-11-09 21:32:16 +01:00
commit 1abb7310f3
88 changed files with 188 additions and 250 deletions

View file

@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/widgets/permission_slider_dialog.dart';
import '../../widgets/matrix.dart';
import 'user_bottom_sheet_view.dart';
class UserBottomSheet extends StatefulWidget {
final User user;
final Function onMention;
final BuildContext outerContext;
const UserBottomSheet({
Key key,
@required this.user,
@required this.outerContext,
this.onMention,
}) : super(key: key);
@override
UserBottomSheetController createState() => UserBottomSheetController();
}
class UserBottomSheetController extends State<UserBottomSheet> {
void participantAction(String action) async {
// ignore: prefer_function_declarations_over_variables
final Function _askConfirmation =
() async => (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).areYouSure,
okLabel: L10n.of(context).yes,
cancelLabel: L10n.of(context).no,
) ==
OkCancelResult.ok);
switch (action) {
case 'mention':
Navigator.of(context, rootNavigator: false).pop();
widget.onMention();
break;
case 'ban':
if (await _askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.ban(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case 'unban':
if (await _askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.unban(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case 'kick':
if (await _askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () => widget.user.kick(),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case 'permission':
final newPermission = await PermissionSliderDialog(
initialPermission: widget.user.powerLevel)
.show(context);
if (newPermission != null) {
if (newPermission == 100 && await _askConfirmation() == false) break;
await showFutureLoadingDialog(
context: context,
future: () => widget.user.setPower(newPermission),
);
Navigator.of(context, rootNavigator: false).pop();
}
break;
case 'message':
final roomIdResult = await showFutureLoadingDialog(
context: context,
future: () async {
final roomId = await widget.user.startDirectChat();
final client = widget.user.room.client;
if (client.getRoomById(roomId) == null) {
await client.onSync.stream.firstWhere(
(sync) => sync.rooms?.join?.containsKey(roomId) ?? false);
}
final room = client.getRoomById(roomId);
if (client.encryptionEnabled && !room.encrypted) {
await client.getRoomById(roomId).enableEncryption();
}
return roomId;
},
);
if (roomIdResult.error != null) return;
VRouter.of(widget.outerContext)
.toSegments(['rooms', roomIdResult.result]);
Navigator.of(context, rootNavigator: false).pop();
break;
case 'ignore':
if (await _askConfirmation()) {
await showFutureLoadingDialog(
context: context,
future: () =>
Matrix.of(context).client.ignoreUser(widget.user.id));
}
}
}
@override
Widget build(BuildContext context) => UserBottomSheetView(this);
}

View file

@ -0,0 +1,167 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import '../../utils/matrix_sdk_extensions.dart/presence_extension.dart';
import '../../widgets/content_banner.dart';
import '../../widgets/matrix.dart';
import 'user_bottom_sheet.dart';
class UserBottomSheetView extends StatelessWidget {
final UserBottomSheetController controller;
const UserBottomSheetView(this.controller, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final user = controller.widget.user;
final client = Matrix.of(context).client;
final presence = client.presences[user.id];
return Center(
child: SizedBox(
width: min(
MediaQuery.of(context).size.width, FluffyThemes.columnWidth * 1.5),
child: Material(
elevation: 4,
child: SafeArea(
child: Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
backgroundColor:
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.5),
leading: IconButton(
icon: const Icon(Icons.arrow_downward_outlined),
onPressed: Navigator.of(context, rootNavigator: false).pop,
tooltip: L10n.of(context).close,
),
title: Text(user.calcDisplayname()),
actions: [
if (user.id != client.userID)
PopupMenuButton(
itemBuilder: (_) => [
if (controller.widget.onMention != null)
PopupMenuItem(
value: 'mention',
child: _TextWithIcon(
L10n.of(context).mention,
Icons.alternate_email_outlined,
),
),
if (user.id != client.userID && !user.room.isDirectChat)
PopupMenuItem(
value: 'message',
child: _TextWithIcon(
L10n.of(context).sendAMessage,
Icons.send_outlined,
),
),
if (user.canChangePowerLevel)
PopupMenuItem(
value: 'permission',
child: _TextWithIcon(
L10n.of(context).setPermissionsLevel,
Icons.edit_attributes_outlined,
),
),
if (user.canKick)
PopupMenuItem(
value: 'kick',
child: _TextWithIcon(
L10n.of(context).kickFromChat,
Icons.exit_to_app_outlined,
),
),
if (user.canBan && user.membership != Membership.ban)
PopupMenuItem(
value: 'ban',
child: _TextWithIcon(
L10n.of(context).banFromChat,
Icons.warning_sharp,
),
)
else if (user.canBan &&
user.membership == Membership.ban)
PopupMenuItem(
value: 'unban',
child: _TextWithIcon(
L10n.of(context).unbanFromChat,
Icons.warning_outlined,
),
),
if (!client.ignoredUsers.contains(user.id))
PopupMenuItem(
value: 'ignore',
child: _TextWithIcon(
L10n.of(context).ignore,
Icons.block,
),
),
],
onSelected: controller.participantAction,
),
],
),
body: Column(
children: [
Expanded(
child: ContentBanner(
user.avatarUrl,
defaultIcon: Icons.person_outline,
client: client,
),
),
ListTile(
title: Text(L10n.of(context).username),
subtitle: Text(user.id),
trailing: const Icon(Icons.share_outlined),
onTap: () => FluffyShare.share(
user.id, controller.widget.outerContext),
),
if (presence != null)
ListTile(
title: Text(presence.getLocalizedStatusMessage(context)),
subtitle:
Text(presence.getLocalizedLastActiveAgo(context)),
trailing: Icon(Icons.circle,
color: presence.presence.currentlyActive ?? false
? Colors.green
: Colors.grey),
),
],
),
),
),
),
),
);
}
}
class _TextWithIcon extends StatelessWidget {
final String text;
final IconData iconData;
const _TextWithIcon(
this.text,
this.iconData, {
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(iconData),
const SizedBox(width: 16),
Text(text),
],
);
}
}