Add Delete Action Button to Sms message
This commit is contained in:
parent
220dec1cd5
commit
b076da3840
|
@ -212,6 +212,15 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".receivers.DeleteSmsReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.simplemobiletools.smsmessenger.action.delete" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".receivers.ScheduledMessageReceiver"
|
android:name=".receivers.ScheduledMessageReceiver"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
|
@ -683,13 +683,13 @@ fun Context.getThreadId(addresses: Set<String>): 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)
|
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val senderName = getNameFromAddress(address, privateCursor)
|
val senderName = getNameFromAddress(address, privateCursor)
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
notificationHelper.showMessageNotification(address, body, threadId, bitmap, senderName)
|
notificationHelper.showMessageNotification(messageId, address, body, threadId, bitmap, senderName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ const val WAS_DB_CLEARED = "was_db_cleared_2"
|
||||||
const val EXTRA_VCARD_URI = "vcard"
|
const val EXTRA_VCARD_URI = "vcard"
|
||||||
const val SCHEDULED_MESSAGE_ID = "scheduled_message_id"
|
const val SCHEDULED_MESSAGE_ID = "scheduled_message_id"
|
||||||
const val SOFT_KEYBOARD_HEIGHT = "soft_keyboard_height"
|
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."
|
private const val PATH = "com.simplemobiletools.smsmessenger.action."
|
||||||
const val MARK_AS_READ = PATH + "mark_as_read"
|
const val MARK_AS_READ = PATH + "mark_as_read"
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||||
import com.simplemobiletools.smsmessenger.extensions.config
|
import com.simplemobiletools.smsmessenger.extensions.config
|
||||||
import com.simplemobiletools.smsmessenger.messaging.isShortCodeWithLetters
|
import com.simplemobiletools.smsmessenger.messaging.isShortCodeWithLetters
|
||||||
|
import com.simplemobiletools.smsmessenger.receivers.DeleteSmsReceiver
|
||||||
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
|
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
|
||||||
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class NotificationHelper(private val context: Context) {
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@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))
|
maybeCreateChannel(name = context.getString(R.string.channel_received_sms))
|
||||||
|
|
||||||
val notificationId = threadId.hashCode()
|
val notificationId = threadId.hashCode()
|
||||||
|
@ -52,8 +53,16 @@ class NotificationHelper(private val context: Context) {
|
||||||
val markAsReadPendingIntent =
|
val markAsReadPendingIntent =
|
||||||
PendingIntent.getBroadcast(context, notificationId, markAsReadIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
|
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
|
var replyAction: NotificationCompat.Action? = null
|
||||||
if (isNougatPlus() && !isShortCodeWithLetters(address)) {
|
val isNoReplySms = isShortCodeWithLetters(address)
|
||||||
|
if (isNougatPlus() && !isNoReplySms) {
|
||||||
val replyLabel = context.getString(R.string.reply)
|
val replyLabel = context.getString(R.string.reply)
|
||||||
val remoteInput = RemoteInput.Builder(REPLY)
|
val remoteInput = RemoteInput.Builder(REPLY)
|
||||||
.setLabel(replyLabel)
|
.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)
|
builder.addAction(R.drawable.ic_check_vector, context.getString(R.string.mark_as_read), markAsReadPendingIntent)
|
||||||
.setChannelId(NOTIFICATION_CHANNEL)
|
.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())
|
notificationManager.notify(notificationId, builder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,6 +59,7 @@
|
||||||
<item quantity="one">%d conversation</item>
|
<item quantity="one">%d conversation</item>
|
||||||
<item quantity="other">%d conversations</item>
|
<item quantity="other">%d conversations</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<string name="delete_messages">Delete message</string>
|
||||||
<!-- Are you sure you want to delete 5 messages? -->
|
<!-- Are you sure you want to delete 5 messages? -->
|
||||||
<plurals name="delete_messages">
|
<plurals name="delete_messages">
|
||||||
<item quantity="one">%d message</item>
|
<item quantity="one">%d message</item>
|
||||||
|
|
Loading…
Reference in New Issue