Skip to content

Commit

Permalink
Fixed: metadata position was not correct sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
idanatz committed Feb 27, 2023
1 parent 6f81962 commit b553171
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Version 2.1.4
-------------
* Fixed: metadata position was not correct sometimes

Version 2.1.3
-------------
* Fixed: timing bug when paging would sometimes not start when initial data was below threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ internal class InternalAdapter(val recyclerView: RecyclerView) : RecyclerView.Ad
return oneViewHolder
}

override fun onBindViewHolder(holder: OneViewHolder<Diffable>, position: Int) {
val model = data[position]
val isFirstBind = holderPositionHandler.isFirstBind(holder.itemViewType, position)
override fun onBindViewHolder(holder: OneViewHolder<Diffable>, position: Int) {
val model = data[position]
val isFirstBind = holderPositionHandler.isFirstBind(holder.itemViewType, position)
val metadata = Metadata(
position = position,
isRebinding = !isFirstBind && !recyclerView.isScrolling,
animationMetadata = object : AnimationMetadata {
override val isAnimatingFirstBind: Boolean = if (holder.firstBindAnimation != null) isFirstBind else false
},
selectionMetadata = object : SelectionMetadata {
override val isSelected: Boolean = isPositionSelected(position)
}
position = holder.adapterPosition, // don't use position variable, caused bugs with swiping
isRebinding = !isFirstBind && !recyclerView.isScrolling,
animationMetadata = object : AnimationMetadata {
override val isAnimatingFirstBind: Boolean = if (holder.firstBindAnimation != null) isFirstBind else false
},
selectionMetadata = object : SelectionMetadata {
override val isSelected: Boolean = isPositionSelected(position)
}
)
logger.logd { "onBindViewHolder -> holder: $holder, model: $model, metadata: $metadata" }
holder.onBindViewHolder(model, metadata)
}
}

private fun onBindSelection(holder: OneViewHolder<Diffable>, position: Int, selected: Boolean) {
val model = data[position]
Expand Down
2 changes: 1 addition & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
MAJOR_VERSION = 2
MINOR_VERSION = 1
HOTFIX_VERSION = 3
HOTFIX_VERSION = 4

VERSION_NAME = "${MAJOR_VERSION}.${MINOR_VERSION}.${HOTFIX_VERSION}"
VERSION_CODE = MAJOR_VERSION * 10000 + MINOR_VERSION * 100 + HOTFIX_VERSION
Expand Down

0 comments on commit b553171

Please sign in to comment.