Skip to content

Commit b3b0298

Browse files
committed
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" } ]
1 parent 5029bc8 commit b3b0298

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

app/src/main/java/com/termux/api/SmsInboxAPI.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void getConversations(Context context, JsonWriter out, int offset,
5959
ContentResolver cr = context.getContentResolver();
6060
String sortOrder = "date DESC";
6161
try (Cursor c = cr.query(Conversations.CONTENT_URI, null, null, null , sortOrder)) {
62-
c.moveToFirst();
62+
c.moveToLast();
6363

6464
Map<String, String> nameCache = new HashMap<>();
6565

@@ -77,7 +77,7 @@ public static void getConversations(Context context, JsonWriter out, int offset,
7777
cc.moveToFirst();
7878
writeElement(cc, out, nameCache, context);
7979
cc.close();
80-
c.moveToNext();
80+
c.moveToPrevious();
8181
}
8282
out.endArray();
8383
}
@@ -123,17 +123,17 @@ private static void writeElement(Cursor c, JsonWriter out, Map<String, String> n
123123
public static void getAllSms(Context context, JsonWriter out, int offset, int limit, String number, Uri contentURI) throws IOException {
124124
ContentResolver cr = context.getContentResolver();
125125
String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset;
126-
try (Cursor c = cr.query(contentURI, null,
127-
ADDRESS + " LIKE '%" + number + "%'",null, sortOrder)) {
128-
c.moveToFirst();
126+
try (Cursor c = cr.query(contentURI, null,
127+
ADDRESS + " LIKE '%" + number + "%'", null, sortOrder)) {
128+
c.moveToLast();
129129

130130
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
131131
Map<String, String> nameCache = new HashMap<>();
132132

133133
out.beginArray();
134134
for (int i = 0, count = c.getCount(); i < count; i++) {
135135
writeElement(c, out, nameCache, context);
136-
c.moveToNext();
136+
c.moveToPrevious();
137137
}
138138
out.endArray();
139139
}

0 commit comments

Comments
 (0)