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
3983b95f
Commit
3983b95f
authored
Jan 15, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace onUpdateListener with a general RecyclerView.AdapterDataObserver.
parent
29235d30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
52 deletions
+39
-52
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+14
-37
RecyclerViewAutoScrollManager.java
.../rocket/android/helper/RecyclerViewAutoScrollManager.java
+25
-0
ExtRealmModelListAdapter.java
...rocket/android/layouthelper/ExtRealmModelListAdapter.java
+0
-15
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
3983b95f
...
...
@@ -27,17 +27,17 @@ import chat.rocket.android.helper.FileUploadHelper;
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.TextUtils
;
import
chat.rocket.android.layouthelper.ExtRealmModelListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.MessageFormManager
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
import
chat.rocket.android.layouthelper.extra_action.MessageExtraActionBehavior
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
...
...
@@ -71,17 +71,7 @@ public class RoomFragment extends AbstractChatRoomFragment
private
LoadMoreScrollListener
scrollListener
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageFormManager
messageFormManager
;
private
LinearLayoutManager
layoutManager
;
private
boolean
userScrolledToEnd
=
true
;
private
ExtRealmModelListAdapter
.
UpdateListener
updateListener
=
count
->
{
if
(
userScrolledToEnd
)
{
scrollToEnd
();
}
else
{
// showNewMessagesAtEndIndicator();
}
};
private
RecyclerViewAutoScrollManager
autoScrollManager
;
public
RoomFragment
()
{
}
...
...
@@ -154,10 +144,11 @@ public class RoomFragment extends AbstractChatRoomFragment
listView
.
setAdapter
(
adapter
);
adapter
.
setOnItemClickListener
(
this
);
layoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
layoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
true
);
listView
.
setLayoutManager
(
layoutManager
);
adapter
.
setUpdateListener
(
updateListener
);
autoScrollManager
=
new
RecyclerViewAutoScrollManager
(
layoutManager
);
adapter
.
registerAdapterDataObserver
(
autoScrollManager
);
scrollListener
=
new
LoadMoreScrollListener
(
layoutManager
,
40
)
{
@Override
...
...
@@ -166,18 +157,18 @@ public class RoomFragment extends AbstractChatRoomFragment
}
};
listView
.
addOnScrollListener
(
scrollListener
);
listView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrollStateChanged
(
RecyclerView
recyclerView
,
int
newState
)
{
super
.
onScrollStateChanged
(
recyclerView
,
newState
);
setUserScrolledToEnd
(
newState
);
}
});
setupSideMenu
();
setupMessageComposer
();
}
@Override
public
void
onDestroyView
()
{
RecyclerView
listView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
recyclerview
);
listView
.
getAdapter
().
unregisterAdapterDataObserver
(
autoScrollManager
);
super
.
onDestroyView
();
}
@Override
public
void
onItemClick
(
PairedMessage
pairedMessage
)
{
if
(
pairedMessage
.
target
!=
null
)
{
...
...
@@ -392,18 +383,4 @@ public class RoomFragment extends AbstractChatRoomFragment
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragment
(
RoomFragment
.
this
);
}
private
void
setUserScrolledToEnd
(
int
newState
)
{
if
(
newState
==
RecyclerView
.
SCROLL_STATE_DRAGGING
||
newState
==
RecyclerView
.
SCROLL_STATE_IDLE
)
{
userScrolledToEnd
=
layoutManager
.
findFirstCompletelyVisibleItemPosition
()
==
1
;
}
}
private
void
scrollToEnd
()
{
if
(
layoutManager
==
null
)
{
return
;
}
layoutManager
.
scrollToPosition
(
0
);
}
}
app/src/main/java/chat/rocket/android/helper/RecyclerViewAutoScrollManager.java
0 → 100644
View file @
3983b95f
package
chat
.
rocket
.
android
.
helper
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
/**
* workaround for bug https://code.google.com/p/android/issues/detail?id=174227
*/
public
class
RecyclerViewAutoScrollManager
extends
RecyclerView
.
AdapterDataObserver
{
private
final
LinearLayoutManager
linearLayoutManager
;
public
RecyclerViewAutoScrollManager
(
LinearLayoutManager
linearLayoutManager
)
{
this
.
linearLayoutManager
=
linearLayoutManager
;
}
@Override
public
void
onItemRangeInserted
(
int
positionStart
,
int
itemCount
)
{
super
.
onItemRangeInserted
(
positionStart
,
itemCount
);
if
(
linearLayoutManager
.
findFirstVisibleItemPosition
()
<=
positionStart
)
{
linearLayoutManager
.
scrollToPosition
(
positionStart
);
}
}
}
app/src/main/java/chat/rocket/android/layouthelper/ExtRealmModelListAdapter.java
View file @
3983b95f
...
...
@@ -17,8 +17,6 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
protected
static
final
int
VIEW_TYPE_HEADER
=
-
1
;
protected
static
final
int
VIEW_TYPE_FOOTER
=
-
2
;
private
UpdateListener
updateListener
;
protected
ExtRealmModelListAdapter
(
Context
context
)
{
super
(
context
);
}
...
...
@@ -40,17 +38,10 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
notifyItemChanged
(
position
+
1
);
}
public
void
setUpdateListener
(
UpdateListener
updateListener
)
{
this
.
updateListener
=
updateListener
;
}
private
final
ListUpdateCallback
listUpdateCallback
=
new
ListUpdateCallback
()
{
@Override
public
void
onInserted
(
int
position
,
int
count
)
{
notifyItemRangeInserted
(
position
+
1
,
count
);
if
(
updateListener
!=
null
)
{
updateListener
.
onInserted
(
count
);
}
}
@Override
...
...
@@ -120,10 +111,4 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
protected
ListUpdateCallback
getListUpdateCallback
()
{
return
listUpdateCallback
;
}
// We'll be using the insert event only as of now
// Let's add more events when/if needed
public
interface
UpdateListener
{
void
onInserted
(
int
count
);
}
}
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