diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 71e5a511..91dfc6ec 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -212,6 +212,15 @@
+
+
+
+
+
+
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
index 0bfbcb2a..f0faebb5 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
@@ -683,13 +683,13 @@ fun Context.getThreadId(addresses: Set): Long {
}
}
-fun Context.showReceivedMessageNotification(address: String, body: String, threadId: Long, bitmap: Bitmap?) {
+fun Context.showReceivedMessageNotification(messageId: Long, address: String, body: String, threadId: Long, bitmap: Bitmap?) {
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
ensureBackgroundThread {
val senderName = getNameFromAddress(address, privateCursor)
Handler(Looper.getMainLooper()).post {
- notificationHelper.showMessageNotification(address, body, threadId, bitmap, senderName)
+ notificationHelper.showMessageNotification(messageId, address, body, threadId, bitmap, senderName)
}
}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
index b7da7d22..4db9a2ad 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
@@ -35,6 +35,8 @@ const val WAS_DB_CLEARED = "was_db_cleared_2"
const val EXTRA_VCARD_URI = "vcard"
const val SCHEDULED_MESSAGE_ID = "scheduled_message_id"
const val SOFT_KEYBOARD_HEIGHT = "soft_keyboard_height"
+const val IS_MMS = "is_mms"
+const val MESSAGE_ID = "message_id"
private const val PATH = "com.simplemobiletools.smsmessenger.action."
const val MARK_AS_READ = PATH + "mark_as_read"
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/NotificationHelper.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/NotificationHelper.kt
index 35117def..e1d4ff45 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/NotificationHelper.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/NotificationHelper.kt
@@ -23,6 +23,7 @@ import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.messaging.isShortCodeWithLetters
+import com.simplemobiletools.smsmessenger.receivers.DeleteSmsReceiver
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
@@ -35,7 +36,7 @@ class NotificationHelper(private val context: Context) {
.build()
@SuppressLint("NewApi")
- fun showMessageNotification(address: String, body: String, threadId: Long, bitmap: Bitmap?, sender: String?, alertOnlyOnce: Boolean = false) {
+ fun showMessageNotification(messageId: Long, address: String, body: String, threadId: Long, bitmap: Bitmap?, sender: String?, alertOnlyOnce: Boolean = false) {
maybeCreateChannel(name = context.getString(R.string.channel_received_sms))
val notificationId = threadId.hashCode()
@@ -52,8 +53,16 @@ class NotificationHelper(private val context: Context) {
val markAsReadPendingIntent =
PendingIntent.getBroadcast(context, notificationId, markAsReadIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
+ val deleteSmsIntent = Intent(context, DeleteSmsReceiver::class.java).apply {
+ putExtra(THREAD_ID, threadId)
+ putExtra(MESSAGE_ID, messageId)
+ }
+ val deleteSmsPendingIntent =
+ PendingIntent.getBroadcast(context, notificationId, deleteSmsIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
+
var replyAction: NotificationCompat.Action? = null
- if (isNougatPlus() && !isShortCodeWithLetters(address)) {
+ val isNoReplySms = isShortCodeWithLetters(address)
+ if (isNougatPlus() && !isNoReplySms) {
val replyLabel = context.getString(R.string.reply)
val remoteInput = RemoteInput.Builder(REPLY)
.setLabel(replyLabel)
@@ -112,7 +121,10 @@ class NotificationHelper(private val context: Context) {
builder.addAction(R.drawable.ic_check_vector, context.getString(R.string.mark_as_read), markAsReadPendingIntent)
.setChannelId(NOTIFICATION_CHANNEL)
-
+ if (isNoReplySms) {
+ builder.addAction(R.drawable.ic_delete_vector, context.getString(R.string.delete_messages), deleteSmsPendingIntent)
+ .setChannelId(NOTIFICATION_CHANNEL)
+ }
notificationManager.notify(notificationId, builder.build())
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DeleteSmsReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DeleteSmsReceiver.kt
new file mode 100644
index 00000000..fc11d50b
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DeleteSmsReceiver.kt
@@ -0,0 +1,31 @@
+package com.simplemobiletools.smsmessenger.receivers
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import com.simplemobiletools.commons.extensions.notificationManager
+import com.simplemobiletools.commons.helpers.ensureBackgroundThread
+import com.simplemobiletools.smsmessenger.extensions.conversationsDB
+import com.simplemobiletools.smsmessenger.extensions.deleteMessage
+import com.simplemobiletools.smsmessenger.extensions.updateLastConversationMessage
+import com.simplemobiletools.smsmessenger.extensions.updateUnreadCountBadge
+import com.simplemobiletools.smsmessenger.helpers.IS_MMS
+import com.simplemobiletools.smsmessenger.helpers.MESSAGE_ID
+import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
+import com.simplemobiletools.smsmessenger.helpers.refreshMessages
+
+class DeleteSmsReceiver: BroadcastReceiver() {
+
+ override fun onReceive(context: Context, intent: Intent) {
+ val threadId = intent.getLongExtra(THREAD_ID, 0L)
+ val messageId = intent.getLongExtra(MESSAGE_ID, 0L)
+ val isMms = intent.getBooleanExtra(IS_MMS, false)
+ context.notificationManager.cancel(threadId.hashCode())
+ ensureBackgroundThread {
+ context.deleteMessage(messageId, isMms)
+ context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
+ context.updateLastConversationMessage(threadId)
+ refreshMessages()
+ }
+ }
+}
diff --git a/app/src/main/res/values-az/strings.xml b/app/src/main/res/values-az/strings.xml
index 669639ec..3fd35085 100644
--- a/app/src/main/res/values-az/strings.xml
+++ b/app/src/main/res/values-az/strings.xml
@@ -59,6 +59,7 @@
- %d conversation
- %d conversations
+ Delete message
- %d message