Skip to content

Commit

Permalink
[BUGFIX] Invalid scroll position when hiding all comments by default (#…
Browse files Browse the repository at this point in the history
…173)

* Function name typo

* Simplify scrollToComment method

* Expand and properly scroll to comment.

If the hideAllComments option is enabled look expand parent and properly find an index of target child comment.
  • Loading branch information
michaldrabik authored and feelfreelinux committed Feb 11, 2019
1 parent 679e506 commit cc33210
Showing 1 changed file with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,39 @@ class LinkDetailsActivity : BaseActivity(), LinkDetailsView, androidx.swiperefre
adapter.notifyDataSetChanged()
inputToolbar.show()
if (linkCommentId != -1 && adapter.link != null) {
scrollToComment(linkCommentId)
if (settingsApi.hideLinkCommentsByDefault) {
expandAndScrollToComment(linkCommentId)
} else {
scrollToComment(linkCommentId)
}
}
}

override fun scrollToComment(id: Int) {
adapter.link!!.comments.forEachIndexed({ index, comment ->
if (comment.id == id) {
recyclerView?.scrollToPosition(index + 1)
private fun expandAndScrollToComment(linkCommentId: Int) {
adapter.link?.comments?.let { allComments ->
val parentId = allComments.find { it.id == linkCommentId }?.parentId
allComments.forEach {
if (it.parentId == parentId) {
it.isCollapsed = false
it.isParentCollapsed = false
}
}
})
}
adapter.notifyDataSetChanged()

val comments = adapter.link!!.comments
var index = 0
for (i in 0 until comments.size) {
if (!comments[i].isParentCollapsed) index++
if (comments[i].id == linkCommentId) break
}

recyclerView?.scrollToPosition(index + 1)
}

override fun scrollToComment(id: Int) {
val index = adapter.link!!.comments.indexOfFirst { it.id == id }
recyclerView?.scrollToPosition(index + 1)
}

override fun updateLink(link: Link) {
Expand Down

0 comments on commit cc33210

Please sign in to comment.