fix #47, mark the whole conversation as read with Mark as Read at notification
This commit is contained in:
parent
26951cc979
commit
a85eb77d31
|
@ -23,7 +23,9 @@ import com.simplemobiletools.commons.models.SimpleContact
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||||
import com.simplemobiletools.smsmessenger.databases.MessagesDatabase
|
import com.simplemobiletools.smsmessenger.databases.MessagesDatabase
|
||||||
import com.simplemobiletools.smsmessenger.helpers.*
|
import com.simplemobiletools.smsmessenger.helpers.Config
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.MARK_AS_READ
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||||
import com.simplemobiletools.smsmessenger.interfaces.ConversationsDao
|
import com.simplemobiletools.smsmessenger.interfaces.ConversationsDao
|
||||||
import com.simplemobiletools.smsmessenger.models.*
|
import com.simplemobiletools.smsmessenger.models.*
|
||||||
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
|
||||||
|
@ -497,6 +499,18 @@ fun Context.markMessageRead(id: Int, isMMS: Boolean) {
|
||||||
contentResolver.update(uri, contentValues, selection, selectionArgs)
|
contentResolver.update(uri, contentValues, selection, selectionArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.markThreadMessagesRead(threadId: Int) {
|
||||||
|
arrayOf(Mms.CONTENT_URI, Sms.CONTENT_URI).forEach { uri ->
|
||||||
|
val contentValues = ContentValues().apply {
|
||||||
|
put(Sms.READ, 1)
|
||||||
|
put(Sms.SEEN, 1)
|
||||||
|
}
|
||||||
|
val selection = "${Sms.THREAD_ID} = ?"
|
||||||
|
val selectionArgs = arrayOf(threadId.toString())
|
||||||
|
contentResolver.update(uri, contentValues, selection, selectionArgs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
fun Context.getThreadId(address: String): Long {
|
fun Context.getThreadId(address: String): Long {
|
||||||
return if (isMarshmallowPlus()) {
|
return if (isMarshmallowPlus()) {
|
||||||
|
@ -524,7 +538,7 @@ fun Context.getThreadId(addresses: Set<String>): Long {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
fun Context.showReceivedMessageNotification(address: String, body: String, threadID: Int, bitmap: Bitmap?, messageId: Int, isMMS: Boolean) {
|
fun Context.showReceivedMessageNotification(address: String, body: String, threadID: Int, bitmap: Bitmap?) {
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||||
val channelId = "simple_sms_messenger"
|
val channelId = "simple_sms_messenger"
|
||||||
|
@ -556,8 +570,6 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
|
||||||
|
|
||||||
val markAsReadIntent = Intent(this, MarkAsReadReceiver::class.java).apply {
|
val markAsReadIntent = Intent(this, MarkAsReadReceiver::class.java).apply {
|
||||||
action = MARK_AS_READ
|
action = MARK_AS_READ
|
||||||
putExtra(MESSAGE_ID, messageId)
|
|
||||||
putExtra(MESSAGE_IS_MMS, isMMS)
|
|
||||||
putExtra(THREAD_ID, threadID)
|
putExtra(THREAD_ID, threadID)
|
||||||
}
|
}
|
||||||
val markAsReadPendingIntent = PendingIntent.getBroadcast(this, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
val markAsReadPendingIntent = PendingIntent.getBroadcast(this, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||||
|
|
|
@ -13,8 +13,6 @@ const val USE_SIM_ID_PREFIX = "use_sim_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"
|
||||||
const val MESSAGE_ID = "message_id"
|
|
||||||
const val MESSAGE_IS_MMS = "message_is_mms"
|
|
||||||
|
|
||||||
// view types for the thread list view
|
// view types for the thread list view
|
||||||
const val THREAD_DATE_TIME = 1
|
const val THREAD_DATE_TIME = 1
|
||||||
|
|
|
@ -6,23 +6,18 @@ import android.content.Intent
|
||||||
import com.simplemobiletools.commons.extensions.notificationManager
|
import com.simplemobiletools.commons.extensions.notificationManager
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
||||||
import com.simplemobiletools.smsmessenger.extensions.markMessageRead
|
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesRead
|
||||||
import com.simplemobiletools.smsmessenger.helpers.MARK_AS_READ
|
import com.simplemobiletools.smsmessenger.helpers.MARK_AS_READ
|
||||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_ID
|
|
||||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_IS_MMS
|
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||||
|
|
||||||
class MarkAsReadReceiver : BroadcastReceiver() {
|
class MarkAsReadReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
MARK_AS_READ -> {
|
MARK_AS_READ -> {
|
||||||
val messageId = intent.getIntExtra(MESSAGE_ID, 0)
|
val threadId = intent.getIntExtra(THREAD_ID, 0)
|
||||||
context.notificationManager.cancel(messageId)
|
context.notificationManager.cancel(threadId)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val isMMS = intent.getBooleanExtra(MESSAGE_IS_MMS, false)
|
context.markThreadMessagesRead(threadId)
|
||||||
context.markMessageRead(messageId, isMMS)
|
|
||||||
|
|
||||||
val threadId = intent.getIntExtra(THREAD_ID, 0)
|
|
||||||
context.conversationsDB.markRead(threadId.toLong())
|
context.conversationsDB.markRead(threadId.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
context.showReceivedMessageNotification(address, mms.body, mms.thread, glideBitmap, mms.id, true)
|
context.showReceivedMessageNotification(address, mms.body, mms.thread, glideBitmap)
|
||||||
val conversation = context.getConversations(mms.thread.toLong()).firstOrNull() ?: return@ensureBackgroundThread
|
val conversation = context.getConversations(mms.thread.toLong()).firstOrNull() ?: return@ensureBackgroundThread
|
||||||
context.conversationsDB.insertOrUpdate(conversation)
|
context.conversationsDB.insertOrUpdate(conversation)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ class SmsReceiver : BroadcastReceiver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.isNumberBlocked(address)) {
|
if (!context.isNumberBlocked(address)) {
|
||||||
val messageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
||||||
context.showReceivedMessageNotification(address, body, threadId.toInt(), null, messageId, false)
|
context.showReceivedMessageNotification(address, body, threadId.toInt(), null)
|
||||||
refreshMessages()
|
refreshMessages()
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
|
|
Loading…
Reference in New Issue