Skip to content

Commit 71ba528

Browse files
author
Stefano Mtangoo
committed
Add API methods for accessing current object position in the Adapter
1 parent 0346643 commit 71ba528

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

messagekit/src/main/java/tz/co/hosannahighertech/messagekit/messages/MessagesListAdapter.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,35 @@ public void clear(boolean notifyDataSetChanged) {
370370
}
371371
}
372372

373+
/**
374+
* Get the message position in the recyclerview
375+
*
376+
* @param messageId Message ID
377+
* @return 0 based position of the message in the adapter
378+
*/
379+
@SuppressWarnings("unchecked")
380+
public int getMessagePosition(String messageId) {
381+
for (int position = 0; position < items.size(); position++) {
382+
if ((items.get(position).item instanceof IMessage)) {
383+
MESSAGE item = (MESSAGE) items.get(position).item;
384+
if(item.getId().equals(messageId)){
385+
return position;
386+
}
387+
}
388+
}
389+
return -1;
390+
}
391+
392+
/**
393+
* Get the message position in the recyclerview
394+
*
395+
* @param message Message
396+
* @return 0 based position of the message in the adapter
397+
*/
398+
public int getMessagePosition(MESSAGE message) {
399+
return getMessagePosition(message.getId());
400+
}
401+
373402
/**
374403
* Enables selection mode.
375404
*

0 commit comments

Comments
 (0)