From 124d44dfb9a2cb2ca4ed7fe313dbde4f56fa1dc5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Nov 2017 17:17:23 +0100 Subject: [PATCH] fix #438, properly handle GET_CONTENT intent --- .../simplemobiletools/gallery/activities/MainActivity.kt | 1 + .../simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index bf132adca..879da62ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -470,6 +470,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { clipData.addItem(ClipData.Item(it)) } + resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION resultIntent.clipData = clipData } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 7a8b1358e..683eb5ffd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -170,7 +170,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val currAdapter = media_grid.adapter if (currAdapter == null) { - media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetAnyIntent, mAllowPickingMultiple) { + media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple) { itemClicked(it.path) } } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index eec2636f3..039ac332a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -25,7 +25,7 @@ import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import java.io.File import java.util.* -class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isPickIntent: Boolean, +class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, val allowMultiplePicks: Boolean, val itemClick: (Medium) -> Unit) : RecyclerView.Adapter() { private val config = activity.config @@ -108,7 +108,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 menu.findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 - menu.findItem(R.id.cab_confirm_selection).isVisible = isPickIntent && allowMultiplePicks && selectedPositions.size > 0 + menu.findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 checkHideBtnVisibility(menu) @@ -279,7 +279,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid val view = LayoutInflater.from(parent?.context).inflate(layoutType, parent, false) - return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, allowMultiplePicks || !isPickIntent, itemClick) + return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, allowMultiplePicks || !isAGetIntent, itemClick) } override fun onBindViewHolder(holder: ViewHolder, position: Int) {