small cleanup at thumbnail adapters

This commit is contained in:
tibbi 2017-06-18 21:40:00 +02:00
parent 2734fe9615
commit 5319a184f3
4 changed files with 45 additions and 42 deletions

View file

@ -361,12 +361,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item, parent, false)
return ViewHolder(view, adapterListener, itemClick)
return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, itemClick)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dir = dirs[position]
itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, dir, pinnedFolders.contains(dir.path), listener))
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path)))
toggleItemSelection(selectedPositions.contains(position), position)
holder.itemView.tag = holder
}
@ -422,34 +422,25 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
}
}
class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Directory) -> (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<Direc
}
}
fun viewLongClicked() {
if (listener != null) {
if (!multiSelector.isSelectable) {
activity.startSupportActionMode(multiSelectorCallback)
adapter.toggleItemSelectionAdapter(true, layoutPosition)
}
listener.itemLongClicked(layoutPosition)
}
}
fun stopLoad() {
Glide.clear(view.dir_thumbnail)
}

View file

@ -270,11 +270,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
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<Medium>,
}
}
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<Medium>,
}
}
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)
}

View file

@ -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)

View file

@ -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)
}
}