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:
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.lineageos.updater;
|
||||
|
||||
public class Update implements Comparable<Update> {
|
||||
public class Update {
|
||||
|
||||
private String mName;
|
||||
private String mDownloadUrl;
|
||||
@@ -83,9 +83,4 @@ public class Update implements Comparable<Update> {
|
||||
public void setDownloadUrl(String downloadUrl) {
|
||||
mDownloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Update u) {
|
||||
return mTimestamp < u.mTimestamp ? -1 : mTimestamp > u.mTimestamp ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user