mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
use an itemView.apply to shorten some adapters
This commit is contained in:
parent
95ff1b1b95
commit
95cc4d1121
2 changed files with 70 additions and 67 deletions
|
@ -321,45 +321,47 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
class ViewHolder(view: View, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
class ViewHolder(view: View, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, pos: Int, isPinned: Boolean)
|
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, pos: Int, isPinned: Boolean)
|
||||||
: View {
|
: View {
|
||||||
itemView.dir_name.text = directory.name
|
itemView.apply {
|
||||||
itemView.photo_cnt.text = directory.mediaCnt.toString()
|
dir_name.text = directory.name
|
||||||
itemView.dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
photo_cnt.text = directory.mediaCnt.toString()
|
||||||
toggleItemSelection(itemView, markedItems.contains(pos), pos)
|
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
||||||
|
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||||
|
|
||||||
val tmb = directory.thumbnail
|
val tmb = directory.thumbnail
|
||||||
val timestampSignature = StringSignature(directory.date_modified.toString())
|
val timestampSignature = StringSignature(directory.date_modified.toString())
|
||||||
if (tmb.isGif()) {
|
if (tmb.isGif()) {
|
||||||
if (animateGifs) {
|
if (animateGifs) {
|
||||||
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.dir_thumbnail)
|
.placeholder(backgroundColor).centerCrop().crossFade().into(dir_thumbnail)
|
||||||
|
} else {
|
||||||
|
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
||||||
|
.placeholder(backgroundColor).centerCrop().into(dir_thumbnail)
|
||||||
|
}
|
||||||
|
} else if (tmb.toLowerCase().endsWith(".png")) {
|
||||||
|
Glide.with(activity).load(tmb).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||||
|
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(dir_thumbnail)
|
||||||
} else {
|
} else {
|
||||||
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
Glide.with(activity).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
||||||
.placeholder(backgroundColor).centerCrop().into(itemView.dir_thumbnail)
|
.placeholder(backgroundColor).centerCrop().crossFade().into(dir_thumbnail)
|
||||||
}
|
}
|
||||||
} else if (tmb.toLowerCase().endsWith(".png")) {
|
|
||||||
Glide.with(activity).load(tmb).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
|
|
||||||
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.dir_thumbnail)
|
|
||||||
} else {
|
|
||||||
Glide.with(activity).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
|
||||||
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.dir_thumbnail)
|
|
||||||
}
|
|
||||||
|
|
||||||
itemView.setOnClickListener { viewClicked(multiSelector, directory, pos) }
|
setOnClickListener { viewClicked(multiSelector, directory, pos) }
|
||||||
itemView.setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
if (!multiSelector.isSelectable) {
|
if (!multiSelector.isSelectable) {
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
activity.startSupportActionMode(multiSelectorCallback)
|
||||||
multiSelector.setSelected(this, true)
|
multiSelector.setSelected(this@ViewHolder, true)
|
||||||
updateTitle(multiSelector.selectedPositions.size)
|
updateTitle(multiSelector.selectedPositions.size)
|
||||||
toggleItemSelection(itemView, true, pos)
|
toggleItemSelection(this, true, pos)
|
||||||
actMode?.invalidate()
|
actMode?.invalidate()
|
||||||
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||||
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
|
(getProperView(this) as FrameLayout).foreground = foregroundColor.createSelector()
|
||||||
else
|
else
|
||||||
getProperView(itemView).foreground = foregroundColor.createSelector()
|
getProperView(this).foreground = foregroundColor.createSelector()
|
||||||
|
}
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,46 +243,47 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
class ViewHolder(view: View, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
class ViewHolder(view: View, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, pos: Int): View {
|
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, pos: Int): View {
|
||||||
itemView.play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE
|
itemView.apply {
|
||||||
itemView.file_name.beVisibleIf(displayFilenames)
|
play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE
|
||||||
itemView.file_name.text = medium.name
|
file_name.beVisibleIf(displayFilenames)
|
||||||
toggleItemSelection(itemView, markedItems.contains(pos), pos)
|
file_name.text = medium.name
|
||||||
|
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||||
|
|
||||||
val path = medium.path
|
val path = medium.path
|
||||||
val timestampSignature = StringSignature(medium.date_modified.toString())
|
val timestampSignature = StringSignature(medium.date_modified.toString())
|
||||||
if (medium.isGif()) {
|
if (medium.isGif()) {
|
||||||
if (animateGifs) {
|
if (animateGifs) {
|
||||||
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.medium_thumbnail)
|
.placeholder(backgroundColor).centerCrop().crossFade().into(medium_thumbnail)
|
||||||
|
} else {
|
||||||
|
Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
|
.placeholder(backgroundColor).centerCrop().into(medium_thumbnail)
|
||||||
|
}
|
||||||
|
} else if (medium.isPng()) {
|
||||||
|
Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||||
|
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(medium_thumbnail)
|
||||||
} else {
|
} else {
|
||||||
Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
||||||
.placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail)
|
.placeholder(backgroundColor).centerCrop().crossFade().into(medium_thumbnail)
|
||||||
}
|
}
|
||||||
} else if (medium.isPng()) {
|
|
||||||
Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
|
|
||||||
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail)
|
|
||||||
} else {
|
|
||||||
Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
|
||||||
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.medium_thumbnail)
|
|
||||||
}
|
|
||||||
|
|
||||||
itemView.setOnClickListener { viewClicked(multiSelector, medium, pos) }
|
setOnClickListener { viewClicked(multiSelector, medium, pos) }
|
||||||
itemView.setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
if (!multiSelector.isSelectable) {
|
if (!multiSelector.isSelectable) {
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
activity.startSupportActionMode(multiSelectorCallback)
|
||||||
multiSelector.setSelected(this, true)
|
multiSelector.setSelected(this@ViewHolder, true)
|
||||||
updateTitle(multiSelector.selectedPositions.size)
|
updateTitle(multiSelector.selectedPositions.size)
|
||||||
toggleItemSelection(itemView, true, pos)
|
toggleItemSelection(this, true, pos)
|
||||||
actMode?.invalidate()
|
actMode?.invalidate()
|
||||||
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
true
|
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||||
|
(getProperView(this) as FrameLayout).foreground = foregroundColor.createSelector()
|
||||||
|
else
|
||||||
|
getProperView(this).foreground = foregroundColor.createSelector()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
|
||||||
(getProperView(itemView) as FrameLayout).foreground = foregroundColor.createSelector()
|
|
||||||
else
|
|
||||||
getProperView(itemView).foreground = foregroundColor.createSelector()
|
|
||||||
|
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue