From 5939e4540ce85b877532cc8f78f67e61f74ff467 Mon Sep 17 00:00:00 2001 From: raphj Date: Fri, 31 Jan 2020 11:50:44 +0100 Subject: [PATCH] Use the share intent subject besides the text When sharing a text, some applications also set the subject field in the share intent. For instance, when sharing a video with NewPipe, the title of the video is put in the subject of the intent. This change makes use of the subject field when providing the shared text. --- .../QKSMS/feature/compose/ComposeActivityModule.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivityModule.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivityModule.kt index dcf9af1f..6929a069 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivityModule.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivityModule.kt @@ -55,14 +55,19 @@ class ComposeActivityModule { @Provides @Named("text") fun provideSharedText(activity: ComposeActivity): String { - return activity.intent.extras?.getString(Intent.EXTRA_TEXT) + var subject = activity.intent.getStringExtra(Intent.EXTRA_SUBJECT) ?: ""; + if (subject != "") { + subject += "\n" + } + + return subject + (activity.intent.extras?.getString(Intent.EXTRA_TEXT) ?: activity.intent.extras?.getString("sms_body") ?: activity.intent?.decodedDataString() ?.substringAfter('?') // Query string ?.split(',') ?.firstOrNull { param -> param.startsWith("body") } ?.substringAfter('=') - ?: "" + ?: "") } @Provides @@ -88,4 +93,4 @@ class ComposeActivityModule { return data } -} \ No newline at end of file +}