Use ascii sum for computing hash for avatar color

This commit is contained in:
Neeraj Gupta 2022-12-19 09:58:23 +05:30
parent b3b9f49464
commit 45f0d120e2
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 4 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import 'package:photos/core/constants.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/clear_selections_event.dart';
import 'package:photos/events/files_updated_event.dart';
import 'package:photos/extensions/string_ext.dart';
import 'package:photos/models/file.dart';
import 'package:photos/models/selected_files.dart';
import 'package:photos/theme/ente_theme.dart';
@ -415,7 +416,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
final avatarColors = getEnteColorScheme(context).avatarColors;
final int randomID = file.ownerID != _currentUserID
? file.ownerID
: file.pubMagicMetadata.uploaderName.hashCode;
: file.pubMagicMetadata.uploaderName.sumAsciiValues;
selectionColor = avatarColors[(randomID).remainder(avatarColors.length)];
}
return GestureDetector(

View file

@ -11,6 +11,7 @@ import 'package:photos/db/files_db.dart';
import 'package:photos/db/trash_db.dart';
import 'package:photos/events/files_updated_event.dart';
import 'package:photos/events/local_photos_updated_event.dart';
import 'package:photos/extensions/string_ext.dart';
import 'package:photos/models/collection.dart';
import 'package:photos/models/file.dart';
import 'package:photos/models/file_type.dart';
@ -132,7 +133,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
// get avatar color
OwnerAvatarOverlayIcon(
User(
id: widget.file.pubMagicMetadata.uploaderName.hashCode,
id: widget.file.pubMagicMetadata.uploaderName.sumAsciiValues,
email: owner.email,
name: widget.file.pubMagicMetadata.uploaderName,
),