mark unread SMS as Read on open

This commit is contained in:
tibbi 2020-04-04 20:22:17 +02:00
parent 654359eaea
commit 3ec40cb979
2 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
import com.simplemobiletools.smsmessenger.extensions.config import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.extensions.markSMSRead
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
@ -73,6 +74,10 @@ class ThreadActivity : SimpleActivity() {
if (it.type == Telephony.Sms.MESSAGE_TYPE_FAILED) { if (it.type == Telephony.Sms.MESSAGE_TYPE_FAILED) {
items.add(ThreadError(it.id)) items.add(ThreadError(it.id))
} }
if (!it.read) {
markSMSRead(it.id)
}
} }
return items return items

View File

@ -167,7 +167,19 @@ fun Context.insertNewSMS(address: String, subject: String, body: String, date: L
put(Telephony.Sms.SUBJECT, subject) put(Telephony.Sms.SUBJECT, subject)
put(Telephony.Sms.BODY, body) put(Telephony.Sms.BODY, body)
put(Telephony.Sms.DATE, date) put(Telephony.Sms.DATE, date)
put(Telephony.Sms.READ, 0)
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX)
} }
contentResolver.insert(uri, contentValues) contentResolver.insert(uri, contentValues)
} }
fun Context.markSMSRead(id: Int) {
val uri = Telephony.Sms.CONTENT_URI
val contentValues = ContentValues().apply {
put(Telephony.Sms.READ, 1)
}
val selection = "${Telephony.Sms._ID} = ? AND ${Telephony.Sms.READ} = ?"
val selectionArgs = arrayOf(id.toString(), "0")
contentResolver.update(uri, contentValues, selection, selectionArgs)
}