From c03504fe99532f3ced0bba0829f057495da1a8af Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 25 Dec 2021 18:47:36 +0100 Subject: [PATCH] feat: Share to story --- assets/l10n/intl_en.arb | 3 +- lib/pages/add_story/add_story.dart | 35 +++++++++++++++++++++ lib/pages/chat_list/chat_list_view.dart | 6 +++- lib/pages/chat_list/stories_header.dart | 42 ++++++++++++++++--------- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 90f62aa3..4b55266b 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2667,5 +2667,6 @@ "publish": "Publish", "whoCanSeeMyStories": "Who can see my stories?", "unsubscribeStories": "Unsubscribe stories", - "thisUserHasNotPostedAnythingYet": "This user has not posted anything in their story yet" + "thisUserHasNotPostedAnythingYet": "This user has not posted anything in their story yet", + "yourStory": "Your story" } diff --git a/lib/pages/add_story/add_story.dart b/lib/pages/add_story/add_story.dart index b688ce2d..c0537adc 100644 --- a/lib/pages/add_story/add_story.dart +++ b/lib/pages/add_story/add_story.dart @@ -152,6 +152,41 @@ class AddStoryController extends State { final text = Matrix.of(context).client.userID!; backgroundColor = text.color; backgroundColorDark = text.darkColor; + + final shareContent = Matrix.of(context).shareContent; + // ignore: unnecessary_null_comparison + if (shareContent != null) { + image = shareContent.tryGet('file'); + controller.text = shareContent.tryGet('body') ?? ''; + if (shareContent.tryGet('msgtype') == MessageTypes.Image) { + Event( + content: shareContent, + type: EventTypes.Message, + room: Room(id: '!tmproom', client: Matrix.of(context).client), + eventId: 'tmpevent', + senderId: '@tmpsender:example', + originServerTs: DateTime.now(), + ).downloadAndDecryptAttachment().then((file) { + setState(() { + image = file; + }); + }); + } else if (shareContent.tryGet('msgtype') == MessageTypes.Video) { + Event( + content: shareContent, + type: EventTypes.Message, + room: Room(id: '!tmproom', client: Matrix.of(context).client), + eventId: 'tmpevent', + senderId: '@tmpsender:example', + originServerTs: DateTime.now(), + ).downloadAndDecryptAttachment().then((file) { + setState(() { + video = file; + }); + }); + } + Matrix.of(context).shareContent = null; + } } @override diff --git a/lib/pages/chat_list/chat_list_view.dart b/lib/pages/chat_list/chat_list_view.dart index b8509d59..e512458b 100644 --- a/lib/pages/chat_list/chat_list_view.dart +++ b/lib/pages/chat_list/chat_list_view.dart @@ -308,7 +308,7 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> { controller: widget.controller.scrollController, itemCount: rooms.length + 1, itemBuilder: (BuildContext context, int i) { - if (i == 0) { + if (i == 0 && widget.controller.activeSpaceId == null) { return const StoriesHeader(); } i--; @@ -332,6 +332,10 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> { ), ); } + child = Material( + color: Theme.of(context).scaffoldBackgroundColor, + child: child, + ); return PageTransitionSwitcher( reverse: reversed, transitionBuilder: ( diff --git a/lib/pages/chat_list/stories_header.dart b/lib/pages/chat_list/stories_header.dart index eaf873bf..646c4cae 100644 --- a/lib/pages/chat_list/stories_header.dart +++ b/lib/pages/chat_list/stories_header.dart @@ -13,7 +13,11 @@ import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_exten import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; -enum ContextualRoomAction { mute, unmute, leave } +enum ContextualRoomAction { + mute, + unmute, + leave, +} class StoriesHeader extends StatelessWidget { const StoriesHeader({Key? key}) : super(key: key); @@ -82,7 +86,8 @@ class StoriesHeader extends StatelessWidget { if (client.storiesRooms.isEmpty && client.contacts.isEmpty) { return Container(); } - if (client.storiesRooms.isEmpty) { + if (client.storiesRooms.isEmpty || + Matrix.of(context).shareContent != null) { return ListTile( leading: CircleAvatar( radius: Avatar.defaultSize / 2, @@ -95,13 +100,13 @@ class StoriesHeader extends StatelessWidget { ); } return SizedBox( - height: 82, + height: 98, child: ListView( padding: const EdgeInsets.symmetric(horizontal: 2), scrollDirection: Axis.horizontal, children: [ _StoryButton( - label: 'Add to story', + label: L10n.of(context)!.yourStory, onPressed: () => _addToStoryAction(context), child: const Icon(Icons.add), ), @@ -116,6 +121,7 @@ class StoriesHeader extends StatelessWidget { .sender .avatarUrl, name: room.creatorDisplayname, + size: 100, ), unread: room.notificationCount > 0 || room.membership == Membership.invite, @@ -168,13 +174,13 @@ class _StoryButton extends StatelessWidget { @override Widget build(BuildContext context) { return SizedBox( - width: 74, + width: 78, child: InkWell( borderRadius: BorderRadius.circular(AppConfig.borderRadius), onTap: onPressed, onLongPress: onLongPressed, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 2), + padding: const EdgeInsets.symmetric(horizontal: 4), child: Column( children: [ const SizedBox(height: 8), @@ -192,14 +198,22 @@ class _StoryButton extends StatelessWidget { end: Alignment.bottomRight, ) : null, - color: unread ? null : Theme.of(context).colorScheme.surface, + color: unread ? null : Theme.of(context).dividerColor, borderRadius: BorderRadius.circular(Avatar.defaultSize), ), - child: CircleAvatar( - radius: Avatar.defaultSize / 2, - backgroundColor: Theme.of(context).colorScheme.surface, - foregroundColor: Theme.of(context).textTheme.bodyText1?.color, - child: child, + child: Material( + color: Theme.of(context).colorScheme.surface, + borderRadius: BorderRadius.circular(Avatar.defaultSize), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: CircleAvatar( + radius: 30, + backgroundColor: Theme.of(context).colorScheme.surface, + foregroundColor: + Theme.of(context).textTheme.bodyText1?.color, + child: child, + ), + ), ), ), const SizedBox(height: 8), @@ -207,9 +221,9 @@ class _StoryButton extends StatelessWidget { label, maxLines: 1, textAlign: TextAlign.center, - style: const TextStyle( + style: TextStyle( fontSize: 12, - fontWeight: FontWeight.bold, + fontWeight: unread ? FontWeight.bold : null, ), ), ],