Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change sms inbox sort order #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/src/main/java/com/termux/api/apis/SmsInboxAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static void onReceive(TermuxApiReceiver apiReceiver, final Context contex

final int offset = intent.getIntExtra("offset", 0);
final int limit = intent.getIntExtra("limit", 10);
final boolean date_asc = intent.getBooleanExtra("date-asc", false);
final String sortPrefix = date_asc ? "date" : "date DESC";
final String number = intent.hasExtra("from") ? intent.getStringExtra("from"):"";
final boolean conversation_list = intent.getBooleanExtra("conversation-list", false);
final Uri contentURI = conversation_list ? typeToContentURI(0) :
Expand All @@ -50,16 +52,16 @@ public static void onReceive(TermuxApiReceiver apiReceiver, final Context contex
ResultReturner.returnData(apiReceiver, intent, new ResultJsonWriter() {
@Override
public void writeJson(JsonWriter out) throws Exception {
if (conversation_list) getConversations(context, out, offset, limit);
else getAllSms(context, out, offset, limit, number, contentURI);
if (conversation_list) getConversations(context, out, offset, limit, sortPrefix);
else getAllSms(context, out, offset, limit, number, contentURI, sortPrefix);
}
});
}

@SuppressLint("SimpleDateFormat")
public static void getConversations(Context context, JsonWriter out, int offset, int limit) throws IOException {
public static void getConversations(Context context, JsonWriter out, int offset, int limit, String sortPrefix) throws IOException {
ContentResolver cr = context.getContentResolver();
String sortOrder = "date DESC";
String sortOrder = sortPrefix;
try (Cursor c = cr.query(Conversations.CONTENT_URI, null, null, null , sortOrder)) {
c.moveToLast();

Expand All @@ -71,7 +73,7 @@ public static void getConversations(Context context, JsonWriter out, int offset,

Cursor cc = cr.query(Sms.CONTENT_URI, null,
THREAD_ID + " == '" + id +"'",
null, "date DESC");
null, sortPrefix);
if (cc.getCount() == 0) {
c.moveToNext();
continue;
Expand Down Expand Up @@ -129,9 +131,9 @@ private static void writeElement(Cursor c, JsonWriter out, Map<String, String> n


@SuppressLint("SimpleDateFormat")
public static void getAllSms(Context context, JsonWriter out, int offset, int limit, String number, Uri contentURI) throws IOException {
public static void getAllSms(Context context, JsonWriter out, int offset, int limit, String number, Uri contentURI, String sortPrefix) throws IOException {
ContentResolver cr = context.getContentResolver();
String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset;
String sortOrder = sortPrefix + " LIMIT + " + limit + " OFFSET " + offset;
try (Cursor c = cr.query(contentURI, null,
ADDRESS + " LIKE '%" + number + "%'", null, sortOrder)) {
c.moveToLast();
Expand Down