Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feature/notifica…
Browse files Browse the repository at this point in the history
…tion-page
  • Loading branch information
micahmo committed Jan 19, 2024
2 parents 2c58261 + 37ee89b commit 35f5720
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 122 deletions.
4 changes: 2 additions & 2 deletions lib/community/pages/create_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/post/cubit/create_post_cubit.dart';
import 'package:thunder/shared/common_markdown_body.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/cross_posts.dart';
import 'package:thunder/shared/input_dialogs.dart';
import 'package:thunder/shared/link_preview_card.dart';
Expand Down Expand Up @@ -789,7 +789,7 @@ class _CommunitySelectorState extends State<CommunitySelector> {
padding: const EdgeInsets.only(left: 8, top: 12, bottom: 12),
child: Row(
children: [
CommunityIcon(community: _communityView?.community, radius: 16),
CommunityAvatar(community: _communityView?.community, radius: 16),
const SizedBox(width: 12),
_communityId != null
? Column(
Expand Down
6 changes: 3 additions & 3 deletions lib/community/widgets/community_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:thunder/account/utils/profiles.dart';
import 'package:thunder/community/bloc/anonymous_subscriptions_bloc.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/feed/feed.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/user_avatar.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/avatars/user_avatar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/instance.dart';
import 'package:thunder/utils/global_context.dart';
Expand Down Expand Up @@ -475,7 +475,7 @@ class CommunityItem extends StatelessWidget {

return Row(
children: [
CommunityIcon(community: community, radius: 16),
CommunityAvatar(community: community, radius: 16),
const SizedBox(width: 16.0),
Expanded(
child: Tooltip(
Expand Down
4 changes: 2 additions & 2 deletions lib/community/widgets/community_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:lemmy_api_client/v3.dart';

import 'package:thunder/core/enums/full_name_separator.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/icon_text.dart';
import 'package:thunder/utils/instance.dart';
import 'package:thunder/utils/numbers.dart';
Expand Down Expand Up @@ -91,7 +91,7 @@ class _CommunityHeaderState extends State<CommunityHeader> {
children: [
Row(
children: [
CommunityIcon(
CommunityAvatar(
community: widget.getCommunityResponse.communityView.community,
radius: 45.0,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/community/widgets/community_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:thunder/feed/bloc/feed_bloc.dart';
import 'package:thunder/instance/instance_view.dart';
import 'package:thunder/shared/common_markdown_body.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/shared/user_avatar.dart';
import 'package:thunder/shared/avatars/user_avatar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/date_time.dart';
import 'package:thunder/utils/instance.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class _PostCardState extends State<PostCard> {
isUserLoggedIn: isUserLoggedIn,
listingType: widget.listingType,
navigateToPost: ({PostViewMedia? postViewMedia}) async => await navigateToPost(context, postViewMedia: widget.postViewMedia),
indicateRead: widget.indicateRead,
)
: PostCardViewComfortable(
postViewMedia: widget.postViewMedia,
Expand Down
4 changes: 2 additions & 2 deletions lib/community/widgets/post_card_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:lemmy_api_client/v3.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/enums/full_name_separator.dart';
import 'package:thunder/feed/feed.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/icon_text.dart';
import 'package:thunder/shared/text/scalable_text.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
Expand Down Expand Up @@ -203,7 +203,7 @@ class PostCommunityAndAuthor extends StatelessWidget {
GestureDetector(
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: CommunityIcon(community: postView.community, radius: 14),
child: CommunityAvatar(community: postView.community, radius: 14),
),
onTap: () => navigateToFeedPage(context, communityId: postView.community.id, feedType: FeedType.community),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/community/widgets/post_card_type_badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TypeBadge extends StatelessWidget {
),
MediaType.image: MediaTypeBadgeItem(
baseColor: Colors.red,
icon: Icon(size: 17, Icons.image_rounded, color: getIconColor(theme, Colors.red)),
icon: Icon(size: 17, Icons.image_outlined, color: getIconColor(theme, Colors.red)),
)
};

Expand Down
21 changes: 17 additions & 4 deletions lib/community/widgets/post_card_view_compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PostCardViewCompact extends StatelessWidget {
final bool isUserLoggedIn;
final ListingType? listingType;
final void Function({PostViewMedia? postViewMedia})? navigateToPost;
final bool? indicateRead;

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

@override
Expand All @@ -39,7 +41,7 @@ class PostCardViewCompact extends StatelessWidget {

bool showThumbnailPreviewOnRight = state.showThumbnailPreviewOnRight;
bool showTextPostIndicator = state.showTextPostIndicator;
bool indicateRead = state.dimReadPosts;
bool indicateRead = this.indicateRead ?? state.dimReadPosts;

final showCommunitySubscription = (listingType == ListingType.all || listingType == ListingType.local) &&
isUserLoggedIn &&
Expand All @@ -61,7 +63,11 @@ class PostCardViewCompact extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
!showThumbnailPreviewOnRight && (postViewMedia.media.isNotEmpty || showTextPostIndicator)
? ThumbnailPreview(postViewMedia: postViewMedia, navigateToPost: navigateToPost)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
Expanded(
child: Column(
Expand Down Expand Up @@ -137,7 +143,11 @@ class PostCardViewCompact extends StatelessWidget {
),
),
showThumbnailPreviewOnRight && (postViewMedia.media.isNotEmpty || showTextPostIndicator)
? ThumbnailPreview(postViewMedia: postViewMedia, navigateToPost: navigateToPost)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
],
),
Expand All @@ -153,18 +163,21 @@ class ThumbnailPreview extends StatelessWidget {
/// The callback function to navigate to the post
final void Function({PostViewMedia? postViewMedia})? navigateToPost;

final bool? indicateRead;

const ThumbnailPreview({
super.key,
required this.postViewMedia,
required this.navigateToPost,
this.indicateRead,
});

@override
Widget build(BuildContext context) {
final state = context.read<ThunderBloc>().state;
final isUserLoggedIn = context.read<AuthBloc>().state.isLoggedIn;

final indicateRead = state.dimReadPosts;
final indicateRead = this.indicateRead ?? state.dimReadPosts;
final hideNsfwPreviews = state.hideNsfwPreviews;
final markPostReadOnMediaView = state.markPostReadOnMediaView;

Expand Down
8 changes: 4 additions & 4 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ class _PostPageState extends State<PostPage> {
PopupMenuItem(
onTap: () => createCrossPost(
context,
title: widget.postView?.postView.post.name ?? '',
url: widget.postView?.postView.post.url,
text: widget.postView?.postView.post.body,
postUrl: widget.postView?.postView.post.apId,
title: widget.postView?.postView.post.name ?? state.postView?.postView.post.name ?? '',
url: widget.postView?.postView.post.url ?? state.postView?.postView.post.url,
text: widget.postView?.postView.post.body ?? state.postView?.postView.post.body,
postUrl: widget.postView?.postView.post.apId ?? state.postView?.postView.post.apId,
scaffoldMessengerKey: _scaffoldMessengerKey,
),
child: ListTile(
Expand Down
6 changes: 3 additions & 3 deletions lib/search/pages/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import 'package:thunder/shared/error_message.dart';
import 'package:thunder/shared/input_dialogs.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/shared/sort_picker.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/user_avatar.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/avatars/user_avatar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/bottom_sheet_list_picker.dart';
import 'package:thunder/utils/constants.dart';
Expand Down Expand Up @@ -713,7 +713,7 @@ class _SearchPageState extends State<SearchPage> with AutomaticKeepAliveClientMi
message: '${communityView.community.title}\n${generateCommunityFullName(context, communityView.community.name, fetchInstanceNameFromUrl(communityView.community.actorId))}',
preferBelow: false,
child: ListTile(
leading: CommunityIcon(community: communityView.community, radius: 25),
leading: CommunityAvatar(community: communityView.community, radius: 25),
title: Text(
communityView.community.title,
overflow: TextOverflow.ellipsis,
Expand Down
1 change: 1 addition & 0 deletions lib/settings/pages/post_appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
communityMode: false,
isUserLoggedIn: true,
listingType: ListingType.all,
indicateRead: dimReadPosts,
),
)
: IgnorePointer(
Expand Down
52 changes: 52 additions & 0 deletions lib/shared/avatars/community_avatar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

import 'package:lemmy_api_client/v3.dart';
import 'package:cached_network_image/cached_network_image.dart';

/// A community avatar. Displays the associated community icon if available.
///
/// Otherwise, displays the first letter of the community title (display name).
/// If no title is available, displays the first letter of the community name.
class CommunityAvatar extends StatelessWidget {
/// The community information to display
final Community? community;

/// The radius of the avatar. Defaults to 12
final double radius;

const CommunityAvatar({super.key, this.community, this.radius = 12.0});

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

CircleAvatar placeholderIcon = CircleAvatar(
backgroundColor: theme.colorScheme.secondaryContainer,
maxRadius: radius,
child: Text(
community?.title.isNotEmpty == true
? community!.title[0].toUpperCase()
: community?.name.isNotEmpty == true
? community!.name[0].toUpperCase()
: '',
semanticsLabel: '',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: radius),
),
);

if (community?.icon?.isNotEmpty != true) return placeholderIcon;

return CachedNetworkImage(
imageUrl: community!.icon!,
imageBuilder: (context, imageProvider) {
return CircleAvatar(
backgroundColor: Colors.transparent,
foregroundImage: imageProvider,
maxRadius: radius,
);
},
placeholder: (context, url) => placeholderIcon,
errorWidget: (context, url, error) => placeholderIcon,
);
}
}
52 changes: 52 additions & 0 deletions lib/shared/avatars/user_avatar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

import 'package:lemmy_api_client/v3.dart';
import 'package:cached_network_image/cached_network_image.dart';

/// A user avatar. Displays the associated user icon if available.
///
/// Otherwise, displays the first letter of the user's display name.
/// If no display name is available, displays the first letter of the user's username.
class UserAvatar extends StatelessWidget {
/// The user information to display
final Person? person;

/// The radius of the avatar. Defaults to 16
final double radius;

const UserAvatar({super.key, this.person, this.radius = 16.0});

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

CircleAvatar placeholderIcon = CircleAvatar(
backgroundColor: theme.colorScheme.secondaryContainer,
maxRadius: radius,
child: Text(
person?.displayName?.isNotEmpty == true
? person!.displayName![0].toUpperCase()
: person?.name.isNotEmpty == true
? person!.name[0].toUpperCase()
: '',
semanticsLabel: '',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: radius),
),
);

if (person?.avatar?.isNotEmpty != true) return placeholderIcon;

return CachedNetworkImage(
imageUrl: person!.avatar!,
imageBuilder: (context, imageProvider) {
return CircleAvatar(
backgroundColor: Colors.transparent,
foregroundImage: imageProvider,
maxRadius: radius,
);
},
placeholder: (context, url) => placeholderIcon,
errorWidget: (context, url, error) => placeholderIcon,
);
}
}
44 changes: 0 additions & 44 deletions lib/shared/community_icon.dart

This file was deleted.

6 changes: 3 additions & 3 deletions lib/shared/input_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import 'package:thunder/core/auth/helpers/fetch_account.dart';
import 'package:thunder/core/enums/full_name_separator.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/feed/utils/community.dart';
import 'package:thunder/shared/community_icon.dart';
import 'package:thunder/shared/avatars/community_avatar.dart';
import 'package:thunder/shared/dialogs.dart';
import 'package:thunder/shared/user_avatar.dart';
import 'package:thunder/shared/avatars/user_avatar.dart';
import 'package:thunder/utils/global_context.dart';
import 'package:thunder/utils/instance.dart';
import 'package:thunder/utils/numbers.dart';
Expand Down Expand Up @@ -185,7 +185,7 @@ Widget buildCommunitySuggestionWidget(BuildContext context, CommunityView payloa
child: InkWell(
onTap: onSelected == null ? null : () => onSelected(payload),
child: ListTile(
leading: CommunityIcon(community: payload.community),
leading: CommunityAvatar(community: payload.community),
title: Text(
payload.community.title,
maxLines: 1,
Expand Down
Loading

0 comments on commit 35f5720

Please sign in to comment.