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 83d750475..f7c940b0a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -361,12 +361,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, - isPinned: Boolean, listener: DirOperationsListener?): View { + class ViewHolder(val view: View, val adapter: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, + val multiSelector: MultiSelector, val listener: DirOperationsListener?, val itemClick: (Directory) -> (Unit)) : + SwappingHolder(view, MultiSelector()) { + fun bindView(directory: Directory, isPinned: Boolean): View { itemView.apply { dir_name.text = directory.name photo_cnt.text = directory.mediaCnt.toString() dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE - activity.loadImage(directory.tmb, dir_thumbnail) + activity.loadImage(directory.tmb, dir_thumbnail, true) - setOnClickListener { viewClicked(multiSelector, directory) } - setOnLongClickListener { - if (listener != null) { - if (!multiSelector.isSelectable) { - activity.startSupportActionMode(multiSelectorCallback) - adapter.toggleItemSelectionAdapter(true, layoutPosition) - } - - listener.itemLongClicked(layoutPosition) - } - true - } + setOnClickListener { viewClicked(directory) } + setOnLongClickListener { viewLongClicked(); true } adapter.setupItemForeground(this) } return itemView } - fun viewClicked(multiSelector: MultiSelector, directory: Directory) { + fun viewClicked(directory: Directory) { if (multiSelector.isSelectable) { val isSelected = adapter.getSelectedPositions().contains(layoutPosition) adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition) @@ -458,6 +449,17 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: 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, itemClick) + return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, itemClick) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, media[position], listener, displayFilenames)) + itemViews.put(position, holder.bindView(media[position], displayFilenames)) toggleItemSelection(selectedPositions.contains(position), position) holder.itemView.tag = holder } @@ -335,34 +335,24 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } - class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, - listener: MediaOperationsListener?, displayFilenames: Boolean): View { + class ViewHolder(val view: View, val adapter: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, + val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { + fun bindView(medium: Medium, displayFilenames: Boolean): View { itemView.apply { play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE photo_name.beVisibleIf(displayFilenames) photo_name.text = medium.name - activity.loadImage(medium.path, medium_thumbnail) + activity.loadImage(medium.path, medium_thumbnail, true) - setOnClickListener { viewClicked(multiSelector, medium) } - setOnLongClickListener { - if (listener != null) { - if (!multiSelector.isSelectable) { - activity.startSupportActionMode(multiSelectorCallback) - adapter.toggleItemSelectionAdapter(true, layoutPosition) - } - - listener.itemLongClicked(layoutPosition) - } - true - } + setOnClickListener { viewClicked(medium) } + setOnLongClickListener { viewLongClicked(); true } adapter.setupItemForeground(this) } return itemView } - fun viewClicked(multiSelector: MultiSelector, medium: Medium) { + fun viewClicked(medium: Medium) { if (multiSelector.isSelectable) { val isSelected = adapter.getSelectedPositions().contains(layoutPosition) adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition) @@ -371,6 +361,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } + fun viewLongClicked() { + if (listener != null) { + if (!multiSelector.isSelectable) { + activity.startSupportActionMode(multiSelectorCallback) + adapter.toggleItemSelectionAdapter(true, layoutPosition) + } + + listener.itemLongClicked(layoutPosition) + } + } + fun stopLoad() { Glide.clear(view.medium_thumbnail) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 40c91d4cb..cc9125a8e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -264,7 +264,8 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: fun Activity.getFileSignature(path: String) = StringSignature(File(path).lastModified().toString()) -fun Activity.loadImage(path: String, target: MySquareImageView) { +fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean) { + target.isVerticalScrolling = verticalScroll if (path.isImageFast() || path.isVideoFast()) { if (path.isPng()) { loadPng(path, target) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MySquareImageView.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/MySquareImageView.kt index c7b40e61f..3e0c79df1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MySquareImageView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/MySquareImageView.kt @@ -1,12 +1,11 @@ package com.simplemobiletools.gallery.views import android.content.Context -import android.support.v7.widget.OrientationHelper import android.util.AttributeSet import android.widget.ImageView class MySquareImageView : ImageView { - var orientation = OrientationHelper.VERTICAL + var isVerticalScrolling = true constructor(context: Context) : super(context) @@ -16,7 +15,7 @@ class MySquareImageView : ImageView { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - val spec = if (orientation == OrientationHelper.VERTICAL) measuredWidth else measuredHeight + val spec = if (isVerticalScrolling) measuredWidth else measuredHeight setMeasuredDimension(spec, spec) } }