From 960b16c99bf2d7970c0c731a5774acdcb0ea4542 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 3 Apr 2020 16:33:57 +0200 Subject: [PATCH] fetch the message Thread field too and group by it --- .../smsmessenger/activities/MainActivity.kt | 9 ++++++--- .../com/simplemobiletools/smsmessenger/models/Message.kt | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index 2df8879d..d65f9e85 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -77,12 +77,14 @@ class MainActivity : SimpleActivity() { Telephony.Sms.ADDRESS, Telephony.Sms.PERSON, Telephony.Sms.DATE, - Telephony.Sms.READ + Telephony.Sms.READ, + Telephony.Sms.THREAD_ID ) + val selection = "1 == 1) GROUP BY (${Telephony.Sms.THREAD_ID}" var cursor: Cursor? = null try { - cursor = contentResolver.query(uri, projection, null, null, null) + cursor = contentResolver.query(uri, projection, selection, null, null) if (cursor?.moveToFirst() == true) { do { val id = cursor.getIntValue(Telephony.Sms._ID) @@ -93,11 +95,12 @@ class MainActivity : SimpleActivity() { val date = (cursor.getLongValue(Telephony.Sms.DATE) / 1000).toInt() val read = cursor.getIntValue(Telephony.Sms.READ) == 1 val person = cursor.getIntValue(Telephony.Sms.PERSON) + val thread = cursor.getIntValue(Telephony.Sms.THREAD_ID) if (address != null && person != 0 && hasContactsPermission) { address = getPersonsName(person) ?: address } - val message = Message(id, subject, body, type, address, date, read) + val message = Message(id, subject, body, type, address, date, read, thread) messages.add(message) } while (cursor.moveToNext()) } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Message.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Message.kt index 5c604737..819ecfa3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Message.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Message.kt @@ -1,3 +1,6 @@ package com.simplemobiletools.smsmessenger.models -data class Message(val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean) +data class Message( + val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean, + val thread: Int +)