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
24809ec5
Commit
24809ec5
authored
Jan 13, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Won't disrupt message reading
parent
575a7ef2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
7 deletions
+46
-7
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+35
-2
ExtRealmModelListAdapter.java
...rocket/android/layouthelper/ExtRealmModelListAdapter.java
+11
-5
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
24809ec5
...
@@ -28,6 +28,7 @@ import chat.rocket.android.helper.LoadMoreScrollListener;
...
@@ -28,6 +28,7 @@ import chat.rocket.android.helper.LoadMoreScrollListener;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.OnBackPressListener
;
import
chat.rocket.android.helper.OnBackPressListener
;
import
chat.rocket.android.helper.TextUtils
;
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.MessageFormManager
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
...
@@ -70,6 +71,17 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -70,6 +71,17 @@ public class RoomFragment extends AbstractChatRoomFragment
private
LoadMoreScrollListener
scrollListener
;
private
LoadMoreScrollListener
scrollListener
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageFormManager
messageFormManager
;
private
MessageFormManager
messageFormManager
;
private
LinearLayoutManager
layoutManager
;
private
boolean
userScrolledToEnd
=
true
;
private
ExtRealmModelListAdapter
.
UpdateListener
updateListener
=
count
->
{
if
(
userScrolledToEnd
)
{
scrollToEnd
();
}
else
{
// showNewMessagesAtEndIndicator();
}
};
public
RoomFragment
()
{
public
RoomFragment
()
{
}
}
...
@@ -142,10 +154,10 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -142,10 +154,10 @@ public class RoomFragment extends AbstractChatRoomFragment
listView
.
setAdapter
(
adapter
);
listView
.
setAdapter
(
adapter
);
adapter
.
setOnItemClickListener
(
this
);
adapter
.
setOnItemClickListener
(
this
);
LinearLayoutManager
layoutManager
=
new
LinearLayoutManager
(
getContext
(),
layoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
true
);
LinearLayoutManager
.
VERTICAL
,
true
);
listView
.
setLayoutManager
(
layoutManager
);
listView
.
setLayoutManager
(
layoutManager
);
adapter
.
set
LayoutManager
(
layoutManag
er
);
adapter
.
set
UpdateListener
(
updateListen
er
);
scrollListener
=
new
LoadMoreScrollListener
(
layoutManager
,
40
)
{
scrollListener
=
new
LoadMoreScrollListener
(
layoutManager
,
40
)
{
@Override
@Override
...
@@ -154,6 +166,13 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -154,6 +166,13 @@ public class RoomFragment extends AbstractChatRoomFragment
}
}
};
};
listView
.
addOnScrollListener
(
scrollListener
);
listView
.
addOnScrollListener
(
scrollListener
);
listView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrollStateChanged
(
RecyclerView
recyclerView
,
int
newState
)
{
super
.
onScrollStateChanged
(
recyclerView
,
newState
);
setUserScrolledToEnd
(
newState
);
}
});
setupSideMenu
();
setupSideMenu
();
setupMessageComposer
();
setupMessageComposer
();
...
@@ -373,4 +392,18 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -373,4 +392,18 @@ public class RoomFragment extends AbstractChatRoomFragment
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
protected
void
onExtraActionSelected
(
MessageExtraActionBehavior
action
)
{
action
.
handleItemSelectedOnFragment
(
RoomFragment
.
this
);
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/layouthelper/ExtRealmModelListAdapter.java
View file @
24809ec5
...
@@ -18,7 +18,7 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
...
@@ -18,7 +18,7 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
protected
static
final
int
VIEW_TYPE_HEADER
=
-
1
;
protected
static
final
int
VIEW_TYPE_HEADER
=
-
1
;
protected
static
final
int
VIEW_TYPE_FOOTER
=
-
2
;
protected
static
final
int
VIEW_TYPE_FOOTER
=
-
2
;
private
RecyclerView
.
LayoutManager
layoutManag
er
;
private
UpdateListener
updateListen
er
;
protected
ExtRealmModelListAdapter
(
Context
context
)
{
protected
ExtRealmModelListAdapter
(
Context
context
)
{
super
(
context
);
super
(
context
);
...
@@ -41,16 +41,16 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
...
@@ -41,16 +41,16 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
notifyItemChanged
(
position
+
1
);
notifyItemChanged
(
position
+
1
);
}
}
public
void
set
LayoutManager
(
RecyclerView
.
LayoutManager
layoutManag
er
)
{
public
void
set
UpdateListener
(
UpdateListener
updateListen
er
)
{
this
.
layoutManager
=
layoutManag
er
;
this
.
updateListener
=
updateListen
er
;
}
}
protected
ListUpdateCallback
listUpdateCallback
=
new
ListUpdateCallback
()
{
protected
ListUpdateCallback
listUpdateCallback
=
new
ListUpdateCallback
()
{
@Override
@Override
public
void
onInserted
(
int
position
,
int
count
)
{
public
void
onInserted
(
int
position
,
int
count
)
{
notifyItemRangeInserted
(
position
+
1
,
count
);
notifyItemRangeInserted
(
position
+
1
,
count
);
if
(
layoutManag
er
!=
null
)
{
if
(
updateListen
er
!=
null
)
{
layoutManager
.
scrollToPosition
(
0
);
updateListener
.
onInserted
(
count
);
}
}
}
}
...
@@ -121,4 +121,10 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
...
@@ -121,4 +121,10 @@ public abstract class ExtRealmModelListAdapter<T extends RealmObject, VM,
public
ListUpdateCallback
getListUpdateCallback
()
{
public
ListUpdateCallback
getListUpdateCallback
()
{
return
listUpdateCallback
;
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