Sort the updates, not their IDs

Also, use a comparator to sort the updates and stop using the
Comparable interface. There are different ways to sort updates,
so don't define one.
This commit is contained in:
Gabriele M
2017-07-10 00:45:49 +02:00
parent 7d55cd93ee
commit 66ca7a79df
2 changed files with 12 additions and 8 deletions

View File

@@ -49,6 +49,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class UpdatesActivity extends AppCompatActivity {
@@ -188,8 +189,16 @@ public class UpdatesActivity extends AppCompatActivity {
}
List<String> updateIds = new ArrayList<>();
updateIds.addAll(controller.getIds());
Collections.sort(updateIds);
List<UpdateDownload> sortedUpdates = controller.getUpdates();
Collections.sort(sortedUpdates, new Comparator<UpdateDownload>() {
@Override
public int compare(UpdateDownload u1, UpdateDownload u2) {
return Long.compare(u2.getTimestamp(), u1.getTimestamp());
}
});
for (Update update : sortedUpdates) {
updateIds.add(update.getDownloadId());
}
mAdapter.setData(updateIds);
mAdapter.notifyDataSetChanged();
}