From 6553d1095b8af0f5cffc5db63722189771879dd2 Mon Sep 17 00:00:00 2001 From: Micah Morrison Date: Tue, 19 Dec 2023 15:12:59 -0500 Subject: [PATCH] Change post body view type to enum --- lib/core/enums/local_settings.dart | 2 +- lib/core/enums/post_body_view_type.dart | 4 +++ lib/l10n/app_en.arb | 12 +++++++ lib/post/widgets/post_view.dart | 9 +++--- .../pages/post_appearance_settings_page.dart | 32 ++++++++++++------- lib/thunder/bloc/thunder_bloc.dart | 5 +-- lib/thunder/bloc/thunder_state.dart | 10 +++--- 7 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 lib/core/enums/post_body_view_type.dart diff --git a/lib/core/enums/local_settings.dart b/lib/core/enums/local_settings.dart index 4e3f1acb8..05281b4ba 100644 --- a/lib/core/enums/local_settings.dart +++ b/lib/core/enums/local_settings.dart @@ -28,7 +28,7 @@ enum LocalSettings { showThumbnailPreviewOnRight(name: 'setting_compact_show_thumbnail_on_right', label: 'Thumbnails on the Right'), showTextPostIndicator(name: 'setting_compact_show_text_post_indicator', label: 'Show Text Post Indicator'), tappableAuthorCommunity(name: 'setting_compact_tappable_author_community', label: 'Tappable Authors & Communities'), - useCompactPostBodyView(name: 'setting_general_use_compact_post_body_view', label: ''), + postBodyViewType(name: 'setting_general_post_body_view_type', label: ''), // General Settings showPostVoteActions(name: 'setting_general_show_vote_actions', label: 'Show Vote Buttons'), diff --git a/lib/core/enums/post_body_view_type.dart b/lib/core/enums/post_body_view_type.dart new file mode 100644 index 000000000..50848038b --- /dev/null +++ b/lib/core/enums/post_body_view_type.dart @@ -0,0 +1,4 @@ +enum PostBodyViewType { + condensed, + mediaPreview, +} diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 422404142..6f9a87677 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -187,6 +187,10 @@ "@compactViewSettings": { "description": "Subcategory in Setting -> Appearance -> Posts" }, + "condensed": "Condensed", + "@condensed": { + "description": "Condensed post body view type" + }, "confirmLogOutBody": "Are you sure you want to log out?", "@confirmLogOutBody": { "description": "The body of the confirm logout dialog" @@ -487,6 +491,10 @@ }, "manageAccounts": "Manage Accounts", "@manageAccounts": {}, + "mediaPreview": "Media preview", + "@mediaPreview": { + "description": "Media preview post body view type" + }, "mention": "{count, plural, zero {Mention} one {Mention} other {Mentions} }", "@mention": {}, "markAllAsRead": "Mark All As Read", @@ -619,6 +627,10 @@ "@postBodySettingsDescription": { "description": "Description of post body settings" }, + "postBodyViewType": "Post Body View Type", + "@postBodyViewType": { + "description": "Setting name for the post body view type setting" + }, "postLocked": "Post locked. No replies allowed.", "@postLocked": {}, "postNSFW": "Mark as NSFW", diff --git a/lib/post/widgets/post_view.dart b/lib/post/widgets/post_view.dart index c2bbe3634..122c41249 100644 --- a/lib/post/widgets/post_view.dart +++ b/lib/post/widgets/post_view.dart @@ -23,6 +23,7 @@ import 'package:thunder/core/auth/helpers/fetch_account.dart'; import 'package:thunder/core/enums/font_scale.dart'; import 'package:thunder/core/enums/full_name_separator.dart'; import 'package:thunder/core/enums/local_settings.dart'; +import 'package:thunder/core/enums/post_body_view_type.dart'; import 'package:thunder/core/enums/view_mode.dart'; import 'package:thunder/core/singletons/lemmy_client.dart'; import 'package:thunder/core/singletons/preferences.dart'; @@ -115,7 +116,7 @@ class _PostSubviewState extends State with SingleTickerProviderStat padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row( children: [ - if (thunderState.useCompactPostBodyView && !thunderState.showThumbnailPreviewOnRight && postViewMedia.media.isNotEmpty) + if (thunderState.postBodyViewType == PostBodyViewType.condensed && !thunderState.showThumbnailPreviewOnRight && postViewMedia.media.isNotEmpty) _getMediaPreview(thunderState, hideNsfwPreviews, markPostReadOnMediaView, isUserLoggedIn), Expanded( child: ScalableText( @@ -124,9 +125,9 @@ class _PostSubviewState extends State with SingleTickerProviderStat style: theme.textTheme.titleMedium, ), ), - if (thunderState.useCompactPostBodyView && thunderState.showThumbnailPreviewOnRight && postViewMedia.media.isNotEmpty) + if (thunderState.postBodyViewType == PostBodyViewType.condensed && thunderState.showThumbnailPreviewOnRight && postViewMedia.media.isNotEmpty) _getMediaPreview(thunderState, hideNsfwPreviews, markPostReadOnMediaView, isUserLoggedIn), - if (!thunderState.useCompactPostBodyView || postViewMedia.media.isEmpty) + if (thunderState.postBodyViewType != PostBodyViewType.condensed || postViewMedia.media.isEmpty) IconButton( visualDensity: VisualDensity.compact, icon: Icon( @@ -141,7 +142,7 @@ class _PostSubviewState extends State with SingleTickerProviderStat ], ), ), - if (!thunderState.useCompactPostBodyView) + if (thunderState.postBodyViewType != PostBodyViewType.condensed) Expandable( controller: expandableController, collapsed: Container(), diff --git a/lib/settings/pages/post_appearance_settings_page.dart b/lib/settings/pages/post_appearance_settings_page.dart index 659680c45..55bfcecf5 100644 --- a/lib/settings/pages/post_appearance_settings_page.dart +++ b/lib/settings/pages/post_appearance_settings_page.dart @@ -9,6 +9,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:thunder/community/widgets/post_card_view_comfortable.dart'; import 'package:thunder/community/widgets/post_card_view_compact.dart'; import 'package:thunder/core/enums/local_settings.dart'; +import 'package:thunder/core/enums/post_body_view_type.dart'; import 'package:thunder/core/models/post_view_media.dart'; import 'package:thunder/core/singletons/preferences.dart'; import 'package:thunder/feed/utils/post.dart'; @@ -74,8 +75,8 @@ class _PostAppearanceSettingsPageState extends State /// Controller to manage expandable state for comment preview ExpandableController expandableController = ExpandableController(); - /// When enabled, the post body is condensed - bool useCompactPostBodyView = false; + /// Determines how post bodies are displayed + PostBodyViewType postBodyViewType = PostBodyViewType.mediaPreview; /// Initialize the settings from the user's shared preferences Future initPreferences() async { @@ -104,7 +105,7 @@ class _PostAppearanceSettingsPageState extends State // Post body settings showCrossPosts = prefs.getBool(LocalSettings.showCrossPosts.name) ?? true; - useCompactPostBodyView = prefs.getBool(LocalSettings.useCompactPostBodyView.name) ?? false; + postBodyViewType = PostBodyViewType.values.byName(prefs.getString(LocalSettings.postBodyViewType.name) ?? PostBodyViewType.mediaPreview.name); }); } @@ -175,9 +176,9 @@ class _PostAppearanceSettingsPageState extends State await prefs.setBool(LocalSettings.showCrossPosts.name, value); setState(() => showCrossPosts = value); break; - case LocalSettings.useCompactPostBodyView: - await prefs.setBool(LocalSettings.useCompactPostBodyView.name, value); - setState(() => useCompactPostBodyView = value); + case LocalSettings.postBodyViewType: + await prefs.setString(LocalSettings.postBodyViewType.name, (value as PostBodyViewType).name); + setState(() => postBodyViewType = value); break; } @@ -205,7 +206,7 @@ class _PostAppearanceSettingsPageState extends State await prefs.remove(LocalSettings.showPostSaveAction.name); await prefs.remove(LocalSettings.showPostCommunityIcons.name); await prefs.remove(LocalSettings.showCrossPosts.name); - await prefs.remove(LocalSettings.useCompactPostBodyView.name); + await prefs.remove(LocalSettings.postBodyViewType.name); await initPreferences(); @@ -648,14 +649,21 @@ class _PostAppearanceSettingsPageState extends State child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: ListOption( - description: l10n.postViewType, - value: ListPickerItem(label: useCompactPostBodyView ? l10n.compactView : l10n.cardView, icon: Icons.crop_16_9_rounded, payload: useCompactPostBodyView), + description: l10n.postBodyViewType, + value: ListPickerItem( + label: switch (postBodyViewType) { + PostBodyViewType.condensed => l10n.condensed, + PostBodyViewType.mediaPreview => l10n.mediaPreview, + }, + icon: Icons.crop_16_9_rounded, + payload: postBodyViewType, + capitalizeLabel: false), options: [ - ListPickerItem(icon: Icons.crop_16_9_rounded, label: l10n.compactView, payload: true), - ListPickerItem(icon: Icons.crop_din_rounded, label: l10n.cardView, payload: false), + ListPickerItem(icon: Icons.crop_16_9_rounded, label: l10n.condensed, payload: PostBodyViewType.condensed), + ListPickerItem(icon: Icons.crop_din_rounded, label: l10n.mediaPreview, payload: PostBodyViewType.mediaPreview), ], icon: Icons.view_list_rounded, - onChanged: (value) => setPreferences(LocalSettings.useCompactPostBodyView, value.payload), + onChanged: (value) => setPreferences(LocalSettings.postBodyViewType, value.payload), ), ), ), diff --git a/lib/thunder/bloc/thunder_bloc.dart b/lib/thunder/bloc/thunder_bloc.dart index 86a45664e..464560039 100644 --- a/lib/thunder/bloc/thunder_bloc.dart +++ b/lib/thunder/bloc/thunder_bloc.dart @@ -13,6 +13,7 @@ import 'package:thunder/core/enums/font_scale.dart'; import 'package:thunder/core/enums/full_name_separator.dart'; import 'package:thunder/core/enums/local_settings.dart'; import 'package:thunder/core/enums/nested_comment_indicator.dart'; +import 'package:thunder/core/enums/post_body_view_type.dart'; import 'package:thunder/core/enums/swipe_action.dart'; import 'package:thunder/core/enums/theme_type.dart'; import 'package:thunder/core/models/version.dart'; @@ -121,7 +122,7 @@ class ThunderBloc extends Bloc { bool showThumbnailPreviewOnRight = prefs.getBool(LocalSettings.showThumbnailPreviewOnRight.name) ?? false; bool showTextPostIndicator = prefs.getBool(LocalSettings.showTextPostIndicator.name) ?? false; bool tappableAuthorCommunity = prefs.getBool(LocalSettings.tappableAuthorCommunity.name) ?? false; - bool useCompactPostBodyView = prefs.getBool(LocalSettings.useCompactPostBodyView.name) ?? false; + PostBodyViewType postBodyViewType = PostBodyViewType.values.byName(prefs.getString(LocalSettings.postBodyViewType.name) ?? PostBodyViewType.mediaPreview.name); // General Settings bool showVoteActions = prefs.getBool(LocalSettings.showPostVoteActions.name) ?? true; @@ -249,7 +250,7 @@ class ThunderBloc extends Bloc { showThumbnailPreviewOnRight: showThumbnailPreviewOnRight, showTextPostIndicator: showTextPostIndicator, tappableAuthorCommunity: tappableAuthorCommunity, - useCompactPostBodyView: useCompactPostBodyView, + postBodyViewType: postBodyViewType, // General Settings showVoteActions: showVoteActions, diff --git a/lib/thunder/bloc/thunder_state.dart b/lib/thunder/bloc/thunder_state.dart index a710a8de6..b456d1138 100644 --- a/lib/thunder/bloc/thunder_state.dart +++ b/lib/thunder/bloc/thunder_state.dart @@ -41,7 +41,7 @@ class ThunderState extends Equatable { this.showThumbnailPreviewOnRight = false, this.showTextPostIndicator = false, this.tappableAuthorCommunity = false, - this.useCompactPostBodyView = false, + this.postBodyViewType = PostBodyViewType.mediaPreview, // General Settings this.showVoteActions = true, @@ -167,7 +167,7 @@ class ThunderState extends Equatable { final bool showThumbnailPreviewOnRight; final bool showTextPostIndicator; final bool tappableAuthorCommunity; - final bool useCompactPostBodyView; + final PostBodyViewType postBodyViewType; // General Settings final bool showVoteActions; @@ -301,7 +301,7 @@ class ThunderState extends Equatable { bool? showThumbnailPreviewOnRight, bool? showTextPostIndicator, bool? tappableAuthorCommunity, - bool? useCompactPostBodyView, + PostBodyViewType? postBodyViewType, // General Settings bool? showVoteActions, @@ -428,7 +428,7 @@ class ThunderState extends Equatable { showThumbnailPreviewOnRight: showThumbnailPreviewOnRight ?? this.showThumbnailPreviewOnRight, showTextPostIndicator: showTextPostIndicator ?? this.showTextPostIndicator, tappableAuthorCommunity: tappableAuthorCommunity ?? this.tappableAuthorCommunity, - useCompactPostBodyView: useCompactPostBodyView ?? this.useCompactPostBodyView, + postBodyViewType: postBodyViewType ?? this.postBodyViewType, // General Settings showVoteActions: showVoteActions ?? this.showVoteActions, @@ -560,7 +560,7 @@ class ThunderState extends Equatable { showThumbnailPreviewOnRight, showTextPostIndicator, tappableAuthorCommunity, - useCompactPostBodyView, + postBodyViewType, // General Settings showVoteActions,