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