From f4e4158b27c2d40cd841b478f41a8ebb2bf382fd Mon Sep 17 00:00:00 2001 From: Ian Parks Date: Sat, 13 Apr 2024 16:20:17 -0400 Subject: [PATCH] Added an option to hide thumbnails in compact feed --- lib/community/widgets/post_card.dart | 1 + .../widgets/post_card_view_comfortable.dart | 2 + .../widgets/post_card_view_compact.dart | 31 +++++---- lib/core/enums/local_settings.dart | 2 + lib/l10n/app_en.arb | 2 + .../pages/post_appearance_settings_page.dart | 68 ++++++++++++------- lib/thunder/bloc/thunder_bloc.dart | 2 + lib/thunder/bloc/thunder_state.dart | 5 ++ 8 files changed, 76 insertions(+), 37 deletions(-) diff --git a/lib/community/widgets/post_card.dart b/lib/community/widgets/post_card.dart index b17c91d96..232346193 100644 --- a/lib/community/widgets/post_card.dart +++ b/lib/community/widgets/post_card.dart @@ -207,6 +207,7 @@ class _PostCardState extends State { ) : PostCardViewComfortable( postViewMedia: widget.postViewMedia, + hideThumbnails: state.hideThumbnails, showThumbnailPreviewOnRight: state.showThumbnailPreviewOnRight, hideNsfwPreviews: state.hideNsfwPreviews, markPostReadOnMediaView: state.markPostReadOnMediaView, diff --git a/lib/community/widgets/post_card_view_comfortable.dart b/lib/community/widgets/post_card_view_comfortable.dart index b566ad2f5..b2acb1d76 100644 --- a/lib/community/widgets/post_card_view_comfortable.dart +++ b/lib/community/widgets/post_card_view_comfortable.dart @@ -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; @@ -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, diff --git a/lib/community/widgets/post_card_view_compact.dart b/lib/community/widgets/post_card_view_compact.dart index 028f22a6e..596000818 100644 --- a/lib/community/widgets/post_card_view_compact.dart +++ b/lib/community/widgets/post_card_view_compact.dart @@ -42,6 +42,7 @@ class PostCardViewCompact extends StatelessWidget { final theme = Theme.of(context); final ThunderState state = context.watch().state; + bool hideThumbnails = state.hideThumbnails; bool showThumbnailPreviewOnRight = state.showThumbnailPreviewOnRight; bool showTextPostIndicator = state.showTextPostIndicator; bool indicateRead = this.indicateRead ?? state.dimReadPosts; @@ -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, @@ -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), ], ), ); diff --git a/lib/core/enums/local_settings.dart b/lib/core/enums/local_settings.dart index 6167f8b17..7d8add259 100644 --- a/lib/core/enums/local_settings.dart +++ b/lib/core/enums/local_settings.dart @@ -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.posts), 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), @@ -328,6 +329,7 @@ extension LocalizationExt on AppLocalizations { 'appLanguage': appLanguage, 'compactView': compactView, 'showPostTitleFirst': showPostTitleFirst, + 'hideThumbnails': hideThumbnails, 'showThumbnailPreviewOnRight': showThumbnailPreviewOnRight, 'showTextPostIndicator': showTextPostIndicator, 'tappableAuthorCommunity': tappableAuthorCommunity, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 775e42c31..022cd0b4a 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -697,6 +697,8 @@ }, "hidePassword": "Hide Password", "@hidePassword": {}, + "hideThumbnails": "Hide thumbnails", + "@hideThumbnails": {}, "hideTopBarOnScroll": "Hide Top Bar on Scroll", "@hideTopBarOnScroll": { "description": "Settings toggle to hide the top bar on scroll" diff --git a/lib/settings/pages/post_appearance_settings_page.dart b/lib/settings/pages/post_appearance_settings_page.dart index 38d9e2f9d..0856a0415 100644 --- a/lib/settings/pages/post_appearance_settings_page.dart +++ b/lib/settings/pages/post_appearance_settings_page.dart @@ -51,6 +51,9 @@ class _PostAppearanceSettingsPageState extends State /// When enabled, posts on the feed will be compacted bool useCompactView = false; + /// When enabled, the thumbnails in compact 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; @@ -149,6 +152,7 @@ class _PostAppearanceSettingsPageState extends State compactPostCardMetadataItems = prefs.getStringList(LocalSettings.compactPostCardMetadataItems.name)?.map((e) => PostCardMetadataItem.values.byName(e)).toList() ?? DEFAULT_COMPACT_POST_CARD_METADATA; cardPostCardMetadataItems = prefs.getStringList(LocalSettings.cardPostCardMetadataItems.name)?.map((e) => PostCardMetadataItem.values.byName(e)).toList() ?? DEFAULT_CARD_POST_CARD_METADATA; + hideThumbnails = prefs.getBool(LocalSettings.hideThumbnails.name) ?? false; showThumbnailPreviewOnRight = prefs.getBool(LocalSettings.showThumbnailPreviewOnRight.name) ?? false; showTextPostIndicator = prefs.getBool(LocalSettings.showTextPostIndicator.name) ?? false; @@ -218,6 +222,10 @@ class _PostAppearanceSettingsPageState extends State case LocalSettings.compactPostCardMetadataItems: await prefs.setStringList(LocalSettings.compactPostCardMetadataItems.name, value); break; + case LocalSettings.hideThumbnails: + await prefs.setBool(LocalSettings.hideThumbnails.name, value); + setState(() => hideThumbnails = value); + break; case LocalSettings.showThumbnailPreviewOnRight: await prefs.setBool(LocalSettings.showThumbnailPreviewOnRight.name, value); setState(() => showThumbnailPreviewOnRight = value); @@ -296,6 +304,7 @@ class _PostAppearanceSettingsPageState extends State await prefs.remove(LocalSettings.feedCardDividerThickness.name); await prefs.remove(LocalSettings.feedCardDividerColor.name); await prefs.remove(LocalSettings.compactPostCardMetadataItems.name); + await prefs.remove(LocalSettings.hideThumbnails.name); await prefs.remove(LocalSettings.showThumbnailPreviewOnRight.name); await prefs.remove(LocalSettings.showTextPostIndicator.name); await prefs.remove(LocalSettings.cardPostCardMetadataItems.name); @@ -509,6 +518,7 @@ class _PostAppearanceSettingsPageState extends State : IgnorePointer( child: PostCardViewComfortable( postViewMedia: snapshot.data![index]!, + hideThumbnails: hideThumbnails, showThumbnailPreviewOnRight: showThumbnailPreviewOnRight, showPostAuthor: showPostAuthor, hideNsfwPreviews: hideNsfwPreviews, @@ -802,6 +812,16 @@ class _PostAppearanceSettingsPageState extends State ), ), const SliverToBoxAdapter(child: SizedBox(height: 8.0)), + SliverToBoxAdapter( + child: ToggleOption( + description: l10n.hideThumbnails, + value: hideThumbnails, + iconEnabled: Icons.hide_image_outlined, + iconDisabled: Icons.image_outlined, + onToggle: useCompactView == false ? null : (bool value) => setPreferences(LocalSettings.hideThumbnails, value), + highlightKey: settingToHighlight == LocalSettings.hideThumbnails ? settingToHighlightKey : null, + ), + ), SliverToBoxAdapter( child: ToggleOption( description: l10n.showThumbnailPreviewOnRight, @@ -1159,17 +1179,18 @@ class _PostAppearanceSettingsPageState extends State 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), @@ -1212,17 +1233,18 @@ class _PostAppearanceSettingsPageState extends State ), ), ), - 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), ], ), ); @@ -1295,7 +1317,7 @@ class PostCardMetadataDraggableTarget extends StatelessWidget { ), ), onLeave: (data) => HapticFeedback.mediumImpact(), - onWillAccept: (data) { + onWillAcceptWithDetails: (data) { if (!containedPostCardMetadataItems.contains(data)) { return true; } diff --git a/lib/thunder/bloc/thunder_bloc.dart b/lib/thunder/bloc/thunder_bloc.dart index 4b66a1d50..f2db6c818 100644 --- a/lib/thunder/bloc/thunder_bloc.dart +++ b/lib/thunder/bloc/thunder_bloc.dart @@ -140,6 +140,7 @@ class ThunderBloc extends Bloc { // Compact Related Settings bool useCompactView = prefs.getBool(LocalSettings.useCompactView.name) ?? false; bool showTitleFirst = prefs.getBool(LocalSettings.showPostTitleFirst.name) ?? false; + bool hideThumbnails = prefs.getBool(LocalSettings.hideThumbnails.name) ?? false; bool showThumbnailPreviewOnRight = prefs.getBool(LocalSettings.showThumbnailPreviewOnRight.name) ?? false; bool showTextPostIndicator = prefs.getBool(LocalSettings.showTextPostIndicator.name) ?? false; bool tappableAuthorCommunity = prefs.getBool(LocalSettings.tappableAuthorCommunity.name) ?? false; @@ -294,6 +295,7 @@ class ThunderBloc extends Bloc { // Compact Related Settings useCompactView: useCompactView, showTitleFirst: showTitleFirst, + hideThumbnails: hideThumbnails, showThumbnailPreviewOnRight: showThumbnailPreviewOnRight, showTextPostIndicator: showTextPostIndicator, tappableAuthorCommunity: tappableAuthorCommunity, diff --git a/lib/thunder/bloc/thunder_state.dart b/lib/thunder/bloc/thunder_state.dart index e48c1c7bc..17930fa38 100644 --- a/lib/thunder/bloc/thunder_state.dart +++ b/lib/thunder/bloc/thunder_state.dart @@ -52,6 +52,7 @@ class ThunderState extends Equatable { // Compact Related Settings this.useCompactView = false, this.showTitleFirst = false, + this.hideThumbnails = false, this.showThumbnailPreviewOnRight = false, this.showTextPostIndicator = false, this.tappableAuthorCommunity = false, @@ -203,6 +204,7 @@ class ThunderState extends Equatable { /// Compact Related Settings final bool useCompactView; final bool showTitleFirst; + final bool hideThumbnails; final bool showThumbnailPreviewOnRight; final bool showTextPostIndicator; final bool tappableAuthorCommunity; @@ -361,6 +363,7 @@ class ThunderState extends Equatable { /// Compact Related Settings bool? useCompactView, bool? showTitleFirst, + bool? hideThumbnails, bool? showThumbnailPreviewOnRight, bool? showTextPostIndicator, bool? tappableAuthorCommunity, @@ -514,6 +517,7 @@ class ThunderState extends Equatable { // Compact Related Settings useCompactView: useCompactView ?? this.useCompactView, showTitleFirst: showTitleFirst ?? this.showTitleFirst, + hideThumbnails: hideThumbnails ?? this.hideThumbnails, showThumbnailPreviewOnRight: showThumbnailPreviewOnRight ?? this.showThumbnailPreviewOnRight, showTextPostIndicator: showTextPostIndicator ?? this.showTextPostIndicator, tappableAuthorCommunity: tappableAuthorCommunity ?? this.tappableAuthorCommunity, @@ -670,6 +674,7 @@ class ThunderState extends Equatable { /// Compact Related Settings useCompactView, showTitleFirst, + hideThumbnails, showThumbnailPreviewOnRight, showTextPostIndicator, tappableAuthorCommunity,