add Share functionality to images

This commit is contained in:
tibbi 2016-11-19 19:57:08 +01:00
parent f1c5699fe6
commit 3049e8f1e8
3 changed files with 40 additions and 38 deletions

View file

@ -231,40 +231,7 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On
false
}
private fun shareMedia() {
/*val selectedMedia = getSelectedMedia()
if (selectedMedia.size <= 1) {
shareMedium(selectedMedia[0])
} else {
shareMedia(selectedMedia)
}*/
}
private fun shareMedia(media: List<Medium>) {
val shareTitle = resources.getString(R.string.share_via)
Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
type = "image/* video/*"
val uris = ArrayList<Uri>(media.size)
media.map { File(it.path) }
.mapTo(uris) { Uri.fromFile(it) }
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
startActivity(Intent.createChooser(this, shareTitle))
}
}
/*private fun getSelectedMedia(): List<Medium> {
val items = media_grid.checkedItemPositions
val cnt = items.size()
val media = (0..cnt - 1)
.filter { items.valueAt(it) }
.map { mMedia[items.keyAt(it)] }
return media
}
private fun prepareForDeleting() {
/*private fun prepareForDeleting() {
if (isShowingPermDialog(File(mPath)))
return
@ -423,10 +390,6 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On
/*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) {
R.id.cab_share -> {
shareMedia()
return true
}
R.id.cab_delete -> {
prepareForDeleting()
mode.finish()

View file

@ -15,6 +15,8 @@ import com.simplemobiletools.gallery.Config
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.extensions.beVisibleIf
import com.simplemobiletools.gallery.extensions.shareMedia
import com.simplemobiletools.gallery.extensions.shareMedium
import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.photo_video_item.view.*
import kotlinx.android.synthetic.main.photo_video_tmb.view.*
@ -45,6 +47,10 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
showProperties()
true
}
R.id.cab_share -> {
shareMedia()
return true
}
else -> false
}
}
@ -75,6 +81,24 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
}
}
private fun shareMedia() {
val selections = multiSelector.selectedPositions
if (selections.size <= 1) {
activity.shareMedium(getSelectedMedia()[0])
} else {
activity.shareMedia(getSelectedMedia())
}
}
private fun getSelectedMedia(): List<Medium> {
val selections = multiSelector.selectedPositions
val cnt = selections.size
val selectedMedia = (0..cnt - 1)
.map { media[selections[it]] }
return selectedMedia
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
views.add(holder.bindView(activity, multiSelectorMode, multiSelector, media[position]))
}

View file

@ -6,6 +6,7 @@ import android.net.Uri
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.models.Medium
import java.io.File
import java.util.*
fun Activity.shareMedium(medium: Medium) {
val shareTitle = resources.getString(R.string.share_via)
@ -18,3 +19,17 @@ fun Activity.shareMedium(medium: Medium) {
startActivity(Intent.createChooser(this, shareTitle))
}
}
fun Activity.shareMedia(media: List<Medium>) {
val shareTitle = resources.getString(R.string.share_via)
Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
type = "image/* video/*"
val uris = ArrayList<Uri>(media.size)
media.map { File(it.path) }
.mapTo(uris) { Uri.fromFile(it) }
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
startActivity(Intent.createChooser(this, shareTitle))
}
}