Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into display_names_and_…
Browse files Browse the repository at this point in the history
…updates

# Conflicts:
#	lib/post/widgets/comment_view.dart
  • Loading branch information
CTalvio committed Jul 10, 2023
2 parents 3196d1a + c4279e5 commit de0748b
Show file tree
Hide file tree
Showing 23 changed files with 632 additions and 276 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- Increased NSFW blur - contribution from @guigs4
- Fixed issue where longer comment threads would not show up properly
- Fixed a bug where the URI was not parsed to lowercase before checking extensions to parse image dimensions - contribution from @Fmstrat
- Fixed issue where not all comments would show up on the profile page - contribution from @ajsosa

## 0.2.1+10 - 2023-07-02
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/community/pages/community_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
icon: const Icon(Icons.refresh_rounded, semanticLabel: 'Refresh'),
onPressed: () {
HapticFeedback.mediumImpact();
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId));
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId, listingType: state.listingType));
}),
IconButton(
icon: Icon(sortTypeIcon, semanticLabel: 'Sort By'),
Expand Down
39 changes: 28 additions & 11 deletions lib/community/widgets/community_drawer.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lemmy_api_client/v3.dart';
Expand Down Expand Up @@ -132,7 +133,7 @@ class _CommunityDrawerState extends State<CommunityDrawer> {
: (context.read<AccountBloc>().state.subsciptions.isNotEmpty)
? Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
padding: const EdgeInsets.symmetric(horizontal: 14.0),
child: Scrollbar(
controller: _scrollController,
child: SingleChildScrollView(
Expand All @@ -159,18 +160,34 @@ class _CommunityDrawerState extends State<CommunityDrawer> {

Navigator.of(context).pop();
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
children: [
Text(
community.title,
overflow: TextOverflow.ellipsis,
maxLines: 1,
CircleAvatar(
backgroundColor: community.icon != null ? Colors.transparent : theme.colorScheme.secondaryContainer,
foregroundImage: community.icon != null ? CachedNetworkImageProvider(community.icon!) : null,
maxRadius: 16,
child: Text( community.name[0].toUpperCase(),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
Text(
'${community.name} · ${fetchInstanceNameFromUrl(community.actorId)}',
style: theme.textTheme.bodyMedium,
const SizedBox(width: 16.0),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
community.title,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
Text(
'${community.name} · ${fetchInstanceNameFromUrl(community.actorId)}',
style: theme.textTheme.bodyMedium,
),
],
),
],
),
Expand Down
11 changes: 10 additions & 1 deletion lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class _PostCardState extends State<PostCard> {
isUserLoggedIn = context.read<AuthBloc>().state.isLoggedIn;
}

final GlobalKey<ScaffoldState> _feedScaffoldKey = GlobalKey<ScaffoldState>();

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
Expand All @@ -72,7 +74,13 @@ class _PostCardState extends State<PostCard> {
VoteType? myVote = widget.postViewMedia.postView.myVote;
bool saved = widget.postViewMedia.postView.saved;

return Listener(
return GestureDetector(
onHorizontalDragEnd: (details) {
if (details.primaryVelocity! > 0) {
_feedScaffoldKey.currentState?.openDrawer();
}
},
child: Listener(
behavior: HitTestBehavior.opaque,
onPointerDown: (event) => {},
onPointerUp: (event) => {
Expand Down Expand Up @@ -211,6 +219,7 @@ class _PostCardState extends State<PostCard> {
],
),
),
),
);
}
}
120 changes: 73 additions & 47 deletions lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PostCardList extends StatefulWidget {

class _PostCardListState extends State<PostCardList> {
final _scrollController = ScrollController(initialScrollOffset: 0);
bool _showReturnToTopButton = false;

@override
void initState() {
Expand All @@ -61,6 +62,9 @@ class _PostCardListState extends State<PostCardList> {
if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent * 0.7) {
widget.onScrollEndReached();
}
setState(() {
_showReturnToTopButton = _scrollController.offset > 300; // Adjust the threshold as needed
});
}

@override
Expand All @@ -74,7 +78,7 @@ class _PostCardListState extends State<PostCardList> {
onRefresh: () async {
HapticFeedback.mediumImpact();
if (widget.personId != null) {
context.read<UserBloc>().add(const GetUserEvent(reset: true));
context.read<UserBloc>().add(GetUserEvent(userId: widget.personId, reset: true));
} else {
context.read<CommunityBloc>().add(GetCommunityPostsEvent(
reset: true,
Expand All @@ -83,52 +87,74 @@ class _PostCardListState extends State<PostCardList> {
));
}
},
child: ListView.builder(
cacheExtent: 500,
controller: _scrollController,
itemCount: widget.postViews?.length != null ? ((widget.communityId != null || widget.communityName != null) ? widget.postViews!.length + 1 : widget.postViews!.length + 1) : 1,
itemBuilder: (context, index) {
if (index == 0 && (widget.communityId != null || widget.communityName != null)) {
return CommunityHeader(communityInfo: widget.communityInfo);
}
if (index == widget.postViews!.length) {
if (widget.hasReachedEnd == true) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: theme.dividerColor.withOpacity(0.1),
padding: const EdgeInsets.symmetric(vertical: 32.0),
child: Text(
'Hmmm. It seems like you\'ve reached the bottom.',
textAlign: TextAlign.center,
style: theme.textTheme.titleSmall,
),
),
],
);
} else {
return Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: const CircularProgressIndicator(),
),
],
);
}
} else {
PostViewMedia postViewMedia = widget.postViews![(widget.communityId != null || widget.communityName != null) ? index - 1 : index];
return PostCard(
postViewMedia: postViewMedia,
showInstanceName: widget.communityId == null,
onVoteAction: (VoteType voteType) => widget.onVoteAction(postViewMedia.postView.post.id, voteType),
onSaveAction: (bool saved) => widget.onSaveAction(postViewMedia.postView.post.id, saved),
);
}
},
child: Stack(
children: [
ListView.builder(
cacheExtent: 500,
controller: _scrollController,
itemCount: widget.postViews?.length != null ? ((widget.communityId != null || widget.communityName != null) ? widget.postViews!.length + 1 : widget.postViews!.length + 1) : 1,
itemBuilder: (context, index) {
if (index == 0 && (widget.communityId != null || widget.communityName != null)) {
return CommunityHeader(communityInfo: widget.communityInfo);
}
if (index == widget.postViews!.length) {
if (widget.hasReachedEnd == true) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: theme.dividerColor.withOpacity(0.1),
padding: const EdgeInsets.symmetric(vertical: 32.0),
child: Text(
'Hmmm. It seems like you\'ve reached the bottom.',
textAlign: TextAlign.center,
style: theme.textTheme.titleSmall,
),
),
],
);
} else {
return Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: const CircularProgressIndicator(),
),
],
);
}
} else {
PostViewMedia postViewMedia = widget.postViews![(widget.communityId != null || widget.communityName != null) ? index - 1 : index];
return PostCard(
postViewMedia: postViewMedia,
showInstanceName: widget.communityId == null,
onVoteAction: (VoteType voteType) => widget.onVoteAction(postViewMedia.postView.post.id, voteType),
onSaveAction: (bool saved) => widget.onSaveAction(postViewMedia.postView.post.id, saved),
);
}
},

),
if (_showReturnToTopButton)
Positioned(
bottom: 16,
left: 20,
child: FloatingActionButton(
onPressed: () {
_scrollController.animateTo(
0,
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
},
child: Icon(Icons.arrow_upward),
),
),
],
),

),
),
);

);
}
}
2 changes: 1 addition & 1 deletion lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class PostCardViewComfortable extends StatelessWidget {
textScaleFactor: state.contentFontSizeScale.textScaleFactor,
style: theme.textTheme.titleSmall?.copyWith(
fontSize: theme.textTheme.titleSmall!.fontSize! * 1.05,
color: postViewMedia.postView.read ? theme.textTheme.titleSmall?.color?.withOpacity(0.4) : null,
color: postViewMedia.postView.read ? theme.textTheme.titleSmall?.color?.withOpacity(0.4) : theme.textTheme.titleSmall?.color?.withOpacity(0.75),
),
),
onTap: () => onTapCommunityName(context, postViewMedia.postView.community.id),
Expand Down
Loading

0 comments on commit de0748b

Please sign in to comment.