Unverified Commit 4b47b911 authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge pull request #1035 from RocketChat/fix/chatroom-crash

[FIX] Crash on Chat Room screen
parents eea3cb16 9914172c
...@@ -205,17 +205,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -205,17 +205,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
adapter = ChatRoomAdapter(chatRoomType, chatRoomName, presenter, adapter = ChatRoomAdapter(chatRoomType, chatRoomName, presenter,
reactionListener = this@ChatRoomFragment) reactionListener = this@ChatRoomFragment)
recycler_view.adapter = adapter recycler_view.adapter = adapter
val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
linearLayoutManager.stackFromEnd = true
recycler_view.layoutManager = linearLayoutManager
recycler_view.itemAnimator = DefaultItemAnimator()
if (dataSet.size >= 30) { if (dataSet.size >= 30) {
endlessRecyclerViewScrollListener = object :
EndlessRecyclerViewScrollListener(recycler_view.layoutManager as LinearLayoutManager) {
override fun onLoadMore(page: Int, totalItemsCount: Int, recyclerView: RecyclerView?) {
presenter.loadMessages(chatRoomId, chatRoomType, page * 30L)
}
}
recycler_view.addOnScrollListener(endlessRecyclerViewScrollListener) recycler_view.addOnScrollListener(endlessRecyclerViewScrollListener)
} }
recycler_view.addOnLayoutChangeListener(layoutChangeListener) recycler_view.addOnLayoutChangeListener(layoutChangeListener)
...@@ -275,6 +265,18 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -275,6 +265,18 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
} }
private val fabScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!recyclerView.canScrollVertically(1)) {
button_fab.hide()
} else {
if (dy < 0 && !button_fab.isVisible()) {
button_fab.show()
}
}
}
}
override fun sendMessage(text: String) { override fun sendMessage(text: String) {
if (!text.isBlank()) { if (!text.isBlank()) {
if (!text.startsWith("/")) { if (!text.startsWith("/")) {
...@@ -473,17 +475,18 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -473,17 +475,18 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
private fun setupRecyclerView() { private fun setupRecyclerView() {
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() { // Initialize the endlessRecyclerViewScrollListener so we don't NPE at onDestroyView
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
if (!recyclerView.canScrollVertically(1)) { linearLayoutManager.stackFromEnd = true
button_fab.hide() recycler_view.layoutManager = linearLayoutManager
} else { recycler_view.itemAnimator = DefaultItemAnimator()
if (dy < 0 && !button_fab.isVisible()) { endlessRecyclerViewScrollListener = object :
button_fab.show() EndlessRecyclerViewScrollListener(recycler_view.layoutManager as LinearLayoutManager) {
} override fun onLoadMore(page: Int, totalItemsCount: Int, recyclerView: RecyclerView?) {
} presenter.loadMessages(chatRoomId, chatRoomType, page * 30L)
} }
}) }
recycler_view.addOnScrollListener(fabScrollListener)
} }
private fun setupFab() { private fun setupFab() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment