Skip to content

Commit

Permalink
Change post body view type to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo committed Dec 19, 2023
1 parent 36f3d2c commit 6553d10
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions lib/core/enums/post_body_view_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum PostBodyViewType {
condensed,
mediaPreview,
}
12 changes: 12 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions lib/post/widgets/post_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -115,7 +116,7 @@ class _PostSubviewState extends State<PostSubview> 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(
Expand All @@ -124,9 +125,9 @@ class _PostSubviewState extends State<PostSubview> 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(
Expand All @@ -141,7 +142,7 @@ class _PostSubviewState extends State<PostSubview> with SingleTickerProviderStat
],
),
),
if (!thunderState.useCompactPostBodyView)
if (thunderState.postBodyViewType != PostBodyViewType.condensed)
Expandable(
controller: expandableController,
collapsed: Container(),
Expand Down
32 changes: 20 additions & 12 deletions lib/settings/pages/post_appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,8 +75,8 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
/// 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<void> initPreferences() async {
Expand Down Expand Up @@ -104,7 +105,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>

// 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);
});
}

Expand Down Expand Up @@ -175,9 +176,9 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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;
}

Expand Down Expand Up @@ -205,7 +206,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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();

Expand Down Expand Up @@ -648,14 +649,21 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
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),
),
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/thunder/bloc/thunder_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -121,7 +122,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
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;
Expand Down Expand Up @@ -249,7 +250,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
showThumbnailPreviewOnRight: showThumbnailPreviewOnRight,
showTextPostIndicator: showTextPostIndicator,
tappableAuthorCommunity: tappableAuthorCommunity,
useCompactPostBodyView: useCompactPostBodyView,
postBodyViewType: postBodyViewType,

// General Settings
showVoteActions: showVoteActions,
Expand Down
10 changes: 5 additions & 5 deletions lib/thunder/bloc/thunder_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -301,7 +301,7 @@ class ThunderState extends Equatable {
bool? showThumbnailPreviewOnRight,
bool? showTextPostIndicator,
bool? tappableAuthorCommunity,
bool? useCompactPostBodyView,
PostBodyViewType? postBodyViewType,

// General Settings
bool? showVoteActions,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -560,7 +560,7 @@ class ThunderState extends Equatable {
showThumbnailPreviewOnRight,
showTextPostIndicator,
tappableAuthorCommunity,
useCompactPostBodyView,
postBodyViewType,

// General Settings
showVoteActions,
Expand Down

0 comments on commit 6553d10

Please sign in to comment.