fluffychat/lib/pages/chat_permissions_settings/permission_list_tile.dart

105 lines
3.2 KiB
Dart
Raw Normal View History

2021-04-15 08:48:26 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
2021-04-15 08:48:26 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
2021-04-15 08:48:26 +02:00
class PermissionsListTile extends StatelessWidget {
final String permissionKey;
final int permission;
2022-01-29 12:35:03 +01:00
final String? category;
final void Function()? onTap;
2021-04-15 08:48:26 +02:00
const PermissionsListTile({
2022-01-29 12:35:03 +01:00
Key? key,
required this.permissionKey,
required this.permission,
2021-04-15 08:48:26 +02:00
this.category,
this.onTap,
}) : super(key: key);
String getLocalizedPowerLevelString(BuildContext context) {
if (category == null) {
switch (permissionKey) {
case 'users_default':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.defaultPermissionLevel;
2021-04-15 08:48:26 +02:00
case 'events_default':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.sendMessages;
2021-04-15 08:48:26 +02:00
case 'state_default':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.configureChat;
2021-04-15 08:48:26 +02:00
case 'ban':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.banFromChat;
2021-04-15 08:48:26 +02:00
case 'kick':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.kickFromChat;
2021-04-15 08:48:26 +02:00
case 'redact':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.deleteMessage;
2021-04-15 08:48:26 +02:00
case 'invite':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.inviteContact;
2021-04-15 08:48:26 +02:00
}
} else if (category == 'notifications') {
switch (permissionKey) {
case 'rooms':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.notifications;
2021-04-15 08:48:26 +02:00
}
} else if (category == 'events') {
switch (permissionKey) {
case EventTypes.RoomName:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.changeTheNameOfTheGroup;
2021-04-15 08:48:26 +02:00
case EventTypes.RoomPowerLevels:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.editChatPermissions;
2021-04-15 08:48:26 +02:00
case EventTypes.HistoryVisibility:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.visibilityOfTheChatHistory;
2021-04-15 08:48:26 +02:00
case EventTypes.RoomCanonicalAlias:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.setInvitationLink;
2021-04-15 08:48:26 +02:00
case EventTypes.RoomAvatar:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.editRoomAvatar;
2021-04-15 08:48:26 +02:00
case EventTypes.RoomTombstone:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.replaceRoomWithNewerVersion;
2021-04-15 08:48:26 +02:00
case EventTypes.Encryption:
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.enableEncryption;
2021-04-15 08:48:26 +02:00
case 'm.room.server_acl':
2022-01-29 12:35:03 +01:00
return L10n.of(context)!.editBlockedServers;
2021-04-15 08:48:26 +02:00
}
}
return permissionKey;
}
@override
Widget build(BuildContext context) {
return ListTile(
onTap: onTap,
leading: CircleAvatar(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
2021-10-14 18:09:30 +02:00
child: const Icon(Icons.edit_attributes_outlined),
2021-04-15 08:48:26 +02:00
),
title: Text(getLocalizedPowerLevelString(context)),
subtitle: Row(
children: [
Container(
2021-10-14 18:09:30 +02:00
padding: const EdgeInsets.all(4),
2021-04-15 08:48:26 +02:00
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Text(permission.toString()),
),
),
2021-10-14 18:09:30 +02:00
const SizedBox(width: 8),
2021-04-15 08:48:26 +02:00
Text(permission.toLocalizedPowerLevelString(context)),
],
),
);
}
}
extension on int {
String toLocalizedPowerLevelString(BuildContext context) {
return this == 100
2022-01-29 12:35:03 +01:00
? L10n.of(context)!.admin
2021-04-15 08:48:26 +02:00
: this >= 50
2022-01-29 12:35:03 +01:00
? L10n.of(context)!.moderator
: L10n.of(context)!.participant;
2021-04-15 08:48:26 +02:00
}
}