fetch the message Thread field too and group by it

This commit is contained in:
tibbi 2020-04-03 16:33:57 +02:00
parent c1363e4d22
commit 960b16c99b
2 changed files with 10 additions and 4 deletions

View File

@ -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())
}

View File

@ -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
)