Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to hide thumbnails in feed #1302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class _PostCardState extends State<PostCard> {
)
: PostCardViewComfortable(
postViewMedia: widget.postViewMedia,
hideThumbnails: state.hideThumbnails,
showThumbnailPreviewOnRight: state.showThumbnailPreviewOnRight,
hideNsfwPreviews: state.hideNsfwPreviews,
markPostReadOnMediaView: state.markPostReadOnMediaView,
Expand Down
3 changes: 3 additions & 0 deletions lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PostCardViewComfortable extends StatelessWidget {
final Function(bool) onSaveAction;

final PostViewMedia postViewMedia;
final bool hideThumbnails;
final bool showThumbnailPreviewOnRight;
final bool hideNsfwPreviews;
final bool edgeToEdgeImages;
Expand All @@ -45,6 +46,7 @@ class PostCardViewComfortable extends StatelessWidget {
const PostCardViewComfortable({
super.key,
required this.postViewMedia,
required this.hideThumbnails,
required this.showThumbnailPreviewOnRight,
required this.hideNsfwPreviews,
required this.edgeToEdgeImages,
Expand Down Expand Up @@ -84,6 +86,7 @@ class PostCardViewComfortable extends StatelessWidget {
postViewMedia: postViewMedia,
showFullHeightImages: showFullHeightImages,
hideNsfwPreviews: hideNsfwPreviews,
hideThumbnails: hideThumbnails,
edgeToEdgeImages: edgeToEdgeImages,
markPostReadOnMediaView: markPostReadOnMediaView,
isUserLoggedIn: isUserLoggedIn,
Expand Down
31 changes: 17 additions & 14 deletions lib/community/widgets/post_card_view_compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PostCardViewCompact extends StatelessWidget {
final theme = Theme.of(context);
final ThunderState state = context.watch<ThunderBloc>().state;

bool hideThumbnails = state.hideThumbnails;
bool showThumbnailPreviewOnRight = state.showThumbnailPreviewOnRight;
bool showTextPostIndicator = state.showTextPostIndicator;
bool indicateRead = this.indicateRead ?? state.dimReadPosts;
Expand All @@ -63,13 +64,14 @@ class PostCardViewCompact extends StatelessWidget {
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
!showThumbnailPreviewOnRight && showMedia && (postViewMedia.media.first.mediaType == MediaType.text ? showTextPostIndicator : true)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
if (!hideThumbnails)
!showThumbnailPreviewOnRight && showMedia && (postViewMedia.media.first.mediaType == MediaType.text ? showTextPostIndicator : true)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -167,13 +169,14 @@ class PostCardViewCompact extends StatelessWidget {
],
),
),
showThumbnailPreviewOnRight && showMedia && (postViewMedia.media.first.mediaType == MediaType.text ? showTextPostIndicator : true)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
if (!hideThumbnails)
showThumbnailPreviewOnRight && showMedia && (postViewMedia.media.first.mediaType == MediaType.text ? showTextPostIndicator : true)
? ThumbnailPreview(
postViewMedia: postViewMedia,
navigateToPost: navigateToPost,
indicateRead: indicateRead,
)
: const SizedBox(width: 8.0),
],
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum LocalSettings {
// Compact Related Settings
useCompactView(name: 'setting_general_use_compact_view', key: 'compactView', category: LocalSettingsCategories.posts, subCategory: LocalSettingsSubCategories.posts),
showPostTitleFirst(name: 'setting_general_show_title_first', key: 'showPostTitleFirst', category: LocalSettingsCategories.posts, subCategory: LocalSettingsSubCategories.posts),
hideThumbnails(name: 'setting_general_hide_thumbnails', key: 'hideThumbnails', category: LocalSettingsCategories.posts, subCategory: LocalSettingsSubCategories.feed),
showThumbnailPreviewOnRight(
name: 'setting_compact_show_thumbnail_on_right', key: 'showThumbnailPreviewOnRight', category: LocalSettingsCategories.posts, subCategory: LocalSettingsSubCategories.posts),
showTextPostIndicator(name: 'setting_compact_show_text_post_indicator', key: 'showTextPostIndicator', category: LocalSettingsCategories.posts, subCategory: LocalSettingsSubCategories.posts),
Expand Down Expand Up @@ -328,6 +329,7 @@ extension LocalizationExt on AppLocalizations {
'appLanguage': appLanguage,
'compactView': compactView,
'showPostTitleFirst': showPostTitleFirst,
'hideThumbnails': hideThumbnails,
'showThumbnailPreviewOnRight': showThumbnailPreviewOnRight,
'showTextPostIndicator': showTextPostIndicator,
'tappableAuthorCommunity': tappableAuthorCommunity,
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@
},
"hidePassword": "Hide Password",
"@hidePassword": {},
"hideThumbnails": "Hide Thumbnails",
"@hideThumbnails": {
"description": "Option to hide thumbnails in feed"
},
"hideTopBarOnScroll": "Hide Top Bar on Scroll",
"@hideTopBarOnScroll": {
"description": "Settings toggle to hide the top bar on scroll"
Expand Down
83 changes: 53 additions & 30 deletions lib/settings/pages/post_appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
/// When enabled, posts on the feed will be compacted
bool useCompactView = false;

/// When enabled, the thumbnails in compact/card mode will be hidden
bool hideThumbnails = false;

/// When enabled, the thumbnail previews will be shown on the right. By default, they are shown on the left
bool showThumbnailPreviewOnRight = false;

Expand Down Expand Up @@ -136,6 +139,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
// General Settings
useCompactView = prefs.getBool(LocalSettings.useCompactView.name) ?? false;
hideNsfwPreviews = prefs.getBool(LocalSettings.hideNsfwPreviews.name) ?? true;
hideThumbnails = prefs.getBool(LocalSettings.hideThumbnails.name) ?? false;
showPostAuthor = prefs.getBool(LocalSettings.showPostAuthor.name) ?? false;
useDisplayNames = prefs.getBool(LocalSettings.useDisplayNamesForUsers.name) ?? true;
postShowUserInstance = prefs.getBool(LocalSettings.postShowUserInstance.name) ?? false;
Expand Down Expand Up @@ -182,6 +186,10 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
await prefs.setBool(LocalSettings.hideNsfwPreviews.name, value);
setState(() => hideNsfwPreviews = value);
break;
case LocalSettings.hideThumbnails:
await prefs.setBool(LocalSettings.hideThumbnails.name, value);
setState(() => hideThumbnails = value);
break;
case LocalSettings.showPostAuthor:
await prefs.setBool(LocalSettings.showPostAuthor.name, value);
setState(() => showPostAuthor = value);
Expand Down Expand Up @@ -287,6 +295,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>

await prefs.remove(LocalSettings.useCompactView.name);
await prefs.remove(LocalSettings.hideNsfwPreviews.name);
await prefs.remove(LocalSettings.hideThumbnails.name);
await prefs.remove(LocalSettings.showPostAuthor.name);
await prefs.remove(LocalSettings.useDisplayNamesForUsers.name);
await prefs.remove(LocalSettings.postShowUserInstance.name);
Expand Down Expand Up @@ -509,6 +518,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
: IgnorePointer(
child: PostCardViewComfortable(
postViewMedia: snapshot.data![index]!,
hideThumbnails: hideThumbnails,
showThumbnailPreviewOnRight: showThumbnailPreviewOnRight,
showPostAuthor: showPostAuthor,
hideNsfwPreviews: hideNsfwPreviews,
Expand Down Expand Up @@ -571,6 +581,16 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
highlightKey: settingToHighlight == LocalSettings.hideNsfwPreviews ? settingToHighlightKey : null,
),
),
SliverToBoxAdapter(
child: ToggleOption(
description: l10n.hideThumbnails,
value: hideThumbnails,
iconEnabled: Icons.hide_image_outlined,
iconDisabled: Icons.image_outlined,
onToggle: (bool value) => setPreferences(LocalSettings.hideThumbnails, value),
highlightKey: settingToHighlight == LocalSettings.hideThumbnails ? settingToHighlightKey : null,
),
),
SliverToBoxAdapter(
child: ToggleOption(
description: l10n.showPostAuthor,
Expand Down Expand Up @@ -1046,14 +1066,15 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
), // Title
const SizedBox(height: 4.0),
],
Container(
height: showFullHeightImages ? 150 : 100,
margin: const EdgeInsets.symmetric(vertical: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
if (!hideThumbnails)
Container(
height: showFullHeightImages ? 150 : 100,
margin: const EdgeInsets.symmetric(vertical: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
),
),
),
if (!showTitleFirst) ...[
const SizedBox(height: 4.0),
Container(
Expand Down Expand Up @@ -1159,17 +1180,18 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
!showThumbnailPreviewOnRight
? Container(
width: ViewMode.compact.height,
height: ViewMode.compact.height,
margin: const EdgeInsets.only(right: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
),
)
: const SizedBox(width: 0),
if (!hideThumbnails)
!showThumbnailPreviewOnRight
? Container(
width: ViewMode.compact.height,
height: ViewMode.compact.height,
margin: const EdgeInsets.only(right: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
),
)
: const SizedBox(width: 0),
Expanded(
child: Padding(
padding: EdgeInsets.only(right: showThumbnailPreviewOnRight ? 8.0 : 0),
Expand Down Expand Up @@ -1212,17 +1234,18 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
),
),
),
showThumbnailPreviewOnRight
? Container(
width: ViewMode.compact.height,
height: ViewMode.compact.height,
margin: const EdgeInsets.only(right: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
),
)
: const SizedBox(width: 0),
if (!hideThumbnails)
showThumbnailPreviewOnRight
? Container(
width: ViewMode.compact.height,
height: ViewMode.compact.height,
margin: const EdgeInsets.only(right: 8.0),
decoration: BoxDecoration(
color: theme.dividerColor,
borderRadius: BorderRadius.circular((showEdgeToEdgeImages ? 0 : 12)),
),
)
: const SizedBox(width: 0),
],
),
);
Expand Down Expand Up @@ -1295,7 +1318,7 @@ class PostCardMetadataDraggableTarget extends StatelessWidget {
),
),
onLeave: (data) => HapticFeedback.mediumImpact(),
onWillAccept: (data) {
onWillAcceptWithDetails: (data) {
if (!containedPostCardMetadataItems.contains(data)) {
return true;
}
Expand Down
72 changes: 72 additions & 0 deletions lib/shared/link_information.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:thunder/core/enums/media_type.dart';
import 'package:thunder/core/enums/view_mode.dart';

class LinkInformation extends StatefulWidget {
/// The view mode of the media
final ViewMode viewMode;
iparks99 marked this conversation as resolved.
Show resolved Hide resolved

/// URL of the media
final String? originURL;

/// Type of media (image, link, text, etc.)
final MediaType? mediaType;

/// Callback for when an image is tapped
final Function? handleTapImage;

const LinkInformation({
super.key,
required this.viewMode,
this.originURL,
this.mediaType,
this.handleTapImage,
});

@override
State<LinkInformation> createState() => _LinkInformationState();
}

class _LinkInformationState extends State<LinkInformation> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final IconData icon =
switch (widget.mediaType) { MediaType.image => Icons.image_outlined, MediaType.video => Icons.play_arrow_rounded, MediaType.text => Icons.wysiwyg_rounded, _ => Icons.link_rounded };
return Semantics(
excludeSemantics: true,
child: Container(
color: ElevationOverlay.applySurfaceTint(
Theme.of(context).colorScheme.surface.withOpacity(0.8),
Theme.of(context).colorScheme.surfaceTint,
10,
),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
child: InkWell(
onTap: () {
if (widget.mediaType == MediaType.image && widget.handleTapImage != null) widget.handleTapImage!();
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(
icon,
color: theme.colorScheme.onSecondaryContainer,
),
),
if (widget.viewMode != ViewMode.compact)
Expanded(
child: Text(
widget.originURL!,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium,
),
),
],
),
),
),
);
}
}
Loading
Loading