Show 2 checks when sms is delivered

- differentiate between sent sms and delivered sms by updating the SmsStatusSentReceiver which updates the type to Telephony.Sms.MESSAGE_TYPE_SENT or Telephony.Sms.MESSAGE_TYPE_FAILED depending on the outcome.
- rename ThreadSuccess to ThreadSent and add a boolean field for the delivery status
- SmsStatusSentReceiver updates the status of the message to Telephony.Sms.STATUS_COMPLETE.
- accommodate for the need to keep track of the status by adding Int field status to the Message class,
- add appropriate database migrations (3 to 4) for the new status field.
- add status to the query for sms in extension function Context.getMessages and Context.getMMS
- add extension function Context.updateMessageStatus to update the status of a message in the database
This commit is contained in:
Paul Akhamiogu 2021-08-25 16:57:07 +01:00
parent 84c1705078
commit 46f71c994f
13 changed files with 58 additions and 27 deletions

View file

@ -21,6 +21,7 @@ class SmsReceiver : BroadcastReceiver() {
var subject = ""
var date = 0L
var threadId = 0L
var status = Telephony.Sms.STATUS_NONE
val type = Telephony.Sms.MESSAGE_TYPE_INBOX
val read = 0
val subscriptionId = intent.getIntExtra("subscription", -1)
@ -29,6 +30,7 @@ class SmsReceiver : BroadcastReceiver() {
messages.forEach {
address = it.originatingAddress ?: ""
subject = it.pseudoSubject
status = it.status
body += it.messageBody
date = Math.min(it.timestampMillis, System.currentTimeMillis())
threadId = context.getThreadId(address)
@ -49,7 +51,7 @@ class SmsReceiver : BroadcastReceiver() {
val participant = SimpleContact(0, 0, address, "", arrayListOf(address), ArrayList(), ArrayList())
val participants = arrayListOf(participant)
val messageDate = (date / 1000).toInt()
val message = Message(newMessageId, body, type, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
val message = Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
context.messagesDB.insertOrUpdate(message)
refreshMessages()
}

View file

@ -9,7 +9,7 @@ import android.provider.Telephony
import com.klinker.android.send_message.DeliveredReceiver
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.smsmessenger.extensions.messagesDB
import com.simplemobiletools.smsmessenger.extensions.updateMessageType
import com.simplemobiletools.smsmessenger.extensions.updateMessageStatus
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
class SmsStatusDeliveredReceiver : DeliveredReceiver() {
@ -19,13 +19,13 @@ class SmsStatusDeliveredReceiver : DeliveredReceiver() {
val uri = Uri.parse(intent.getStringExtra("message_uri"))
val messageId = uri?.lastPathSegment?.toLong() ?: 0L
ensureBackgroundThread {
val type = Telephony.Sms.MESSAGE_TYPE_SENT
context.updateMessageType(messageId, type)
val updated = context.messagesDB.updateType(messageId, type)
val status = Telephony.Sms.STATUS_COMPLETE
context.updateMessageStatus(messageId, status)
val updated = context.messagesDB.updateStatus(messageId, status)
if (updated == 0) {
Handler(Looper.getMainLooper()).postDelayed({
ensureBackgroundThread {
context.messagesDB.updateType(messageId, type)
context.messagesDB.updateStatus(messageId, status)
}
}, 2000)
}

View file

@ -39,7 +39,7 @@ class SmsStatusSentReceiver : SentReceiver() {
showSendingFailedNotification(context, messageId)
Telephony.Sms.MESSAGE_TYPE_FAILED
} else {
Telephony.Sms.MESSAGE_TYPE_OUTBOX
Telephony.Sms.MESSAGE_TYPE_SENT
}
context.updateMessageType(messageId, type)