Merge pull request #196 from Aga-C/fix-plus-sign

Fixed missing plus sign when opened from another app (#107)
This commit is contained in:
Tibor Kaputa 2021-09-09 22:36:20 +02:00 committed by GitHub
commit 99c80b15df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 2 deletions

View File

@ -102,7 +102,7 @@ class NewConversationActivity : SimpleActivity() {
private fun isThirdPartyIntent(): Boolean {
if ((intent.action == Intent.ACTION_SENDTO || intent.action == Intent.ACTION_SEND || intent.action == Intent.ACTION_VIEW) && intent.dataString != null) {
val number = intent.dataString!!.removePrefix("sms:").removePrefix("smsto:").removePrefix("mms").removePrefix("mmsto:").trim()
val number = intent.dataString!!.removePrefix("sms:").removePrefix("smsto:").removePrefix("mms").removePrefix("mmsto:").replace("+", "%2b").trim()
launchThreadActivity(URLDecoder.decode(number), "")
finish()
return true

View File

@ -29,6 +29,8 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.klinker.android.send_message.Settings
import com.klinker.android.send_message.Transaction
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -390,7 +392,10 @@ class ThreadActivity : SimpleActivity() {
private fun setupParticipants() {
if (participants.isEmpty()) {
participants = if (messages.isEmpty()) {
getThreadParticipants(threadId, null)
val intentNumbers = getPhoneNumbersFromIntent()
val participants = getThreadParticipants(threadId, null)
fixParticipantNumbers(participants, intentNumbers)
} else {
messages.first().participants
}
@ -781,6 +786,41 @@ class ThreadActivity : SimpleActivity() {
showSelectedContacts()
}
private fun getPhoneNumbersFromIntent(): ArrayList<String> {
val numberFromIntent = intent.getStringExtra(THREAD_NUMBER)
val numbers = ArrayList<String>()
if (numberFromIntent != null) {
if (numberFromIntent.startsWith('[') && numberFromIntent.endsWith(']')) {
val type = object : TypeToken<List<String>>() {}.type
numbers.addAll(Gson().fromJson(numberFromIntent, type))
} else {
numbers.add(numberFromIntent)
}
}
return numbers
}
private fun fixParticipantNumbers(participants: ArrayList<SimpleContact>, properNumbers: ArrayList<String>): ArrayList<SimpleContact> {
for (number in properNumbers) {
for (participant in participants) {
participant.phoneNumbers = participant.phoneNumbers.map {
val numberWithoutPlus = number.replace("+", "")
if (numberWithoutPlus == it.trim()) {
if (participant.name == it) {
participant.name = number
}
number
} else {
it
}
} as ArrayList<String>
}
}
return participants
}
@SuppressLint("MissingPermission")
@Subscribe(threadMode = ThreadMode.ASYNC)
fun refreshMessages(event: Events.RefreshMessages) {