mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 22:42:33 +01:00
Merge branch 'krille/change-device-name' into 'main'
feat: Implement change device name See merge request ChristianPauly/fluffychat-flutter!210
This commit is contained in:
commit
ec53ead45b
@ -159,6 +159,11 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"changeDeviceName": "Change device name",
|
||||
"@changeDeviceName": {
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"changedTheChatAvatar": "{username} changed the chat avatar",
|
||||
"@changedTheChatAvatar": {
|
||||
"type": "text",
|
||||
@ -1718,4 +1723,4 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
}
|
@ -56,6 +56,19 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
||||
}
|
||||
}
|
||||
|
||||
void _renameDeviceAction(BuildContext context, Device device) async {
|
||||
final displayName = await SimpleDialogs(context).enterText(
|
||||
hintText: device.displayName,
|
||||
labelText: L10n.of(context).changeDeviceName,
|
||||
);
|
||||
if (displayName == null) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
Matrix.of(context)
|
||||
.client
|
||||
.setDeviceMetadata(device.deviceId, displayName: displayName),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -117,6 +130,7 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
||||
itemBuilder: (BuildContext context, int i) =>
|
||||
UserDeviceListItem(
|
||||
devices[i],
|
||||
rename: (d) => _renameDeviceAction(context, d),
|
||||
remove: (d) => _removeDevicesAction(context, [d]),
|
||||
),
|
||||
),
|
||||
@ -132,23 +146,34 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
||||
class UserDeviceListItem extends StatelessWidget {
|
||||
final Device userDevice;
|
||||
final Function remove;
|
||||
final Function rename;
|
||||
|
||||
const UserDeviceListItem(this.userDevice, {this.remove, Key key})
|
||||
const UserDeviceListItem(this.userDevice, {this.remove, this.rename, Key key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopupMenuButton(
|
||||
onSelected: (String action) {
|
||||
if (action == 'remove' && remove != null) {
|
||||
remove(userDevice);
|
||||
switch (action) {
|
||||
case 'remove':
|
||||
if (remove != null) remove(userDevice);
|
||||
break;
|
||||
case 'rename':
|
||||
if (rename != null) rename(userDevice);
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) => [
|
||||
PopupMenuItem<String>(
|
||||
value: 'rename',
|
||||
child: Text(L10n.of(context).changeDeviceName),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'remove',
|
||||
child: Text(L10n.of(context).removeDevice,
|
||||
style: TextStyle(color: Colors.red)),
|
||||
child: Text(
|
||||
L10n.of(context).removeDevice,
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: ListTile(
|
||||
|
Loading…
Reference in New Issue
Block a user