Skip to content

Commit 60f6a23

Browse files
committed
subscription_list: Show muted streams below unmuted ones
1 parent f1035d7 commit 60f6a23

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/widgets/subscription_list.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:collection/collection.dart';
21
import 'package:flutter/material.dart';
32

43
import '../api/model/model.dart';
@@ -48,6 +47,15 @@ class _SubscriptionListPageState extends State<SubscriptionListPage> with PerAcc
4847
});
4948
}
5049

50+
void _sortSubs(List<Subscription> list) {
51+
list.sort((a, b) {
52+
if (a.isMuted && !b.isMuted) return 1;
53+
if (!a.isMuted && b.isMuted) return -1;
54+
// TODO(i18n): add locale-aware sorting
55+
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
56+
});
57+
}
58+
5159
@override
5260
Widget build(BuildContext context) {
5361
// Design referenced from:
@@ -77,9 +85,8 @@ class _SubscriptionListPageState extends State<SubscriptionListPage> with PerAcc
7785
unpinned.add(subscription);
7886
}
7987
}
80-
// TODO(i18n): add locale-aware sorting
81-
pinned.sortBy((subscription) => subscription.name.toLowerCase());
82-
unpinned.sortBy((subscription) => subscription.name.toLowerCase());
88+
_sortSubs(pinned);
89+
_sortSubs(unpinned);
8390

8491
return Scaffold(
8592
appBar: AppBar(title: const Text("Channels")),

test/widgets/subscription_list_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ void main() {
132132
]);
133133
check(listedStreamIds(tester)).deepEquals([1, 2, 3, 4, 5, 6]);
134134
});
135+
136+
testWidgets('muted subscriptions come last among pinned streams and among unpinned streams', (tester) async {
137+
await setupStreamListPage(tester, subscriptions: [
138+
eg.subscription(eg.stream(streamId: 1, name: 'a'), isMuted: true, pinToTop: true),
139+
eg.subscription(eg.stream(streamId: 2, name: 'b'), isMuted: false, pinToTop: true),
140+
eg.subscription(eg.stream(streamId: 3, name: 'c'), isMuted: true, pinToTop: true),
141+
eg.subscription(eg.stream(streamId: 4, name: 'd'), isMuted: false, pinToTop: false),
142+
eg.subscription(eg.stream(streamId: 5, name: 'e'), isMuted: true, pinToTop: false),
143+
eg.subscription(eg.stream(streamId: 6, name: 'f'), isMuted: false, pinToTop: false),
144+
]);
145+
check(listedStreamIds(tester)).deepEquals([2, 1, 3, 4, 6, 5]);
146+
});
135147
});
136148

137149
testWidgets('unread badge shows with unreads', (tester) async {

0 commit comments

Comments
 (0)