Skip to content

Commit

Permalink
Added an option to hide thumbnails in compact feed
Browse files Browse the repository at this point in the history
  • Loading branch information
iparks99 committed Apr 13, 2024
1 parent 3082ff8 commit f4e4158
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 37 deletions.
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
2 changes: 2 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
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.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),
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
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
68 changes: 45 additions & 23 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 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 @@ -149,6 +152,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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;

Expand Down Expand Up @@ -218,6 +222,10 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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);
Expand Down Expand Up @@ -296,6 +304,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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);
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 @@ -802,6 +812,16 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
),
),
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,
Expand Down Expand Up @@ -1159,17 +1179,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 +1233,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 +1317,7 @@ class PostCardMetadataDraggableTarget extends StatelessWidget {
),
),
onLeave: (data) => HapticFeedback.mediumImpact(),
onWillAccept: (data) {
onWillAcceptWithDetails: (data) {
if (!containedPostCardMetadataItems.contains(data)) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/thunder/bloc/thunder_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
// 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;
Expand Down Expand Up @@ -294,6 +295,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
// Compact Related Settings
useCompactView: useCompactView,
showTitleFirst: showTitleFirst,
hideThumbnails: hideThumbnails,
showThumbnailPreviewOnRight: showThumbnailPreviewOnRight,
showTextPostIndicator: showTextPostIndicator,
tappableAuthorCommunity: tappableAuthorCommunity,
Expand Down
5 changes: 5 additions & 0 deletions lib/thunder/bloc/thunder_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -361,6 +363,7 @@ class ThunderState extends Equatable {
/// Compact Related Settings
bool? useCompactView,
bool? showTitleFirst,
bool? hideThumbnails,
bool? showThumbnailPreviewOnRight,
bool? showTextPostIndicator,
bool? tappableAuthorCommunity,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -670,6 +674,7 @@ class ThunderState extends Equatable {
/// Compact Related Settings
useCompactView,
showTitleFirst,
hideThumbnails,
showThumbnailPreviewOnRight,
showTextPostIndicator,
tappableAuthorCommunity,
Expand Down

0 comments on commit f4e4158

Please sign in to comment.