Merge remote-tracking branch 'origin/master' into fix/sending-glitch
This commit is contained in:
commit
550504a6c2
12 changed files with 411 additions and 73 deletions
|
|
@ -631,12 +631,14 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
var prevDateTime = 0
|
||||
var prevSIMId = -2
|
||||
var hadUnreadItems = false
|
||||
val cnt = messages.size
|
||||
for (i in 0 until cnt) {
|
||||
val message = messages.getOrNull(i) ?: continue
|
||||
// do not show the date/time above every message, only if the difference between the 2 messages is at least MIN_DATE_TIME_DIFF_SECS
|
||||
if (message.date - prevDateTime > MIN_DATE_TIME_DIFF_SECS) {
|
||||
// do not show the date/time above every message, only if the difference between the 2 messages is at least MIN_DATE_TIME_DIFF_SECS,
|
||||
// or if the message is sent from a different SIM
|
||||
if (message.date - prevDateTime > MIN_DATE_TIME_DIFF_SECS || prevSIMId != message.subscriptionId) {
|
||||
val simCardID = subscriptionIdToSimId[message.subscriptionId] ?: "?"
|
||||
items.add(ThreadDateTime(message.date, simCardID))
|
||||
prevDateTime = message.date
|
||||
|
|
@ -660,6 +662,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
if (i == cnt - 1 && (message.type == Telephony.Sms.MESSAGE_TYPE_SENT)) {
|
||||
items.add(ThreadSent(message.id, delivered = message.status == Telephony.Sms.STATUS_COMPLETE))
|
||||
}
|
||||
prevSIMId = message.subscriptionId
|
||||
}
|
||||
|
||||
if (hadUnreadItems) {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
package com.simplemobiletools.smsmessenger.receivers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.telephony.SubscriptionManager
|
||||
import androidx.core.app.RemoteInput
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import com.simplemobiletools.commons.extensions.notificationManager
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
||||
import com.simplemobiletools.smsmessenger.extensions.getSendMessageSettings
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesRead
|
||||
import com.simplemobiletools.smsmessenger.extensions.removeDiacriticsIfNeeded
|
||||
import com.simplemobiletools.smsmessenger.extensions.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.REPLY
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
|
||||
|
||||
class DirectReplyReceiver : BroadcastReceiver() {
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val address = intent.getStringExtra(THREAD_NUMBER)
|
||||
val threadId = intent.getLongExtra(THREAD_ID, 0L)
|
||||
|
|
@ -25,6 +25,17 @@ class DirectReplyReceiver : BroadcastReceiver() {
|
|||
msg = context.removeDiacriticsIfNeeded(msg)
|
||||
|
||||
val settings = context.getSendMessageSettings()
|
||||
if (address != null) {
|
||||
val availableSIMs = SubscriptionManager.from(context).activeSubscriptionInfoList
|
||||
if (availableSIMs?.size ?: 0 > 1) {
|
||||
val currentSIMCardIndex = context.config.getUseSIMIdAtNumber(address)
|
||||
val wantedId = availableSIMs.getOrNull(currentSIMCardIndex)
|
||||
if (wantedId != null) {
|
||||
settings.subscriptionId = wantedId.subscriptionId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val transaction = Transaction(context, settings)
|
||||
val message = com.klinker.android.send_message.Message(msg, address)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.provider.Telephony
|
|||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.getMyContactsCursor
|
||||
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
|
|
@ -34,6 +35,7 @@ class SmsReceiver : BroadcastReceiver() {
|
|||
val read = 0
|
||||
val subscriptionId = intent.getIntExtra("subscription", -1)
|
||||
|
||||
val privateCursor = context.getMyContactsCursor(false, true)
|
||||
ensureBackgroundThread {
|
||||
messages.forEach {
|
||||
address = it.originatingAddress ?: ""
|
||||
|
|
@ -44,39 +46,53 @@ class SmsReceiver : BroadcastReceiver() {
|
|||
threadId = context.getThreadId(address)
|
||||
}
|
||||
|
||||
val bitmap = getPhotoForNotification(address, context)
|
||||
if (context.baseConfig.blockUnknownNumbers) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(context)
|
||||
simpleContactsHelper.exists(address, privateCursor) { exists ->
|
||||
if (exists) {
|
||||
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
private fun handleMessage(
|
||||
context: Context, address: String, subject: String, body: String, date: Long, read: Int, threadId: Long, type: Int, subscriptionId: Int, status: Int
|
||||
) {
|
||||
val bitmap = getPhotoForNotification(address, context)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (!context.isNumberBlocked(address)) {
|
||||
val privateCursor = context.getMyContactsCursor(false, true)
|
||||
if (!context.isNumberBlocked(address)) {
|
||||
ensureBackgroundThread {
|
||||
val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
||||
ensureBackgroundThread {
|
||||
val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
|
||||
|
||||
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
|
||||
try {
|
||||
context.conversationsDB.insertOrUpdate(conversation)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
val senderName = context.getNameFromAddress(address, privateCursor)
|
||||
val phoneNumber = PhoneNumber(address, 0, "", address)
|
||||
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
|
||||
val participants = arrayListOf(participant)
|
||||
val messageDate = (date / 1000).toInt()
|
||||
|
||||
val message =
|
||||
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
|
||||
context.messagesDB.insertOrUpdate(message)
|
||||
refreshMessages()
|
||||
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
|
||||
try {
|
||||
context.conversationsDB.insertOrUpdate(conversation)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
context.showReceivedMessageNotification(address, body, threadId, bitmap)
|
||||
try {
|
||||
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
val senderName = context.getNameFromAddress(address, privateCursor)
|
||||
val phoneNumber = PhoneNumber(address, 0, "", address)
|
||||
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
|
||||
val participants = arrayListOf(participant)
|
||||
val messageDate = (date / 1000).toInt()
|
||||
|
||||
val message =
|
||||
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId)
|
||||
context.messagesDB.insertOrUpdate(message)
|
||||
refreshMessages()
|
||||
}
|
||||
|
||||
context.showReceivedMessageNotification(address, body, threadId, bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue