Use stable sort for album

This commit is contained in:
Ming Ming 2021-07-09 02:35:32 +08:00
parent 8de5597575
commit 1a5fc2bbe2
2 changed files with 9 additions and 1 deletions

View file

@ -137,7 +137,7 @@ class AlbumTimeSortProvider extends AlbumReversibleSortProvider {
return Tuple2( return Tuple2(
prevFileTime ?? DateTime.fromMillisecondsSinceEpoch(0), e); prevFileTime ?? DateTime.fromMillisecondsSinceEpoch(0), e);
}) })
.sorted((x, y) { .stableSorted((x, y) {
if (isAscending) { if (isAscending) {
return x.item1.compareTo(y.item1); return x.item1.compareTo(y.item1);
} else { } else {

View file

@ -1,9 +1,17 @@
import 'package:flutter/foundation.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
extension IterableExtension<T> on Iterable<T> { extension IterableExtension<T> on Iterable<T> {
/// Return a new sorted list /// Return a new sorted list
List<T> sorted([int compare(T a, T b)]) => this.toList()..sort(compare); List<T> sorted([int compare(T a, T b)]) => this.toList()..sort(compare);
/// Return a new stable sorted list
List<T> stableSorted([int compare(T a, T b)]) {
final tmp = this.toList();
mergeSort(tmp, compare: compare);
return tmp;
}
/// Return a string representation of this iterable by joining the result of /// Return a string representation of this iterable by joining the result of
/// toString for each items /// toString for each items
String toReadableString() => "[${join(', ')}]"; String toReadableString() => "[${join(', ')}]";