mark unread SMS as Read on open
This commit is contained in:
parent
654359eaea
commit
3ec40cb979
|
@ -10,6 +10,7 @@ import com.simplemobiletools.smsmessenger.R
|
|||
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.config
|
||||
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_NAME
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
|
||||
|
@ -73,6 +74,10 @@ class ThreadActivity : SimpleActivity() {
|
|||
if (it.type == Telephony.Sms.MESSAGE_TYPE_FAILED) {
|
||||
items.add(ThreadError(it.id))
|
||||
}
|
||||
|
||||
if (!it.read) {
|
||||
markSMSRead(it.id)
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
|
|
|
@ -167,7 +167,19 @@ fun Context.insertNewSMS(address: String, subject: String, body: String, date: L
|
|||
put(Telephony.Sms.SUBJECT, subject)
|
||||
put(Telephony.Sms.BODY, body)
|
||||
put(Telephony.Sms.DATE, date)
|
||||
put(Telephony.Sms.READ, 0)
|
||||
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue