+27
-8
modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt
+27
-8
modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt
···
78
78
intent.getParcelableExtra(Intent.EXTRA_STREAM)
79
79
}
80
80
81
+
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
82
+
81
83
uri?.let {
82
84
when (type) {
83
-
AttachmentType.IMAGE -> handleImageIntents(listOf(it))
84
-
AttachmentType.VIDEO -> handleVideoIntents(listOf(it))
85
+
AttachmentType.IMAGE -> handleImageIntents(listOf(it), text)
86
+
AttachmentType.VIDEO -> handleVideoIntents(listOf(it), text)
85
87
}
86
88
}
87
89
}
···
103
105
?.take(4)
104
106
}
105
107
108
+
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
109
+
106
110
uris?.let {
107
111
when (type) {
108
-
AttachmentType.IMAGE -> handleImageIntents(it)
112
+
AttachmentType.IMAGE -> handleImageIntents(it, text)
109
113
else -> return
110
114
}
111
115
}
112
116
}
113
117
114
-
private fun handleImageIntents(uris: List<Uri>) {
118
+
private fun handleImageIntents(
119
+
uris: List<Uri>,
120
+
text: String?
121
+
) {
115
122
var allParams = ""
116
123
117
124
uris.forEachIndexed { index, uri ->
···
124
131
}
125
132
}
126
133
127
-
val encoded = URLEncoder.encode(allParams, "UTF-8")
134
+
val encodedUris = URLEncoder.encode(allParams, "UTF-8")
135
+
val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") }
136
+
137
+
var composeIntent = "bluesky://intent/compose?imageUris=$encodedUris"
138
+
encodedText?.let { composeIntent += "&text=$it" }
128
139
129
-
"bluesky://intent/compose?imageUris=$encoded".toUri().let {
140
+
composeIntent.toUri().let {
130
141
val newIntent = Intent(Intent.ACTION_VIEW, it)
131
142
appContext.currentActivity?.startActivity(newIntent)
132
143
}
133
144
}
134
145
135
-
private fun handleVideoIntents(uris: List<Uri>) {
146
+
private fun handleVideoIntents(
147
+
uris: List<Uri>,
148
+
text: String?
149
+
) {
136
150
val uri = uris[0]
137
151
// If there is no extension for the file, substringAfterLast returns the original string - not
138
152
// null, so we check for that below
···
151
165
152
166
val info = getVideoInfo(uri) ?: return
153
167
154
-
"bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}".toUri().let {
168
+
val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") }
169
+
170
+
var composeIntent = "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}"
171
+
encodedText?.let { composeIntent += "&text=$it" }
172
+
173
+
composeIntent.toUri().let {
155
174
val newIntent = Intent(Intent.ACTION_VIEW, it)
156
175
appContext.currentActivity?.startActivity(newIntent)
157
176
}