small cleanup at thumbnail adapters
This commit is contained in:
parent
2734fe9615
commit
5319a184f3
4 changed files with 45 additions and 42 deletions
|
@ -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,17 +422,34 @@ 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 {
|
||||
setOnClickListener { viewClicked(directory) }
|
||||
setOnLongClickListener { viewLongClicked(); true }
|
||||
|
||||
adapter.setupItemForeground(this)
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(directory: Directory) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||
} else {
|
||||
itemClick(directory)
|
||||
}
|
||||
}
|
||||
|
||||
fun viewLongClicked() {
|
||||
if (listener != null) {
|
||||
if (!multiSelector.isSelectable) {
|
||||
activity.startSupportActionMode(multiSelectorCallback)
|
||||
|
@ -441,21 +458,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
|
||||
listener.itemLongClicked(layoutPosition)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
adapter.setupItemForeground(this)
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(multiSelector: MultiSelector, directory: Directory) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||
} else {
|
||||
itemClick(directory)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopLoad() {
|
||||
|
|
|
@ -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,17 +335,33 @@ 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 {
|
||||
setOnClickListener { viewClicked(medium) }
|
||||
setOnLongClickListener { viewLongClicked(); true }
|
||||
|
||||
adapter.setupItemForeground(this)
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(medium: Medium) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||
} else {
|
||||
itemClick(medium)
|
||||
}
|
||||
}
|
||||
|
||||
fun viewLongClicked() {
|
||||
if (listener != null) {
|
||||
if (!multiSelector.isSelectable) {
|
||||
activity.startSupportActionMode(multiSelectorCallback)
|
||||
|
@ -354,21 +370,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
|
||||
listener.itemLongClicked(layoutPosition)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
adapter.setupItemForeground(this)
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(multiSelector: MultiSelector, medium: Medium) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||
} else {
|
||||
itemClick(medium)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopLoad() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue