add file sharing
This commit is contained in:
parent
6e88949363
commit
732fca704c
2 changed files with 35 additions and 71 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.simplemobiletools.filemanager.adapters
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.*
|
||||
|
@ -13,6 +15,7 @@ import com.simplemobiletools.filemanager.R
|
|||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
import com.simplemobiletools.filepicker.extensions.formatSize
|
||||
import com.simplemobiletools.filepicker.extensions.isGif
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
|
@ -40,6 +43,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
showProperties()
|
||||
true
|
||||
}
|
||||
R.id.cab_share -> {
|
||||
shareFiles()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +77,33 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
}
|
||||
}
|
||||
|
||||
private fun shareFiles() {
|
||||
val selectedItems = getSelectedMedia().filterNot { it.isDirectory }
|
||||
val uris = ArrayList<Uri>(selectedItems.size)
|
||||
selectedItems.mapTo(uris) { Uri.fromFile(File(it.path)) }
|
||||
|
||||
if (uris.isEmpty()) {
|
||||
activity.toast(R.string.no_files_selected)
|
||||
return
|
||||
}
|
||||
|
||||
val shareTitle = activity.resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND_MULTIPLE
|
||||
putExtra(Intent.EXTRA_SUBJECT, activity.resources.getString(R.string.shared_files))
|
||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
|
||||
type = "*/*"
|
||||
activity.startActivity(Intent.createChooser(this, shareTitle))
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectedMedia(): List<FileDirItem> {
|
||||
val positions = multiSelector.selectedPositions
|
||||
val selectedMedia = ArrayList<FileDirItem>(positions.size)
|
||||
positions.forEach { selectedMedia.add(mItems[it]) }
|
||||
return selectedMedia
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.list_item, parent, false)
|
||||
return ViewHolder(activity, view, itemClick)
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
|||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||
import com.simplemobiletools.filepicker.views.RecyclerViewDivider
|
||||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
||||
import kotlinx.android.synthetic.main.items_fragment.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
@ -179,26 +178,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
return type + "/*"
|
||||
}
|
||||
|
||||
/*override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean) {
|
||||
if (checked) {
|
||||
mSelectedItemsCnt++
|
||||
} else {
|
||||
mSelectedItemsCnt--
|
||||
}
|
||||
|
||||
if (mSelectedItemsCnt > 0) {
|
||||
mode.title = mSelectedItemsCnt.toString()
|
||||
}
|
||||
|
||||
mode.invalidate()
|
||||
}
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.cab, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
/*override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
val menuItem = menu.findItem(R.id.cab_rename)
|
||||
menuItem.isVisible = mSelectedItemsCnt == 1
|
||||
return true
|
||||
|
@ -210,8 +190,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
displayRenameDialog()
|
||||
mode.finish()
|
||||
}
|
||||
R.id.cab_properties -> displayPropertiesDialog()
|
||||
R.id.cab_share -> shareFiles()
|
||||
R.id.cab_copy -> {
|
||||
displayCopyDialog()
|
||||
mode.finish()
|
||||
|
@ -226,54 +204,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
return true
|
||||
}*/
|
||||
|
||||
private fun shareFiles() {
|
||||
val itemIndexes = getSelectedItemIndexes()
|
||||
if (itemIndexes.isEmpty())
|
||||
return
|
||||
|
||||
val uris = ArrayList<Uri>(itemIndexes.size)
|
||||
itemIndexes.map { File(mItems[it].path) }
|
||||
.filterNot { it.isDirectory }
|
||||
.mapTo(uris) { Uri.fromFile(it) }
|
||||
|
||||
if (uris.isEmpty()) {
|
||||
context.toast(R.string.no_files_selected)
|
||||
return
|
||||
}
|
||||
|
||||
val shareTitle = resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND_MULTIPLE
|
||||
putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.shared_files))
|
||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
|
||||
type = "*/*"
|
||||
startActivity(Intent.createChooser(this, shareTitle))
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayPropertiesDialog() {
|
||||
val itemIndexes = getSelectedItemIndexes()
|
||||
if (itemIndexes.isEmpty())
|
||||
return
|
||||
|
||||
if (itemIndexes.size == 1) {
|
||||
showOneItemProperties()
|
||||
} else {
|
||||
showMultipleItemProperties(itemIndexes)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showOneItemProperties() {
|
||||
val item = getSelectedItem() ?: return
|
||||
PropertiesDialog(activity, item.path, mConfig.showHidden)
|
||||
}
|
||||
|
||||
private fun showMultipleItemProperties(itemIndexes: List<Int>) {
|
||||
val paths = ArrayList<String>(itemIndexes.size)
|
||||
itemIndexes.mapTo(paths) { mItems[it].path }
|
||||
PropertiesDialog(activity, paths, mConfig.showHidden)
|
||||
}
|
||||
|
||||
private fun displayRenameDialog() {
|
||||
val item = getSelectedItem() ?: return
|
||||
|
||||
|
|
Loading…
Reference in a new issue