diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index cc136d47..1f867c88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -108,6 +108,7 @@ class ThreadActivity : SimpleActivity() { private var isRecycleBin = false private var isScheduledMessage: Boolean = false + private var messageToResend: Long? = null private var scheduledMessage: Message? = null private lateinit var scheduledDateTime: DateTime @@ -296,6 +297,7 @@ class ThreadActivity : SimpleActivity() { super.onActivityResult(requestCode, resultCode, resultData) if (resultCode != Activity.RESULT_OK) return val data = resultData?.data + messageToResend = null if (requestCode == CAPTURE_PHOTO_INTENT && capturedImageUri != null) { addAttachment(capturedImageUri!!) @@ -514,7 +516,10 @@ class ThreadActivity : SimpleActivity() { private fun handleItemClick(any: Any) { when { any is Message && any.isScheduled -> showScheduledMessageInfo(any) - any is ThreadError -> thread_type_message.setText(any.messageText) + any is ThreadError -> { + thread_type_message.setText(any.messageText) + messageToResend = any.messageId + } } } @@ -663,6 +668,7 @@ class ThreadActivity : SimpleActivity() { thread_send_message.isClickable = false thread_type_message.onTextChangeListener { + messageToResend = null checkSendMessageAvailability() val messageString = if (config.useSimpleCharacters) { it.normalizeString() @@ -1378,7 +1384,7 @@ class ThreadActivity : SimpleActivity() { try { refreshedSinceSent = false - sendMessageCompat(text, addresses, subscriptionId, attachments) + sendMessageCompat(text, addresses, subscriptionId, attachments, messageToResend) ensureBackgroundThread { val messageIds = messages.map { it.id } val messages = getMessages(threadId, getImageResolutions = true, limit = maxOf(1, attachments.size)) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/Messaging.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/Messaging.kt index e02a1a6c..9a391395 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/Messaging.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/Messaging.kt @@ -32,7 +32,7 @@ fun Context.isLongMmsMessage(text: String, settings: Settings = getSendMessageSe } /** Sends the message using the in-app SmsManager API wrappers if it's an SMS or using android-smsmms for MMS. */ -fun Context.sendMessageCompat(text: String, addresses: List, subId: Int?, attachments: List) { +fun Context.sendMessageCompat(text: String, addresses: List, subId: Int?, attachments: List, messageId: Long? = null) { val settings = getSendMessageSettings() if (subId != null) { settings.subscriptionId = subId @@ -47,18 +47,18 @@ fun Context.sendMessageCompat(text: String, addresses: List, subId: Int? if (attachments.size > 1) { for (i in 0 until lastIndex) { val attachment = attachments[i] - messagingUtils.sendMmsMessage("", addresses, attachment, settings) + messagingUtils.sendMmsMessage("", addresses, attachment, settings, messageId) } } val lastAttachment = attachments[lastIndex] - messagingUtils.sendMmsMessage(text, addresses, lastAttachment, settings) + messagingUtils.sendMmsMessage(text, addresses, lastAttachment, settings, messageId) } else { - messagingUtils.sendMmsMessage(text, addresses, null, settings) + messagingUtils.sendMmsMessage(text, addresses, null, settings, messageId) } } else { try { - messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports) + messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports, messageId) } catch (e: SmsException) { when (e.errorCode) { EMPTY_DESTINATION_ADDRESS -> toast(id = R.string.empty_destination_address, length = LENGTH_LONG) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/MessagingUtils.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/MessagingUtils.kt index 8d79ea7d..211efadf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/MessagingUtils.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/messaging/MessagingUtils.kt @@ -31,7 +31,7 @@ class MessagingUtils(val context: Context) { */ private fun insertSmsMessage( subId: Int, dest: String, text: String, timestamp: Long, threadId: Long, - status: Int = Sms.STATUS_NONE, type: Int = Sms.MESSAGE_TYPE_OUTBOX + status: Int = Sms.STATUS_NONE, type: Int = Sms.MESSAGE_TYPE_OUTBOX, messageId: Long? = null ): Uri { val response: Uri? val values = ContentValues().apply { @@ -58,7 +58,18 @@ class MessagingUtils(val context: Context) { } try { - response = context.contentResolver.insert(Sms.CONTENT_URI, values) + if (messageId != null) { + val selection = "${Sms._ID} = ?" + val selectionArgs = arrayOf(messageId.toString()) + val count = context.contentResolver.update(Sms.CONTENT_URI, values, selection, selectionArgs) + if (count > 0) { + response = Uri.parse("${Sms.CONTENT_URI}/${messageId}") + } else { + response = null + } + } else { + response = context.contentResolver.insert(Sms.CONTENT_URI, values) + } } catch (e: Exception) { throw SmsException(ERROR_PERSISTING_MESSAGE, e) } @@ -67,7 +78,7 @@ class MessagingUtils(val context: Context) { /** Send an SMS message given [text] and [addresses]. A [SmsException] is thrown in case any errors occur. */ fun sendSmsMessage( - text: String, addresses: Set, subId: Int, requireDeliveryReport: Boolean + text: String, addresses: Set, subId: Int, requireDeliveryReport: Boolean, messageId: Long? = null ) { if (addresses.size > 1) { // insert a dummy message for this thread if it is a group message @@ -76,7 +87,8 @@ class MessagingUtils(val context: Context) { insertSmsMessage( subId = subId, dest = mergedAddresses, text = text, timestamp = System.currentTimeMillis(), threadId = broadCastThreadId, - status = Sms.Sent.STATUS_COMPLETE, type = Sms.Sent.MESSAGE_TYPE_SENT + status = Sms.Sent.STATUS_COMPLETE, type = Sms.Sent.MESSAGE_TYPE_SENT, + messageId = messageId ) } @@ -84,7 +96,8 @@ class MessagingUtils(val context: Context) { val threadId = context.getThreadId(address) val messageUri = insertSmsMessage( subId = subId, dest = address, text = text, - timestamp = System.currentTimeMillis(), threadId = threadId + timestamp = System.currentTimeMillis(), threadId = threadId, + messageId = messageId ) try { context.smsSender.sendMessage( @@ -133,7 +146,7 @@ class MessagingUtils(val context: Context) { } @Deprecated("TODO: Move/rewrite MMS code into the app.") - fun sendMmsMessage(text: String, addresses: List, attachment: Attachment?, settings: Settings) { + fun sendMmsMessage(text: String, addresses: List, attachment: Attachment?, settings: Settings, messageId: Long? = null) { val transaction = Transaction(context, settings) val message = Message(text, addresses.toTypedArray()) @@ -158,6 +171,7 @@ class MessagingUtils(val context: Context) { } val mmsSentIntent = Intent(context, MmsSentReceiver::class.java) + mmsSentIntent.putExtra(MmsSentReceiver.EXTRA_ORIGINAL_RESENT_MESSAGE_ID, messageId) transaction.setExplicitBroadcastForSentMms(mmsSentIntent) try { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsSentReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsSentReceiver.kt index e3c92eef..b2650622 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsSentReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/MmsSentReceiver.kt @@ -11,6 +11,7 @@ import android.widget.Toast import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.smsmessenger.R +import com.simplemobiletools.smsmessenger.extensions.deleteMessage import com.simplemobiletools.smsmessenger.helpers.refreshMessages import java.io.File @@ -19,6 +20,7 @@ class MmsSentReceiver : SendStatusReceiver() { override fun updateAndroidDatabase(context: Context, intent: Intent, receiverResultCode: Int) { val uri = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI)) + val originalResentMessageId = intent.getLongExtra(EXTRA_ORIGINAL_RESENT_MESSAGE_ID, -1L) val messageBox = if (receiverResultCode == Activity.RESULT_OK) { Telephony.Mms.MESSAGE_BOX_SENT } else { @@ -37,6 +39,11 @@ class MmsSentReceiver : SendStatusReceiver() { context.showErrorToast(e) } + // In case of resent message, delete original to prevent duplication + if (originalResentMessageId != -1L) { + context.deleteMessage(originalResentMessageId, true) + } + val filePath = intent.getStringExtra(EXTRA_FILE_PATH) if (filePath != null) { File(filePath).delete() @@ -50,5 +57,6 @@ class MmsSentReceiver : SendStatusReceiver() { companion object { private const val EXTRA_CONTENT_URI = "content_uri" private const val EXTRA_FILE_PATH = "file_path" + const val EXTRA_ORIGINAL_RESENT_MESSAGE_ID = "original_message_id" } } diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index bbb40a7a..cad1defa 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -59,14 +59,14 @@ Marcar com no llegit Me - Unarchive - Delete all archived conversations - Archive - Show archived conversations - Archive - No archived conversations have been found - The archive has been emptied successfully - Are you sure you want to empty the archive? All archived conversations will be permanently lost. + Desarxivar + Suprimeix totes les converses arxivades + Arxiva + Mostra les converses arxivades + Arxiu + No s\'ha trobat cap conversa arxivada + L\'arxiu s\'ha buidat correctament + Segur que voleu buidar l\'arxiu\? Totes les converses arxivades es perdran permanentment. Restore Restore all messages @@ -74,7 +74,7 @@ Skip the Recycle Bin, delete messages directly Confirmeu que voleu suprimir tots els missatges d\'aquesta conversa\? - Are you sure you want to archive %s? + Segur que voleu arxivar %s\? Are you sure you want to restore all messages of this conversation? Are you sure you want to restore %s? diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 4c828243..87c0cf0c 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -49,10 +49,10 @@ Enviar agora Message details - Sender - Receiver - Sent at - Received at + Remetente + Destinatário + Enviada a + Recebida a SMS recebida Nova mensagem @@ -60,14 +60,14 @@ Marcar como não lida Eu - Unarchive - Delete all archived conversations - Archive - Show archived conversations - Archive - No archived conversations have been found - The archive has been emptied successfully - Are you sure you want to empty the archive? All archived conversations will be permanently lost. + Desarquivar + Eliminar todas as conversas arquivadas + Arquivo + Mostrar conversas arquivadas + Arquivo + Não existem conversas arquivadas + O arquivo foi limpo com sucesso + Tem a certeza de que pretende limpar o arquivo\? Todas as conversas arquivadas serão eliminadas. Restore Restore all messages @@ -75,7 +75,7 @@ Skip the Recycle Bin, delete messages directly Tem a certeza de que pretende apagar todas as mensagens desta conversa\? - Are you sure you want to archive %s? + Tem a certeza de que pretende arquivar %s\? Are you sure you want to restore all messages of this conversation? Are you sure you want to restore %s? @@ -91,11 +91,11 @@ %d mensagens - Keyword - Blocked keywords - Manage blocked keywords - You are not blocking any keywords. You may add keywords here to block all messages containing them. - Add a blocked keyword + Palavra-chave + Palavras-chave bloqueadas + Gerir palavras-chave bloqueadas + Não existem quaisquer palavras-chave bloqueadas. Pode adicionar as palavras-chave aqui para poder bloquear todas as mensagens que as contenham. + Adicionar palavra-chave de bloqueio Notificação no ecrã de bloqueio Remetente e mensagem Apenas remetente diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e8e45e96..aef48f67 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -62,13 +62,13 @@ Я Разархивировать - Delete all archived conversations - Archive - Show archived conversations + Удалить все архивные переписки + Архивная + Показывать архивные переписки Архивировать - No archived conversations have been found - The archive has been emptied successfully - Are you sure you want to empty the archive? All archived conversations will be permanently lost. + Нет архивных переписок + Архив успешно очищен + Очистить архив\? Все архивные переписки будут безвозвратно потеряны. Restore Restore all messages @@ -76,7 +76,7 @@ Skip the Recycle Bin, delete messages directly Удалить все сообщения в этой переписке\? - Are you sure you want to archive %s? + Архивировать %s\? Are you sure you want to restore all messages of this conversation? Are you sure you want to restore %s? @@ -141,4 +141,4 @@ Haven't found some strings? There's more at https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res --> - \ No newline at end of file + diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 23c09c50..50faf3d8 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -59,14 +59,14 @@ Markera som oläst Jag - Unarchive - Delete all archived conversations - Archive - Show archived conversations - Archive - No archived conversations have been found - The archive has been emptied successfully - Are you sure you want to empty the archive? All archived conversations will be permanently lost. + Ångra arkivering + Ta bort alla arkiverade konversationer + Arkiv + Visa arkiverade konversationer + Arkivera + Inga arkiverade konversationer hittades + Arkivet har tömts + Är du säker på att du vill tömma arkivet\? Alla arkiverade konversationer tas bort permanent. Restore Restore all messages @@ -74,7 +74,7 @@ Skip the Recycle Bin, delete messages directly Är du säker på att du vill ta bort alla meddelanden i konversationen\? - Are you sure you want to archive %s? + Är du säker på att du vill arkivera %s\? Are you sure you want to restore all messages of this conversation? Are you sure you want to restore %s? @@ -88,11 +88,11 @@ %d meddelanden - Keyword - Blocked keywords - Manage blocked keywords - You are not blocking any keywords. You may add keywords here to block all messages containing them. - Add a blocked keyword + Nyckelord + Blockerade nyckelord + Hantera blockerade nyckelord + Du blockerar inte några nyckelord. Du kan lägga till nyckelord här för att blockera alla meddelanden som innehåller dem. + Lägg till ett blockerat nyckelord Synlighet för aviseringar på låsskärmen Avsändare och meddelande Endast avsändare @@ -116,10 +116,10 @@ Kan inte skicka meddelande utan nummer Det går inte att spara meddelandet på telefonen - Kunde inte skicka meddelande, ingen nätverkstjänst - Misslyckades att skicka meddelande, radion avstängd - Misslyckades att skicka meddelande, nätoperatörsfel - Misslyckades att skicka meddelande, felkod: %1$d + Det gick inte att skicka meddelandet, tjänsten är inte tillgänglig + Det gick inte att skicka meddelandet, radion är avstängd + Det gick inte att skicka meddelandet, operatörsfel + Det gick inte att skicka meddelandet, felkod: %d Det går inte att svara på korta koder som den här Du kan svara på korta koder med siffror som \"503501\", men inte på koder som innehåller bokstäver och siffror som \"AB-CD0\". Bilagans storlek överskrider maxgränsen för mms