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

Use profile picture for drawer #1312

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ enum LocalSettings {
showUpdateChangelogs(name: 'setting_show_update_changelogs', key: 'showUpdateChangelogs', category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.notifications),
scoreCounters(name: 'setting_score_counters', key: "showScoreCounters", category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.feed),
appLanguageCode(name: 'setting_app_language_code', key: 'appLanguage', category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.feedTypeAndSorts),
useProfilePictureForDrawer(
name: 'setting_use_profile_picture_for_drawer', key: 'useProfilePictureForDrawer', category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.feedTypeAndSorts),
enableInboxNotifications(
name: 'setting_enable_inbox_notifications', key: 'enableInboxNotifications', category: LocalSettingsCategories.general, subCategory: LocalSettingsSubCategories.notifications),

Expand Down Expand Up @@ -358,6 +360,7 @@ extension LocalizationExt on AppLocalizations {
'imageCachingMode': imageCachingMode,
'showNavigationLabels': showNavigationLabels,
'defaultCommentSortType': defaultCommentSortType,
'useProfilePictureForDrawer': useProfilePictureForDrawer,
'collapseParentCommentBodyOnGesture': collapseParentCommentBodyOnGesture,
'showCommentActionButtons': showCommentActionButtons,
'showUserInstance': showUserInstance,
Expand Down
59 changes: 43 additions & 16 deletions lib/feed/widgets/feed_page_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:thunder/feed/view/feed_page.dart';
import 'package:thunder/modlog/utils/navigate_modlog.dart';
import 'package:thunder/search/bloc/search_bloc.dart';
import 'package:thunder/search/pages/search_page.dart';
import 'package:thunder/shared/avatars/user_avatar.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/shared/sort_picker.dart';
import 'package:thunder/shared/thunder_popup_menu_item.dart';
Expand All @@ -43,6 +44,8 @@ class FeedPageAppBar extends StatelessWidget {
Widget build(BuildContext context) {
final feedBloc = context.read<FeedBloc>();
final thunderBloc = context.read<ThunderBloc>();
final AuthState authState = context.read<AuthBloc>().state;
final AccountState accountState = context.read<AccountBloc>().state;

return SliverAppBar(
pinned: !thunderBloc.state.hideTopBarOnScroll,
Expand All @@ -51,22 +54,39 @@ class FeedPageAppBar extends StatelessWidget {
toolbarHeight: 70.0,
surfaceTintColor: thunderBloc.state.hideTopBarOnScroll ? Colors.transparent : null,
title: FeedAppBarTitle(visible: showAppBarTitle),
leading: IconButton(
icon: scaffoldStateKey == null
? (!kIsWeb && Platform.isIOS
? Icon(
Icons.arrow_back_ios_new_rounded,
semanticLabel: MaterialLocalizations.of(context).backButtonTooltip,
)
: Icon(Icons.arrow_back_rounded, semanticLabel: MaterialLocalizations.of(context).backButtonTooltip))
: Icon(Icons.menu, semanticLabel: MaterialLocalizations.of(context).openAppDrawerTooltip),
onPressed: () {
HapticFeedback.mediumImpact();
(scaffoldStateKey == null && (feedBloc.state.feedType == FeedType.community || feedBloc.state.feedType == FeedType.user))
? Navigator.of(context).maybePop()
: scaffoldStateKey?.currentState?.openDrawer();
},
),
leadingWidth: thunderBloc.state.useProfilePictureForDrawer && authState.isLoggedIn ? 50 : null,
leading: thunderBloc.state.useProfilePictureForDrawer && authState.isLoggedIn
? Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: UserAvatar(
person: accountState.personView?.person,
),
),
Material(
color: Colors.transparent,
child: InkWell(
customBorder: const CircleBorder(),
onTap: () => _openDrawer(context, feedBloc),
),
),
],
),
)
: IconButton(
icon: scaffoldStateKey == null
? (!kIsWeb && Platform.isIOS
? Icon(
Icons.arrow_back_ios_new_rounded,
semanticLabel: MaterialLocalizations.of(context).backButtonTooltip,
)
: Icon(Icons.arrow_back_rounded, semanticLabel: MaterialLocalizations.of(context).backButtonTooltip))
: Icon(Icons.menu, semanticLabel: MaterialLocalizations.of(context).openAppDrawerTooltip),
onPressed: () => _openDrawer(context, feedBloc),
),
actions: (feedBloc.state.status != FeedStatus.initial && feedBloc.state.status != FeedStatus.failureLoadingCommunity && feedBloc.state.status != FeedStatus.failureLoadingUser)
? [
if (feedBloc.state.feedType == FeedType.general) const FeedAppBarGeneralActions(),
Expand All @@ -76,6 +96,13 @@ class FeedPageAppBar extends StatelessWidget {
: [],
);
}

void _openDrawer(BuildContext context, FeedBloc feedBloc) {
HapticFeedback.mediumImpact();
(scaffoldStateKey == null && (feedBloc.state.feedType == FeedType.community || feedBloc.state.feedType == FeedType.user))
? Navigator.of(context).maybePop()
: scaffoldStateKey?.currentState?.openDrawer();
}
}

/// The title of the app bar. This shows the title (feed type, community, user) and the sort type
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,14 @@
"@useMaterialYouThemeDescription": {
"description": "Subtitle of the setting for using Material You theme"
},
"useProfilePictureForDrawer": "Use Profile Picture for Drawer",
"@useProfilePictureForDrawer": {
"description": "Setting name for using the profile picture for the drawer"
},
"useProfilePictureForDrawerSubtitle": "When logged in, shows the user's profile picture in place of the drawer icon",
"@useProfilePictureForDrawerSubtitle": {
"description": "Setting subtitle for using the profile picture for the drawer"
},
"useSuggestedTitle": "Use suggested title: {title}",
"@useSuggestedTitle": {},
"user": "User",
Expand Down
20 changes: 20 additions & 0 deletions lib/settings/pages/general_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
/// The current locale
late Locale currentLocale;

/// Whether to show the user's profile picture instead of the drawer icon
bool useProfilePictureForDrawer = false;

/// Default listing type for posts on the feed (subscribed, all, local)
ListingType defaultListingType = DEFAULT_LISTING_TYPE;

Expand Down Expand Up @@ -134,6 +137,10 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
await prefs.setString(LocalSettings.appLanguageCode.name, value.languageCode);
setState(() => currentLocale = value);
break;
case LocalSettings.useProfilePictureForDrawer:
await prefs.setBool(LocalSettings.useProfilePictureForDrawer.name, value);
setState(() => useProfilePictureForDrawer = value);
break;

case LocalSettings.hideNsfwPosts:
await prefs.setBool(LocalSettings.hideNsfwPosts.name, value);
Expand Down Expand Up @@ -228,6 +235,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi

defaultCommentSortType = CommentSortType.values.byName(prefs.getString(LocalSettings.defaultCommentSortType.name) ?? DEFAULT_COMMENT_SORT_TYPE.name);
currentLocale = Localizations.localeOf(context);
useProfilePictureForDrawer = prefs.getBool(LocalSettings.useProfilePictureForDrawer.name) ?? false;

hideNsfwPosts = prefs.getBool(LocalSettings.hideNsfwPosts.name) ?? false;
tappableAuthorCommunity = prefs.getBool(LocalSettings.tappableAuthorCommunity.name) ?? false;
Expand Down Expand Up @@ -408,6 +416,18 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
),
),
const SliverToBoxAdapter(child: SizedBox(height: 16.0)),
SliverToBoxAdapter(
child: ToggleOption(
description: l10n.useProfilePictureForDrawer,
subtitle: l10n.useProfilePictureForDrawerSubtitle,
value: useProfilePictureForDrawer,
iconEnabled: Icons.person_rounded,
iconDisabled: Icons.person_outline_rounded,
onToggle: (value) => setPreferences(LocalSettings.useProfilePictureForDrawer, value),
highlightKey: settingToHighlight == LocalSettings.useProfilePictureForDrawer ? settingToHighlightKey : null,
),
),
const SliverToBoxAdapter(child: SizedBox(height: 16.0)),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
Expand Down
3 changes: 3 additions & 0 deletions lib/thunder/bloc/thunder_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
defaultSortType = SortType.values.byName(DEFAULT_SORT_TYPE.name);
}

bool useProfilePictureForDrawer = prefs.getBool(LocalSettings.useProfilePictureForDrawer.name) ?? false;

// NSFW Settings
bool hideNsfwPosts = prefs.getBool(LocalSettings.hideNsfwPosts.name) ?? false;
bool hideNsfwPreviews = prefs.getBool(LocalSettings.hideNsfwPreviews.name) ?? true;
Expand Down Expand Up @@ -257,6 +259,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
// Default Listing/Sort Settings
defaultListingType: defaultListingType,
defaultSortType: defaultSortType,
useProfilePictureForDrawer: useProfilePictureForDrawer,

// NSFW Settings
hideNsfwPosts: hideNsfwPosts,
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 @@ -14,6 +14,7 @@ class ThunderState extends Equatable {
// Default Listing/Sort Settings
this.defaultListingType = DEFAULT_LISTING_TYPE,
this.defaultSortType = DEFAULT_SORT_TYPE,
this.useProfilePictureForDrawer = false,

// NSFW Settings
this.hideNsfwPosts = false,
Expand Down Expand Up @@ -165,6 +166,7 @@ class ThunderState extends Equatable {
final ListingType defaultListingType;
final SortType defaultSortType;
SortType get sortTypeForInstance => LemmyClient.instance.supportsSortType(defaultSortType) ? defaultSortType : DEFAULT_SORT_TYPE;
final bool useProfilePictureForDrawer;

// NSFW Settings
final bool hideNsfwPosts;
Expand Down Expand Up @@ -324,6 +326,7 @@ class ThunderState extends Equatable {
// Default Listing/Sort Settings
ListingType? defaultListingType,
SortType? defaultSortType,
bool? useProfilePictureForDrawer,

// NSFW Settings
bool? hideNsfwPosts,
Expand Down Expand Up @@ -475,6 +478,7 @@ class ThunderState extends Equatable {
/// Default Listing/Sort Settings
defaultListingType: defaultListingType ?? this.defaultListingType,
defaultSortType: defaultSortType ?? this.defaultSortType,
useProfilePictureForDrawer: useProfilePictureForDrawer ?? this.useProfilePictureForDrawer,

// NSFW Settings
hideNsfwPosts: hideNsfwPosts ?? this.hideNsfwPosts,
Expand Down Expand Up @@ -635,6 +639,7 @@ class ThunderState extends Equatable {
/// Default Listing/Sort Settings
defaultListingType,
defaultSortType,
useProfilePictureForDrawer,

// NSFW Settings
hideNsfwPosts,
Expand Down
Loading