Skip to content

Commit

Permalink
Sort native tracks by time
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Feb 5, 2024
1 parent c6979d7 commit 7967105
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/src/main/java/mobi/maptrek/DataLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Andrey Novikov
* Copyright 2024 Andrey Novikov
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand Down Expand Up @@ -29,6 +29,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -203,6 +205,8 @@ public void deliverResult(List<FileDataSource> data) {
mData = newData;
}

Collections.sort(mData, fileDataSourceComparator);

for (FileDataSource source : data) {
mFiles.add(source.path);
}
Expand Down Expand Up @@ -309,4 +313,14 @@ public void onCanceled(List<FileDataSource> data) {
// Attempt to cancel the current asynchronous load.
super.onCanceled(data);
}

private final Comparator<? super FileDataSource> fileDataSourceComparator = (Comparator<FileDataSource>) (o1, o2) -> {
if (o1.isNativeTrack() && o2.isNativeTrack()) {
File o1f = new File(o1.path);
File o2f = new File(o2.path);
return Long.compare(o1f.lastModified(), o2f.lastModified());
} else {
return o1.path.compareTo(o2.path);
}
};
}

0 comments on commit 7967105

Please sign in to comment.