mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 11:05:10 +00:00
design: Redesign permissions settings with dropdownbuttons
This commit is contained in:
parent
de68f62aef
commit
ac7e424b7b
4 changed files with 68 additions and 38 deletions
|
@ -2525,6 +2525,13 @@
|
||||||
"@thisDevice": {},
|
"@thisDevice": {},
|
||||||
"initAppError": "An error occured while init the app",
|
"initAppError": "An error occured while init the app",
|
||||||
"@initAppError": {},
|
"@initAppError": {},
|
||||||
|
"minimumPowerLevel": "{level} is the minimum power level.",
|
||||||
|
"@minimumPowerLevel": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {
|
||||||
|
"level": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"databaseBuildErrorBody": "Unable to build the SQlite database. The app tries to use the legacy database for now. Please report this error to the developers at {url}. The error message is: {error}",
|
"databaseBuildErrorBody": "Unable to build the SQlite database. The app tries to use the legacy database for now. Please report this error to the developers at {url}. The error message is: {error}",
|
||||||
"@databaseBuildErrorBody": {
|
"@databaseBuildErrorBody": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
@ -9,7 +10,6 @@ import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_permissions_settings/chat_permissions_settings_view.dart';
|
import 'package:fluffychat/pages/chat_permissions_settings/chat_permissions_settings_view.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import 'package:fluffychat/widgets/permission_slider_dialog.dart';
|
|
||||||
|
|
||||||
class ChatPermissionsSettings extends StatefulWidget {
|
class ChatPermissionsSettings extends StatefulWidget {
|
||||||
const ChatPermissionsSettings({super.key});
|
const ChatPermissionsSettings({super.key});
|
||||||
|
@ -25,6 +25,7 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
String key,
|
String key,
|
||||||
int currentLevel, {
|
int currentLevel, {
|
||||||
|
int? newLevel,
|
||||||
String? category,
|
String? category,
|
||||||
}) async {
|
}) async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||||
|
@ -34,9 +35,30 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final newLevel = await showPermissionChooser(
|
newLevel ??= int.tryParse(
|
||||||
context,
|
(await showTextInputDialog(
|
||||||
currentLevel: currentLevel,
|
context: context,
|
||||||
|
title: L10n.of(context)!.setPermissionsLevel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
initialText: currentLevel.toString(),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
autocorrect: false,
|
||||||
|
validator: (text) {
|
||||||
|
if (text == null) {
|
||||||
|
return L10n.of(context)!.pleaseEnterANumber;
|
||||||
|
}
|
||||||
|
final level = int.tryParse(text);
|
||||||
|
if (level == null || level < 0) {
|
||||||
|
return L10n.of(context)!.pleaseEnterANumber;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
))
|
||||||
|
?.singleOrNull ??
|
||||||
|
'',
|
||||||
);
|
);
|
||||||
if (newLevel == null) return;
|
if (newLevel == null) return;
|
||||||
final content = Map<String, dynamic>.from(
|
final content = Map<String, dynamic>.from(
|
||||||
|
|
|
@ -48,11 +48,13 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
||||||
PermissionsListTile(
|
PermissionsListTile(
|
||||||
permissionKey: entry.key,
|
permissionKey: entry.key,
|
||||||
permission: entry.value,
|
permission: entry.value,
|
||||||
onTap: () => controller.editPowerLevel(
|
onChanged: (level) => controller.editPowerLevel(
|
||||||
context,
|
context,
|
||||||
entry.key,
|
entry.key,
|
||||||
entry.value,
|
entry.value,
|
||||||
|
newLevel: level,
|
||||||
),
|
),
|
||||||
|
canEdit: room.canChangePowerLevel,
|
||||||
),
|
),
|
||||||
Divider(color: Theme.of(context).dividerColor),
|
Divider(color: Theme.of(context).dividerColor),
|
||||||
ListTile(
|
ListTile(
|
||||||
|
@ -78,10 +80,12 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
||||||
permissionKey: key,
|
permissionKey: key,
|
||||||
permission: value,
|
permission: value,
|
||||||
category: 'notifications',
|
category: 'notifications',
|
||||||
onTap: () => controller.editPowerLevel(
|
canEdit: room.canChangePowerLevel,
|
||||||
|
onChanged: (level) => controller.editPowerLevel(
|
||||||
context,
|
context,
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
|
newLevel: level,
|
||||||
category: 'notifications',
|
category: 'notifications',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -102,10 +106,12 @@ class ChatPermissionsSettingsView extends StatelessWidget {
|
||||||
permissionKey: entry.key,
|
permissionKey: entry.key,
|
||||||
category: 'events',
|
category: 'events',
|
||||||
permission: entry.value ?? 0,
|
permission: entry.value ?? 0,
|
||||||
onTap: () => controller.editPowerLevel(
|
canEdit: room.canChangePowerLevel,
|
||||||
|
onChanged: (level) => controller.editPowerLevel(
|
||||||
context,
|
context,
|
||||||
entry.key,
|
entry.key,
|
||||||
entry.value ?? 0,
|
entry.value ?? 0,
|
||||||
|
newLevel: level,
|
||||||
category: 'events',
|
category: 'events',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -7,14 +7,16 @@ class PermissionsListTile extends StatelessWidget {
|
||||||
final String permissionKey;
|
final String permissionKey;
|
||||||
final int permission;
|
final int permission;
|
||||||
final String? category;
|
final String? category;
|
||||||
final void Function()? onTap;
|
final void Function(int? level)? onChanged;
|
||||||
|
final bool canEdit;
|
||||||
|
|
||||||
const PermissionsListTile({
|
const PermissionsListTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.permissionKey,
|
required this.permissionKey,
|
||||||
required this.permission,
|
required this.permission,
|
||||||
this.category,
|
this.category,
|
||||||
this.onTap,
|
required this.onChanged,
|
||||||
|
required this.canEdit,
|
||||||
});
|
});
|
||||||
|
|
||||||
String getLocalizedPowerLevelString(BuildContext context) {
|
String getLocalizedPowerLevelString(BuildContext context) {
|
||||||
|
@ -66,39 +68,32 @@ class PermissionsListTile extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: onTap,
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
foregroundColor: Colors.grey,
|
|
||||||
child: const Icon(Icons.edit_attributes_outlined),
|
|
||||||
),
|
|
||||||
title: Text(getLocalizedPowerLevelString(context)),
|
title: Text(getLocalizedPowerLevelString(context)),
|
||||||
subtitle: Row(
|
subtitle: Text(
|
||||||
children: [
|
L10n.of(context)!.minimumPowerLevel(permission.toString()),
|
||||||
Container(
|
),
|
||||||
padding: const EdgeInsets.all(4),
|
trailing: DropdownButton<int>(
|
||||||
decoration: BoxDecoration(
|
onChanged: canEdit ? onChanged : null,
|
||||||
color: Theme.of(context).secondaryHeaderColor,
|
value: {0, 50, 100}.contains(permission) ? permission : null,
|
||||||
borderRadius: BorderRadius.circular(8),
|
items: [
|
||||||
),
|
DropdownMenuItem(
|
||||||
child: Center(
|
value: 0,
|
||||||
child: Text(permission.toString()),
|
child: Text(L10n.of(context)!.user),
|
||||||
),
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: 50,
|
||||||
|
child: Text(L10n.of(context)!.moderator),
|
||||||
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: 100,
|
||||||
|
child: Text(L10n.of(context)!.admin),
|
||||||
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: null,
|
||||||
|
child: Text(L10n.of(context)!.custom),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(permission.toLocalizedPowerLevelString(context)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on int {
|
|
||||||
String toLocalizedPowerLevelString(BuildContext context) {
|
|
||||||
return this == 100
|
|
||||||
? L10n.of(context)!.admin
|
|
||||||
: this >= 50
|
|
||||||
? L10n.of(context)!.moderator
|
|
||||||
: L10n.of(context)!.participant;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue