From bfd38886074a7dea953ad17518df5a169e511de0 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 6 Oct 2020 09:01:49 +0200 Subject: [PATCH] feat: Implement change device name --- lib/l10n/intl_en.arb | 7 ++++++- lib/views/settings_devices.dart | 35 ++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 5ac25ce..a6faa73 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -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": {} } -} +} \ No newline at end of file diff --git a/lib/views/settings_devices.dart b/lib/views/settings_devices.dart index 1894b13..a1a5620 100644 --- a/lib/views/settings_devices.dart +++ b/lib/views/settings_devices.dart @@ -56,6 +56,19 @@ class DevicesSettingsState extends State { } } + 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 { 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 { 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( + value: 'rename', + child: Text(L10n.of(context).changeDeviceName), + ), PopupMenuItem( 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(