mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-07 04:43:24 +01:00
Merge pull request #668 from AAlier/master
Add Delete Action No Reply Notification message
This commit is contained in:
commit
6dc79837d3
@ -212,6 +212,15 @@
|
||||
</intent-filter>
|
||||
</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
|
||||
android:name=".receivers.ScheduledMessageReceiver"
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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), deleteSmsPendingIntent)
|
||||
.setChannelId(NOTIFICATION_CHANNEL)
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
@ -37,11 +37,13 @@ class DirectReplyReceiver : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
ensureBackgroundThread {
|
||||
var messageId: Long = 0L
|
||||
try {
|
||||
context.sendMessageCompat(body, listOf(address), subscriptionId, emptyList())
|
||||
val message = context.getMessages(threadId, getImageResolutions = false, includeScheduledMessages = false, limit = 1).lastOrNull()
|
||||
if (message != null) {
|
||||
context.messagesDB.insertOrUpdate(message)
|
||||
messageId = message.id
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
@ -50,7 +52,7 @@ class DirectReplyReceiver : BroadcastReceiver() {
|
||||
val photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(address)
|
||||
val bitmap = context.getNotificationBitmap(photoUri)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
context.notificationHelper.showMessageNotification(address, body, threadId, bitmap, sender = null, alertOnlyOnce = true)
|
||||
context.notificationHelper.showMessageNotification(messageId, address, body, threadId, bitmap, sender = null, alertOnlyOnce = true)
|
||||
}
|
||||
|
||||
context.markThreadMessagesRead(threadId)
|
||||
|
@ -38,7 +38,7 @@ class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
context.showReceivedMessageNotification(address, mms.body, mms.threadId, glideBitmap)
|
||||
context.showReceivedMessageNotification(mms.id, address, mms.body, mms.threadId, glideBitmap)
|
||||
val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post
|
||||
ensureBackgroundThread {
|
||||
context.insertOrUpdateConversation(conversation)
|
||||
|
@ -86,9 +86,8 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, senderName, photoUri, subscriptionId)
|
||||
context.messagesDB.insertOrUpdate(message)
|
||||
refreshMessages()
|
||||
context.showReceivedMessageNotification(newMessageId, address, body, threadId, bitmap)
|
||||
}
|
||||
|
||||
context.showReceivedMessageNotification(address, body, threadId, bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user