Skip to content

Commit

Permalink
Merge pull request #61 from hbmartin/master
Browse files Browse the repository at this point in the history
Added upsert(Message) method to add or update message to adapter as appropriate
  • Loading branch information
bevzaanton authored Jul 10, 2018
2 parents dc881f4 + 86b2a86 commit 97a6c1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 0 additions & 4 deletions chatkit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stfalcon.chatkit">

<application
android:allowBackup="true"
android:supportsRtl="true"/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public void addToEnd(List<MESSAGE> messages, boolean reverse) {
*
* @param message updated message object.
*/
public void update(MESSAGE message) {
update(message.getId(), message);
public boolean update(MESSAGE message) {
return update(message.getId(), message);
}

/**
Expand All @@ -190,12 +190,26 @@ public void update(MESSAGE message) {
* @param oldId an identifier of message to update.
* @param newMessage new message object.
*/
public void update(String oldId, MESSAGE newMessage) {
public boolean update(String oldId, MESSAGE newMessage) {
int position = getMessagePositionById(oldId);
if (position >= 0) {
Wrapper<MESSAGE> element = new Wrapper<>(newMessage);
items.set(position, element);
notifyItemChanged(position);
return true;
} else {
return false;
}
}

/**
* Updates message by its id if it exists, add to start if not
*
* @param message message object to insert or update.
*/
public void upsert(MESSAGE message) {
if (!update(message)) {
addToStart(message, false);
}
}

Expand Down

0 comments on commit 97a6c1d

Please sign in to comment.