Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 7f36ce5

Browse files
committed
Add new messages to new headers
1 parent 93d71d7 commit 7f36ce5

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

app/src/main/java/com/zulip/android/activities/MessageListFragment.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
151151
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
152152
mListener.recyclerViewScrolled();
153153
final int near = 6;
154-
if (!paused && !loadingMessages && firstMessageId > 0 && lastMessageId > 0) {
155-
int lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition();
156-
if (lastVisiblePosition > adapter.getItemCount(false) - near) { // At the bottom of the list
157-
Log.i("scroll", "Starting request below");
158-
loadMoreMessages(LoadPosition.BELOW);
159-
}
160-
if (linearLayoutManager.findFirstCompletelyVisibleItemPosition() < near && !loadedToTop) {
161-
// At the top of the list
162-
Log.i("scroll", "Starting request above");
163-
loadMoreMessages(LoadPosition.ABOVE);
154+
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
155+
if (!paused && !loadingMessages && firstMessageId > 0 && lastMessageId > 0) {
156+
int lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition();
157+
if (lastVisiblePosition > adapter.getItemCount(false) - near) { // At the bottom of the list
158+
Log.i("scroll", "Starting request below");
159+
loadMoreMessages(LoadPosition.BELOW);
160+
}
161+
if (linearLayoutManager.findFirstCompletelyVisibleItemPosition() < near && !loadedToTop) {
162+
// At the top of the list
163+
Log.i("scroll", "Starting request above");
164+
loadMoreMessages(LoadPosition.ABOVE);
165+
}
164166
}
165167
}
166168
}
@@ -360,7 +362,7 @@ public void onMessages(Message[] messages, LoadPosition pos,
360362
}
361363

362364
if (pos == LoadPosition.NEW || pos == LoadPosition.BELOW) {
363-
this.adapter.addMessage(message);
365+
this.adapter.addNewMessage(message);
364366
messageList.add(message);
365367
} else if (pos == LoadPosition.ABOVE || pos == LoadPosition.INITIAL) {
366368
headerParents = (this.adapter.addMessage(message, addedCount + headerParents)) ? headerParents + 1 : headerParents;

app/src/main/java/com/zulip/android/activities/RecyclerMessageAdapter.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ public boolean addMessage(Message message, int messageAndHeadersCount) {
214214

215215

216216

217+
public void addNewMessage(Message message) {
218+
MessageHeaderParent item = null;
219+
for (int i = getItemCount(false) - 1; i > 1; i--) {
220+
//Find the last header and check if it belongs to this message!
221+
if (items.get(i) instanceof MessageHeaderParent) {
222+
item = (MessageHeaderParent) items.get(i);
223+
if (!item.getId().equals(message.getIdForHolder())) {
224+
item = null;
225+
}
226+
break;
227+
}
228+
}
229+
if (item == null) {
230+
item = new MessageHeaderParent((message.getStream() == null) ? null :
231+
message.getStream().getName(), message.getSubject(), message.getIdForHolder());
232+
item.setMessageType(message.getType());
233+
item.setDisplayRecipent(message.getDisplayRecipient(zulipApp));
234+
if (message.getType() == MessageType.STREAM_MESSAGE)
235+
item.setMute(zulipApp.isTopicMute(message));
236+
item.setColor((message.getStream() == null) ? mDefaultStreamHeaderColor : message.getStream().getColor());
237+
items.add(getItemCount(true) - 1, item);
238+
notifyItemInserted(getItemCount(true) - 1);
239+
}
240+
items.add(getItemCount(true) - 1, message);
241+
notifyItemInserted(getItemCount(true) - 1);
242+
}
243+
217244

218245
public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
219246
switch (viewType) {

0 commit comments

Comments
 (0)