Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added upsert(Message) method to add or update message to adapter as appropriate #61

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -178,8 +178,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 @@ -188,12 +188,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