Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
1e2a248d
Commit
1e2a248d
authored
Jan 15, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
call "readMessage" when the latest item is shown.
parent
3983b95f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+3
-0
RecyclerViewScrolledToBottomListener.java
.../android/helper/RecyclerViewScrolledToBottomListener.java
+67
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
1e2a248d
...
...
@@ -28,6 +28,7 @@ import chat.rocket.android.helper.LoadMoreScrollListener;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.OnBackPressListener
;
import
chat.rocket.android.helper.RecyclerViewAutoScrollManager
;
import
chat.rocket.android.helper.RecyclerViewScrolledToBottomListener
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.MessageFormManager
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
...
...
@@ -157,6 +158,8 @@ public class RoomFragment extends AbstractChatRoomFragment
}
};
listView
.
addOnScrollListener
(
scrollListener
);
listView
.
addOnScrollListener
(
new
RecyclerViewScrolledToBottomListener
(
layoutManager
,
1
,
this
::
markAsReadIfNeeded
));
setupSideMenu
();
setupMessageComposer
();
...
...
app/src/main/java/chat/rocket/android/helper/RecyclerViewScrolledToBottomListener.java
0 → 100644
View file @
1e2a248d
package
chat
.
rocket
.
android
.
helper
;
import
android.os.Handler
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
/**
* ScrollListener for detecting scrolled on the bottom of the RecyclerView.
*/
public
class
RecyclerViewScrolledToBottomListener
extends
RecyclerView
.
OnScrollListener
{
/**
* callback.
*/
public
interface
Callback
{
void
onScrolledToBottom
();
}
private
final
LinearLayoutManager
layoutManager
;
private
final
int
thresholdPosition
;
private
final
Handler
handler
;
private
final
Callback
callback
;
/**
* Trigger callback if the bottom item position > thresholdPosition.
*/
public
RecyclerViewScrolledToBottomListener
(
LinearLayoutManager
layoutManager
,
int
thresholdPosition
,
Callback
callback
)
{
this
.
layoutManager
=
layoutManager
;
this
.
thresholdPosition
=
thresholdPosition
;
this
.
callback
=
callback
;
this
.
handler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
android
.
os
.
Message
msg
)
{
onScrollEnd
();
}
};
}
@Override
public
void
onScrolled
(
RecyclerView
recyclerView
,
int
dx
,
int
dy
)
{
super
.
onScrolled
(
recyclerView
,
dx
,
dy
);
handler
.
removeMessages
(
0
);
handler
.
sendEmptyMessageDelayed
(
0
,
120
);
}
private
void
onScrollEnd
()
{
if
(
layoutManager
.
getReverseLayout
())
{
if
(
layoutManager
.
findFirstVisibleItemPosition
()
<=
thresholdPosition
)
{
doCallback
();
}
}
else
{
if
(
layoutManager
.
findLastVisibleItemPosition
()
>=
thresholdPosition
)
{
doCallback
();
}
}
}
private
void
doCallback
()
{
if
(
callback
!=
null
)
{
callback
.
onScrolledToBottom
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment