diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index df8550d2..d74758c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.filemanager.activities import android.app.Activity +import android.content.ClipData import android.content.Intent import android.net.Uri import android.os.Bundle @@ -30,7 +31,6 @@ import java.util.* class MainActivity : SimpleActivity() { private val BACK_PRESS_TIMEOUT = 5000 private var wasBackJustPressed = false - private var isGetContentIntent = false private lateinit var fragment: ItemsFragment @@ -40,8 +40,10 @@ class MainActivity : SimpleActivity() { storeStoragePaths() fragment = fragment_holder as ItemsFragment - isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT + val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT + val allowPickingMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) fragment.isGetContentIntent = isGetContentIntent + fragment.isPickMultipleIntent = allowPickingMultiple tryInitFileManager() checkWhatsNewDialog() @@ -205,6 +207,20 @@ class MainActivity : SimpleActivity() { finish() } + fun pickedPaths(paths: ArrayList) { + val uris = paths.map { Uri.fromFile(File(it)) } as ArrayList + val clipData = ClipData("Attachment", arrayOf(uris.getMimeType()), ClipData.Item(uris.removeAt(0))) + + uris.forEach { + clipData.addItem(ClipData.Item(it)) + } + + val resultIntent = Intent() + resultIntent.clipData = clipData + setResult(Activity.RESULT_OK, resultIntent) + finish() + } + private fun checkWhatsNewDialog() { arrayListOf().apply { add(Release(26, R.string.release_26)) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 7106cbc1..51fba619 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -37,9 +37,8 @@ import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipOutputStream - -class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) : - RecyclerView.Adapter() { +class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList, val listener: ItemOperationsListener?, val isPickMultipleIntent: Boolean, + val itemClick: (FileDirItem) -> Unit) : RecyclerView.Adapter() { private var textColor = activity.config.textColor private val multiSelector = MultiSelector() @@ -101,6 +100,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList confirmSelection() R.id.cab_rename -> displayRenameDialog() R.id.cab_properties -> showProperties() R.id.cab_share -> shareFiles() @@ -125,6 +125,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList + listener?.selectedPaths(paths) + } + private fun displayRenameDialog() { RenameItemDialog(activity, getSelectedMedia()[0].path) { activity.runOnUiThread { @@ -559,5 +565,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList) fun itemLongClicked(position: Int) + + fun selectedPaths(paths: ArrayList) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 0bfb0b07..b89d9ce0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -35,6 +35,7 @@ import kotlin.collections.ArrayList class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { var currentPath = "" var isGetContentIntent = false + var isPickMultipleIntent = false private var storedTextColor = 0 private var showHidden = false @@ -121,7 +122,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum val currAdapter = items_list.adapter if (currAdapter == null) { items_list.apply { - this.adapter = ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment) { + this.adapter = ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, isPickMultipleIntent) { itemClicked(it) } @@ -310,4 +311,8 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum override fun itemLongClicked(position: Int) { items_list.setDragSelectActive(position) } + + override fun selectedPaths(paths: ArrayList) { + (activity as MainActivity).pickedPaths(paths) + } } diff --git a/app/src/main/res/menu/cab.xml b/app/src/main/res/menu/cab.xml index bc58e7c4..f8d3142d 100644 --- a/app/src/main/res/menu/cab.xml +++ b/app/src/main/res/menu/cab.xml @@ -1,6 +1,11 @@ +