sort construct list on construct list update, don't repeat sort operation
This commit is contained in:
parent
f1a782eac5
commit
4a518e053b
2 changed files with 9 additions and 15 deletions
|
|
@ -52,16 +52,21 @@ class ConstructListModel {
|
|||
_updateMetrics();
|
||||
}
|
||||
|
||||
int _sortConstructs(ConstructUses a, ConstructUses b) {
|
||||
final comp = b.points.compareTo(a.points);
|
||||
if (comp != 0) return comp;
|
||||
return a.lemma.compareTo(b.lemma);
|
||||
}
|
||||
|
||||
/// A map of lemmas to ConstructUses, each of which contains a lemma
|
||||
/// key = lemmma + constructType.string, value = ConstructUses
|
||||
void _updateConstructMap(final List<OneConstructUse> newUses) {
|
||||
for (final use in newUses) {
|
||||
if (use.lemma == null) continue;
|
||||
final currentUses = _constructMap[use.identifier.string] ??
|
||||
ConstructUses(
|
||||
uses: [],
|
||||
constructType: use.constructType,
|
||||
lemma: use.lemma!,
|
||||
lemma: use.lemma,
|
||||
category: use.category,
|
||||
);
|
||||
currentUses.uses.add(use);
|
||||
|
|
@ -75,11 +80,7 @@ class ConstructListModel {
|
|||
void _updateConstructList() {
|
||||
// TODO check how expensive this is
|
||||
_constructList = _constructMap.values.toList();
|
||||
_constructList.sort((a, b) {
|
||||
final comp = b.uses.length.compareTo(a.uses.length);
|
||||
if (comp != 0) return comp;
|
||||
return a.lemma.compareTo(b.lemma);
|
||||
});
|
||||
_constructList.sort(_sortConstructs);
|
||||
}
|
||||
|
||||
void _updateCategoriesToUses() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/progress_indicators_enum.dart';
|
||||
import 'package:fluffychat/pangea/models/analytics/construct_list_model.dart';
|
||||
|
|
@ -94,11 +93,7 @@ class AnalyticsPopupState extends State<AnalyticsPopup> {
|
|||
dialogContent = Center(child: Text(L10n.of(context)!.noDataFound));
|
||||
} else if (hasNoCategories || !widget.showGroups) {
|
||||
dialogContent = ConstructsTileList(
|
||||
_constructsModel.constructList(type: widget.type).sorted((a, b) {
|
||||
final comp = b.points.compareTo(a.points);
|
||||
if (comp != 0) return comp;
|
||||
return a.lemma.compareTo(b.lemma);
|
||||
}),
|
||||
_constructsModel.constructList(type: widget.type),
|
||||
);
|
||||
} else {
|
||||
dialogContent = ListView.builder(
|
||||
|
|
@ -156,8 +151,6 @@ class ConstructsTileList extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// sort list by xp
|
||||
constructs.sort((a, b) => b.points.compareTo(a.points));
|
||||
return ListView.builder(
|
||||
itemCount: constructs.length,
|
||||
itemBuilder: (context, index) => ConstructUsesXPTile(constructs[index]),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue