diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index e91766e2..a9c69ca2 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -1228,6 +1228,21 @@ "type": "text", "placeholders": {} }, + "pleaseChoose": "Please choose", + "@pleaseChoose": { + "type": "text", + "placeholders": {} + }, + "changeYourAvatar": "Change your avatar", + "@changeYourAvatar": { + "type": "text", + "placeholders": {} + }, + "removeYourAvatar": "Remove your avatar", + "@removeYourAvatar": { + "type": "text", + "placeholders": {} + }, "oopsPushError": "Oops! Unfortunately, an error occurred when setting up the push notifications.", "@oopsPushError": { "type": "text", diff --git a/lib/config/themes.dart b/lib/config/themes.dart index 9db493b4..885c5b83 100644 --- a/lib/config/themes.dart +++ b/lib/config/themes.dart @@ -60,6 +60,7 @@ abstract class FluffyThemes { ), ), popupMenuTheme: PopupMenuThemeData( + elevation: 4, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppConfig.borderRadius), ), diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 1e320da3..7c4abab8 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -194,6 +194,37 @@ class SettingsController extends State { } void setAvatarAction() async { + final action = await showConfirmationDialog( + context: context, + title: L10n.of(context).pleaseChoose, + actions: [ + AlertDialogAction( + key: AvatarAction.change, + label: L10n.of(context).changeYourAvatar, + isDefaultAction: true, + ), + AlertDialogAction( + key: AvatarAction.remove, + label: L10n.of(context).removeYourAvatar, + isDestructiveAction: true, + ), + ], + ); + if (action == null) return; + final matrix = Matrix.of(context); + if (action == AvatarAction.remove) { + final success = await showFutureLoadingDialog( + context: context, + future: () => matrix.client.setAvatarUrl(matrix.client.userID, null), + ); + if (success.error == null) { + setState(() { + profileFuture = null; + profile = null; + }); + } + return; + } MatrixFile file; if (PlatformInfos.isMobile) { final result = await ImagePicker().getImage( @@ -215,7 +246,6 @@ class SettingsController extends State { name: result.fileName, ); } - final matrix = Matrix.of(context); final success = await showFutureLoadingDialog( context: context, future: () => matrix.client.setAvatar(file), @@ -358,7 +388,13 @@ class SettingsController extends State { @override Widget build(BuildContext context) { final client = Matrix.of(context).client; - profileFuture ??= client.ownProfile.then((p) { + profileFuture ??= client + .getProfileFromUserId( + client.userID, + cache: false, + getFromRooms: false, + ) + .then((p) { if (mounted) setState(() => profile = p); return p; }); @@ -377,3 +413,5 @@ class SettingsController extends State { return SettingsView(this); } } + +enum AvatarAction { change, remove } diff --git a/lib/pages/views/settings_view.dart b/lib/pages/views/settings_view.dart index 67516f54..74af05c9 100644 --- a/lib/pages/views/settings_view.dart +++ b/lib/pages/views/settings_view.dart @@ -63,8 +63,11 @@ class SettingsView extends StatelessWidget { ], backgroundColor: Theme.of(context).appBarTheme.color, flexibleSpace: FlexibleSpaceBar( - background: ContentBanner(controller.profile?.avatarUrl, - onEdit: controller.setAvatarAction), + background: ContentBanner( + controller.profile?.avatarUrl, + onEdit: controller.setAvatarAction, + defaultIcon: Icons.account_circle_outlined, + ), ), ), ], diff --git a/lib/widgets/content_banner.dart b/lib/widgets/content_banner.dart index d6c79575..e2715992 100644 --- a/lib/widgets/content_banner.dart +++ b/lib/widgets/content_banner.dart @@ -51,13 +51,14 @@ class ContentBanner extends StatelessWidget { bottom: 0, child: Opacity( opacity: opacity, - child: (!loading && mxContent != null) - ? CachedNetworkImage( - imageUrl: src.toString(), - height: 300, - fit: BoxFit.cover, - ) - : Icon(defaultIcon, size: 200), + child: + (!loading && mxContent != null && mxContent.host.isNotEmpty) + ? CachedNetworkImage( + imageUrl: src.toString(), + height: 300, + fit: BoxFit.cover, + ) + : Icon(defaultIcon, size: 200), ), ), if (onEdit != null) @@ -67,6 +68,8 @@ class ContentBanner extends StatelessWidget { child: FloatingActionButton( mini: true, onPressed: onEdit, + backgroundColor: Theme.of(context).backgroundColor, + foregroundColor: Theme.of(context).textTheme.bodyText1.color, child: Icon(Icons.camera_alt_outlined), ), ),