Skip to content

Commit

Permalink
modify caching view in the PostListAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjs committed Jul 18, 2017
1 parent 72e8376 commit 1aa74e2
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PostListAdapter : RecyclerView.Adapter<PostListAdapter.ViewHolder>() {

var preLoader: ((Long) -> Unit)? = null

var viewCaches = hashMapOf<Long, View>()
var viewCaches = LinkedHashMap<Long, View>(50)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val frame = FrameLayout(parent.context)
Expand All @@ -41,22 +41,15 @@ class PostListAdapter : RecyclerView.Adapter<PostListAdapter.ViewHolder>() {

setupBodies(this@itemView, post)

} else if (childCount == 1) {
val child = getChildAt(0)
if (post != (child.tag as? Post)) {
this@itemView.removeView(child)

setupBodies(this@itemView, post)
} else {

}
} else {

this@itemView.removeAllViews()
viewCaches[post.id]?.let {
this@itemView.addView(it)
} ?: let {
setupBodies(this@itemView, post)
}

}
}

Expand Down

0 comments on commit 1aa74e2

Please # to comment.