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

Improve user colors #710

Merged
merged 4 commits into from
Sep 8, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Star indicator for saved posts now prefixes the post title so that it's consistent with the indicators for locked posts and featured community posts - contribution from @ajsosa
- Improved ability to refresh posts - contribution from @micahmo
- Improve the option selector dialog to show the currently selected item - contribution from @micahmo
- Improve contrast and distinction of special user identifiers - contribution from @micahmo
- Show swatches and live previews for accent color selection - contribution from @micahmo
- Use Android system back button to navigate from Saved to History on profile page - contribution from @micahmo

Expand Down
37 changes: 31 additions & 6 deletions lib/user/utils/special_user_checks.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:thunder/core/theme/bloc/theme_bloc.dart';

// These checks are for whether a given user falls into a given category

Expand Down Expand Up @@ -31,14 +33,37 @@ bool isSpecialUser(BuildContext context, bool isOwnComment, Post? post, Comment?

Color? fetchUsernameColor(BuildContext context, bool isOwnComment, Post? post, Comment? comment, PersonSafe creator, List<CommunityModeratorView>? moderators) {
final theme = Theme.of(context);
final bool darkTheme = context.read<ThemeBloc>().state.useDarkTheme;

if (commentAuthorIsPostAuthor(post, comment)) return theme.colorScheme.secondaryContainer;
if (isOwnComment) return theme.colorScheme.primaryContainer;
if (isAdmin(creator)) return theme.colorScheme.errorContainer;
if (isModerator(creator, moderators)) return theme.colorScheme.tertiaryContainer;
if (isBot(creator)) return Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.75), Colors.purple);
Color? color;

return null;
if (isBot(creator)) {
color = Colors.purple;
}
if (isModerator(creator, moderators)) {
color = Colors.orange;
}
if (isAdmin(creator)) {
color = Colors.red;
}
if (isOwnComment) {
color = Colors.green;
}
if (commentAuthorIsPostAuthor(post, comment)) {
color = Colors.blue;
}

if (color != null) {
// Blend with theme
color = Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.35), color);

// Lighten for light mode
if (!darkTheme) {
color = HSLColor.fromColor(color).withLightness(0.85).toColor();
}
}

return color;
}

String fetchUsernameDescriptor(bool isOwnComment, Post? post, Comment? comment, PersonSafe creator, List<CommunityModeratorView>? moderators) {
Expand Down