Skip to content

Commit 3b658bd

Browse files
committed
model [nfc]: Shorten StreamColorVariant to StreamColor
The old name seems longer than it needs to be.
1 parent 39f69e6 commit 3b658bd

10 files changed

+34
-34
lines changed

lib/api/model/model.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,17 @@ class Subscription extends ZulipStream {
416416
return 0xff000000 | int.parse(str.substring(1), radix: 16);
417417
}
418418

419-
ColorSwatch<StreamColorVariant>? _swatch;
419+
ColorSwatch<StreamColor>? _swatch;
420420
/// A [ColorSwatch<StreamColorVariant>] for the subscription, memoized.
421421
// TODO I'm not sure this is the right home for this; it seems like we might
422422
// instead have chosen to put it in more UI-centered code, like in a custom
423423
// material [ColorScheme] class or something. But it works for now.
424-
ColorSwatch<StreamColorVariant> colorSwatch() =>
424+
ColorSwatch<StreamColor> colorSwatch() =>
425425
_swatch ??= streamColorSwatch(color);
426426

427427
@visibleForTesting
428428
@JsonKey(includeToJson: false)
429-
ColorSwatch<StreamColorVariant>? get debugCachedSwatchValue => _swatch;
429+
ColorSwatch<StreamColor>? get debugCachedSwatchValue => _swatch;
430430

431431
Subscription({
432432
required super.streamId,
@@ -463,36 +463,36 @@ class Subscription extends ZulipStream {
463463
///
464464
/// Use this in UI code for colors related to [Subscription.color],
465465
/// such as the background of an unread count badge.
466-
ColorSwatch<StreamColorVariant> streamColorSwatch(int base) {
466+
ColorSwatch<StreamColor> streamColorSwatch(int base) {
467467
final baseAsColor = Color(base);
468468

469469
final clamped20to75 = clampLchLightness(baseAsColor, 20, 75);
470470
final clamped20to75AsHsl = HSLColor.fromColor(clamped20to75);
471471

472472
final map = {
473-
StreamColorVariant.base: baseAsColor,
473+
StreamColor.base: baseAsColor,
474474

475475
// Follows `.unread-count` in Vlad's replit:
476476
// <https://replit.com/@VladKorobov/zulip-sidebar#script.js>
477477
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
478478
//
479479
// TODO fix bug where our results differ from the replit's (see unit tests)
480-
StreamColorVariant.unreadCountBadgeBackground:
480+
StreamColor.unreadCountBadgeBackground:
481481
clampLchLightness(baseAsColor, 30, 70)
482482
.withOpacity(0.3),
483483

484484
// Follows `.sidebar-row__icon` in Vlad's replit:
485485
// <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js>
486486
//
487487
// TODO fix bug where our results differ from the replit's (see unit tests)
488-
StreamColorVariant.iconOnPlainBackground: clamped20to75,
488+
StreamColor.iconOnPlainBackground: clamped20to75,
489489

490490
// Follows `.recepeient__icon` in Vlad's replit:
491491
// <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js>
492492
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
493493
//
494494
// TODO fix bug where our results differ from the replit's (see unit tests)
495-
StreamColorVariant.iconOnBarBackground:
495+
StreamColor.iconOnBarBackground:
496496
clamped20to75AsHsl
497497
.withLightness(clamped20to75AsHsl.lightness - 0.12)
498498
.toColor(),
@@ -505,16 +505,16 @@ ColorSwatch<StreamColorVariant> streamColorSwatch(int base) {
505505
// <https://pub.dev/documentation/flutter_color_models/latest/flutter_color_models/ColorModel/interpolate.html>
506506
// which does ordinary RGB mixing. Investigate and send a PR?
507507
// TODO fix bug where our results differ from the replit's (see unit tests)
508-
StreamColorVariant.barBackground:
508+
StreamColor.barBackground:
509509
LabColor.fromColor(const Color(0xfff9f9f9))
510510
.interpolate(LabColor.fromColor(clamped20to75), 0.22)
511511
.toColor(),
512512
};
513513

514-
return ColorSwatch<StreamColorVariant>(base, map);
514+
return ColorSwatch<StreamColor>(base, map);
515515
}
516516

517-
enum StreamColorVariant {
517+
enum StreamColor {
518518
/// The [Subscription.color] int that the swatch is based on.
519519
base,
520520

lib/widgets/inbox.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,13 @@ class _StreamHeaderItem extends _HeaderItem {
411411
@override get title => subscription.name;
412412
@override get icon => iconDataForStream(subscription);
413413
@override get collapsedIconColor =>
414-
subscription.colorSwatch()[StreamColorVariant.iconOnPlainBackground]!;
414+
subscription.colorSwatch()[StreamColor.iconOnPlainBackground]!;
415415
@override get uncollapsedIconColor =>
416-
subscription.colorSwatch()[StreamColorVariant.iconOnBarBackground]!;
416+
subscription.colorSwatch()[StreamColor.iconOnBarBackground]!;
417417
@override get uncollapsedBackgroundColor =>
418-
subscription.colorSwatch()[StreamColorVariant.barBackground]!;
418+
subscription.colorSwatch()[StreamColor.barBackground]!;
419419
@override get unreadCountBadgeBackgroundColor =>
420-
subscription.colorSwatch()[StreamColorVariant.unreadCountBadgeBackground]!;
420+
subscription.colorSwatch()[StreamColor.unreadCountBadgeBackground]!;
421421

422422
@override get onCollapseButtonTap => () async {
423423
await super.onCollapseButtonTap();

lib/widgets/message_list.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class _MessageListPageState extends State<MessageListPage> {
6767
case StreamNarrow(:final streamId):
6868
case TopicNarrow(:final streamId):
6969
backgroundColor =
70-
store.subscriptions[streamId]?.colorSwatch()[StreamColorVariant.barBackground]!
70+
store.subscriptions[streamId]?.colorSwatch()[StreamColor.barBackground]!
7171
?? _kUnsubscribedStreamRecipientHeaderColor;
7272
// All recipient headers will match this color; remove distracting line
7373
// (but are recipient headers even needed for topic narrows?)
@@ -656,12 +656,12 @@ class StreamMessageRecipientHeader extends StatelessWidget {
656656
final Color iconColor;
657657
if (subscription != null) {
658658
final swatch = subscription.colorSwatch();
659-
backgroundColor = swatch[StreamColorVariant.barBackground]!;
659+
backgroundColor = swatch[StreamColor.barBackground]!;
660660
contrastingColor =
661661
(ThemeData.estimateBrightnessForColor(backgroundColor) == Brightness.dark)
662662
? Colors.white
663663
: Colors.black;
664-
iconColor = swatch[StreamColorVariant.iconOnBarBackground]!;
664+
iconColor = swatch[StreamColor.iconOnBarBackground]!;
665665
} else {
666666
backgroundColor = _kUnsubscribedStreamRecipientHeaderColor;
667667
contrastingColor = Colors.black;

lib/widgets/subscription_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class SubscriptionItem extends StatelessWidget {
208208
const SizedBox(width: 16),
209209
Padding(
210210
padding: const EdgeInsets.symmetric(vertical: 11),
211-
child: Icon(size: 18, color: swatch[StreamColorVariant.iconOnPlainBackground]!,
211+
child: Icon(size: 18, color: swatch[StreamColor.iconOnPlainBackground]!,
212212
iconDataForStream(subscription))),
213213
const SizedBox(width: 5),
214214
Expanded(

lib/widgets/unread_count_badge.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class UnreadCountBadge extends StatelessWidget {
3131
Widget build(BuildContext context) {
3232
final backgroundColor = this.backgroundColor;
3333
final effectiveBackgroundColor = switch (backgroundColor) {
34-
ColorSwatch<StreamColorVariant>() =>
35-
backgroundColor[StreamColorVariant.unreadCountBadgeBackground]!,
34+
ColorSwatch<StreamColor>() =>
35+
backgroundColor[StreamColor.unreadCountBadgeBackground]!,
3636
Color() => backgroundColor,
3737
null => const Color.fromRGBO(102, 102, 153, 0.15),
3838
};

test/api/model/model_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,24 @@ void main() {
122122
check(sub.debugCachedSwatchValue).isNull();
123123
sub.colorSwatch();
124124
check(sub.debugCachedSwatchValue).isNotNull()
125-
[StreamColorVariant.base].equals(const Color(0xffffffff));
125+
[StreamColor.base].equals(const Color(0xffffffff));
126126
sub.color = 0xffff0000;
127127
check(sub.debugCachedSwatchValue).isNull();
128128
sub.colorSwatch();
129129
check(sub.debugCachedSwatchValue).isNotNull()
130-
[StreamColorVariant.base].equals(const Color(0xffff0000));
130+
[StreamColor.base].equals(const Color(0xffff0000));
131131
});
132132

133133
group('streamColorSwatch', () {
134134
test('base', () {
135-
check(streamColorSwatch(0xffffffff))[StreamColorVariant.base]
135+
check(streamColorSwatch(0xffffffff))[StreamColor.base]
136136
.equals(const Color(0xffffffff));
137137
});
138138

139139
test('unreadCountBadgeBackground', () {
140140
void runCheck(int base, Color expected) {
141141
check(streamColorSwatch(base))
142-
[StreamColorVariant.unreadCountBadgeBackground].equals(expected);
142+
[StreamColor.unreadCountBadgeBackground].equals(expected);
143143
}
144144

145145
// Check against everything in ZULIP_ASSIGNMENT_COLORS and EXTREME_COLORS
@@ -202,7 +202,7 @@ void main() {
202202
test('iconOnPlainBackground', () {
203203
void runCheck(int base, Color expected) {
204204
check(streamColorSwatch(base))
205-
[StreamColorVariant.iconOnPlainBackground].equals(expected);
205+
[StreamColor.iconOnPlainBackground].equals(expected);
206206
}
207207

208208
// Check against everything in ZULIP_ASSIGNMENT_COLORS
@@ -244,7 +244,7 @@ void main() {
244244
test('iconOnBarBackground', () {
245245
void runCheck(int base, Color expected) {
246246
check(streamColorSwatch(base))
247-
[StreamColorVariant.iconOnBarBackground].equals(expected);
247+
[StreamColor.iconOnBarBackground].equals(expected);
248248
}
249249

250250
// Check against everything in ZULIP_ASSIGNMENT_COLORS
@@ -286,7 +286,7 @@ void main() {
286286
test('barBackground', () {
287287
void runCheck(int base, Color expected) {
288288
check(streamColorSwatch(base))
289-
[StreamColorVariant.barBackground].equals(expected);
289+
[StreamColor.barBackground].equals(expected);
290290
}
291291

292292
// Check against everything in ZULIP_ASSIGNMENT_COLORS

test/widgets/inbox_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void main() {
412412
check(collapseIcon).icon.equals(ZulipIcons.arrow_down);
413413
final streamIcon = findStreamHeaderIcon(tester, streamId);
414414
check(streamIcon).color
415-
.equals(subscription.colorSwatch()[StreamColorVariant.iconOnBarBackground]!);
415+
.equals(subscription.colorSwatch()[StreamColor.iconOnBarBackground]!);
416416
// TODO check bar background color
417417
check(tester.widgetList(findSectionContent)).isNotEmpty();
418418
}
@@ -434,7 +434,7 @@ void main() {
434434
check(collapseIcon).icon.equals(ZulipIcons.arrow_right);
435435
final streamIcon = findStreamHeaderIcon(tester, streamId);
436436
check(streamIcon).color
437-
.equals(subscription.colorSwatch()[StreamColorVariant.iconOnPlainBackground]!);
437+
.equals(subscription.colorSwatch()[StreamColor.iconOnPlainBackground]!);
438438
// TODO check bar background color
439439
check(tester.widgetList(findSectionContent)).isEmpty();
440440
}

test/widgets/message_list_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void main() {
282282
find.descendant(
283283
of: find.byType(StreamMessageRecipientHeader),
284284
matching: find.byType(ColoredBox),
285-
))).color.equals(swatch[StreamColorVariant.barBackground]!);
285+
))).color.equals(swatch[StreamColor.barBackground]!);
286286
});
287287

288288
testWidgets('color of stream icon', (tester) async {
@@ -294,7 +294,7 @@ void main() {
294294
subscriptions: [subscription]);
295295
await tester.pump();
296296
check(tester.widget<Icon>(find.byIcon(ZulipIcons.globe)))
297-
.color.equals(swatch[StreamColorVariant.iconOnBarBackground]!);
297+
.color.equals(swatch[StreamColor.iconOnBarBackground]!);
298298
});
299299

300300
testWidgets('normal streams show hash icon', (tester) async {

test/widgets/subscription_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void main() {
186186
], unreadMsgs: unreadMsgs);
187187
check(getItemCount()).equals(1);
188188
check(tester.widget<Icon>(find.byType(Icon)).color)
189-
.equals(swatch[StreamColorVariant.iconOnPlainBackground]!);
189+
.equals(swatch[StreamColor.iconOnPlainBackground]!);
190190
check(tester.widget<UnreadCountBadge>(find.byType(UnreadCountBadge)).backgroundColor)
191191
.equals(swatch);
192192
});

test/widgets/unread_count_badge_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
testWidgets('stream color', (WidgetTester tester) async {
4141
final swatch = streamColorSwatch(0xff76ce90);
4242
await prepare(tester, swatch);
43-
check(findBackgroundColor(tester)).equals(swatch[StreamColorVariant.unreadCountBadgeBackground]!);
43+
check(findBackgroundColor(tester)).equals(swatch[StreamColor.unreadCountBadgeBackground]!);
4444
});
4545
});
4646
});

0 commit comments

Comments
 (0)