From 910aa365ac07ddb1fe7952106db9169db8f612bd Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 18 May 2020 23:16:06 +0200 Subject: [PATCH] fix #25, ensure that the top conversations are at the top --- .../com/simplemobiletools/smsmessenger/extensions/Context.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index dee4134e..a41bdf12 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -185,8 +185,9 @@ fun Context.getConversations(): ArrayList { val selection = "${Threads.MESSAGE_COUNT} > ?" val selectionArgs = arrayOf("0") + val sortOrder = "${Threads.DATE} DESC" val conversations = ArrayList() - queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor -> + queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor -> val id = cursor.getIntValue(Threads._ID) var snippet = cursor.getStringValue(Threads.SNIPPET) ?: "" if (snippet.isEmpty()) { @@ -211,9 +212,11 @@ fun Context.getConversations(): ArrayList { val photoUri = if (phoneNumbers.size == 1) SimpleContactsHelper(this).getPhotoUriFromPhoneNumber(phoneNumbers.first()) else "" val isGroupConversation = phoneNumbers.size > 1 val conversation = Conversation(id, snippet, date.toInt(), read, title, photoUri, isGroupConversation, phoneNumbers.first()) + conversations.add(conversation) } + conversations.sortByDescending { it.date } return conversations }