From 24765789df851eebb23598069521804e18ad8b0b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 12 Feb 2021 22:45:17 +0100 Subject: [PATCH] Improve account image settings --- assets/langs/fr.json | 2 +- .../settings/account_image_settings.dart | 83 ++++++++----------- lib/ui/screens/group_settings_screen.dart | 2 + 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/assets/langs/fr.json b/assets/langs/fr.json index 4a8b538..8e2f7ab 100644 --- a/assets/langs/fr.json +++ b/assets/langs/fr.json @@ -414,7 +414,7 @@ "You can choose a new password.": "Vous pouvez choisir un nouveau mot de passe.", "You can reach us at contact@communiquons.org": "Vous pouvez nous contacter à l'adresse contact@communiquons.org", "You can use this virtual directory.": "Vous pouvez utiliser ce répertoire virtuel.", - "You do not have any notification now.": "Vous n'avez pas de notifications pour l'intant.", + "You do not have any notification now.": "Vous n'avez pas de notification pour l'intant.", "You do not have any unread conversation yet...": "Vous n'avez aucune conversation non lue pour le moment...", "You must accept the Terms Of Service to continue.": "Vous devez accepter les Conditions d'utilisation pour continuer.", "You security questions have been successfully updated!": "Vos questions de sécurité ont été mises avec succès !", diff --git a/lib/ui/routes/settings/account_image_settings.dart b/lib/ui/routes/settings/account_image_settings.dart index d891ed5..ab5d7df 100644 --- a/lib/ui/routes/settings/account_image_settings.dart +++ b/lib/ui/routes/settings/account_image_settings.dart @@ -1,9 +1,11 @@ import 'package:comunic/helpers/database/users_database_helper.dart'; import 'package:comunic/helpers/settings_helper.dart'; import 'package:comunic/models/account_image_settings.dart'; +import 'package:comunic/ui/dialogs/multi_choices_dialog.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; import 'package:comunic/ui/widgets/network_image_widget.dart'; import 'package:comunic/ui/widgets/settings/header_spacer_section.dart'; +import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart'; import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/files_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; @@ -87,6 +89,27 @@ class _AccountImageSettingsScreenState ]; } + List> get _visibilityLevels => + [ + MultiChoiceEntry( + id: AccountImageVisibilityLevels.EVERYONE, + title: tr("Everyone"), + subtitle: tr( + "Your account image is visible by everyone, including users external to Comunic."), + ), + MultiChoiceEntry( + id: AccountImageVisibilityLevels.COMUNIC_USERS, + title: tr("Connected users"), + subtitle: tr( + "Your account image is visible only to connected Comunic users."), + ), + MultiChoiceEntry( + id: AccountImageVisibilityLevels.FRIENDS_ONLY, + title: tr("My friends"), + subtitle: tr("Your account image is visible only by your friends."), + ), + ]; + /// When the user has an account image List _buildHasAccountImageTiles() { return [ @@ -112,18 +135,16 @@ class _AccountImageSettingsScreenState ), // Change account image visibility - SettingsTile( - title: tr("Change account image visibility"), - onPressed: (_) => _chooseAccountImageVisibility(), - subtitle: tr("Current level: %level%", args: { - "level": - _settings.visibility == AccountImageVisibilityLevels.EVERYONE - ? tr("Everyone") - : _settings.visibility == - AccountImageVisibilityLevels.COMUNIC_USERS - ? tr("Comunic users") - : tr("My friends only"), - })), + MultiChoicesSettingsTile( + title: tr("Account image visibility"), + choices: _visibilityLevels, + currentValue: _settings.visibility, + onChanged: (newLevel) async { + if (!await SettingsHelper.setAccountImageVisibilityLevel(newLevel)) + showSimpleSnack(context, + tr("Could not update account image visibility level!")); + _key.currentState.refresh(); + }), // Delete account image SettingsTile( @@ -161,44 +182,6 @@ class _AccountImageSettingsScreenState _key.currentState.refresh(); } - /// Change account image visibility - void _chooseAccountImageVisibility() async { - final newLevel = await showDialog( - context: context, - builder: (c) => AlertDialog( - title: Text(tr("Account image visiblity")), - content: - Text(tr("Please choose new account image visibility level:")), - actions: [ - MaterialButton( - child: Text(tr("Everyone")), - onPressed: () => - Navigator.pop(c, AccountImageVisibilityLevels.EVERYONE), - ), - MaterialButton( - child: Text(tr("Connected users")), - onPressed: () => Navigator.pop( - c, AccountImageVisibilityLevels.COMUNIC_USERS), - ), - MaterialButton( - child: Text(tr("My friends")), - onPressed: () => Navigator.pop( - c, AccountImageVisibilityLevels.FRIENDS_ONLY), - ) - ], - )); - - if (newLevel == null) return; - - if (!await SettingsHelper.setAccountImageVisibilityLevel(newLevel)) { - showSimpleSnack( - context, tr("Could not update account image visibility level!")); - return; - } - - _key.currentState.refresh(); - } - /// Delete user account image void _deleteAccountImage() async { if (!await showConfirmDialog( diff --git a/lib/ui/screens/group_settings_screen.dart b/lib/ui/screens/group_settings_screen.dart index 9e0148e..4cf2429 100644 --- a/lib/ui/screens/group_settings_screen.dart +++ b/lib/ui/screens/group_settings_screen.dart @@ -11,6 +11,7 @@ import 'package:comunic/ui/widgets/async_screen_widget.dart'; import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; import 'package:comunic/ui/widgets/group_icon_widget.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; +import 'package:comunic/ui/widgets/settings/header_spacer_section.dart'; import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart'; import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart'; import 'package:comunic/utils/files_utils.dart'; @@ -81,6 +82,7 @@ class _GroupSettingsScreenState extends SafeState { Widget _buildContent() { return SettingsList( sections: [ + HeadSpacerSection(), _buildGeneralSection(), _buildAccessRestrictions(), _buildGroupLogoArea(),