Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
✨ add post & comment mention notification tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenautjoe committed Aug 11, 2019
1 parent 4cf7b1b commit 99cd4ce
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/services/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,18 @@ class LocalizationService {
name: 'notifications__reacted_to_post_comment_tile');
}

String get notifications__mentioned_in_post_comment_tile {
return Intl.message("[name] [username] mentioned you on a comment.",
desc: "Eg.: James @jamest mentioned you on a comment.",
name: 'notifications__mentioned_in_post_comment_tile');
}

String get notifications__mentioned_in_post_tile {
return Intl.message("[name] [username] mentioned you on a post.",
desc: "Eg.: James @jamest mentioned you on a post.",
name: 'notifications__mentioned_in_post_tile');
}

String get notifications__following_you_tile {
return Intl.message("[name] [username] is now following you.",
desc: "Eg.: James @jamest is now following you.",
Expand Down
18 changes: 18 additions & 0 deletions lib/widgets/tiles/notification_tile/notification_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:Okuna/models/notifications/notification.dart';
import 'package:Okuna/models/notifications/post_comment_notification.dart';
import 'package:Okuna/models/notifications/post_comment_reaction_notification.dart';
import 'package:Okuna/models/notifications/post_comment_reply_notification.dart';
import 'package:Okuna/models/notifications/post_comment_user_mention_notification.dart';
import 'package:Okuna/models/notifications/post_reaction_notification.dart';
import 'package:Okuna/models/notifications/post_user_mention_notification.dart';
import 'package:Okuna/models/theme.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/services/theme.dart';
Expand All @@ -18,7 +20,9 @@ import 'package:Okuna/widgets/tiles/notification_tile/widgets/follow_notificatio
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart';
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_reaction_notification_tile.dart';
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_reply_notification_tile.dart';
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart';
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_reaction_notification_tile.dart';
import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

Expand Down Expand Up @@ -117,6 +121,20 @@ class OBNotificationTile extends StatelessWidget {
onPressed: finalOnPressed,
);
break;
case PostCommentUserMentionNotification:
notificationTile = OBPostCommentUserMentionNotificationTile(
notification: notification,
postCommentUserMentionNotification: notificationContentObject,
onPressed: finalOnPressed,
);
break;
case PostUserMentionNotification:
notificationTile = OBPostUserMentionNotificationTile(
notification: notification,
postUserMentionNotification: notificationContentObject,
onPressed: finalOnPressed,
);
break;
default:
print('Unsupported notification content object type');
return const SizedBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class OBPostCommentNotificationTile extends StatelessWidget {
Widget build(BuildContext context) {
PostComment postComment = postCommentNotification.postComment;
Post post = postComment.post;
String postCommenterUsername = postComment.getCommenterUsername();
String postCommentText = postComment.text;
String postCommenterName = postComment.getCommenterName();

int postCreatorId = postCommentNotification.getPostCreatorId();
OpenbookProviderState openbookProvider = OpenbookProvider.of(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:Okuna/models/notifications/notification.dart';
import 'package:Okuna/models/notifications/post_comment_user_mention_notification.dart';
import 'package:Okuna/models/post.dart';
import 'package:Okuna/models/post_comment.dart';
import 'package:Okuna/models/post_comment_user_mention.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/services/localization.dart';
import 'package:Okuna/widgets/avatars/avatar.dart';
import 'package:Okuna/widgets/theming/actionable_smart_text.dart';
import 'package:Okuna/widgets/theming/secondary_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';

import 'notification_tile_skeleton.dart';
import 'notification_tile_title.dart';

class OBPostCommentUserMentionNotificationTile extends StatelessWidget {
final OBNotification notification;
final PostCommentUserMentionNotification postCommentUserMentionNotification;
static final double postCommentImagePreviewSize = 40;
final VoidCallback onPressed;

const OBPostCommentUserMentionNotificationTile(
{Key key,
@required this.notification,
@required this.postCommentUserMentionNotification,
this.onPressed})
: super(key: key);

@override
Widget build(BuildContext context) {
PostCommentUserMention postCommentUserMention =
postCommentUserMentionNotification.postCommentUserMention;
PostComment postComment = postCommentUserMention.postComment;
Post post = postComment.post;

Widget postCommentImagePreview;
if (post.hasImage()) {
postCommentImagePreview = ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image(
image: AdvancedNetworkImage(post.getImage(), useDiskCache: true),
height: postCommentImagePreviewSize,
width: postCommentImagePreviewSize,
fit: BoxFit.cover,
),
);
}
OpenbookProviderState openbookProvider = OpenbookProvider.of(context);
var utilsService = openbookProvider.utilsService;

Function navigateToMentionerProfile = () {
openbookProvider.navigationService.navigateToUserProfile(
user: postCommentUserMention.postComment.commenter, context: context);
};
LocalizationService _localizationService = openbookProvider.localizationService;

return OBNotificationTileSkeleton(
onTap: () {
if (onPressed != null) onPressed();
OpenbookProviderState openbookProvider = OpenbookProvider.of(context);

PostComment parentComment = postComment.parentComment;
if(parentComment!=null){
openbookProvider.navigationService.navigateToPostCommentRepliesLinked(
postComment: postComment,
context: context,
parentComment: parentComment);
}else {
openbookProvider.navigationService.navigateToPostCommentsLinked(
postComment: postComment, context: context);
}
},
leading: OBAvatar(
onPressed: navigateToMentionerProfile,
size: OBAvatarSize.medium,
avatarUrl: postCommentUserMention.postComment.commenter.getProfileAvatar(),
),
title: OBNotificationTileTitle(
text: TextSpan(text: _localizationService.notifications__mentioned_in_post_comment_tile),
onUsernamePressed: navigateToMentionerProfile,
user: postCommentUserMention.postComment.commenter,
),
subtitle: OBSecondaryText(
utilsService.timeAgo(notification.created),
size: OBTextSize.small,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:Okuna/models/notifications/notification.dart';
import 'package:Okuna/models/notifications/post_user_mention_notification.dart';
import 'package:Okuna/models/post.dart';
import 'package:Okuna/models/post_user_mention.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/services/localization.dart';
import 'package:Okuna/widgets/avatars/avatar.dart';
import 'package:Okuna/widgets/theming/actionable_smart_text.dart';
import 'package:Okuna/widgets/theming/secondary_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';

import 'notification_tile_skeleton.dart';
import 'notification_tile_title.dart';

class OBPostUserMentionNotificationTile extends StatelessWidget {
final OBNotification notification;
final PostUserMentionNotification postUserMentionNotification;
static final double postImagePreviewSize = 40;
final VoidCallback onPressed;

const OBPostUserMentionNotificationTile(
{Key key,
@required this.notification,
@required this.postUserMentionNotification,
this.onPressed})
: super(key: key);

@override
Widget build(BuildContext context) {
PostUserMention postUserMention =
postUserMentionNotification.postUserMention;
Post post = postUserMention.post;

Widget postImagePreview;
if (post.hasImage()) {
postImagePreview = ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image(
image: AdvancedNetworkImage(post.getImage(), useDiskCache: true),
height: postImagePreviewSize,
width: postImagePreviewSize,
fit: BoxFit.cover,
),
);
}
OpenbookProviderState openbookProvider = OpenbookProvider.of(context);
var utilsService = openbookProvider.utilsService;

Function navigateToMentionerProfile = () {
openbookProvider.navigationService.navigateToUserProfile(
user: postUserMention.post.creator, context: context);
};
LocalizationService _localizationService = openbookProvider.localizationService;

return OBNotificationTileSkeleton(
onTap: () {
if (onPressed != null) onPressed();
OpenbookProviderState openbookProvider = OpenbookProvider.of(context);
openbookProvider.navigationService
.navigateToPost(post: postUserMention.post, context: context);
},
leading: OBAvatar(
onPressed: navigateToMentionerProfile,
size: OBAvatarSize.medium,
avatarUrl: postUserMention.post.creator.getProfileAvatar(),
),
title: OBNotificationTileTitle(
text: TextSpan(text: _localizationService.notifications__mentioned_in_post_tile),
onUsernamePressed: navigateToMentionerProfile,
user: postUserMention.post.creator,
),
subtitle: OBSecondaryText(
utilsService.timeAgo(notification.created),
size: OBTextSize.small,
),
);
}
}

0 comments on commit 99cd4ce

Please sign in to comment.