diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index 421d6f1704..d686249277 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -416,17 +416,17 @@ class Subscription extends ZulipStream { return 0xff000000 | int.parse(str.substring(1), radix: 16); } - ColorSwatch? _swatch; + ColorSwatch? _swatch; /// A [ColorSwatch] for the subscription, memoized. // TODO I'm not sure this is the right home for this; it seems like we might // instead have chosen to put it in more UI-centered code, like in a custom // material [ColorScheme] class or something. But it works for now. - ColorSwatch colorSwatch() => + ColorSwatch colorSwatch() => _swatch ??= streamColorSwatch(color); @visibleForTesting @JsonKey(includeToJson: false) - ColorSwatch? get debugCachedSwatchValue => _swatch; + ColorSwatch? get debugCachedSwatchValue => _swatch; Subscription({ required super.streamId, @@ -463,21 +463,21 @@ class Subscription extends ZulipStream { /// /// Use this in UI code for colors related to [Subscription.color], /// such as the background of an unread count badge. -ColorSwatch streamColorSwatch(int base) { +ColorSwatch streamColorSwatch(int base) { final baseAsColor = Color(base); final clamped20to75 = clampLchLightness(baseAsColor, 20, 75); final clamped20to75AsHsl = HSLColor.fromColor(clamped20to75); final map = { - StreamColorVariant.base: baseAsColor, + StreamColor.base: baseAsColor, // Follows `.unread-count` in Vlad's replit: // // // // TODO fix bug where our results differ from the replit's (see unit tests) - StreamColorVariant.unreadCountBadgeBackground: + StreamColor.unreadCountBadgeBackground: clampLchLightness(baseAsColor, 30, 70) .withOpacity(0.3), @@ -485,14 +485,14 @@ ColorSwatch streamColorSwatch(int base) { // // // TODO fix bug where our results differ from the replit's (see unit tests) - StreamColorVariant.iconOnPlainBackground: clamped20to75, + StreamColor.iconOnPlainBackground: clamped20to75, // Follows `.recepeient__icon` in Vlad's replit: // // // // TODO fix bug where our results differ from the replit's (see unit tests) - StreamColorVariant.iconOnBarBackground: + StreamColor.iconOnBarBackground: clamped20to75AsHsl .withLightness(clamped20to75AsHsl.lightness - 0.12) .toColor(), @@ -505,16 +505,16 @@ ColorSwatch streamColorSwatch(int base) { // // which does ordinary RGB mixing. Investigate and send a PR? // TODO fix bug where our results differ from the replit's (see unit tests) - StreamColorVariant.barBackground: + StreamColor.barBackground: LabColor.fromColor(const Color(0xfff9f9f9)) .interpolate(LabColor.fromColor(clamped20to75), 0.22) .toColor(), }; - return ColorSwatch(base, map); + return ColorSwatch(base, map); } -enum StreamColorVariant { +enum StreamColor { /// The [Subscription.color] int that the swatch is based on. base, diff --git a/lib/widgets/inbox.dart b/lib/widgets/inbox.dart index 9e70f0220e..5dd16ea942 100644 --- a/lib/widgets/inbox.dart +++ b/lib/widgets/inbox.dart @@ -411,13 +411,13 @@ class _StreamHeaderItem extends _HeaderItem { @override get title => subscription.name; @override get icon => iconDataForStream(subscription); @override get collapsedIconColor => - subscription.colorSwatch()[StreamColorVariant.iconOnPlainBackground]!; + subscription.colorSwatch()[StreamColor.iconOnPlainBackground]!; @override get uncollapsedIconColor => - subscription.colorSwatch()[StreamColorVariant.iconOnBarBackground]!; + subscription.colorSwatch()[StreamColor.iconOnBarBackground]!; @override get uncollapsedBackgroundColor => - subscription.colorSwatch()[StreamColorVariant.barBackground]!; + subscription.colorSwatch()[StreamColor.barBackground]!; @override get unreadCountBadgeBackgroundColor => - subscription.colorSwatch()[StreamColorVariant.unreadCountBadgeBackground]!; + subscription.colorSwatch()[StreamColor.unreadCountBadgeBackground]!; @override get onCollapseButtonTap => () async { await super.onCollapseButtonTap(); diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index c43d42c577..23f0de6798 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -67,7 +67,7 @@ class _MessageListPageState extends State { case StreamNarrow(:final streamId): case TopicNarrow(:final streamId): backgroundColor = - store.subscriptions[streamId]?.colorSwatch()[StreamColorVariant.barBackground]! + store.subscriptions[streamId]?.colorSwatch()[StreamColor.barBackground]! ?? _kUnsubscribedStreamRecipientHeaderColor; // All recipient headers will match this color; remove distracting line // (but are recipient headers even needed for topic narrows?) @@ -656,12 +656,12 @@ class StreamMessageRecipientHeader extends StatelessWidget { final Color iconColor; if (subscription != null) { final swatch = subscription.colorSwatch(); - backgroundColor = swatch[StreamColorVariant.barBackground]!; + backgroundColor = swatch[StreamColor.barBackground]!; contrastingColor = (ThemeData.estimateBrightnessForColor(backgroundColor) == Brightness.dark) ? Colors.white : Colors.black; - iconColor = swatch[StreamColorVariant.iconOnBarBackground]!; + iconColor = swatch[StreamColor.iconOnBarBackground]!; } else { backgroundColor = _kUnsubscribedStreamRecipientHeaderColor; contrastingColor = Colors.black; diff --git a/lib/widgets/subscription_list.dart b/lib/widgets/subscription_list.dart index 32a41404a2..67db4316d6 100644 --- a/lib/widgets/subscription_list.dart +++ b/lib/widgets/subscription_list.dart @@ -208,7 +208,7 @@ class SubscriptionItem extends StatelessWidget { const SizedBox(width: 16), Padding( padding: const EdgeInsets.symmetric(vertical: 11), - child: Icon(size: 18, color: swatch[StreamColorVariant.iconOnPlainBackground]!, + child: Icon(size: 18, color: swatch[StreamColor.iconOnPlainBackground]!, iconDataForStream(subscription))), const SizedBox(width: 5), Expanded( diff --git a/lib/widgets/unread_count_badge.dart b/lib/widgets/unread_count_badge.dart index 116d5d285f..f98cbd67a6 100644 --- a/lib/widgets/unread_count_badge.dart +++ b/lib/widgets/unread_count_badge.dart @@ -31,8 +31,8 @@ class UnreadCountBadge extends StatelessWidget { Widget build(BuildContext context) { final backgroundColor = this.backgroundColor; final effectiveBackgroundColor = switch (backgroundColor) { - ColorSwatch() => - backgroundColor[StreamColorVariant.unreadCountBadgeBackground]!, + ColorSwatch() => + backgroundColor[StreamColor.unreadCountBadgeBackground]!, Color() => backgroundColor, null => const Color.fromRGBO(102, 102, 153, 0.15), }; diff --git a/test/api/model/model_test.dart b/test/api/model/model_test.dart index 93d28f045f..afa8a4b541 100644 --- a/test/api/model/model_test.dart +++ b/test/api/model/model_test.dart @@ -122,24 +122,24 @@ void main() { check(sub.debugCachedSwatchValue).isNull(); sub.colorSwatch(); check(sub.debugCachedSwatchValue).isNotNull() - [StreamColorVariant.base].equals(const Color(0xffffffff)); + [StreamColor.base].equals(const Color(0xffffffff)); sub.color = 0xffff0000; check(sub.debugCachedSwatchValue).isNull(); sub.colorSwatch(); check(sub.debugCachedSwatchValue).isNotNull() - [StreamColorVariant.base].equals(const Color(0xffff0000)); + [StreamColor.base].equals(const Color(0xffff0000)); }); group('streamColorSwatch', () { test('base', () { - check(streamColorSwatch(0xffffffff))[StreamColorVariant.base] + check(streamColorSwatch(0xffffffff))[StreamColor.base] .equals(const Color(0xffffffff)); }); test('unreadCountBadgeBackground', () { void runCheck(int base, Color expected) { check(streamColorSwatch(base)) - [StreamColorVariant.unreadCountBadgeBackground].equals(expected); + [StreamColor.unreadCountBadgeBackground].equals(expected); } // Check against everything in ZULIP_ASSIGNMENT_COLORS and EXTREME_COLORS @@ -202,7 +202,7 @@ void main() { test('iconOnPlainBackground', () { void runCheck(int base, Color expected) { check(streamColorSwatch(base)) - [StreamColorVariant.iconOnPlainBackground].equals(expected); + [StreamColor.iconOnPlainBackground].equals(expected); } // Check against everything in ZULIP_ASSIGNMENT_COLORS @@ -244,7 +244,7 @@ void main() { test('iconOnBarBackground', () { void runCheck(int base, Color expected) { check(streamColorSwatch(base)) - [StreamColorVariant.iconOnBarBackground].equals(expected); + [StreamColor.iconOnBarBackground].equals(expected); } // Check against everything in ZULIP_ASSIGNMENT_COLORS @@ -286,7 +286,7 @@ void main() { test('barBackground', () { void runCheck(int base, Color expected) { check(streamColorSwatch(base)) - [StreamColorVariant.barBackground].equals(expected); + [StreamColor.barBackground].equals(expected); } // Check against everything in ZULIP_ASSIGNMENT_COLORS diff --git a/test/widgets/inbox_test.dart b/test/widgets/inbox_test.dart index 113ad3d928..f3b9eb9a9e 100644 --- a/test/widgets/inbox_test.dart +++ b/test/widgets/inbox_test.dart @@ -412,7 +412,7 @@ void main() { check(collapseIcon).icon.equals(ZulipIcons.arrow_down); final streamIcon = findStreamHeaderIcon(tester, streamId); check(streamIcon).color - .equals(subscription.colorSwatch()[StreamColorVariant.iconOnBarBackground]!); + .equals(subscription.colorSwatch()[StreamColor.iconOnBarBackground]!); // TODO check bar background color check(tester.widgetList(findSectionContent)).isNotEmpty(); } @@ -434,7 +434,7 @@ void main() { check(collapseIcon).icon.equals(ZulipIcons.arrow_right); final streamIcon = findStreamHeaderIcon(tester, streamId); check(streamIcon).color - .equals(subscription.colorSwatch()[StreamColorVariant.iconOnPlainBackground]!); + .equals(subscription.colorSwatch()[StreamColor.iconOnPlainBackground]!); // TODO check bar background color check(tester.widgetList(findSectionContent)).isEmpty(); } diff --git a/test/widgets/message_list_test.dart b/test/widgets/message_list_test.dart index b6fa70b090..4102bf6d7f 100644 --- a/test/widgets/message_list_test.dart +++ b/test/widgets/message_list_test.dart @@ -282,7 +282,7 @@ void main() { find.descendant( of: find.byType(StreamMessageRecipientHeader), matching: find.byType(ColoredBox), - ))).color.equals(swatch[StreamColorVariant.barBackground]!); + ))).color.equals(swatch[StreamColor.barBackground]!); }); testWidgets('color of stream icon', (tester) async { @@ -294,7 +294,7 @@ void main() { subscriptions: [subscription]); await tester.pump(); check(tester.widget(find.byIcon(ZulipIcons.globe))) - .color.equals(swatch[StreamColorVariant.iconOnBarBackground]!); + .color.equals(swatch[StreamColor.iconOnBarBackground]!); }); testWidgets('normal streams show hash icon', (tester) async { diff --git a/test/widgets/subscription_list_test.dart b/test/widgets/subscription_list_test.dart index 88cfd6c7cd..80503956bf 100644 --- a/test/widgets/subscription_list_test.dart +++ b/test/widgets/subscription_list_test.dart @@ -186,7 +186,7 @@ void main() { ], unreadMsgs: unreadMsgs); check(getItemCount()).equals(1); check(tester.widget(find.byType(Icon)).color) - .equals(swatch[StreamColorVariant.iconOnPlainBackground]!); + .equals(swatch[StreamColor.iconOnPlainBackground]!); check(tester.widget(find.byType(UnreadCountBadge)).backgroundColor) .equals(swatch); }); diff --git a/test/widgets/unread_count_badge_test.dart b/test/widgets/unread_count_badge_test.dart index 62d31ec809..bd76dacd4a 100644 --- a/test/widgets/unread_count_badge_test.dart +++ b/test/widgets/unread_count_badge_test.dart @@ -40,7 +40,7 @@ void main() { testWidgets('stream color', (WidgetTester tester) async { final swatch = streamColorSwatch(0xff76ce90); await prepare(tester, swatch); - check(findBackgroundColor(tester)).equals(swatch[StreamColorVariant.unreadCountBadgeBackground]!); + check(findBackgroundColor(tester)).equals(swatch[StreamColor.unreadCountBadgeBackground]!); }); }); });