forked from upstream-mirrors/quik
fix to handle sms:12345678?body=hello%20there style intent data uri for compose activity start
This commit is contained in:
+31
-26
@@ -42,31 +42,45 @@ class ComposeActivityModule {
|
||||
|
||||
@Provides
|
||||
@Named("addresses")
|
||||
fun provideAddresses(activity: ComposeActivity): List<String> {
|
||||
return activity.intent
|
||||
?.decodedDataString()
|
||||
?.substringAfter(':') // Remove scheme
|
||||
?.substringBefore("?") // Remove query
|
||||
fun provideAddresses(activity: ComposeActivity): List<String> =
|
||||
if ((activity.intent?.data?.scheme == "sms") || (activity.intent?.data?.scheme == "smsto"))
|
||||
activity.intent?.data
|
||||
?.schemeSpecificPart
|
||||
?.removeSuffix("?${activity.intent?.data?.query}")
|
||||
?.split(",", ";")
|
||||
?.filter { number -> number.isNotEmpty() }
|
||||
?.filter { it.isNotEmpty() }
|
||||
?: listOf()
|
||||
}
|
||||
else
|
||||
listOf()
|
||||
|
||||
@Provides
|
||||
@Named("text")
|
||||
fun provideSharedText(activity: ComposeActivity): String {
|
||||
var subject = activity.intent.getStringExtra(Intent.EXTRA_SUBJECT) ?: "";
|
||||
if (subject != "") {
|
||||
subject += "\n"
|
||||
}
|
||||
var retVal = StringBuilder()
|
||||
|
||||
return subject + (activity.intent.extras?.getString(Intent.EXTRA_TEXT)
|
||||
?: activity.intent.extras?.getString("sms_body")
|
||||
?: activity.intent?.decodedDataString()
|
||||
?.substringAfter('?') // Query string
|
||||
?.takeIf { it.startsWith("body") }
|
||||
?.substringAfter('=')
|
||||
// from subject, if passed in intent
|
||||
retVal.append(activity.intent?.getStringExtra(Intent.EXTRA_SUBJECT) ?: "")
|
||||
if (retVal.isNotEmpty())
|
||||
retVal.append("\n")
|
||||
|
||||
// from extra_text or sms_body extras, if passed in intent
|
||||
retVal.append(
|
||||
activity.intent?.extras?.getString(Intent.EXTRA_TEXT)
|
||||
?: activity.intent?.extras?.getString("sms_body")
|
||||
?: "")
|
||||
|
||||
// from body param value(s) if intent data uri is like
|
||||
// sms:12345678?body=hello%20there&body=goodbye
|
||||
if ((activity.intent?.data?.scheme == "sms") || (activity.intent?.data?.scheme == "smsto"))
|
||||
retVal.append(
|
||||
activity.intent?.data?.query
|
||||
?.split("&")
|
||||
?.filter { it.startsWith("body=") }
|
||||
?.joinToString("\n") { it.removePrefix("body=") }
|
||||
?: ""
|
||||
)
|
||||
|
||||
return retVal.toString()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -105,13 +119,4 @@ class ComposeActivityModule {
|
||||
@ViewModelKey(ComposeViewModel::class)
|
||||
fun provideComposeViewModel(viewModel: ComposeViewModel): ViewModel = viewModel
|
||||
|
||||
// The dialer app on Oreo sends a URL encoded string, make sure to decode it
|
||||
private fun Intent.decodedDataString(): String? {
|
||||
val data = data?.toString()
|
||||
if (data?.contains('%') == true) {
|
||||
return URLDecoder.decode(data, "UTF-8")
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user