Skip to content

Commit fbc6cdf

Browse files
Simplify handleIntent, lay groundwork for ACTION_SEND_MULTIPLE support
1 parent 244ef51 commit fbc6cdf

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,41 @@ class DetailsActivity : ComponentActivity() {
156156
}
157157
Log.d("getPreferences] handleIntent] intent", "action: $action, type: $type, data: $data")
158158

159-
val content = when (action) {
160-
Intent.ACTION_SEND -> if (type == "text/plain") {
161-
intent.getCharSequenceExtra(Intent.EXTRA_TEXT)
162-
} else null
159+
var content: CharSequence? = null
160+
var fileUri: Uri? = null
161+
var uriList: ArrayList<Uri>? = null
163162

164-
else -> null
165-
}
166-
Log.d("getPreferences] handleIntent] content", content.toString())
163+
when (action) {
164+
Intent.ACTION_SEND -> {
165+
when (type) {
166+
"text/plain" -> {
167+
content = intent.getCharSequenceExtra(Intent.EXTRA_TEXT)
168+
Log.d("getPreferences] handleIntent] content", content.toString())
169+
}
167170

168-
val fileUri = when (action) {
169-
Intent.ACTION_SEND -> if (content == null) {
170-
IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)
171-
} else null
171+
else -> {
172+
fileUri = IntentCompat.getParcelableExtra(
173+
intent, Intent.EXTRA_STREAM, Uri::class.java
174+
)
175+
Log.d("getPreferences] handleIntent] fileUri", fileUri.toString())
176+
}
177+
}
178+
}
179+
180+
Intent.ACTION_SEND_MULTIPLE -> {
181+
uriList = IntentCompat.getParcelableArrayListExtra(
182+
intent, Intent.EXTRA_STREAM, Uri::class.java
183+
)
184+
Log.d("getPreferences] handleIntent] uriList", uriList.toString())
185+
}
186+
187+
Intent.ACTION_VIEW -> {
188+
fileUri = data
189+
Log.d("getPreferences] handleIntent] fileUri", fileUri.toString())
190+
}
172191

173-
Intent.ACTION_VIEW -> data
174192
else -> null
175193
}
176-
Log.d("getPreferences] handleIntent] fileUri", fileUri.toString())
177194

178195
content?.let {
179196
createFile = registerForActivityResult(
@@ -192,7 +209,7 @@ class DetailsActivity : ComponentActivity() {
192209
}
193210

194211
fileUri?.let {
195-
this.fileUri = fileUri
212+
this.fileUri = it
196213
val uriData = getUriData(contentResolver, fileUri) ?: return
197214

198215
this.uriData = uriData

0 commit comments

Comments
 (0)