diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index f100208e2..ca8cb8b04 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -284,7 +284,7 @@ class ChatDetailsView extends StatelessWidget { roomId: controller.roomId, startOpen: false, ), - if (room.pangeaRoomRules != null && room.isRoomAdmin) + if (room.pangeaRoomRules != null) RoomRulesEditor( roomId: controller.roomId, startOpen: false, diff --git a/lib/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart b/lib/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart index 5a6616f37..00b93f09a 100644 --- a/lib/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart +++ b/lib/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart @@ -77,8 +77,18 @@ class RoomRulesState extends State { // rules = PangeaRoomRules(); // } + void showNoPermission() { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(L10n.of(context)!.noPermission), + ), + ); + } + @override Widget build(BuildContext context) { + final darkGray = Theme.of(context).colorScheme.primary; + final lightGray = Theme.of(context).colorScheme.onPrimary; return Column( children: [ // if (widget.showAdd) @@ -138,107 +148,128 @@ class RoomRulesState extends State { height: isOpen ? null : 0, child: Padding( padding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 8.0), - child: Column( - children: [ - for (final setting in ToolSetting.values) - Column( - children: [ - ListTile( - title: Text( - "${setting.toolName( - context, - )}: ${rules.languageToolPermissionsText( + child: Opacity( + opacity: (room?.isRoomAdmin ?? false) ? 1 : 0.5, + child: Column( + children: [ + for (final setting in ToolSetting.values) + Column( + children: [ + ListTile( + title: Text( + "${setting.toolName( + context, + )}: ${rules.languageToolPermissionsText( + context, + setting, + )}", + ), + subtitle: Text(setting.toolDescription(context)), + ), + Slider( + value: rules.getToolSettings(setting).toDouble(), + onChanged: (value) { + if (room?.isRoomAdmin ?? false) { + updatePermission(() { + rules.setLanguageToolSetting( + setting, + value.toInt(), + ); + }); + } else { + showNoPermission(); + } + }, + divisions: 2, + max: 2, + min: 0, + label: rules.languageToolPermissionsText( context, setting, - )}", + ), ), - subtitle: Text(setting.toolDescription(context)), - ), - Slider( - value: rules.getToolSettings(setting).toDouble(), - onChanged: (value) { - updatePermission(() { - rules.setLanguageToolSetting( - setting, - value.toInt(), - ); - }); - }, - divisions: 2, - max: 2, - min: 0, - label: rules.languageToolPermissionsText( - context, - setting, - ), - ), - ], + ], + ), + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.oneToOneChatsWithinClass), + subtitle: + Text(L10n.of(context)!.oneToOneChatsWithinClassDesc), + value: rules.oneToOneChatClass, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.oneToOneChatClass = value, + ) + : showNoPermission(), ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.oneToOneChatsWithinClass), - subtitle: - Text(L10n.of(context)!.oneToOneChatsWithinClassDesc), - value: rules.oneToOneChatClass, - onChanged: (value) => updatePermission( - () => rules.oneToOneChatClass = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.createGroupChats), + subtitle: Text(L10n.of(context)!.createGroupChatsDesc), + value: rules.isCreateRooms, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isCreateRooms = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.createGroupChats), - subtitle: Text(L10n.of(context)!.createGroupChatsDesc), - value: rules.isCreateRooms, - onChanged: (value) => updatePermission( - () => rules.isCreateRooms = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.shareVideo), + subtitle: Text(L10n.of(context)!.shareVideoDesc), + value: rules.isShareVideo, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isShareVideo = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.shareVideo), - subtitle: Text(L10n.of(context)!.shareVideoDesc), - value: rules.isShareVideo, - onChanged: (value) => updatePermission( - () => rules.isShareVideo = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.sharePhotos), + subtitle: Text(L10n.of(context)!.sharePhotosDesc), + value: rules.isSharePhoto, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isSharePhoto = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.sharePhotos), - subtitle: Text(L10n.of(context)!.sharePhotosDesc), - value: rules.isSharePhoto, - onChanged: (value) => updatePermission( - () => rules.isSharePhoto = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.shareFiles), + subtitle: Text(L10n.of(context)!.shareFilesDesc), + value: rules.isShareFiles, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isShareFiles = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.shareFiles), - subtitle: Text(L10n.of(context)!.shareFilesDesc), - value: rules.isShareFiles, - onChanged: (value) => updatePermission( - () => rules.isShareFiles = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.sendVoiceNotes), + subtitle: Text(L10n.of(context)!.sendVoiceNotesDesc), + value: rules.isVoiceNotes, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isVoiceNotes = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.sendVoiceNotes), - subtitle: Text(L10n.of(context)!.sendVoiceNotesDesc), - value: rules.isVoiceNotes, - onChanged: (value) => updatePermission( - () => rules.isVoiceNotes = value, + SwitchListTile.adaptive( + activeColor: AppConfig.activeToggleColor, + title: Text(L10n.of(context)!.shareLocation), + subtitle: Text(L10n.of(context)!.shareLocationDesc), + value: rules.isShareLocation, + onChanged: (value) => (room?.isRoomAdmin ?? false) + ? updatePermission( + () => rules.isShareLocation = value, + ) + : showNoPermission(), ), - ), - SwitchListTile.adaptive( - activeColor: AppConfig.activeToggleColor, - title: Text(L10n.of(context)!.shareLocation), - subtitle: Text(L10n.of(context)!.shareLocationDesc), - value: rules.isShareLocation, - onChanged: (value) => updatePermission( - () => rules.isShareLocation = value, - ), - ), - ], + ], + ), ), ), ),