From b3b0298431a9680d6185e1c45699f6facd02208e Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Mon, 26 Apr 2021 08:15:20 +0200 Subject: [PATCH] SmsInboxAPI: print messages in opposite order With this the newest messages appear at the bottom of the printed list, which is the same behaviour we had before merging recent SmsInboxAPI changes. Finding the newest message is easier if it is at the end of printed message, no need to scroll or at least search for the start of the printed output. Before this commit we had: [ { "threadid": 7, "type": "inbox", "read": true, "number": "+123", "received": "2021-04-24 20:59:16", "body": "bar" }, { "threadid": 5, "type": "inbox", "read": true, "sender": "foo", "number": "+123", "received": "2021-04-23 13:12:28", "body": "bar" }, { "threadid": 5, "type": "sent", "read": true, "sender": "foo", "number": "+123", "received": "2021-04-21 13:11:14", "body": "bar" } ] With this we get: [ { "threadid": 5, "type": "sent", "read": true, "sender": "foo", "number": "+123", "received": "2021-04-21 13:11:14", "body": "bar" }, { "threadid": 5, "type": "inbox", "read": true, "sender": "foo", "number": "+123", "received": "2021-04-23 13:12:28", "body": "bar" }, { "threadid": 7, "type": "inbox", "read": true, "number": "+123", "received": "2021-04-24 20:59:16", "body": "bar" } ] --- app/src/main/java/com/termux/api/SmsInboxAPI.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/termux/api/SmsInboxAPI.java b/app/src/main/java/com/termux/api/SmsInboxAPI.java index 7cda2df4..42b7c252 100644 --- a/app/src/main/java/com/termux/api/SmsInboxAPI.java +++ b/app/src/main/java/com/termux/api/SmsInboxAPI.java @@ -59,7 +59,7 @@ public static void getConversations(Context context, JsonWriter out, int offset, ContentResolver cr = context.getContentResolver(); String sortOrder = "date DESC"; try (Cursor c = cr.query(Conversations.CONTENT_URI, null, null, null , sortOrder)) { - c.moveToFirst(); + c.moveToLast(); Map nameCache = new HashMap<>(); @@ -77,7 +77,7 @@ public static void getConversations(Context context, JsonWriter out, int offset, cc.moveToFirst(); writeElement(cc, out, nameCache, context); cc.close(); - c.moveToNext(); + c.moveToPrevious(); } out.endArray(); } @@ -123,9 +123,9 @@ private static void writeElement(Cursor c, JsonWriter out, Map n public static void getAllSms(Context context, JsonWriter out, int offset, int limit, String number, Uri contentURI) throws IOException { ContentResolver cr = context.getContentResolver(); String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset; - try (Cursor c = cr.query(contentURI, null, - ADDRESS + " LIKE '%" + number + "%'",null, sortOrder)) { - c.moveToFirst(); + try (Cursor c = cr.query(contentURI, null, + ADDRESS + " LIKE '%" + number + "%'", null, sortOrder)) { + c.moveToLast(); new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Map nameCache = new HashMap<>(); @@ -133,7 +133,7 @@ public static void getAllSms(Context context, JsonWriter out, int offset, int li out.beginArray(); for (int i = 0, count = c.getCount(); i < count; i++) { writeElement(c, out, nameCache, context); - c.moveToNext(); + c.moveToPrevious(); } out.endArray(); }