Skip to content

Commit 2122ec0

Browse files
authored
Add setting for colorized usernames (#1092)
* Setting to use colorized usernames * fix sort intl * Fix arb sort
1 parent 5148b8e commit 2122ec0

7 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Added ability to subscribe/unsubscribe to community from long press action on posts
66
- Added option to hide top app bar on scroll
77
- Ability to search through settings/preferences contribution from @ggichure.
8+
- Setting to use colorized usernames - contribution from @ggichure.
89
- Show the number of new comments a read post has received since last visited
910

1011
## Changed

lib/core/enums/local_settings.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ enum LocalSettings {
144144
name: 'setting_general_nested_comment_indicator_style', key: 'nestedCommentIndicatorStyle', category: LocalSettingsCategories.comments, subCategory: LocalSettingsSubCategories.comments),
145145
nestedCommentIndicatorColor(
146146
name: 'setting_general_nested_comment_indicator_color', key: 'nestedCommentIndicatorColor', category: LocalSettingsCategories.comments, subCategory: LocalSettingsSubCategories.comments),
147+
commentUseColorizedUsername(
148+
name: 'settings_general_comments_colorized_usernames', key: 'commentUseColorizedUsername', category: LocalSettingsCategories.comments, subCategory: LocalSettingsSubCategories.comments),
147149

148150
/// -------------------------- Accessibility Related Settings --------------------------
149151
reduceAnimations(name: 'setting_accessibility_reduce_animations', key: 'reduceAnimations', category: LocalSettingsCategories.accessibility, subCategory: LocalSettingsSubCategories.animations),
@@ -343,6 +345,7 @@ extension LocalizationExt on AppLocalizations {
343345
'feedTypeAndSorts': feedTypeAndSorts,
344346
'profiles': profiles,
345347
'animations': animations,
348+
'commentUseColorizedUsername': commentUseColorizedUsername
346349
};
347350

348351
if (localizationMap.containsKey(key)) {

lib/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@
209209
},
210210
"commentSwipeGesturesHint": "Looking to use buttons instead? Enable them in the comments section in general settings.",
211211
"@commentSwipeGesturesHint": {},
212+
"commentUseColorizedUsername": "Colorized Usernames",
213+
"@commentUseColorizedUsername": {
214+
"description": "Setting used to toggle colorized comments creator display name."
215+
},
212216
"comments": "Comments",
213217
"@comments": {},
214218
"communities": "Communities",

lib/settings/pages/comment_appearance_settings_page.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ class _CommentAppearanceSettingsPageState extends State<CommentAppearanceSetting
3030
/// When toggled on, comments will show a row of actions to perform
3131
bool showCommentButtonActions = false;
3232

33-
/// When toggled on, user intance is displayed alongside the display name/username
33+
/// When toggled on, user instance is displayed alongside the display name/username
3434
bool commentShowUserInstance = false;
3535

3636
/// When toggled on, comment scores will be combined instead of having separate upvotes and downvotes
3737
bool combineCommentScores = false;
3838

39+
/// When toggled on, usernames in comments will be colorized.
40+
bool commentUseColorizedUsername = false;
41+
3942
/// Indicates the style of the nested comment indicator
4043
NestedCommentIndicatorStyle nestedIndicatorStyle = DEFAULT_NESTED_COMMENT_INDICATOR_STYLE;
4144

@@ -56,6 +59,7 @@ class _CommentAppearanceSettingsPageState extends State<CommentAppearanceSetting
5659
showCommentButtonActions = prefs.getBool(LocalSettings.showCommentActionButtons.name) ?? false;
5760
commentShowUserInstance = prefs.getBool(LocalSettings.commentShowUserInstance.name) ?? false;
5861
combineCommentScores = prefs.getBool(LocalSettings.combineCommentScores.name) ?? false;
62+
commentUseColorizedUsername = prefs.getBool(LocalSettings.commentUseColorizedUsername.name) ?? false;
5963
nestedIndicatorStyle = NestedCommentIndicatorStyle.values.byName(prefs.getString(LocalSettings.nestedCommentIndicatorStyle.name) ?? DEFAULT_NESTED_COMMENT_INDICATOR_STYLE.name);
6064
nestedIndicatorColor = NestedCommentIndicatorColor.values.byName(prefs.getString(LocalSettings.nestedCommentIndicatorColor.name) ?? DEFAULT_NESTED_COMMENT_INDICATOR_COLOR.name);
6165
});
@@ -87,6 +91,9 @@ class _CommentAppearanceSettingsPageState extends State<CommentAppearanceSetting
8791
await prefs.setString(LocalSettings.nestedCommentIndicatorColor.name, value);
8892
setState(() => nestedIndicatorColor = NestedCommentIndicatorColor.values.byName(value ?? DEFAULT_NESTED_COMMENT_INDICATOR_COLOR.name));
8993
break;
94+
case LocalSettings.commentUseColorizedUsername:
95+
await prefs.setBool(LocalSettings.commentUseColorizedUsername.name, value);
96+
setState(() => commentUseColorizedUsername = value);
9097
}
9198

9299
if (context.mounted) {
@@ -103,6 +110,7 @@ class _CommentAppearanceSettingsPageState extends State<CommentAppearanceSetting
103110
await prefs.remove(LocalSettings.nestedCommentIndicatorStyle.name);
104111
await prefs.remove(LocalSettings.nestedCommentIndicatorColor.name);
105112
await prefs.remove(LocalSettings.commentShowUserInstance.name);
113+
await prefs.remove(LocalSettings.commentUseColorizedUsername.name);
106114

107115
await initPreferences();
108116

@@ -322,6 +330,18 @@ class _CommentAppearanceSettingsPageState extends State<CommentAppearanceSetting
322330
),
323331
),
324332
),
333+
SliverToBoxAdapter(
334+
child: Padding(
335+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
336+
child: ToggleOption(
337+
description: l10n.commentUseColorizedUsername,
338+
value: commentUseColorizedUsername,
339+
iconEnabled: Icons.brush_sharp,
340+
iconDisabled: Icons.brush_outlined,
341+
onToggle: (bool value) => setPreferences(LocalSettings.commentUseColorizedUsername, value),
342+
),
343+
),
344+
),
325345
SliverToBoxAdapter(
326346
child: Padding(
327347
padding: const EdgeInsets.symmetric(horizontal: 16.0),

lib/shared/comment_header.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class CommentHeader extends StatelessWidget {
157157
TextSpan(
158158
style: theme.textTheme.bodyMedium?.copyWith(
159159
fontWeight: FontWeight.w500,
160+
color: state.commentUseColorizedUsername ? theme.colorScheme.secondary : theme.textTheme.bodyLarge?.color,
160161
fontSize: MediaQuery.textScalerOf(context).scale(theme.textTheme.bodyMedium!.fontSize! * state.metadataFontSizeScale.textScaleFactor),
161162
),
162163
text: comment.creator.displayName != null && state.useDisplayNames ? comment.creator.displayName! : comment.creator.name,
@@ -166,6 +167,7 @@ class CommentHeader extends StatelessWidget {
166167
text: generateUserFullNameSuffix(context, fetchInstanceNameFromUrl(comment.creator.actorId)),
167168
style: theme.textTheme.bodyMedium?.copyWith(
168169
fontWeight: FontWeight.w300,
170+
color: state.commentUseColorizedUsername ? theme.colorScheme.secondary : theme.textTheme.bodyLarge?.color,
169171
fontSize: MediaQuery.textScalerOf(context).scale(theme.textTheme.bodyMedium!.fontSize! * state.metadataFontSizeScale.textScaleFactor),
170172
),
171173
)

lib/thunder/bloc/thunder_bloc.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
155155
bool showCommentButtonActions = prefs.getBool(LocalSettings.showCommentActionButtons.name) ?? false;
156156
bool commentShowUserInstance = prefs.getBool(LocalSettings.commentShowUserInstance.name) ?? false;
157157
bool combineCommentScores = prefs.getBool(LocalSettings.combineCommentScores.name) ?? false;
158+
bool commentUseColorizedUsername = prefs.getBool(LocalSettings.commentUseColorizedUsername.name) ?? false;
158159
NestedCommentIndicatorStyle nestedCommentIndicatorStyle =
159160
NestedCommentIndicatorStyle.values.byName(prefs.getString(LocalSettings.nestedCommentIndicatorStyle.name) ?? DEFAULT_NESTED_COMMENT_INDICATOR_STYLE.name);
160161
NestedCommentIndicatorColor nestedCommentIndicatorColor =
@@ -288,6 +289,7 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
288289
combineCommentScores: combineCommentScores,
289290
nestedCommentIndicatorStyle: nestedCommentIndicatorStyle,
290291
nestedCommentIndicatorColor: nestedCommentIndicatorColor,
292+
commentUseColorizedUsername: commentUseColorizedUsername,
291293

292294
/// -------------------------- Theme Related Settings --------------------------
293295
// Theme Settings

lib/thunder/bloc/thunder_state.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ThunderState extends Equatable {
7070
this.showCommentButtonActions = false,
7171
this.commentShowUserInstance = false,
7272
this.combineCommentScores = false,
73+
this.commentUseColorizedUsername = false,
7374
this.nestedCommentIndicatorStyle = NestedCommentIndicatorStyle.thick,
7475
this.nestedCommentIndicatorColor = NestedCommentIndicatorColor.colorful,
7576

@@ -200,6 +201,7 @@ class ThunderState extends Equatable {
200201
final bool showCommentButtonActions;
201202
final bool commentShowUserInstance;
202203
final bool combineCommentScores;
204+
final bool commentUseColorizedUsername;
203205
final NestedCommentIndicatorStyle nestedCommentIndicatorStyle;
204206
final NestedCommentIndicatorColor nestedCommentIndicatorColor;
205207

@@ -336,6 +338,7 @@ class ThunderState extends Equatable {
336338
bool? showCommentButtonActions,
337339
bool? commentShowUserInstance,
338340
bool? combineCommentScores,
341+
bool? commentUseColorizedUsername,
339342
NestedCommentIndicatorStyle? nestedCommentIndicatorStyle,
340343
NestedCommentIndicatorColor? nestedCommentIndicatorColor,
341344

@@ -468,6 +471,7 @@ class ThunderState extends Equatable {
468471
showCommentButtonActions: showCommentButtonActions ?? this.showCommentButtonActions,
469472
commentShowUserInstance: commentShowUserInstance ?? this.commentShowUserInstance,
470473
combineCommentScores: combineCommentScores ?? this.combineCommentScores,
474+
commentUseColorizedUsername: commentUseColorizedUsername ?? this.commentUseColorizedUsername,
471475
nestedCommentIndicatorStyle: nestedCommentIndicatorStyle ?? this.nestedCommentIndicatorStyle,
472476
nestedCommentIndicatorColor: nestedCommentIndicatorColor ?? this.nestedCommentIndicatorColor,
473477

@@ -604,6 +608,7 @@ class ThunderState extends Equatable {
604608
showCommentButtonActions,
605609
commentShowUserInstance,
606610
combineCommentScores,
611+
commentUseColorizedUsername,
607612

608613
nestedCommentIndicatorStyle,
609614
nestedCommentIndicatorColor,

0 commit comments

Comments
 (0)