Merge branch 'master' into feature/451-recycle-bin

This commit is contained in:
Ensar Sarajčić 2023-07-25 08:08:04 +02:00
commit 450a0c22d1
8 changed files with 94 additions and 66 deletions

View File

@ -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))

View File

@ -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<String>, subId: Int?, attachments: List<Attachment>) {
fun Context.sendMessageCompat(text: String, addresses: List<String>, subId: Int?, attachments: List<Attachment>, messageId: Long? = null) {
val settings = getSendMessageSettings()
if (subId != null) {
settings.subscriptionId = subId
@ -47,18 +47,18 @@ fun Context.sendMessageCompat(text: String, addresses: List<String>, 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)

View File

@ -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<String>, subId: Int, requireDeliveryReport: Boolean
text: String, addresses: Set<String>, 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<String>, attachment: Attachment?, settings: Settings) {
fun sendMmsMessage(text: String, addresses: List<String>, 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 {

View File

@ -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"
}
}

View File

@ -59,14 +59,14 @@
<string name="mark_as_unread">Marcar com no llegit</string>
<string name="me">Me</string>
<!-- Archive -->
<string name="unarchive">Unarchive</string>
<string name="empty_archive">Delete all archived conversations</string>
<string name="archived_conversations">Archive</string>
<string name="show_archived_conversations">Show archived conversations</string>
<string name="archive">Archive</string>
<string name="no_archived_conversations">No archived conversations have been found</string>
<string name="archive_emptied_successfully">The archive has been emptied successfully</string>
<string name="empty_archive_confirmation">Are you sure you want to empty the archive? All archived conversations will be permanently lost.</string>
<string name="unarchive">Desarxivar</string>
<string name="empty_archive">Suprimeix totes les converses arxivades</string>
<string name="archived_conversations">Arxiva</string>
<string name="show_archived_conversations">Mostra les converses arxivades</string>
<string name="archive">Arxiu</string>
<string name="no_archived_conversations">No s\'ha trobat cap conversa arxivada</string>
<string name="archive_emptied_successfully">L\'arxiu s\'ha buidat correctament</string>
<string name="empty_archive_confirmation">Segur que voleu buidar l\'arxiu\? Totes les converses arxivades es perdran permanentment.</string>
<!-- Recycle bin -->
<string name="restore">Restore</string>
<string name="restore_all_messages">Restore all messages</string>
@ -74,7 +74,7 @@
<string name="skip_the_recycle_bin_messages">Skip the Recycle Bin, delete messages directly</string>
<!-- Confirmation dialog -->
<string name="delete_whole_conversation_confirmation">Confirmeu que voleu suprimir tots els missatges d\'aquesta conversa\?</string>
<string name="archive_confirmation">Are you sure you want to archive %s?</string>
<string name="archive_confirmation">Segur que voleu arxivar %s\?</string>
<string name="restore_whole_conversation_confirmation">Are you sure you want to restore all messages of this conversation?</string>
<string name="restore_confirmation">Are you sure you want to restore %s?</string>
<!-- Are you sure you want to delete 5 conversations? -->

View File

@ -49,10 +49,10 @@
<string name="send_now">Enviar agora</string>
<!-- Message details -->
<string name="message_details">Message details</string>
<string name="message_details_sender">Sender</string>
<string name="message_details_receiver">Receiver</string>
<string name="message_details_sent_at">Sent at</string>
<string name="message_details_received_at">Received at</string>
<string name="message_details_sender">Remetente</string>
<string name="message_details_receiver">Destinatário</string>
<string name="message_details_sent_at">Enviada a</string>
<string name="message_details_received_at">Recebida a</string>
<!-- Notifications -->
<string name="channel_received_sms">SMS recebida</string>
<string name="new_message">Nova mensagem</string>
@ -60,14 +60,14 @@
<string name="mark_as_unread">Marcar como não lida</string>
<string name="me">Eu</string>
<!-- Archive -->
<string name="unarchive">Unarchive</string>
<string name="empty_archive">Delete all archived conversations</string>
<string name="archived_conversations">Archive</string>
<string name="show_archived_conversations">Show archived conversations</string>
<string name="archive">Archive</string>
<string name="no_archived_conversations">No archived conversations have been found</string>
<string name="archive_emptied_successfully">The archive has been emptied successfully</string>
<string name="empty_archive_confirmation">Are you sure you want to empty the archive? All archived conversations will be permanently lost.</string>
<string name="unarchive">Desarquivar</string>
<string name="empty_archive">Eliminar todas as conversas arquivadas</string>
<string name="archived_conversations">Arquivo</string>
<string name="show_archived_conversations">Mostrar conversas arquivadas</string>
<string name="archive">Arquivo</string>
<string name="no_archived_conversations">Não existem conversas arquivadas</string>
<string name="archive_emptied_successfully">O arquivo foi limpo com sucesso</string>
<string name="empty_archive_confirmation">Tem a certeza de que pretende limpar o arquivo\? Todas as conversas arquivadas serão eliminadas.</string>
<!-- Recycle bin -->
<string name="restore">Restore</string>
<string name="restore_all_messages">Restore all messages</string>
@ -75,7 +75,7 @@
<string name="skip_the_recycle_bin_messages">Skip the Recycle Bin, delete messages directly</string>
<!-- Confirmation dialog -->
<string name="delete_whole_conversation_confirmation">Tem a certeza de que pretende apagar todas as mensagens desta conversa\?</string>
<string name="archive_confirmation">Are you sure you want to archive %s?</string>
<string name="archive_confirmation">Tem a certeza de que pretende arquivar %s\?</string>
<string name="restore_whole_conversation_confirmation">Are you sure you want to restore all messages of this conversation?</string>
<string name="restore_confirmation">Are you sure you want to restore %s?</string>
<!-- Are you sure you want to delete 5 conversations? -->
@ -91,11 +91,11 @@
<item quantity="other">%d mensagens</item>
</plurals>
<!-- Settings -->
<string name="keyword">Keyword</string>
<string name="blocked_keywords">Blocked keywords</string>
<string name="manage_blocked_keywords">Manage blocked keywords</string>
<string name="not_blocking_keywords">You are not blocking any keywords. You may add keywords here to block all messages containing them.</string>
<string name="add_a_blocked_keyword">Add a blocked keyword</string>
<string name="keyword">Palavra-chave</string>
<string name="blocked_keywords">Palavras-chave bloqueadas</string>
<string name="manage_blocked_keywords">Gerir palavras-chave bloqueadas</string>
<string name="not_blocking_keywords">Não existem quaisquer palavras-chave bloqueadas. Pode adicionar as palavras-chave aqui para poder bloquear todas as mensagens que as contenham.</string>
<string name="add_a_blocked_keyword">Adicionar palavra-chave de bloqueio</string>
<string name="lock_screen_visibility">Notificação no ecrã de bloqueio</string>
<string name="sender_and_message">Remetente e mensagem</string>
<string name="sender_only">Apenas remetente</string>

View File

@ -62,13 +62,13 @@
<string name="me">Я</string>
<!-- Archive -->
<string name="unarchive">Разархивировать</string>
<string name="empty_archive">Delete all archived conversations</string>
<string name="archived_conversations">Archive</string>
<string name="show_archived_conversations">Show archived conversations</string>
<string name="empty_archive">Удалить все архивные переписки</string>
<string name="archived_conversations">Архивная</string>
<string name="show_archived_conversations">Показывать архивные переписки</string>
<string name="archive">Архивировать</string>
<string name="no_archived_conversations">No archived conversations have been found</string>
<string name="archive_emptied_successfully">The archive has been emptied successfully</string>
<string name="empty_archive_confirmation">Are you sure you want to empty the archive? All archived conversations will be permanently lost.</string>
<string name="no_archived_conversations">Нет архивных переписок</string>
<string name="archive_emptied_successfully">Архив успешно очищен</string>
<string name="empty_archive_confirmation">Очистить архив\? Все архивные переписки будут безвозвратно потеряны.</string>
<!-- Recycle bin -->
<string name="restore">Restore</string>
<string name="restore_all_messages">Restore all messages</string>
@ -76,7 +76,7 @@
<string name="skip_the_recycle_bin_messages">Skip the Recycle Bin, delete messages directly</string>
<!-- Confirmation dialog -->
<string name="delete_whole_conversation_confirmation">Удалить все сообщения в этой переписке\?</string>
<string name="archive_confirmation">Are you sure you want to archive %s?</string>
<string name="archive_confirmation">Архивировать %s\?</string>
<string name="restore_whole_conversation_confirmation">Are you sure you want to restore all messages of this conversation?</string>
<string name="restore_confirmation">Are you sure you want to restore %s?</string>
<!-- Are you sure you want to delete 5 conversations? -->

View File

@ -59,14 +59,14 @@
<string name="mark_as_unread">Markera som oläst</string>
<string name="me">Jag</string>
<!-- Archive -->
<string name="unarchive">Unarchive</string>
<string name="empty_archive">Delete all archived conversations</string>
<string name="archived_conversations">Archive</string>
<string name="show_archived_conversations">Show archived conversations</string>
<string name="archive">Archive</string>
<string name="no_archived_conversations">No archived conversations have been found</string>
<string name="archive_emptied_successfully">The archive has been emptied successfully</string>
<string name="empty_archive_confirmation">Are you sure you want to empty the archive? All archived conversations will be permanently lost.</string>
<string name="unarchive">Ångra arkivering</string>
<string name="empty_archive">Ta bort alla arkiverade konversationer</string>
<string name="archived_conversations">Arkiv</string>
<string name="show_archived_conversations">Visa arkiverade konversationer</string>
<string name="archive">Arkivera</string>
<string name="no_archived_conversations">Inga arkiverade konversationer hittades</string>
<string name="archive_emptied_successfully">Arkivet har tömts</string>
<string name="empty_archive_confirmation">Är du säker på att du vill tömma arkivet\? Alla arkiverade konversationer tas bort permanent.</string>
<!-- Recycle bin -->
<string name="restore">Restore</string>
<string name="restore_all_messages">Restore all messages</string>
@ -74,7 +74,7 @@
<string name="skip_the_recycle_bin_messages">Skip the Recycle Bin, delete messages directly</string>
<!-- Confirmation dialog -->
<string name="delete_whole_conversation_confirmation">Är du säker på att du vill ta bort alla meddelanden i konversationen\?</string>
<string name="archive_confirmation">Are you sure you want to archive %s?</string>
<string name="archive_confirmation">Är du säker på att du vill arkivera %s\?</string>
<string name="restore_whole_conversation_confirmation">Are you sure you want to restore all messages of this conversation?</string>
<string name="restore_confirmation">Are you sure you want to restore %s?</string>
<!-- Are you sure you want to delete 5 conversations? -->
@ -88,11 +88,11 @@
<item quantity="other">%d meddelanden</item>
</plurals>
<!-- Settings -->
<string name="keyword">Keyword</string>
<string name="blocked_keywords">Blocked keywords</string>
<string name="manage_blocked_keywords">Manage blocked keywords</string>
<string name="not_blocking_keywords">You are not blocking any keywords. You may add keywords here to block all messages containing them.</string>
<string name="add_a_blocked_keyword">Add a blocked keyword</string>
<string name="keyword">Nyckelord</string>
<string name="blocked_keywords">Blockerade nyckelord</string>
<string name="manage_blocked_keywords">Hantera blockerade nyckelord</string>
<string name="not_blocking_keywords">Du blockerar inte några nyckelord. Du kan lägga till nyckelord här för att blockera alla meddelanden som innehåller dem.</string>
<string name="add_a_blocked_keyword">Lägg till ett blockerat nyckelord</string>
<string name="lock_screen_visibility">Synlighet för aviseringar på låsskärmen</string>
<string name="sender_and_message">Avsändare och meddelande</string>
<string name="sender_only">Endast avsändare</string>
@ -116,10 +116,10 @@
<!-- Errors -->
<string name="empty_destination_address">Kan inte skicka meddelande utan nummer</string>
<string name="unable_to_save_message">Det går inte att spara meddelandet på telefonen</string>
<string name="error_service_is_unavailable">Kunde inte skicka meddelande, ingen nätverkstjänst</string>
<string name="error_radio_turned_off">Misslyckades att skicka meddelande, radion avstängd</string>
<string name="carrier_send_error">Misslyckades att skicka meddelande, nätoperatörsfel</string>
<string name="unknown_error_occurred_sending_message">Misslyckades att skicka meddelande, felkod: %1$d</string>
<string name="error_service_is_unavailable">Det gick inte att skicka meddelandet, tjänsten är inte tillgänglig</string>
<string name="error_radio_turned_off">Det gick inte att skicka meddelandet, radion är avstängd</string>
<string name="carrier_send_error">Det gick inte att skicka meddelandet, operatörsfel</string>
<string name="unknown_error_occurred_sending_message">Det gick inte att skicka meddelandet, felkod: %d</string>
<string name="invalid_short_code">Det går inte att svara på korta koder som den här</string>
<string name="invalid_short_code_desc">Du kan svara på korta koder med siffror som \"503501\", men inte på koder som innehåller bokstäver och siffror som \"AB-CD0\".</string>
<string name="attachment_sized_exceeds_max_limit">Bilagans storlek överskrider maxgränsen för mms</string>