do not allow long pressing items if its a third party pick intent

This commit is contained in:
tibbi 2017-06-26 23:15:09 +02:00
parent bbdf72b52e
commit a0b9dc7754
6 changed files with 21 additions and 20 deletions

View file

@ -392,12 +392,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun setupAdapter() { private fun setupAdapter() {
val currAdapter = directories_grid.adapter val currAdapter = directories_grid.adapter
if (currAdapter != null) { if (currAdapter == null) {
(currAdapter as DirectoryAdapter).updateDirs(mDirs) directories_grid.adapter = DirectoryAdapter(this, mDirs, this, isPickIntent(intent) || isGetAnyContentIntent(intent)) {
} else {
directories_grid.adapter = DirectoryAdapter(this, mDirs, this) {
itemClicked(it.path) itemClicked(it.path)
} }
} else {
(currAdapter as DirectoryAdapter).updateDirs(mDirs)
} }
setupScrollDirection() setupScrollDirection()
} }

View file

@ -141,12 +141,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
return return
val currAdapter = media_grid.adapter val currAdapter = media_grid.adapter
if (currAdapter != null) { if (currAdapter == null) {
(currAdapter as MediaAdapter).updateMedia(mMedia) media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetAnyIntent) {
} else {
media_grid.adapter = MediaAdapter(this, mMedia, this) {
itemClicked(it.path) itemClicked(it.path)
} }
} else {
(currAdapter as MediaAdapter).updateMedia(mMedia)
} }
setupScrollDirection() setupScrollDirection()
} }

View file

@ -30,8 +30,8 @@ import kotlinx.android.synthetic.main.directory_tmb.view.*
import java.io.File import java.io.File
import java.util.* import java.util.*
class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, val itemClick: (Directory) -> Unit) : class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, val isPickIntent: Boolean,
RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() { val itemClick: (Directory) -> Unit) : RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
val multiSelector = MultiSelector() val multiSelector = MultiSelector()
val config = activity.config val config = activity.config
@ -357,7 +357,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item, parent, false) val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_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) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -419,7 +419,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
} }
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
val multiSelector: MultiSelector, val listener: DirOperationsListener?, val itemClick: (Directory) -> (Unit)) : val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) :
SwappingHolder(view, MultiSelector()) { SwappingHolder(view, MultiSelector()) {
fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean): View { fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean): View {
itemView.apply { itemView.apply {
@ -429,7 +429,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
activity.loadImage(directory.tmb, dir_thumbnail, scrollVertically) activity.loadImage(directory.tmb, dir_thumbnail, scrollVertically)
setOnClickListener { viewClicked(directory) } setOnClickListener { viewClicked(directory) }
setOnLongClickListener { viewLongClicked(); true } setOnLongClickListener { if (isPickIntent) viewClicked(directory) else viewLongClicked(); true }
adapterListener.setupItemForeground(this) adapterListener.setupItemForeground(this)
} }

View file

@ -23,8 +23,8 @@ import kotlinx.android.synthetic.main.photo_video_tmb.view.*
import java.io.File import java.io.File
import java.util.* import java.util.*
class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val itemClick: (Medium) -> Unit) : class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isPickIntent: Boolean,
RecyclerView.Adapter<MediaAdapter.ViewHolder>() { val itemClick: (Medium) -> Unit) : RecyclerView.Adapter<MediaAdapter.ViewHolder>() {
val multiSelector = MultiSelector() val multiSelector = MultiSelector()
val config = activity.config val config = activity.config
@ -266,7 +266,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.photo_video_item, parent, false) 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) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -332,7 +332,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
} }
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, 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 { fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean): View {
itemView.apply { itemView.apply {
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
@ -341,7 +342,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
activity.loadImage(medium.path, medium_thumbnail, scrollVertically) activity.loadImage(medium.path, medium_thumbnail, scrollVertically)
setOnClickListener { viewClicked(medium) } setOnClickListener { viewClicked(medium) }
setOnLongClickListener { viewLongClicked(); true } setOnLongClickListener { if (isPickIntent) viewClicked(medium) else viewLongClicked(); true }
adapterListener.setupItemForeground(this) adapterListener.setupItemForeground(this)
} }

View file

@ -60,7 +60,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
return return
shownDirectories = directories shownDirectories = directories
val adapter = DirectoryAdapter(activity, directories, null) { val adapter = DirectoryAdapter(activity, directories, null, true) {
if (it.path.trimEnd('/') == sourcePath) { if (it.path.trimEnd('/') == sourcePath) {
activity.toast(R.string.source_and_destination_same) activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter return@DirectoryAdapter

View file

@ -47,7 +47,7 @@ class PickMediumDialog(val activity: SimpleActivity, val path: String, val callb
return return
shownMedia = media shownMedia = media
val adapter = MediaAdapter(activity, media, null) { val adapter = MediaAdapter(activity, media, null, true) {
callback(it.path) callback(it.path)
dialog.dismiss() dialog.dismiss()
} }