Only show failure notification when in background

This commit is contained in:
Naveen 2022-12-08 01:40:34 +05:30
parent 2fc70b2dc5
commit 0523d93243
2 changed files with 7 additions and 3 deletions

View File

@ -70,6 +70,7 @@ dependencies {
implementation "me.leolin:ShortcutBadger:1.1.22"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
implementation 'androidx.lifecycle:lifecycle-process:2.5.1'
kapt "androidx.room:room-compiler:2.4.3"
implementation "androidx.room:room-runtime:2.4.3"

View File

@ -7,6 +7,8 @@ import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.provider.Telephony
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ProcessLifecycleOwner
import com.klinker.android.send_message.SentReceiver
import com.simplemobiletools.commons.extensions.getMyContactsCursor
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -20,12 +22,10 @@ class SmsStatusSentReceiver : SentReceiver() {
val uri = Uri.parse(intent.getStringExtra("message_uri"))
val messageId = uri?.lastPathSegment?.toLong() ?: 0L
ensureBackgroundThread {
if (intent.extras!!.containsKey("errorCode")) {
showSendingFailedNotification(context, messageId)
}
val type = if (receiverResultCode == Activity.RESULT_OK) {
Telephony.Sms.MESSAGE_TYPE_SENT
} else {
showSendingFailedNotification(context, messageId)
Telephony.Sms.MESSAGE_TYPE_FAILED
}
@ -46,6 +46,9 @@ class SmsStatusSentReceiver : SentReceiver() {
private fun showSendingFailedNotification(context: Context, messageId: Long) {
Handler(Looper.getMainLooper()).post {
if (ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
return@post
}
val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
ensureBackgroundThread {
val address = context.getMessageRecipientAddress(messageId)