From e6df6960775a0b3b3ec2efdc0ceb61971c2fb749 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 28 Apr 2020 19:03:23 +0200 Subject: [PATCH] Display user emojies --- lib/helpers/users_helper.dart | 6 +- .../account_settings_route.dart | 12 +++- .../emojies_account_settings.dart | 58 +++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 lib/ui/routes/account_settings/emojies_account_settings.dart diff --git a/lib/helpers/users_helper.dart b/lib/helpers/users_helper.dart index 75442f5..be0f7e4 100644 --- a/lib/helpers/users_helper.dart +++ b/lib/helpers/users_helper.dart @@ -83,8 +83,10 @@ class UsersHelper { } /// Get information about a single user. Throws in case of failure - Future getSingleWithThrow(int user) async { - return (await getListWithThrow(Set()..add(user)))[0]; + Future getSingleWithThrow(int user, + {bool forceDownload = false}) async { + return (await getListWithThrow(Set()..add(user), + forceDownload: forceDownload))[0]; } /// Get users information from a given [Set] diff --git a/lib/ui/routes/account_settings/account_settings_route.dart b/lib/ui/routes/account_settings/account_settings_route.dart index 8fbec61..5af235e 100644 --- a/lib/ui/routes/account_settings/account_settings_route.dart +++ b/lib/ui/routes/account_settings/account_settings_route.dart @@ -1,4 +1,5 @@ import 'package:comunic/ui/routes/account_settings/account_image_settings.dart'; +import 'package:comunic/ui/routes/account_settings/emojies_account_settings.dart'; import 'package:comunic/ui/routes/account_settings/general_account_settings.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -33,7 +34,7 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> { SettingsSection( title: tr("Account settings"), tiles: [ - + // General settings SettingsTile( title: tr("General settings"), subtitle: tr("Configure the main settings of your account"), @@ -41,6 +42,15 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> { onTap: () => _openSection(GeneralAccountSettingsScreen()), ), + // Emoticons + SettingsTile( + title: tr("Custom emojis"), + subtitle: tr("Set your own emoticon shorcuts"), + leading: Icon(Icons.insert_emoticon), + onTap: () => _openSection(EmojisAccountSettings()), + ), + + // Account image SettingsTile( title: tr("Account image"), subtitle: tr("Customize your account image"), diff --git a/lib/ui/routes/account_settings/emojies_account_settings.dart b/lib/ui/routes/account_settings/emojies_account_settings.dart new file mode 100644 index 0000000..9baa236 --- /dev/null +++ b/lib/ui/routes/account_settings/emojies_account_settings.dart @@ -0,0 +1,58 @@ +import 'package:comunic/helpers/users_helper.dart'; +import 'package:comunic/models/user.dart'; +import 'package:comunic/ui/widgets/async_screen_widget.dart'; +import 'package:comunic/ui/widgets/network_image_widget.dart'; +import 'package:comunic/utils/account_utils.dart'; +import 'package:comunic/utils/intl_utils.dart'; +import 'package:flutter/material.dart'; + +/// Emojies account settings +/// +/// @author Pierre Hubert + +class EmojisAccountSettings extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(tr("Emojies settings")), + ), + body: _EmojiesAccountBody(), + ); + } +} + +class _EmojiesAccountBody extends StatefulWidget { + @override + __EmojiesAccountBodyState createState() => __EmojiesAccountBodyState(); +} + +class __EmojiesAccountBodyState extends State<_EmojiesAccountBody> { + User _user; + + Future _reload() async { + _user = await UsersHelper().getSingleWithThrow( + userID(), + forceDownload: true, + ); + } + + @override + Widget build(BuildContext context) { + return AsyncScreenWidget( + onReload: _reload, + onBuild: _buildSettings, + errorMessage: tr("Could not refresh user information!"), + ); + } + + Widget _buildSettings() { + return ListView( + children: _user.customEmojies + .map((u) => ListTile( + leading: NetworkImageWidget(url: u.url, width: 50), + title: Text(u.shortcut), + )) + .toList()); + } +}