Skip to content

Commit 4107d83

Browse files
committed
allow sharing folder content, related to #55
1 parent b67a9e5 commit 4107d83

File tree

1 file changed

+19
-6
lines changed
  • app/src/main/kotlin/com/simplemobiletools/filemanager/adapters

1 file changed

+19
-6
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
134134
}
135135

136136
private fun shareFiles() {
137-
val selectedItems = getSelectedMedia().filterNot { it.isDirectory }
137+
val selectedItems = getSelectedMedia()
138138
val uris = ArrayList<Uri>(selectedItems.size)
139-
selectedItems.mapTo(uris) { Uri.fromFile(File(it.path)) }
139+
selectedItems.forEach {
140+
val file = File(it.path)
141+
addFileUris(file, uris)
142+
}
140143

141144
if (uris.isEmpty()) {
142145
activity.toast(R.string.no_files_selected)
@@ -147,16 +150,26 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
147150
Intent().apply {
148151
action = if (uris.size <= 1) Intent.ACTION_SEND else Intent.ACTION_SEND_MULTIPLE
149152
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
150-
type = getMimeType(selectedItems)
153+
type = getMimeType(uris)
151154
activity.startActivity(Intent.createChooser(this, shareTitle))
152155
}
153156
}
154157

155-
private fun getMimeType(items: List<FileDirItem>): String {
156-
val firstMimeType = items.first().path.getMimeTypeFromPath()
158+
private fun addFileUris(file: File, uris: ArrayList<Uri>) {
159+
if (file.isDirectory) {
160+
file.listFiles()?.forEach {
161+
addFileUris(it, uris)
162+
}
163+
} else {
164+
uris.add(Uri.fromFile(file))
165+
}
166+
}
167+
168+
private fun getMimeType(uris: List<Uri>): String {
169+
val firstMimeType = uris.first().path.getMimeTypeFromPath()
157170
val firstMimeGroup = firstMimeType.substringBefore("/")
158171

159-
items.forEach {
172+
uris.forEach {
160173
val mimeGroup = it.path.getMimeTypeFromPath().substringBefore("/")
161174
if (mimeGroup != firstMimeGroup) {
162175
return "*/*"

0 commit comments

Comments
 (0)