Skip to content

Commit cacae0e

Browse files
committed
subscription_list: Show muted streams below unmuted ones
1 parent 41d4a9c commit cacae0e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/widgets/subscription_list.dart

Lines changed: 11 additions & 5 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';
@@ -47,6 +46,15 @@ class _SubscriptionListPageState extends State<SubscriptionListPage> with PerAcc
4746
});
4847
}
4948

49+
void _sortSubs(List<Subscription> list) {
50+
list.sort((a, b) {
51+
if (a.isMuted && !b.isMuted) return 1;
52+
if (!a.isMuted && b.isMuted) return -1;
53+
// TODO(i18n): add locale-aware sorting
54+
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
55+
});
56+
}
57+
5058
@override
5159
Widget build(BuildContext context) {
5260
// Design referenced from:
@@ -76,10 +84,8 @@ class _SubscriptionListPageState extends State<SubscriptionListPage> with PerAcc
7684
unpinned.add(subscription);
7785
}
7886
}
79-
// TODO(i18n): add locale-aware sorting
80-
pinned.sortBy((subscription) => subscription.name.toLowerCase());
81-
unpinned.sortBy((subscription) => subscription.name.toLowerCase());
82-
87+
_sortSubs(pinned);
88+
_sortSubs(unpinned);
8389
return Scaffold(
8490
appBar: AppBar(title: const Text("Streams")),
8591
body: SafeArea(

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 at last', (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)