mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-25 07:28:47 +02:00
allow sharing folder content, related to #55
This commit is contained in:
parent
b67a9e56a2
commit
4107d830a3
@ -134,9 +134,12 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareFiles() {
|
private fun shareFiles() {
|
||||||
val selectedItems = getSelectedMedia().filterNot { it.isDirectory }
|
val selectedItems = getSelectedMedia()
|
||||||
val uris = ArrayList<Uri>(selectedItems.size)
|
val uris = ArrayList<Uri>(selectedItems.size)
|
||||||
selectedItems.mapTo(uris) { Uri.fromFile(File(it.path)) }
|
selectedItems.forEach {
|
||||||
|
val file = File(it.path)
|
||||||
|
addFileUris(file, uris)
|
||||||
|
}
|
||||||
|
|
||||||
if (uris.isEmpty()) {
|
if (uris.isEmpty()) {
|
||||||
activity.toast(R.string.no_files_selected)
|
activity.toast(R.string.no_files_selected)
|
||||||
@ -147,16 +150,26 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||||||
Intent().apply {
|
Intent().apply {
|
||||||
action = if (uris.size <= 1) Intent.ACTION_SEND else Intent.ACTION_SEND_MULTIPLE
|
action = if (uris.size <= 1) Intent.ACTION_SEND else Intent.ACTION_SEND_MULTIPLE
|
||||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
|
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
|
||||||
type = getMimeType(selectedItems)
|
type = getMimeType(uris)
|
||||||
activity.startActivity(Intent.createChooser(this, shareTitle))
|
activity.startActivity(Intent.createChooser(this, shareTitle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMimeType(items: List<FileDirItem>): String {
|
private fun addFileUris(file: File, uris: ArrayList<Uri>) {
|
||||||
val firstMimeType = items.first().path.getMimeTypeFromPath()
|
if (file.isDirectory) {
|
||||||
|
file.listFiles()?.forEach {
|
||||||
|
addFileUris(it, uris)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uris.add(Uri.fromFile(file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getMimeType(uris: List<Uri>): String {
|
||||||
|
val firstMimeType = uris.first().path.getMimeTypeFromPath()
|
||||||
val firstMimeGroup = firstMimeType.substringBefore("/")
|
val firstMimeGroup = firstMimeType.substringBefore("/")
|
||||||
|
|
||||||
items.forEach {
|
uris.forEach {
|
||||||
val mimeGroup = it.path.getMimeTypeFromPath().substringBefore("/")
|
val mimeGroup = it.path.getMimeTypeFromPath().substringBefore("/")
|
||||||
if (mimeGroup != firstMimeGroup) {
|
if (mimeGroup != firstMimeGroup) {
|
||||||
return "*/*"
|
return "*/*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user