From a0b9dc7754948be7242ea1af049325c1ab4963e6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 26 Jun 2017 23:15:09 +0200 Subject: [PATCH] do not allow long pressing items if its a third party pick intent --- .../gallery/activities/MainActivity.kt | 8 ++++---- .../gallery/activities/MediaActivity.kt | 8 ++++---- .../gallery/adapters/DirectoryAdapter.kt | 10 +++++----- .../gallery/adapters/MediaAdapter.kt | 11 ++++++----- .../gallery/dialogs/PickDirectoryDialog.kt | 2 +- .../gallery/dialogs/PickMediumDialog.kt | 2 +- 6 files changed, 21 insertions(+), 20 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 18e80805a..de37a3534 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -392,12 +392,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun setupAdapter() { val currAdapter = directories_grid.adapter - if (currAdapter != null) { - (currAdapter as DirectoryAdapter).updateDirs(mDirs) - } else { - directories_grid.adapter = DirectoryAdapter(this, mDirs, this) { + if (currAdapter == null) { + directories_grid.adapter = DirectoryAdapter(this, mDirs, this, isPickIntent(intent) || isGetAnyContentIntent(intent)) { itemClicked(it.path) } + } else { + (currAdapter as DirectoryAdapter).updateDirs(mDirs) } setupScrollDirection() } 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 78c2d610e..d2d33fb8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -141,12 +141,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { return val currAdapter = media_grid.adapter - if (currAdapter != null) { - (currAdapter as MediaAdapter).updateMedia(mMedia) - } else { - media_grid.adapter = MediaAdapter(this, mMedia, this) { + if (currAdapter == null) { + media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetAnyIntent) { itemClicked(it.path) } + } else { + (currAdapter as MediaAdapter).updateMedia(mMedia) } setupScrollDirection() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index e0dec09e6..4c43bf660 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -30,8 +30,8 @@ import kotlinx.android.synthetic.main.directory_tmb.view.* import java.io.File import java.util.* -class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) : - RecyclerView.Adapter() { +class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, val isPickIntent: Boolean, + val itemClick: (Directory) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() val config = activity.config @@ -357,7 +357,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList (Unit)) : + val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) { fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean): View { itemView.apply { @@ -429,7 +429,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, val listener: MediaOperationsListener?, val itemClick: (Medium) -> Unit) : - RecyclerView.Adapter() { +class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isPickIntent: Boolean, + val itemClick: (Medium) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() val config = activity.config @@ -266,7 +266,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent?.context).inflate(R.layout.photo_video_item, parent, false) - return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, itemClick) + return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, isPickIntent, itemClick) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { @@ -332,7 +332,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, - val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { + val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val isPickIntent: Boolean, val itemClick: (Medium) -> (Unit)) : + SwappingHolder(view, MultiSelector()) { fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean): View { itemView.apply { play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE @@ -341,7 +342,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, activity.loadImage(medium.path, medium_thumbnail, scrollVertically) setOnClickListener { viewClicked(medium) } - setOnLongClickListener { viewLongClicked(); true } + setOnLongClickListener { if (isPickIntent) viewClicked(medium) else viewLongClicked(); true } adapterListener.setupItemForeground(this) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index 7b3c93971..ea4fcb14d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -60,7 +60,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, return shownDirectories = directories - val adapter = DirectoryAdapter(activity, directories, null) { + val adapter = DirectoryAdapter(activity, directories, null, true) { if (it.path.trimEnd('/') == sourcePath) { activity.toast(R.string.source_and_destination_same) return@DirectoryAdapter diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 8d2bacf2b..4c57c68f1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -47,7 +47,7 @@ class PickMediumDialog(val activity: SimpleActivity, val path: String, val callb return shownMedia = media - val adapter = MediaAdapter(activity, media, null) { + val adapter = MediaAdapter(activity, media, null, true) { callback(it.path) dialog.dismiss() }