From 6819ae46f9160401142eaef5f52f04f989af8d42 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Tue, 1 Dec 2020 04:31:27 +0100 Subject: [PATCH] Sort replies from oldest to newest --- app/src/main/java/io/lbry/browser/model/Comment.java | 7 ++++++- .../main/java/io/lbry/browser/tasks/CommentListTask.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/lbry/browser/model/Comment.java b/app/src/main/java/io/lbry/browser/model/Comment.java index c998ca55..157a2174 100644 --- a/app/src/main/java/io/lbry/browser/model/Comment.java +++ b/app/src/main/java/io/lbry/browser/model/Comment.java @@ -11,7 +11,7 @@ import io.lbry.browser.utils.Helper; import lombok.Data; @Data -public class Comment { +public class Comment implements Comparable { public static final double LBC_COST = 1; public static final int MAX_LENGTH = 2000; @@ -66,4 +66,9 @@ public class Comment { return null; } } + + @Override + public int compareTo(Comment comment) { + return (int)(this.getTimestamp() - comment.getTimestamp()); + } } diff --git a/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java index bb08073e..2833e003 100644 --- a/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java @@ -8,6 +8,7 @@ import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,6 +68,9 @@ public class CommentListTask extends AsyncTask> { } } + // Sort all replies from oldest to newest at once + Collections.sort(children); + for (Comment child : children) { for (Comment parent : comments) { if (parent.getId().equalsIgnoreCase(child.getParentId())) { -- 2.45.2