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 {
|
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, itemClick)
|
return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, itemClick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val dir = dirs[position]
|
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)
|
toggleItemSelection(selectedPositions.contains(position), position)
|
||||||
holder.itemView.tag = holder
|
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()) {
|
class ViewHolder(val view: View, val adapter: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory,
|
val multiSelector: MultiSelector, val listener: DirOperationsListener?, val itemClick: (Directory) -> (Unit)) :
|
||||||
isPinned: Boolean, listener: DirOperationsListener?): View {
|
SwappingHolder(view, MultiSelector()) {
|
||||||
|
fun bindView(directory: Directory, isPinned: Boolean): View {
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
dir_name.text = directory.name
|
dir_name.text = directory.name
|
||||||
photo_cnt.text = directory.mediaCnt.toString()
|
photo_cnt.text = directory.mediaCnt.toString()
|
||||||
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
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) }
|
setOnClickListener { viewClicked(directory) }
|
||||||
setOnLongClickListener {
|
setOnLongClickListener { viewLongClicked(); true }
|
||||||
if (listener != null) {
|
|
||||||
if (!multiSelector.isSelectable) {
|
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
|
||||||
adapter.toggleItemSelectionAdapter(true, layoutPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener.itemLongClicked(layoutPosition)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter.setupItemForeground(this)
|
adapter.setupItemForeground(this)
|
||||||
}
|
}
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
fun viewClicked(multiSelector: MultiSelector, directory: Directory) {
|
fun viewClicked(directory: Directory) {
|
||||||
if (multiSelector.isSelectable) {
|
if (multiSelector.isSelectable) {
|
||||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||||
adapter.toggleItemSelectionAdapter(!isSelected, 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() {
|
fun stopLoad() {
|
||||||
Glide.clear(view.dir_thumbnail)
|
Glide.clear(view.dir_thumbnail)
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,11 +270,11 @@ 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, itemClick)
|
return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, itemClick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
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)
|
toggleItemSelection(selectedPositions.contains(position), position)
|
||||||
holder.itemView.tag = holder
|
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()) {
|
class ViewHolder(val view: View, val adapter: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium,
|
val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
listener: MediaOperationsListener?, displayFilenames: Boolean): View {
|
fun bindView(medium: Medium, displayFilenames: 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
|
||||||
photo_name.beVisibleIf(displayFilenames)
|
photo_name.beVisibleIf(displayFilenames)
|
||||||
photo_name.text = medium.name
|
photo_name.text = medium.name
|
||||||
activity.loadImage(medium.path, medium_thumbnail)
|
activity.loadImage(medium.path, medium_thumbnail, true)
|
||||||
|
|
||||||
setOnClickListener { viewClicked(multiSelector, medium) }
|
setOnClickListener { viewClicked(medium) }
|
||||||
setOnLongClickListener {
|
setOnLongClickListener { viewLongClicked(); true }
|
||||||
if (listener != null) {
|
|
||||||
if (!multiSelector.isSelectable) {
|
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
|
||||||
adapter.toggleItemSelectionAdapter(true, layoutPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener.itemLongClicked(layoutPosition)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter.setupItemForeground(this)
|
adapter.setupItemForeground(this)
|
||||||
}
|
}
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
fun viewClicked(multiSelector: MultiSelector, medium: Medium) {
|
fun viewClicked(medium: Medium) {
|
||||||
if (multiSelector.isSelectable) {
|
if (multiSelector.isSelectable) {
|
||||||
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||||
adapter.toggleItemSelectionAdapter(!isSelected, 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() {
|
fun stopLoad() {
|
||||||
Glide.clear(view.medium_thumbnail)
|
Glide.clear(view.medium_thumbnail)
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,8 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
|
||||||
|
|
||||||
fun Activity.getFileSignature(path: String) = StringSignature(File(path).lastModified().toString())
|
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.isImageFast() || path.isVideoFast()) {
|
||||||
if (path.isPng()) {
|
if (path.isPng()) {
|
||||||
loadPng(path, target)
|
loadPng(path, target)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.simplemobiletools.gallery.views
|
package com.simplemobiletools.gallery.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.support.v7.widget.OrientationHelper
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
|
||||||
class MySquareImageView : ImageView {
|
class MySquareImageView : ImageView {
|
||||||
var orientation = OrientationHelper.VERTICAL
|
var isVerticalScrolling = true
|
||||||
|
|
||||||
constructor(context: Context) : super(context)
|
constructor(context: Context) : super(context)
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ class MySquareImageView : ImageView {
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
val spec = if (orientation == OrientationHelper.VERTICAL) measuredWidth else measuredHeight
|
val spec = if (isVerticalScrolling) measuredWidth else measuredHeight
|
||||||
setMeasuredDimension(spec, spec)
|
setMeasuredDimension(spec, spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue