Skip to content

Commit

Permalink
SmsInboxAPI: print messages in opposite order
Browse files Browse the repository at this point in the history
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"
  }
]
  • Loading branch information
Grimler91 committed Apr 26, 2021
1 parent 5029bc8 commit b3b0298
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/com/termux/api/SmsInboxAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> nameCache = new HashMap<>();

Expand All @@ -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();
}
Expand Down Expand Up @@ -123,17 +123,17 @@ private static void writeElement(Cursor c, JsonWriter out, Map<String, String> 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<String, String> nameCache = new HashMap<>();

out.beginArray();
for (int i = 0, count = c.getCount(); i < count; i++) {
writeElement(c, out, nameCache, context);
c.moveToNext();
c.moveToPrevious();
}
out.endArray();
}
Expand Down

0 comments on commit b3b0298

Please sign in to comment.