handle picking multiple items at get_content too

This commit is contained in:
tibbi 2017-10-23 10:28:00 +02:00
parent 679d68fc26
commit f081f8039a
4 changed files with 40 additions and 6 deletions

View File

@ -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<String>) {
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<Release>().apply {
add(Release(26, R.string.release_26))

View File

@ -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<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDirItem>, val listener: ItemOperationsListener?, val isPickMultipleIntent: Boolean,
val itemClick: (FileDirItem) -> Unit) : RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
private var textColor = activity.config.textColor
private val multiSelector = MultiSelector()
@ -101,6 +100,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) {
R.id.cab_confirm_selection -> 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<FileDir
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size <= 1
menu.findItem(R.id.cab_decompress).isVisible = getSelectedMedia().map { it.path }.any { it.isZipFile() }
menu.findItem(R.id.cab_confirm_selection).isVisible = isPickMultipleIntent
return true
}
@ -138,6 +139,11 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
}
}
private fun confirmSelection() {
val paths = getSelectedMedia().filter { !it.isDirectory }.map { it.path } as ArrayList<String>
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<FileDir
fun deleteFiles(files: ArrayList<File>)
fun itemLongClicked(position: Int)
fun selectedPaths(paths: ArrayList<String>)
}
}

View File

@ -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<String>) {
(activity as MainActivity).pickedPaths(paths)
}
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_confirm_selection"
android:icon="@drawable/ic_check"
android:title="@string/confirm_selection"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_properties"
android:icon="@drawable/ic_info"