Skip to content

Commit

Permalink
Do not grey out read own/saved posts in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
CTalvio committed Aug 16, 2023
1 parent 074f5d6 commit 2cd3872
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 73 deletions.
4 changes: 4 additions & 0 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../../user/bloc/user_bloc.dart';
class PostCard extends StatefulWidget {
final PostViewMedia postViewMedia;
final bool showInstanceName;
final bool indicateRead;

final Function(VoteType) onVoteAction;
final Function(bool) onSaveAction;
Expand All @@ -39,6 +40,7 @@ class PostCard extends StatefulWidget {
required this.onSaveAction,
required this.onToggleReadAction,
required this.listingType,
required this.indicateRead,
});

@override
Expand Down Expand Up @@ -204,6 +206,7 @@ class _PostCardState extends State<PostCard> {
isUserLoggedIn: isUserLoggedIn,
listingType: widget.listingType,
navigateToPost: () async => await navigateToPost(context),
indicateRead: widget.indicateRead!,
)
: PostCardViewComfortable(
postViewMedia: widget.postViewMedia,
Expand All @@ -224,6 +227,7 @@ class _PostCardState extends State<PostCard> {
onSaveAction: widget.onSaveAction,
listingType: widget.listingType,
navigateToPost: () async => await navigateToPost(context),
indicateRead: widget.indicateRead!,
),
onLongPress: () => showPostActionBottomModalSheet(
context,
Expand Down
3 changes: 3 additions & 0 deletions lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PostCardList extends StatefulWidget {
final BlockedCommunity? blockedCommunity;
final SortType? sortType;
final List<Tagline>? taglines;
final bool indicateRead;

final VoidCallback onScrollEndReached;
final Function(int, VoteType) onVoteAction;
Expand All @@ -51,6 +52,7 @@ class PostCardList extends StatefulWidget {
this.sortType,
this.blockedCommunity,
this.taglines,
this.indicateRead = true,
});

@override
Expand Down Expand Up @@ -279,6 +281,7 @@ class _PostCardListState extends State<PostCardList> with TickerProviderStateMix
onSaveAction: (bool saved) => widget.onSaveAction(postViewMedia.postView.post.id, saved),
onToggleReadAction: (bool read) => widget.onToggleReadAction(postViewMedia.postView.post.id, read),
listingType: widget.listingType,
indicateRead: widget.indicateRead,
)
: null,
);
Expand Down
8 changes: 5 additions & 3 deletions lib/community/widgets/post_card_type_badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ class TypeBadge extends StatelessWidget {
const TypeBadge({
super.key,
required this.postViewMedia,
required this.read,
});

final PostViewMedia postViewMedia;
final bool read;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

Color getMaterialColor(Color blendColor) {
return Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.6), blendColor).withOpacity(postViewMedia.postView.read ? 0.55 : 1);
return Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.6), blendColor).withOpacity(read ? 0.55 : 1);
}

Color getIconColor(Color blendColor) {
return Color.alphaBlend(theme.colorScheme.onPrimaryContainer.withOpacity(0.9), blendColor).withOpacity(postViewMedia.postView.read ? 0.55 : 1);
return Color.alphaBlend(theme.colorScheme.onPrimaryContainer.withOpacity(0.9), blendColor).withOpacity(read ? 0.55 : 1);
}

final bool darkTheme = context.read<ThemeBloc>().state.useDarkTheme;
Expand All @@ -39,7 +41,7 @@ class TypeBadge extends StatelessWidget {
),
// This is the thin sliver between the badge and the preview.
// It should be made to match the read background color in the compact file.
color: postViewMedia.postView.read
color: read
? Color.alphaBlend(
theme.colorScheme.onBackground.withOpacity(darkTheme ? 0.05 : 0.075),
theme.colorScheme.background,
Expand Down
24 changes: 13 additions & 11 deletions lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PostCardViewComfortable extends StatelessWidget {
final bool markPostReadOnMediaView;
final PostListingType? listingType;
final void Function()? navigateToPost;
final bool indicateRead;

const PostCardViewComfortable({
super.key,
Expand All @@ -55,6 +56,7 @@ class PostCardViewComfortable extends StatelessWidget {
required this.onSaveAction,
required this.markPostReadOnMediaView,
required this.listingType,
required this.indicateRead,
this.navigateToPost,
});

Expand All @@ -69,10 +71,10 @@ class PostCardViewComfortable extends StatelessWidget {

final String textContent = postViewMedia.postView.post.body ?? "";
final TextStyle? textStyleCommunityAndAuthor = theme.textTheme.bodyMedium?.copyWith(
color: postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.85),
color: indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.85),
);

final Color? readColor = postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.90);
final Color? readColor = indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.90);

var mediaView = MediaView(
scrapeMissingPreviews: state.scrapeMissingPreviews,
Expand All @@ -83,7 +85,7 @@ class PostCardViewComfortable extends StatelessWidget {
markPostReadOnMediaView: markPostReadOnMediaView,
isUserLoggedIn: isUserLoggedIn,
navigateToPost: navigateToPost,
read: postViewMedia.postView.read,
read: indicateRead && postViewMedia.postView.read,
);

final bool useSaveButton = state.showSaveAction;
Expand All @@ -92,7 +94,7 @@ class PostCardViewComfortable extends StatelessWidget {
final bool darkTheme = context.read<ThemeBloc>().state.useDarkTheme;

return Container(
color: postViewMedia.postView.read ? theme.colorScheme.onBackground.withOpacity(darkTheme ? 0.05 : 0.075) : null,
color: indicateRead && postViewMedia.postView.read ? theme.colorScheme.onBackground.withOpacity(darkTheme ? 0.05 : 0.075) : null,
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand All @@ -109,8 +111,8 @@ class PostCardViewComfortable extends StatelessWidget {
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: postViewMedia.postView.post.featuredCommunity
? (postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green)
: (postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.55) : null),
? (indicateRead && postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green)
: (indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.55) : null),
),
),
if (postViewMedia.postView.post.featuredCommunity)
Expand All @@ -122,7 +124,7 @@ class PostCardViewComfortable extends StatelessWidget {
child: Icon(
Icons.push_pin_rounded,
size: 17.0 * textScaleFactor,
color: postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
color: indicateRead && postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
),
),
),
Expand All @@ -134,7 +136,7 @@ class PostCardViewComfortable extends StatelessWidget {
),
child: Icon(
Icons.star_rounded,
color: postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
color: indicateRead && postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
size: 16.0 * textScaleFactor,
semanticLabel: 'Saved',
),
Expand Down Expand Up @@ -165,7 +167,7 @@ class PostCardViewComfortable extends StatelessWidget {
text: postViewMedia.postView.post.name,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.65) : null,
color: indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.65) : null,
),
),
if (postViewMedia.postView.post.featuredCommunity)
Expand All @@ -177,7 +179,7 @@ class PostCardViewComfortable extends StatelessWidget {
child: Icon(
Icons.push_pin_rounded,
size: 17.0 * textScaleFactor,
color: postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
color: indicateRead && postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
),
),
),
Expand All @@ -189,7 +191,7 @@ class PostCardViewComfortable extends StatelessWidget {
),
child: Icon(
Icons.star_rounded,
color: postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
color: indicateRead && postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
size: 16.0 * textScaleFactor,
semanticLabel: 'Saved',
),
Expand Down
27 changes: 16 additions & 11 deletions lib/community/widgets/post_card_view_compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PostCardViewCompact extends StatelessWidget {
final bool isUserLoggedIn;
final PostListingType? listingType;
final void Function()? navigateToPost;
final bool indicateRead;

const PostCardViewCompact({
super.key,
Expand All @@ -36,6 +37,7 @@ class PostCardViewCompact extends StatelessWidget {
required this.markPostReadOnMediaView,
required this.isUserLoggedIn,
required this.listingType,
required this.indicateRead,
this.navigateToPost,
});

Expand All @@ -49,16 +51,16 @@ class PostCardViewCompact extends StatelessWidget {
context.read<AccountBloc>().state.subsciptions.map((subscription) => subscription.community.actorId).contains(postViewMedia.postView.community.actorId);

final TextStyle? textStyleCommunityAndAuthor = theme.textTheme.bodyMedium?.copyWith(
color: postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.75),
color: indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.75),
);

final Color? readColor = postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.90);
final Color? readColor = indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.45) : theme.textTheme.bodyMedium?.color?.withOpacity(0.90);
final double textScaleFactor = state.titleFontSizeScale.textScaleFactor;

final bool darkTheme = context.read<ThemeBloc>().state.useDarkTheme;

return Container(
color: postViewMedia.postView.read ? theme.colorScheme.onBackground.withOpacity(darkTheme ? 0.05 : 0.075) : null,
color: indicateRead && postViewMedia.postView.read ? theme.colorScheme.onBackground.withOpacity(darkTheme ? 0.05 : 0.075) : null,
padding: const EdgeInsets.only(
bottom: 8.0,
top: 6,
Expand All @@ -85,12 +87,12 @@ class PostCardViewCompact extends StatelessWidget {
viewMode: ViewMode.compact,
isUserLoggedIn: isUserLoggedIn,
navigateToPost: navigateToPost,
read: postViewMedia.postView.read,
read: indicateRead && postViewMedia.postView.read,
),
),
Padding(
padding: const EdgeInsets.only(right: 6, bottom: 0),
child: TypeBadge(postViewMedia: postViewMedia),
child: TypeBadge(postViewMedia: postViewMedia, read: indicateRead && postViewMedia.postView.read),
),
],
),
Expand All @@ -108,8 +110,8 @@ class PostCardViewCompact extends StatelessWidget {
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: postViewMedia.postView.post.featuredCommunity
? (postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green)
: (postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.55) : null),
? (indicateRead && postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green)
: (indicateRead && postViewMedia.postView.read ? theme.textTheme.bodyMedium?.color?.withOpacity(0.55) : null),
),
),
if (postViewMedia.postView.post.featuredCommunity)
Expand All @@ -121,7 +123,7 @@ class PostCardViewCompact extends StatelessWidget {
child: Icon(
Icons.push_pin_rounded,
size: 17.0 * textScaleFactor,
color: postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
color: indicateRead && postViewMedia.postView.read ? Colors.green.withOpacity(0.55) : Colors.green,
),
),
),
Expand All @@ -133,7 +135,7 @@ class PostCardViewCompact extends StatelessWidget {
),
child: Icon(
Icons.star_rounded,
color: postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
color: indicateRead && postViewMedia.postView.read ? Colors.purple.withOpacity(0.55) : Colors.purple,
size: 16.0 * textScaleFactor,
semanticLabel: 'Saved',
),
Expand Down Expand Up @@ -186,12 +188,15 @@ class PostCardViewCompact extends StatelessWidget {
viewMode: ViewMode.compact,
isUserLoggedIn: isUserLoggedIn,
navigateToPost: navigateToPost,
read: postViewMedia.postView.read,
read: indicateRead && postViewMedia.postView.read,
),
),
Padding(
padding: const EdgeInsets.only(right: 6, bottom: 0),
child: TypeBadge(postViewMedia: postViewMedia),
child: TypeBadge(
postViewMedia: postViewMedia,
read: indicateRead && postViewMedia.postView.read,
),
),
],
),
Expand Down
2 changes: 2 additions & 0 deletions lib/user/pages/user_page_success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class _UserPageSuccessState extends State<UserPageSuccess> with TickerProviderSt
onSaveAction: (int postId, bool save) => context.read<UserBloc>().add(SavePostEvent(postId: postId, save: save)),
onVoteAction: (int postId, VoteType voteType) => context.read<UserBloc>().add(VotePostEvent(postId: postId, score: voteType)),
onToggleReadAction: (int postId, bool read) => context.read<UserBloc>().add(MarkUserPostAsReadEvent(postId: postId, read: read)),
indicateRead: widget.isAccountUser ? false : true,
),
),
if (!savedToggle && selectedUserOption == 1)
Expand All @@ -259,6 +260,7 @@ class _UserPageSuccessState extends State<UserPageSuccess> with TickerProviderSt
onSaveAction: (int postId, bool save) => context.read<UserBloc>().add(SavePostEvent(postId: postId, save: save)),
onVoteAction: (int postId, VoteType voteType) => context.read<UserBloc>().add(VotePostEvent(postId: postId, score: voteType)),
onToggleReadAction: (int postId, bool read) => context.read<UserBloc>().add(MarkUserPostAsReadEvent(postId: postId, read: read)),
indicateRead: widget.isAccountUser ? false : true,
),
),
if (savedToggle && selectedUserOption == 1)
Expand Down
Loading

0 comments on commit 2cd3872

Please sign in to comment.