diff --git a/build.gradle b/build.gradle
index 3fda7a4b4..1ce7ac317 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.3'
+ classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:2.0.0-beta2'
}
}
@@ -16,6 +16,7 @@ allprojects {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
+
}
ext {
@@ -31,9 +32,9 @@ ext {
lintAbortOnError = false
// QuickBlox SDK version
- qbSdkVersion = '2.6.1'
+ qbSdkVersion = '3.0'
- versionName = "2.6.1"
+ versionName = "3.0"
testRunnerVersion = "0.4.1"
diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle
index 7116c3642..b5deb52d6 100644
--- a/sample-chat/build.gradle
+++ b/sample-chat/build.gradle
@@ -1,4 +1,20 @@
+buildscript {
+ repositories {
+ maven { url 'https://maven.fabric.io/public' }
+ }
+
+ dependencies {
+ classpath 'io.fabric.tools:gradle:1.20.1'
+ }
+}
+
+
apply plugin: 'com.android.application'
+apply plugin: 'io.fabric'
+
+repositories {
+ maven { url 'https://maven.fabric.io/public' }
+}
android {
compileSdkVersion rootProject.compileSdkVersion
@@ -9,7 +25,7 @@ android {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 201
- versionName "2.0.3"
+ versionName "3.0"
}
productFlavors {
@@ -29,6 +45,10 @@ android {
proguardFile 'proguard-rules.pro'
zipAlignEnabled false
}
+
+ release {
+ signingConfig signingConfigs.debug
+ }
}
signingConfigs {
@@ -40,6 +60,11 @@ android {
}
}
+ lintOptions {
+ abortOnError false
+ }
+
+
}
@@ -52,7 +77,6 @@ dependencies {
compile "com.google.android.gms:play-services-gcm:${rootProject.playServicesVersion}"
compile "com.github.bumptech.glide:glide:${rootProject.glideVersion}"
compile "se.emilsjolander:stickylistheaders:${rootProject.stickyListHeaders}"
- compile 'com.google.android.gms:play-services-gcm:8.4.0'
}
apply from: "../artifacts.gradle"
diff --git a/sample-chat/fabric.properties b/sample-chat/fabric.properties
new file mode 100755
index 000000000..3e56afcff
--- /dev/null
+++ b/sample-chat/fabric.properties
@@ -0,0 +1,3 @@
+#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public.
+#Wed Mar 25 11:57:04 GMT+02:00 2015
+apiSecret=343e58f13448a59778de3a8f630a0bd4a03803d1ae397818fbe2e76c66d09398
diff --git a/sample-chat/src/main/AndroidManifest.xml b/sample-chat/src/main/AndroidManifest.xml
index fc15a7bd2..679fa0017 100644
--- a/sample-chat/src/main/AndroidManifest.xml
+++ b/sample-chat/src/main/AndroidManifest.xml
@@ -93,5 +93,9 @@
+
+
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/managers/DialogsManager.java b/sample-chat/src/main/java/com/quickblox/sample/chat/managers/DialogsManager.java
new file mode 100644
index 000000000..819cf0f63
--- /dev/null
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/managers/DialogsManager.java
@@ -0,0 +1,163 @@
+package com.quickblox.sample.chat.managers;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+
+import com.quickblox.chat.QBChatService;
+import com.quickblox.chat.QBSystemMessagesManager;
+import com.quickblox.chat.model.QBChatDialog;
+import com.quickblox.chat.model.QBChatMessage;
+import com.quickblox.chat.model.QBDialogType;
+import com.quickblox.sample.chat.utils.chat.ChatHelper;
+import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
+import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
+import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackImpl;
+import com.quickblox.users.model.QBUser;
+
+import org.jivesoftware.smack.SmackException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+public class DialogsManager {
+
+ public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids";
+ public static final String PROPERTY_DIALOG_TYPE = "dialog_type";
+ public static final String PROPERTY_DIALOG_NAME = "dialog_name";
+ public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type";
+ public static final String CREATING_DIALOG = "creating_dialog";
+
+ private Set managingDialogsCallbackListener = new CopyOnWriteArraySet<>();
+
+ private boolean isMessageCreatingDialog(QBChatMessage systemMessage){
+ return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE));
+ }
+
+ private QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){
+ QBChatMessage qbChatMessage = new QBChatMessage();
+ qbChatMessage.setDialogId(dialog.getDialogId());
+ qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, QbDialogUtils.getOccupantsIdsStringFromList(dialog.getOccupants()));
+ qbChatMessage.setProperty(PROPERTY_DIALOG_TYPE, String.valueOf(dialog.getType().getCode()));
+ qbChatMessage.setProperty(PROPERTY_DIALOG_NAME, String.valueOf(dialog.getName()));
+ qbChatMessage.setProperty(PROPERTY_NOTIFICATION_TYPE, CREATING_DIALOG);
+
+ return qbChatMessage;
+ }
+
+ private QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChatMessage){
+ QBChatDialog chatDialog = new QBChatDialog();
+ chatDialog.setDialogId(qbChatMessage.getDialogId());
+ chatDialog.setOccupantsIds(QbDialogUtils.getOccupantsIdsListFromString((String) qbChatMessage.getProperty(PROPERTY_OCCUPANTS_IDS)));
+ chatDialog.setType(QBDialogType.parseByCode(Integer.parseInt(qbChatMessage.getProperty(PROPERTY_DIALOG_TYPE).toString())));
+ chatDialog.setName(qbChatMessage.getProperty(PROPERTY_DIALOG_NAME).toString());
+ chatDialog.setUnreadMessageCount(0);
+
+ return chatDialog;
+ }
+
+ public void sendSystemMessageAboutCreatingDialog(QBSystemMessagesManager systemMessagesManager, QBChatDialog dialog) {
+ QBChatMessage systemMessageCreatingDialog = buildSystemMessageAboutCreatingGroupDialog(dialog);
+
+ try {
+ for (Integer recipientId : dialog.getOccupants()) {
+ if (!recipientId.equals(QBChatService.getInstance().getUser().getId())) {
+ systemMessageCreatingDialog.setRecipientId(recipientId);
+ systemMessagesManager.sendSystemMessage(systemMessageCreatingDialog);
+ }
+ }
+ } catch (SmackException.NotConnectedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void loadUsersFromDialog(QBChatDialog chatDialog){
+ ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl>());
+ }
+
+ public void onGlobalMessageReceived(String dialogId, QBChatMessage chatMessage){
+ if (chatMessage.getBody() != null && chatMessage.isMarkable()) { //for excluding status messages until will be released v.3.1
+ if (QbDialogHolder.getInstance().hasDialogWithId(dialogId)) {
+ QbDialogHolder.getInstance().updateDialog(dialogId, chatMessage);
+ notifyListenersDialogUpdated(dialogId);
+ } else {
+ ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl() {
+ @Override
+ public void onSuccess(QBChatDialog chatDialog, Bundle bundle) {
+ loadUsersFromDialog(chatDialog);
+ QbDialogHolder.getInstance().addDialog(chatDialog);
+ notifyListenersNewDialogLoaded(chatDialog);
+ }
+ });
+ }
+ }
+ }
+
+ public void onSystemMessageReceived(QBChatMessage systemMessage){
+ if (isMessageCreatingDialog(systemMessage)) {
+ QBChatDialog chatDialog = buildChatDialogFromSystemMessage(systemMessage);
+ chatDialog.initForChat(QBChatService.getInstance());
+ QbDialogHolder.getInstance().addDialog(chatDialog);
+ notifyListenersDialogCreated(chatDialog);
+ }
+ }
+
+ private void notifyListenersDialogCreated(final QBChatDialog chatDialog){
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
+ listener.onDialogCreated(chatDialog);
+ }
+ }
+ });
+ }
+
+ private void notifyListenersDialogUpdated(final String dialogId){
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
+ listener.onDialogUpdated(dialogId);
+ }
+ }
+ });
+ }
+
+ private void notifyListenersNewDialogLoaded(final QBChatDialog chatDialog){
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
+ listener.onNewDialogLoaded(chatDialog);
+ }
+ }
+ });
+ }
+
+ public void addManagingDialogsCallbackListener(ManagingDialogsCallbacks listener){
+ if (listener != null){
+ managingDialogsCallbackListener.add(listener);
+ }
+ }
+
+ public void removeManagingDialogsCallbackListener(ManagingDialogsCallbacks listener) {
+ managingDialogsCallbackListener.remove(listener);
+ }
+
+ public Collection getManagingDialogsCallbackListeners() {
+ return Collections.unmodifiableCollection(managingDialogsCallbackListener);
+ }
+
+ public interface ManagingDialogsCallbacks{
+
+ void onDialogCreated(QBChatDialog chatDialog);
+
+ void onDialogUpdated(String chatDialog);
+
+ void onNewDialogLoaded(QBChatDialog chatDialog);
+ }
+}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatActivity.java
index 883c5fb24..5d185a6f4 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatActivity.java
@@ -15,10 +15,9 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;
-import com.quickblox.chat.QBChat;
import com.quickblox.chat.model.QBAttachment;
import com.quickblox.chat.model.QBChatMessage;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.chat.model.QBDialogType;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
@@ -26,12 +25,10 @@
import com.quickblox.sample.chat.ui.adapter.AttachmentPreviewAdapter;
import com.quickblox.sample.chat.ui.adapter.ChatAdapter;
import com.quickblox.sample.chat.ui.widget.AttachmentPreviewAdapterView;
-import com.quickblox.sample.chat.utils.chat.Chat;
import com.quickblox.sample.chat.utils.chat.ChatHelper;
-import com.quickblox.sample.chat.utils.chat.GroupChatImpl;
-import com.quickblox.sample.chat.utils.chat.PrivateChatImpl;
-import com.quickblox.sample.chat.utils.chat.QBChatMessageListener;
import com.quickblox.sample.chat.utils.qb.PaginationHistoryListener;
+import com.quickblox.sample.chat.utils.qb.QbChatDialogMessageListenerImp;
+import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
import com.quickblox.sample.chat.utils.qb.VerboseQbChatConnectionListener;
import com.quickblox.sample.core.ui.dialog.ProgressDialogFragment;
@@ -57,10 +54,8 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener
private static final int REQUEST_CODE_ATTACHMENT = 721;
private static final int REQUEST_CODE_SELECT_PEOPLE = 752;
- private static final String EXTRA_DIALOG = "dialog";
private static final String PROPERTY_SAVE_TO_HISTORY = "save_to_history";
- public static final String EXTRA_MARK_READ = "markRead";
public static final String EXTRA_DIALOG_ID = "dialogId";
private ProgressBar progressBar;
@@ -74,15 +69,14 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener
private AttachmentPreviewAdapter attachmentPreviewAdapter;
private ConnectionListener chatConnectionListener;
- private Chat chat;
- private QBDialog qbDialog;
- private ArrayList chatMessageIds;
+ private QBChatDialog qbChatDialog;
private ArrayList unShownMessages;
private int skipPagination = 0;
+ private ChatMessageListener chatMessageListener;
- public static void startForResult(Activity activity, int code, QBDialog dialog) {
+ public static void startForResult(Activity activity, int code, String dialogId) {
Intent intent = new Intent(activity, ChatActivity.class);
- intent.putExtra(ChatActivity.EXTRA_DIALOG, dialog);
+ intent.putExtra(ChatActivity.EXTRA_DIALOG_ID, dialogId);
activity.startActivityForResult(intent, code);
}
@@ -91,8 +85,14 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
- qbDialog = (QBDialog) getIntent().getSerializableExtra(EXTRA_DIALOG);
- chatMessageIds = new ArrayList<>();
+ Log.v("ChatHelper", "onCreate ChatActivity on Thread ID = " + Thread.currentThread().getId());
+
+ qbChatDialog = QbDialogHolder.getInstance().getChatDialogById(
+ getIntent().getStringExtra(EXTRA_DIALOG_ID));
+ chatMessageListener = new ChatMessageListener();
+
+ qbChatDialog.addMessageListener(chatMessageListener);
+
initChatConnectionListener();
initViews();
@@ -100,8 +100,8 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
- if (qbDialog != null) {
- outState.putSerializable(EXTRA_DIALOG, qbDialog);
+ if (qbChatDialog != null) {
+ outState.putString(EXTRA_DIALOG_ID, qbChatDialog.getDialogId());
}
super.onSaveInstanceState(outState, outPersistentState);
}
@@ -109,8 +109,8 @@ public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistent
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
- if (qbDialog == null) {
- qbDialog = (QBDialog) savedInstanceState.getSerializable(EXTRA_DIALOG);
+ if (qbChatDialog == null) {
+ qbChatDialog = QbDialogHolder.getInstance().getChatDialogById(savedInstanceState.getString(EXTRA_DIALOG_ID));
}
}
@@ -129,7 +129,7 @@ protected void onPause() {
@Override
public void onBackPressed() {
releaseChat();
- sendReadMessageId();
+ sendDialogId();
super.onBackPressed();
}
@@ -148,7 +148,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
MenuItem menuItemLeave = menu.findItem(R.id.menu_chat_action_leave);
MenuItem menuItemAdd = menu.findItem(R.id.menu_chat_action_add);
MenuItem menuItemDelete = menu.findItem(R.id.menu_chat_action_delete);
- if (qbDialog.getType() == QBDialogType.PRIVATE) {
+ if (qbChatDialog.getType() == QBDialogType.PRIVATE) {
menuItemLeave.setVisible(false);
menuItemAdd.setVisible(false);
} else {
@@ -163,11 +163,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.menu_chat_action_info:
- ChatInfoActivity.start(this, qbDialog);
+ ChatInfoActivity.start(this, qbChatDialog);
return true;
case R.id.menu_chat_action_add:
- SelectUsersActivity.startForResult(this, REQUEST_CODE_SELECT_PEOPLE, qbDialog);
+ SelectUsersActivity.startForResult(this, REQUEST_CODE_SELECT_PEOPLE, qbChatDialog);
return true;
case R.id.menu_chat_action_leave:
@@ -187,20 +187,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}
- private void sendReadMessageId() {
+ private void sendDialogId() {
Intent result = new Intent();
- result.putExtra(EXTRA_MARK_READ, chatMessageIds);
- result.putExtra(EXTRA_DIALOG_ID, qbDialog.getDialogId());
+ result.putExtra(EXTRA_DIALOG_ID, qbChatDialog.getDialogId());
setResult(RESULT_OK, result);
}
private void leaveGroupChat() {
- ((GroupChatImpl) chat).leaveChatRoom();
ProgressDialogFragment.show(getSupportFragmentManager());
- ChatHelper.getInstance().leaveDialog(qbDialog, new QBEntityCallback() {
+ ChatHelper.getInstance().exitFromDialog(qbChatDialog, new QBEntityCallback() {
@Override
- public void onSuccess(QBDialog qbDialog, Bundle bundle) {
+ public void onSuccess(QBChatDialog qbDialog, Bundle bundle) {
ProgressDialogFragment.hide(getSupportFragmentManager());
+ QbDialogHolder.getInstance().deleteDialog(qbDialog);
finish();
}
@@ -329,11 +328,17 @@ private void sendChatMessage(String text, QBAttachment attachment) {
}
chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
chatMessage.setDateSent(System.currentTimeMillis() / 1000);
+ chatMessage.setMarkable(true);
+
+ if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType()) && !qbChatDialog.isJoined()){
+ Toaster.shortToast("You're still joining a group chat, please wait a bit");
+ return;
+ }
try {
- chat.sendMessage(chatMessage);
+ qbChatDialog.sendMessage(chatMessage);
- if (qbDialog.getType() == QBDialogType.PRIVATE) {
+ if (QBDialogType.PRIVATE.equals(qbChatDialog.getType())) {
showMessage(chatMessage);
}
@@ -342,27 +347,25 @@ private void sendChatMessage(String text, QBAttachment attachment) {
} else {
messageEditText.setText("");
}
- } catch (XMPPException | SmackException e) {
- Log.e(TAG, "Failed to send a message", e);
- Toaster.shortToast(R.string.chat_send_message_error);
+ } catch (SmackException.NotConnectedException e) {
+ Log.w(TAG, e);
+ Toaster.shortToast("Can't send a message, You are not connected to chat");
}
}
private void initChat() {
- switch (qbDialog.getType()) {
+ switch (qbChatDialog.getType()) {
case GROUP:
case PUBLIC_GROUP:
- chat = new GroupChatImpl(chatMessageListener);
joinGroupChat();
break;
case PRIVATE:
- chat = new PrivateChatImpl(chatMessageListener, QbDialogUtils.getOpponentIdForPrivateDialog(qbDialog));
loadDialogUsers();
break;
default:
- Toaster.shortToast(String.format("%s %s", getString(R.string.chat_unsupported_type), qbDialog.getType().name()));
+ Toaster.shortToast(String.format("%s %s", getString(R.string.chat_unsupported_type), qbChatDialog.getType().name()));
finish();
break;
}
@@ -370,8 +373,7 @@ private void initChat() {
private void joinGroupChat() {
progressBar.setVisibility(View.VISIBLE);
-
- ((GroupChatImpl) chat).joinGroupChat(qbDialog, new QBEntityCallback() {
+ ChatHelper.getInstance().join(qbChatDialog, new QBEntityCallback() {
@Override
public void onSuccess(Void result, Bundle b) {
if (snackbar != null) {
@@ -388,28 +390,26 @@ public void onError(QBResponseException e) {
});
}
- private void leaveGroupChatRoom() {
- if (chat != null) {
- ((GroupChatImpl) chat).leaveChatRoom();
+ private void leaveGroupDialog() {
+ try {
+ ChatHelper.getInstance().leaveChatDialog(qbChatDialog);
+ } catch (XMPPException | SmackException.NotConnectedException e) {
+ Log.w(TAG, e);
}
}
private void releaseChat() {
- try {
- if (chat != null) {
- chat.release();
- }
- } catch (XMPPException e) {
- Log.e(TAG, "Failed to release chat", e);
+ qbChatDialog.removeMessageListrener(chatMessageListener);
+ if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType())) {
+ leaveGroupDialog();
}
}
-
private void updateDialog(final ArrayList selectedUsers) {
- ChatHelper.getInstance().updateDialogUsers(qbDialog, selectedUsers,
- new QBEntityCallback() {
+ ChatHelper.getInstance().updateDialogUsers(qbChatDialog, selectedUsers,
+ new QBEntityCallback() {
@Override
- public void onSuccess(QBDialog dialog, Bundle args) {
- qbDialog = dialog;
+ public void onSuccess(QBChatDialog dialog, Bundle args) {
+ qbChatDialog = dialog;
loadDialogUsers();
}
@@ -428,7 +428,7 @@ public void onClick(View v) {
}
private void loadDialogUsers() {
- ChatHelper.getInstance().getUsersFromDialog(qbDialog, new QBEntityCallback>() {
+ ChatHelper.getInstance().getUsersFromDialog(qbChatDialog, new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList users, Bundle bundle) {
setChatNameToActionBar();
@@ -449,7 +449,7 @@ public void onClick(View v) {
}
private void setChatNameToActionBar() {
- String chatName = QbDialogUtils.getDialogName(qbDialog);
+ String chatName = QbDialogUtils.getDialogName(qbChatDialog);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setTitle(chatName);
@@ -459,14 +459,14 @@ private void setChatNameToActionBar() {
}
private void loadChatHistory() {
- ChatHelper.getInstance().loadChatHistory(qbDialog, skipPagination, new QBEntityCallback>() {
+ ChatHelper.getInstance().loadChatHistory(qbChatDialog, skipPagination, new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList messages, Bundle args) {
// The newest messages should be in the end of list,
// so we need to reverse list to show messages in the right order
Collections.reverse(messages);
if (chatAdapter == null) {
- chatAdapter = new ChatAdapter(ChatActivity.this, messages);
+ chatAdapter = new ChatAdapter(ChatActivity.this, qbChatDialog, messages);
chatAdapter.setPaginationHistoryListener(new PaginationHistoryListener() {
@Override
public void downloadMore() {
@@ -526,7 +526,7 @@ private void scrollMessageListDown() {
}
private void deleteChat() {
- ChatHelper.getInstance().deleteDialog(qbDialog, new QBEntityCallback() {
+ ChatHelper.getInstance().deleteDialog(qbChatDialog, new QBEntityCallback() {
@Override
public void onSuccess(Void aVoid, Bundle bundle) {
setResult(RESULT_OK);
@@ -548,27 +548,12 @@ public void onClick(View v) {
private void initChatConnectionListener() {
chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) {
- @Override
- public void connectionClosedOnError(final Exception e) {
- super.connectionClosedOnError(e);
-
- // Leave active room if we're in Group Chat
- if (qbDialog.getType() == QBDialogType.GROUP) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- leaveGroupChatRoom();
- }
- });
- }
- }
-
@Override
public void reconnectionSuccessful() {
super.reconnectionSuccessful();
skipPagination = 0;
chatAdapter = null;
- switch (qbDialog.getType()) {
+ switch (qbChatDialog.getType()) {
case PRIVATE:
runOnUiThread(new Runnable() {
@Override
@@ -591,11 +576,10 @@ public void run() {
};
}
- private QBChatMessageListener chatMessageListener = new QBChatMessageListener() {
+ public class ChatMessageListener extends QbChatDialogMessageListenerImp {
@Override
- public void onQBChatMessageReceived(QBChat chat, QBChatMessage message) {
- chatMessageIds.add(message.getId());
- showMessage(message);
+ public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) {
+ showMessage(qbChatMessage);
}
- };
+ }
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatInfoActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatInfoActivity.java
index c4407b0ea..f9076d7a2 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatInfoActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/ChatInfoActivity.java
@@ -6,7 +6,7 @@
import android.view.View;
import android.widget.ListView;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.sample.chat.R;
import com.quickblox.sample.chat.ui.adapter.UsersAdapter;
import com.quickblox.sample.chat.utils.qb.QbUsersHolder;
@@ -19,9 +19,9 @@ public class ChatInfoActivity extends BaseActivity {
private static final String EXTRA_DIALOG = "dialog";
private ListView usersListView;
- private QBDialog qbDialog;
+ private QBChatDialog qbDialog;
- public static void start(Context context, QBDialog qbDialog) {
+ public static void start(Context context, QBChatDialog qbDialog) {
Intent intent = new Intent(context, ChatInfoActivity.class);
intent.putExtra(EXTRA_DIALOG, qbDialog);
context.startActivity(intent);
@@ -32,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
- qbDialog = (QBDialog) getIntent().getSerializableExtra(EXTRA_DIALOG);
+ qbDialog = (QBChatDialog) getIntent().getSerializableExtra(EXTRA_DIALOG);
usersListView = _findViewById(R.id.list_login_users);
actionBar.setDisplayHomeAsUpEnabled(true);
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/DialogsActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/DialogsActivity.java
index e3f12f86a..d1cef7f1c 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/DialogsActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/DialogsActivity.java
@@ -23,42 +23,38 @@
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout;
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection;
import com.quickblox.chat.QBChatService;
-import com.quickblox.chat.QBGroupChat;
-import com.quickblox.chat.QBGroupChatManager;
-import com.quickblox.chat.QBPrivateChat;
-import com.quickblox.chat.QBPrivateChatManager;
+import com.quickblox.chat.QBIncomingMessagesManager;
+import com.quickblox.chat.QBSystemMessagesManager;
import com.quickblox.chat.exception.QBChatException;
-import com.quickblox.chat.listeners.QBGroupChatManagerListener;
-import com.quickblox.chat.listeners.QBMessageListener;
-import com.quickblox.chat.listeners.QBPrivateChatManagerListener;
+import com.quickblox.chat.listeners.QBChatDialogMessageListener;
+import com.quickblox.chat.listeners.QBSystemMessageListener;
import com.quickblox.chat.model.QBChatMessage;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
-import com.quickblox.core.helper.StringifyArrayList;
import com.quickblox.core.request.QBRequestGetBuilder;
import com.quickblox.sample.chat.R;
import com.quickblox.sample.chat.ui.adapter.DialogsAdapter;
import com.quickblox.sample.chat.utils.Consts;
import com.quickblox.sample.chat.utils.SharedPreferencesUtil;
+import com.quickblox.sample.chat.managers.DialogsManager;
import com.quickblox.sample.chat.utils.chat.ChatHelper;
+import com.quickblox.sample.chat.utils.qb.QbChatDialogMessageListenerImp;
import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
-import com.quickblox.sample.chat.utils.qb.VerboseQbChatConnectionListener;
+import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackImpl;
import com.quickblox.sample.core.gcm.GooglePlayServicesHelper;
import com.quickblox.sample.core.ui.dialog.ProgressDialogFragment;
import com.quickblox.sample.core.utils.ErrorUtils;
import com.quickblox.sample.core.utils.constant.GcmConsts;
import com.quickblox.users.model.QBUser;
-import org.jivesoftware.smack.ConnectionListener;
-
import java.util.ArrayList;
import java.util.Collection;
-public class DialogsActivity extends BaseActivity {
+public class DialogsActivity extends BaseActivity implements DialogsManager.ManagingDialogsCallbacks {
private static final String TAG = DialogsActivity.class.getSimpleName();
private static final int REQUEST_SELECT_PEOPLE = 174;
- private static final int REQUEST_MARK_READ = 165;
+ private static final int REQUEST_DIALOG_ID_FOR_UPDATE = 165;
private ProgressBar progressBar;
private FloatingActionButton fab;
@@ -67,22 +63,22 @@ public class DialogsActivity extends BaseActivity {
private QBRequestGetBuilder requestBuilder;
private Menu menu;
private int skipRecords = 0;
- private boolean isActivityForeground;
private boolean isProcessingResultInProgress;
private BroadcastReceiver pushBroadcastReceiver;
private GooglePlayServicesHelper googlePlayServicesHelper;
private DialogsAdapter dialogsAdapter;
+ private QBChatDialogMessageListener allDialogsMessagesListener;
+ private SystemMessagesListener systemMessagesListener;
+ private QBSystemMessagesManager systemMessagesManager;
+ private QBIncomingMessagesManager incomingMessagesManager;
+ private DialogsManager dialogsManager;
public static void start(Context context) {
Intent intent = new Intent(context, DialogsActivity.class);
context.startActivity(intent);
}
- private QBPrivateChatManagerListener privateChatManagerListener;
- private QBGroupChatManagerListener groupChatManagerListener;
- private ConnectionListener chatConnectionListener;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -95,31 +91,12 @@ protected void onCreate(Bundle savedInstanceState) {
pushBroadcastReceiver = new PushBroadcastReceiver();
- privateChatManagerListener = new QBPrivateChatManagerListener() {
- @Override
- public void chatCreated(QBPrivateChat qbPrivateChat, boolean createdLocally) {
- if (!createdLocally) {
- qbPrivateChat.addMessageListener(privateChatMessageListener);
- }
- }
- };
- groupChatManagerListener = new QBGroupChatManagerListener() {
- @Override
- public void chatCreated(QBGroupChat qbGroupChat) {
- requestBuilder.setSkip(skipRecords = 0);
- loadDialogsFromQbInUiThread(true);
- }
- };
- chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) {
-
- @Override
- public void reconnectionSuccessful() {
- super.reconnectionSuccessful();
+ if (isAppSessionActive) {
+ allDialogsMessagesListener = new AllDialogsMessageListener();
+ systemMessagesListener = new SystemMessagesListener();
+ }
- requestBuilder.setSkip(skipRecords = 0);
- loadDialogsFromQbInUiThread(true);
- }
- };
+ dialogsManager = new DialogsManager();
initUi();
}
@@ -127,8 +104,6 @@ public void reconnectionSuccessful() {
@Override
protected void onResume() {
super.onResume();
- ChatHelper.getInstance().addConnectionListener(chatConnectionListener);
- isActivityForeground = true;
googlePlayServicesHelper.checkPlayServicesAvailable(this);
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver,
@@ -138,8 +113,6 @@ protected void onResume() {
@Override
protected void onPause() {
super.onPause();
- ChatHelper.getInstance().removeConnectionListener(chatConnectionListener);
- isActivityForeground = false;
LocalBroadcastManager.getInstance(this).unregisterReceiver(pushBroadcastReceiver);
}
@@ -186,10 +159,10 @@ public void onSessionCreated(boolean success) {
}
registerQbChatListeners();
- if (QbDialogHolder.getInstance().getDialogList().size() > 0) {
+ if (QbDialogHolder.getInstance().getDialogs().size() > 0) {
loadDialogsFromQb(true, true);
} else {
- loadDialogsFromQb();
+ loadDialogsFromQb(false, true);
}
}
}
@@ -201,31 +174,55 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
isProcessingResultInProgress = true;
if (requestCode == REQUEST_SELECT_PEOPLE) {
- ProgressDialogFragment.show(getSupportFragmentManager(), R.string.create_chat);
ArrayList selectedUsers = (ArrayList) data
.getSerializableExtra(SelectUsersActivity.EXTRA_QB_USERS);
- createDialog(selectedUsers);
- } else if (requestCode == REQUEST_MARK_READ) {
+ if (isPrivateDialogExist(selectedUsers)){
+ selectedUsers.remove(ChatHelper.getCurrentUser());
+ QBChatDialog existingPrivateDialog = QbDialogHolder.getInstance().getPrivateDialogWithUser(selectedUsers.get(0));
+ isProcessingResultInProgress = false;
+ ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, existingPrivateDialog.getDialogId());
+ } else {
+ ProgressDialogFragment.show(getSupportFragmentManager(), R.string.create_chat);
+ createDialog(selectedUsers);
+ }
+ } else if (requestCode == REQUEST_DIALOG_ID_FOR_UPDATE) {
if (data != null) {
- ArrayList chatMessageIds = (ArrayList) data
- .getSerializableExtra(ChatActivity.EXTRA_MARK_READ);
- final StringifyArrayList messagesIds = new StringifyArrayList<>();
- messagesIds.addAll(chatMessageIds);
-
- String dialogId = (String) data.getSerializableExtra(ChatActivity.EXTRA_DIALOG_ID);
-
- markMessagesRead(messagesIds, dialogId);
+ String dialogId = data.getStringExtra(ChatActivity.EXTRA_DIALOG_ID);
+ loadUpdatedDialog(dialogId);
} else {
isProcessingResultInProgress = false;
updateDialogsList();
}
}
} else {
- updateDialogsList();
+ updateDialogsAdapter();
}
}
+ private boolean isPrivateDialogExist(ArrayList allSelectedUsers){
+ ArrayList selectedUsers = new ArrayList<>();
+ selectedUsers.addAll(allSelectedUsers);
+ selectedUsers.remove(ChatHelper.getCurrentUser());
+ return selectedUsers.size() == 1 && QbDialogHolder.getInstance().hasPrivateDialogWithUser(selectedUsers.get(0));
+ }
+
+ private void loadUpdatedDialog(String dialogId) {
+ ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl() {
+ @Override
+ public void onSuccess(QBChatDialog result, Bundle bundle) {
+ isProcessingResultInProgress = false;
+ QbDialogHolder.getInstance().addDialog(result);
+ updateDialogsAdapter();
+ }
+
+ @Override
+ public void onError(QBResponseException e) {
+ isProcessingResultInProgress = false;
+ }
+ });
+ }
+
@Override
protected View getSnackbarAnchorView() {
return findViewById(R.id.layout_root);
@@ -238,18 +235,24 @@ public ActionMode startSupportActionMode(ActionMode.Callback callback) {
}
private void userLogout() {
- if (ChatHelper.getInstance().logout()) {
- if (googlePlayServicesHelper.checkPlayServicesAvailable()) {
- googlePlayServicesHelper.unregisterFromGcm(Consts.GCM_SENDER_ID);
+ ChatHelper.getInstance().logout(new QBEntityCallback() {
+ @Override
+ public void onSuccess(Void aVoid, Bundle bundle) {
+ if (googlePlayServicesHelper.checkPlayServicesAvailable()) {
+ googlePlayServicesHelper.unregisterFromGcm(Consts.GCM_SENDER_ID);
+ }
+ SharedPreferencesUtil.removeQbUser();
+ LoginActivity.start(DialogsActivity.this);
+ QbDialogHolder.getInstance().clear();
+ ProgressDialogFragment.hide(getSupportFragmentManager());
+ finish();
}
- SharedPreferencesUtil.removeQbUser();
- LoginActivity.start(this);
- QbDialogHolder.getInstance().clear();
- ProgressDialogFragment.hide(getSupportFragmentManager());
- finish();
- } else {
- reconnectToChatLogout(SharedPreferencesUtil.getQbUser());
- }
+
+ @Override
+ public void onError(QBResponseException e) {
+ reconnectToChatLogout(SharedPreferencesUtil.getQbUser());
+ }
+ });
}
private void reconnectToChatLogout(final QBUser user) {
@@ -277,26 +280,6 @@ public void onClick(View v) {
});
}
- private void markMessagesRead(StringifyArrayList messagesIds, String dialogId) {
- if (messagesIds.size() > 0) {
- QBChatService.markMessagesAsRead(dialogId, messagesIds, new QBEntityCallback() {
- @Override
- public void onSuccess(Void aVoid, Bundle bundle) {
- isProcessingResultInProgress = false;
- updateDialogsList();
- }
-
- @Override
- public void onError(QBResponseException e) {
- isProcessingResultInProgress = false;
- }
- });
- } else {
- isProcessingResultInProgress = false;
- updateDialogsList();
- }
- }
-
private void updateDialogsList() {
if (isAppSessionActive) {
requestBuilder.setSkip(skipRecords = 0);
@@ -316,7 +299,7 @@ private void initUi() {
fab = _findViewById(R.id.fab_dialogs_new_chat);
setOnRefreshListener = _findViewById(R.id.swipy_refresh_layout);
- dialogsAdapter = new DialogsAdapter(this, QbDialogHolder.getInstance().getDialogList());
+ dialogsAdapter = new DialogsAdapter(this, new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values()));
TextView listHeader = (TextView) LayoutInflater.from(this)
.inflate(R.layout.include_list_hint_header, dialogsListView, false);
@@ -329,9 +312,9 @@ private void initUi() {
dialogsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- QBDialog selectedDialog = (QBDialog) parent.getItemAtPosition(position);
+ QBChatDialog selectedDialog = (QBChatDialog) parent.getItemAtPosition(position);
if (currentActionMode == null) {
- ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, selectedDialog);
+ ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, selectedDialog.getDialogId());
} else {
dialogsAdapter.toggleSelection(selectedDialog);
}
@@ -340,7 +323,7 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
dialogsListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
- QBDialog selectedDialog = (QBDialog) parent.getItemAtPosition(position);
+ QBChatDialog selectedDialog = (QBChatDialog) parent.getItemAtPosition(position);
startSupportActionMode(new DeleteActionModeCallback());
dialogsAdapter.selectItem(selectedDialog);
return true;
@@ -357,52 +340,43 @@ public void onRefresh(SwipyRefreshLayoutDirection direction) {
});
}
- QBMessageListener privateChatMessageListener = new QBMessageListener() {
- @Override
- public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) {
- requestBuilder.setSkip(skipRecords = 0);
- if (isActivityForeground) {
- loadDialogsFromQbInUiThread(true);
- }
- }
-
- @Override
- public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage) {
+ private void registerQbChatListeners() {
+ incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager();
+ systemMessagesManager = QBChatService.getInstance().getSystemMessagesManager();
+ if (incomingMessagesManager != null) {
+ incomingMessagesManager.addDialogMessageListener(allDialogsMessagesListener != null
+ ? allDialogsMessagesListener : new AllDialogsMessageListener());
}
- };
- private void registerQbChatListeners() {
- QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager();
- QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager();
- if (privateChatManager != null) {
- privateChatManager.addPrivateChatManagerListener(privateChatManagerListener);
+ if (systemMessagesManager != null) {
+ systemMessagesManager.addSystemMessageListener(systemMessagesListener != null
+ ? systemMessagesListener : new SystemMessagesListener());
}
- if (groupChatManager != null) {
- groupChatManager.addGroupChatManagerListener(groupChatManagerListener);
- }
+ dialogsManager.addManagingDialogsCallbackListener(this);
}
private void unregisterQbChatListeners() {
- QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager();
- QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager();
- if (privateChatManager != null) {
- privateChatManager.removePrivateChatManagerListener(privateChatManagerListener);
+ if (incomingMessagesManager != null) {
+ incomingMessagesManager.removeDialogMessageListrener(allDialogsMessagesListener);
}
- if (groupChatManager != null) {
- groupChatManager.removeGroupChatManagerListener(groupChatManagerListener);
+ if (systemMessagesManager != null) {
+ systemMessagesManager.removeSystemMessageListener(systemMessagesListener);
}
+
+ dialogsManager.removeManagingDialogsCallbackListener(this);
}
private void createDialog(final ArrayList selectedUsers) {
ChatHelper.getInstance().createDialogWithSelectedUsers(selectedUsers,
- new QBEntityCallback() {
+ new QBEntityCallback() {
@Override
- public void onSuccess(QBDialog dialog, Bundle args) {
+ public void onSuccess(QBChatDialog dialog, Bundle args) {
isProcessingResultInProgress = false;
- ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, dialog);
+ dialogsManager.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog);
+ ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, dialog.getDialogId());
ProgressDialogFragment.hide(getSupportFragmentManager());
}
@@ -416,27 +390,16 @@ public void onError(QBResponseException e) {
);
}
- private void loadDialogsFromQb() {
- loadDialogsFromQb(false, true);
- }
-
- private void loadDialogsFromQbInUiThread(final boolean silentUpdate) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- loadDialogsFromQb(silentUpdate, true);
- }
- });
- }
-
private void loadDialogsFromQb(final boolean silentUpdate, final boolean clearDialogHolder) {
+ isProcessingResultInProgress = true;
if (!silentUpdate) {
progressBar.setVisibility(View.VISIBLE);
}
- ChatHelper.getInstance().getDialogs(requestBuilder, new QBEntityCallback>() {
+ ChatHelper.getInstance().getDialogs(requestBuilder, new QBEntityCallback>() {
@Override
- public void onSuccess(ArrayList dialogs, Bundle bundle) {
+ public void onSuccess(ArrayList dialogs, Bundle bundle) {
+ isProcessingResultInProgress = false;
progressBar.setVisibility(View.GONE);
setOnRefreshListener.setRefreshing(false);
@@ -444,11 +407,12 @@ public void onSuccess(ArrayList dialogs, Bundle bundle) {
QbDialogHolder.getInstance().clear();
}
QbDialogHolder.getInstance().addDialogs(dialogs);
- dialogsAdapter.notifyDataSetChanged();
+ updateDialogsAdapter();
}
@Override
public void onError(QBResponseException e) {
+ isProcessingResultInProgress = false;
progressBar.setVisibility(View.GONE);
setOnRefreshListener.setRefreshing(false);
Toast.makeText(DialogsActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
@@ -456,6 +420,25 @@ public void onError(QBResponseException e) {
});
}
+ private void updateDialogsAdapter() {
+ dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values()));
+ }
+
+ @Override
+ public void onDialogCreated(QBChatDialog chatDialog) {
+ updateDialogsAdapter();
+ }
+
+ @Override
+ public void onDialogUpdated(String chatDialog) {
+ updateDialogsAdapter();
+ }
+
+ @Override
+ public void onNewDialogLoaded(QBChatDialog chatDialog) {
+ updateDialogsAdapter();
+ }
+
private class DeleteActionModeCallback implements ActionMode.Callback {
public DeleteActionModeCallback() {
@@ -494,11 +477,12 @@ public void onDestroyActionMode(ActionMode mode) {
}
private void deleteSelectedDialogs() {
- final Collection selectedDialogs = dialogsAdapter.getSelectedItems();
- ChatHelper.getInstance().deleteDialogs(selectedDialogs, new QBEntityCallback() {
+ final Collection selectedDialogs = dialogsAdapter.getSelectedItems();
+ ChatHelper.getInstance().deleteDialogs(selectedDialogs, new QBEntityCallback>() {
@Override
- public void onSuccess(Void aVoid, Bundle bundle) {
- QbDialogHolder.getInstance().deleteDialogs(selectedDialogs);
+ public void onSuccess(ArrayList dialogsIds, Bundle bundle) {
+ QbDialogHolder.getInstance().deleteDialogs(dialogsIds);
+ updateDialogsAdapter();
}
@Override
@@ -520,8 +504,30 @@ private class PushBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
String message = intent.getStringExtra(GcmConsts.EXTRA_GCM_MESSAGE);
- Log.i(TAG, "Received broadcast " + intent.getAction() + " with data: " + message);
+ Log.v(TAG, "Received broadcast " + intent.getAction() + " with data: " + message);
+ requestBuilder.setSkip(skipRecords = 0);
loadDialogsFromQb(true, true);
}
}
+
+ private class SystemMessagesListener implements QBSystemMessageListener {
+ @Override
+ public void processMessage(final QBChatMessage qbChatMessage) {
+ dialogsManager.onSystemMessageReceived(qbChatMessage);
+ }
+
+ @Override
+ public void processError(QBChatException e, QBChatMessage qbChatMessage) {
+
+ }
+ }
+
+ private class AllDialogsMessageListener extends QbChatDialogMessageListenerImp {
+ @Override
+ public void processMessage(final String dialogId, final QBChatMessage qbChatMessage, Integer senderId) {
+ if (!senderId.equals(ChatHelper.getCurrentUser().getId())) {
+ dialogsManager.onGlobalMessageReceived(dialogId, qbChatMessage);
+ }
+ }
+ }
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/LoginActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/LoginActivity.java
index 9b3965429..8ed6f775e 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/LoginActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/LoginActivity.java
@@ -55,7 +55,7 @@ private void buildUsersList() {
List tags = new ArrayList<>();
tags.add(Consts.QB_USERS_TAG);
- QBUsers.getUsersByTags(tags, null, new QBEntityCallback>() {
+ QBUsers.getUsersByTags(tags, null).performAsync(new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList result, Bundle params) {
UsersAdapter adapter = new UsersAdapter(LoginActivity.this, result);
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SelectUsersActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SelectUsersActivity.java
index 1303f1248..b5ad733c2 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SelectUsersActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SelectUsersActivity.java
@@ -13,7 +13,7 @@
import android.widget.ProgressBar;
import android.widget.TextView;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.sample.chat.R;
@@ -57,7 +57,7 @@ public static void startForResult(Activity activity, int code) {
startForResult(activity, code, null);
}
- public static void startForResult(Activity activity, int code, QBDialog dialog) {
+ public static void startForResult(Activity activity, int code, QBChatDialog dialog) {
Intent intent = new Intent(activity, SelectUsersActivity.class);
intent.putExtra(EXTRA_QB_DIALOG, dialog);
activity.startActivityForResult(intent, code);
@@ -139,10 +139,10 @@ private void loadUsersFromQb() {
tags.add(Consts.QB_USERS_TAG);
progressBar.setVisibility(View.VISIBLE);
- QBUsers.getUsersByTags(tags, null, new QBEntityCallback>() {
+ QBUsers.getUsersByTags(tags, null).performAsync(new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList result, Bundle params) {
- QBDialog dialog = (QBDialog) getIntent().getSerializableExtra(EXTRA_QB_DIALOG);
+ QBChatDialog dialog = (QBChatDialog) getIntent().getSerializableExtra(EXTRA_QB_DIALOG);
usersAdapter = new CheckboxUsersAdapter(SelectUsersActivity.this, result);
if (dialog != null) {
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SplashActivity.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SplashActivity.java
index d707db569..56e582aa7 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SplashActivity.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/activity/SplashActivity.java
@@ -41,7 +41,7 @@ protected void proceedToTheNextActivity() {
}
private void createSession() {
- QBAuth.createSession(new QBEntityCallback() {
+ QBAuth.createSession().performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession result, Bundle params) {
proceedToTheNextActivity();
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/ChatAdapter.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/ChatAdapter.java
index 2bb366696..b85d69804 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/ChatAdapter.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/ChatAdapter.java
@@ -2,6 +2,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
+import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -16,7 +17,9 @@
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.quickblox.chat.model.QBAttachment;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.chat.model.QBChatMessage;
+import com.quickblox.core.helper.CollectionsUtil;
import com.quickblox.sample.chat.R;
import com.quickblox.sample.chat.ui.activity.AttachmentImageActivity;
import com.quickblox.sample.chat.ui.widget.MaskedImageView;
@@ -29,6 +32,9 @@
import com.quickblox.sample.core.utils.ResourceUtils;
import com.quickblox.users.model.QBUser;
+import org.jivesoftware.smack.SmackException;
+import org.jivesoftware.smack.XMPPException;
+
import java.util.Collection;
import java.util.List;
@@ -36,12 +42,15 @@
public class ChatAdapter extends BaseListAdapter implements StickyListHeadersAdapter {
+ private static final String TAG = ChatAdapter.class.getSimpleName();
+ private final QBChatDialog chatDialog;
private OnItemInfoExpandedListener onItemInfoExpandedListener;
private PaginationHistoryListener paginationListener;
private int previousGetCount = 0;
- public ChatAdapter(Context context, List chatMessages) {
+ public ChatAdapter(Context context, QBChatDialog chatDialog, List chatMessages) {
super(context, chatMessages);
+ this.chatDialog = chatDialog;
}
public void setOnItemInfoExpandedListener(OnItemInfoExpandedListener onItemInfoExpandedListener) {
@@ -100,6 +109,10 @@ public boolean onLongClick(View v) {
});
holder.messageInfoTextView.setVisibility(View.GONE);
+ if (isIncoming(chatMessage) && !isRead(chatMessage)){
+ readMessage(chatMessage);
+ }
+
downloadMore(position);
return convertView;
@@ -266,6 +279,19 @@ private boolean isIncoming(QBChatMessage chatMessage) {
return chatMessage.getSenderId() != null && !chatMessage.getSenderId().equals(currentUser.getId());
}
+ private boolean isRead(QBChatMessage chatMessage){
+ Integer currentUserId = ChatHelper.getCurrentUser().getId();
+ return !CollectionsUtil.isEmpty(chatMessage.getReadIds()) && chatMessage.getReadIds().contains(currentUserId);
+ }
+
+ private void readMessage(QBChatMessage chatMessage){
+ try {
+ chatDialog.readMessage(chatMessage);
+ } catch (XMPPException | SmackException.NotConnectedException e) {
+ Log.w(TAG, e);
+ }
+ }
+
private static class HeaderViewHolder {
public TextView dateTextView;
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/DialogsAdapter.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/DialogsAdapter.java
index ed2bb5532..96082c5a1 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/DialogsAdapter.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/DialogsAdapter.java
@@ -7,9 +7,10 @@
import android.widget.ImageView;
import android.widget.TextView;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.chat.model.QBDialogType;
import com.quickblox.sample.chat.R;
+import com.quickblox.sample.chat.utils.StringUtils;
import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
import com.quickblox.sample.core.ui.adapter.BaseSelectableListAdapter;
import com.quickblox.sample.core.utils.ResourceUtils;
@@ -17,9 +18,11 @@
import java.util.List;
-public class DialogsAdapter extends BaseSelectableListAdapter {
+public class DialogsAdapter extends BaseSelectableListAdapter {
- public DialogsAdapter(Context context, List dialogs) {
+ private static final String EMPTY_STRING = "";
+
+ public DialogsAdapter(Context context, List dialogs) {
super(context, dialogs);
}
@@ -41,7 +44,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder = (ViewHolder) convertView.getTag();
}
- QBDialog dialog = getItem(position);
+ QBChatDialog dialog = getItem(position);
if (dialog.getType().equals(QBDialogType.GROUP)) {
holder.dialogImageView.setBackgroundDrawable(UiUtils.getGreyCircleDrawable());
holder.dialogImageView.setImageResource(R.drawable.ic_chat_group);
@@ -51,11 +54,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
holder.nameTextView.setText(QbDialogUtils.getDialogName(dialog));
- if (isLastMessageAttachment(dialog)) {
- holder.lastMessageTextView.setText(R.string.chat_attachment);
- } else {
- holder.lastMessageTextView.setText(dialog.getLastMessage());
- }
+ holder.lastMessageTextView.setText(prepareTextLastMessage(dialog));
int unreadMessagesCount = dialog.getUnreadMessageCount();
if (unreadMessagesCount == 0) {
@@ -71,10 +70,20 @@ public View getView(int position, View convertView, ViewGroup parent) {
return convertView;
}
- private boolean isLastMessageAttachment(QBDialog dialog) {
+ private boolean isLastMessageAttachment(QBChatDialog dialog) {
String lastMessage = dialog.getLastMessage();
Integer lastMessageSenderId = dialog.getLastMessageUserId();
- return TextUtils.isEmpty(lastMessage) && lastMessageSenderId != null;
+ return (StringUtils.textIsNull(lastMessage) || TextUtils.isEmpty(lastMessage)) && lastMessageSenderId != null;
+ }
+
+ private String prepareTextLastMessage(QBChatDialog chatDialog){
+ if (isLastMessageAttachment(chatDialog)){
+ return context.getString(R.string.chat_attachment);
+ } else if (!TextUtils.isEmpty(chatDialog.getLastMessage())){
+ return StringUtils.textIsNull(chatDialog.getLastMessage()) ? EMPTY_STRING : chatDialog.getLastMessage();
+ }
+
+ return EMPTY_STRING;
}
private static class ViewHolder {
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/StringUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/StringUtils.java
new file mode 100644
index 000000000..6a2d43516
--- /dev/null
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/StringUtils.java
@@ -0,0 +1,9 @@
+package com.quickblox.sample.chat.utils;
+
+public class StringUtils {
+ private static final String NULL_TEXT = "null";
+
+ public static boolean textIsNull(String text){
+ return NULL_TEXT.equals(text);
+ }
+}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/BaseChatImpl.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/BaseChatImpl.java
deleted file mode 100644
index 0f16431cc..000000000
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/BaseChatImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.quickblox.sample.chat.utils.chat;
-
-import android.os.Handler;
-import android.os.Looper;
-import android.util.Log;
-
-import com.quickblox.chat.QBChat;
-import com.quickblox.chat.exception.QBChatException;
-import com.quickblox.chat.listeners.QBMessageListener;
-import com.quickblox.chat.model.QBChatMessage;
-import com.quickblox.sample.core.utils.Toaster;
-
-import org.jivesoftware.smack.SmackException;
-import org.jivesoftware.smack.XMPPException;
-
-public abstract class BaseChatImpl implements Chat, QBMessageListener {
- private static final String TAG = BaseChatImpl.class.getSimpleName();
-
- protected Handler mainThreadHandler = new Handler(Looper.getMainLooper());
- protected QBChatMessageListener chatMessageListener;
- protected T qbChat;
-
- public BaseChatImpl(QBChatMessageListener chatMessageListener) {
- // It's not a good practice to pass Activity to other classes as it may lead to memory leak
- // We're doing this only for chat sample simplicity, don't do this in your projects
- this.chatMessageListener = chatMessageListener;
- initManagerIfNeed();
- }
-
- protected abstract void initManagerIfNeed();
-
- @Override
- public void sendMessage(QBChatMessage message) throws XMPPException, SmackException.NotConnectedException {
- if (qbChat != null) {
- try {
- qbChat.sendMessage(message);
- } catch (SmackException.NotConnectedException e) {
- Log.w(TAG, e);
- Toaster.shortToast("Can't send a message, You are not connected to chat");
- } catch (IllegalStateException e) {
- Log.w(TAG, e);
- Toaster.shortToast("You're still joining a group chat, please wait a bit");
- }
- } else {
- Toaster.longToast("Join unsuccessful");
- }
- }
-
- @Override
- public void processMessage(final T qbChat, final QBChatMessage chatMessage) {
- // Show message in activity
- Log.i(TAG, "New incoming message: " + chatMessage);
- mainThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- chatMessageListener.onQBChatMessageReceived(qbChat, chatMessage);
- }
- });
- }
-
- @Override
- public void processError(T qbChat, QBChatException e, QBChatMessage qbChatMessage) {
- Log.w(TAG, "Error processing message", e);
- }
-}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/Chat.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/Chat.java
deleted file mode 100644
index 570d4f990..000000000
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/Chat.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.quickblox.sample.chat.utils.chat;
-
-import com.quickblox.chat.model.QBChatMessage;
-
-import org.jivesoftware.smack.SmackException;
-import org.jivesoftware.smack.XMPPException;
-
-public interface Chat {
-
- void sendMessage(QBChatMessage message) throws XMPPException, SmackException.NotConnectedException;
-
- void release() throws XMPPException;
-}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/ChatHelper.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/ChatHelper.java
index 145e49c2d..3f9812076 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/ChatHelper.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/ChatHelper.java
@@ -6,10 +6,13 @@
import com.quickblox.auth.QBAuth;
import com.quickblox.auth.model.QBSession;
import com.quickblox.chat.QBChatService;
+import com.quickblox.chat.QBRestChatService;
import com.quickblox.chat.model.QBAttachment;
import com.quickblox.chat.model.QBChatMessage;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.chat.model.QBDialogType;
+import com.quickblox.chat.request.QBDialogRequestBuilder;
+import com.quickblox.chat.utils.DialogUtils;
import com.quickblox.content.QBContent;
import com.quickblox.content.model.QBFile;
import com.quickblox.core.LogLevel;
@@ -17,11 +20,12 @@
import com.quickblox.core.QBProgressCallback;
import com.quickblox.core.QBSettings;
import com.quickblox.core.exception.QBResponseException;
+import com.quickblox.core.helper.StringifyArrayList;
import com.quickblox.core.request.QBPagedRequestBuilder;
import com.quickblox.core.request.QBRequestGetBuilder;
-import com.quickblox.core.request.QBRequestUpdateBuilder;
import com.quickblox.sample.chat.R;
import com.quickblox.sample.chat.utils.SharedPreferencesUtil;
+import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
import com.quickblox.sample.chat.utils.qb.QbUsersHolder;
import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackTwoTypeWrapper;
@@ -32,6 +36,8 @@
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.SmackException;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
import java.io.File;
import java.util.ArrayList;
@@ -44,7 +50,7 @@
public class ChatHelper {
private static final String TAG = ChatHelper.class.getSimpleName();
- private static final int AUTO_PRESENCE_INTERVAL_IN_SECONDS = 30;
+ private static final int CHAT_SOCKET_TIMEOUT = 0;
public static final int DIALOG_ITEMS_PER_PAGE = 100;
public static final int CHAT_HISTORY_ITEMS_PER_PAGE = 50;
@@ -58,7 +64,7 @@ public static synchronized ChatHelper getInstance() {
if (instance == null) {
QBSettings.getInstance().setLogLevel(LogLevel.DEBUG);
QBChatService.setDebugEnabled(true);
- QBChatService.setDefaultAutoSendPresenceInterval(AUTO_PRESENCE_INTERVAL_IN_SECONDS);
+ QBChatService.setConfigurationBuilder(buildChatConfigs());
instance = new ChatHelper();
}
return instance;
@@ -73,6 +79,15 @@ private ChatHelper() {
qbChatService.setUseStreamManagement(true);
}
+ private static QBChatService.ConfigurationBuilder buildChatConfigs(){
+ QBChatService.ConfigurationBuilder configurationBuilder = new QBChatService.ConfigurationBuilder();
+ configurationBuilder.setKeepAlive(true)
+ .setSocketTimeout(CHAT_SOCKET_TIMEOUT)
+ .setAutojoinEnabled(false);
+
+ return configurationBuilder;
+ }
+
public void addConnectionListener(ConnectionListener listener) {
qbChatService.addConnectionListener(listener);
}
@@ -83,7 +98,7 @@ public void removeConnectionListener(ConnectionListener listener) {
public void login(final QBUser user, final QBEntityCallback callback) {
// Create REST API session on QuickBlox
- QBAuth.createSession(user, new QbEntityCallbackTwoTypeWrapper(callback) {
+ QBAuth.createSession(user).performAsync(new QbEntityCallbackTwoTypeWrapper(callback) {
@Override
public void onSuccess(QBSession session, Bundle args) {
user.setId(session.getUserId());
@@ -111,74 +126,79 @@ public void onError(QBResponseException e) {
});
}
- public boolean logout() {
- try {
- qbChatService.logout();
- return true;
- } catch (SmackException.NotConnectedException e) {
- e.printStackTrace();
- }
- return false;
+ public void join(QBChatDialog chatDialog, final QBEntityCallback callback){
+ DiscussionHistory history = new DiscussionHistory();
+ history.setMaxStanzas(0);
+
+ chatDialog.join(history, new QbEntityCallbackWrapper(callback) {
+ @Override
+ public void onSuccess(final Void result, final Bundle b) {
+ onSuccessInMainThread(result, b);
+ }
+
+ @Override
+ public void onError(final QBResponseException e) {
+ onErrorInMainThread(e);
+ }
+ });
+ }
+
+ public void leaveChatDialog(QBChatDialog chatDialog) throws XMPPException, SmackException.NotConnectedException {
+ chatDialog.leave();
+ }
+
+ public void logout(final QBEntityCallback callback) {
+ qbChatService.logout(callback);
}
public void createDialogWithSelectedUsers(final List users,
- final QBEntityCallback callback) {
- QBChatService.getInstance().getGroupChatManager().createDialog(QbDialogUtils.createDialog(users),
- new QbEntityCallbackWrapper(callback) {
+ final QBEntityCallback callback) {
+
+ QBRestChatService.createChatDialog(QbDialogUtils.createDialog(users)).performAsync(
+ new QbEntityCallbackWrapper(callback) {
@Override
- public void onSuccess(QBDialog dialog, Bundle args) {
+ public void onSuccess(QBChatDialog dialog, Bundle args) {
+ QbDialogHolder.getInstance().addDialog(dialog);
QbUsersHolder.getInstance().putUsers(users);
super.onSuccess(dialog, args);
}
- }
- );
+ });
}
- public void deleteDialogs(Collection dialogs, QBEntityCallback callback) {
- for (QBDialog dialog : dialogs) {
- deleteDialog(dialog, new QBEntityCallback() {
- @Override
- public void onSuccess(Void aVoid, Bundle bundle) {
- }
-
- @Override
- public void onError(QBResponseException e) {
- }
- });
+ public void deleteDialogs(Collection dialogs, final QBEntityCallback> callback) {
+ StringifyArrayList dialogsIds = new StringifyArrayList<>();
+ for (QBChatDialog dialog : dialogs) {
+ dialogsIds.add(dialog.getDialogId());
}
- callback.onSuccess(null, null);
+ QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(callback);
}
- public void deleteDialog(QBDialog qbDialog, QBEntityCallback callback) {
- if (qbDialog.getType() == QBDialogType.GROUP) {
- QBChatService.getInstance().getGroupChatManager().deleteDialog(qbDialog.getDialogId(), true,
- new QbEntityCallbackWrapper(callback));
- } else if (qbDialog.getType() == QBDialogType.PRIVATE) {
- QBChatService.getInstance().getPrivateChatManager().deleteDialog(qbDialog.getDialogId(),
- true,
- new QbEntityCallbackWrapper(callback));
- } else if (qbDialog.getType() == QBDialogType.PUBLIC_GROUP) {
+ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) {
+ if (qbDialog.getType() == QBDialogType.PUBLIC_GROUP){
Toaster.shortToast(R.string.public_group_chat_cannot_be_deleted);
+ } else {
+ QBRestChatService.deleteDialog(qbDialog.getDialogId(), false)
+ .performAsync(new QbEntityCallbackWrapper(callback));
}
}
- public void leaveDialog(QBDialog qbDialog, QBEntityCallback callback) {
- QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder();
- qbRequestBuilder.pullAll("occupants_ids", SharedPreferencesUtil.getQbUser().getId());
+ public void exitFromDialog(QBChatDialog qbDialog, QBEntityCallback callback) {
+ try {
+ leaveChatDialog(qbDialog);
+ } catch (XMPPException | SmackException.NotConnectedException e) {
+ callback.onError(new QBResponseException(e.getMessage()));
+ }
- QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder,
- new QbEntityCallbackWrapper(callback) {
- @Override
- public void onSuccess(QBDialog qbDialog, Bundle bundle) {
- super.onSuccess(qbDialog, bundle);
- }
- });
+ QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder();
+ qbRequestBuilder.removeUsers(SharedPreferencesUtil.getQbUser().getId());
+
+ QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync(callback);
}
- public void updateDialogUsers(QBDialog qbDialog,
+ public void updateDialogUsers(QBChatDialog qbDialog,
final List newQbDialogUsersList,
- QBEntityCallback callback) {
+ QBEntityCallback callback) {
List addedUsers = QbDialogUtils.getAddedUsers(qbDialog, newQbDialogUsersList);
List removedUsers = QbDialogUtils.getRemovedUsers(qbDialog, newQbDialogUsersList);
@@ -187,19 +207,20 @@ public void updateDialogUsers(QBDialog qbDialog,
Log.w(TAG, "=======================");
QbDialogUtils.logUsers(removedUsers);
- QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder();
+ QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder();
if (!addedUsers.isEmpty()) {
- qbRequestBuilder.pushAll("occupants_ids", QbDialogUtils.getUserIds(addedUsers));
+ qbRequestBuilder.addUsers(addedUsers.toArray(new QBUser[addedUsers.size()]));
}
if (!removedUsers.isEmpty()) {
- qbRequestBuilder.pullAll("occupants_ids", QbDialogUtils.getUserIds(removedUsers));
+ qbRequestBuilder.removeUsers(removedUsers.toArray(new QBUser[removedUsers.size()]));
}
- qbDialog.setName(QbDialogUtils.createChatNameFromUserList(newQbDialogUsersList));
+ qbDialog.setName(DialogUtils.createChatNameFromUserList(
+ newQbDialogUsersList.toArray(new QBUser[newQbDialogUsersList.size()])));
- QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder,
- new QbEntityCallbackWrapper(callback) {
+ QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync(
+ new QbEntityCallbackWrapper(callback) {
@Override
- public void onSuccess(QBDialog qbDialog, Bundle bundle) {
+ public void onSuccess(QBChatDialog qbDialog, Bundle bundle) {
QbUsersHolder.getInstance().putUsers(newQbDialogUsersList);
QbDialogUtils.logDialogUsers(qbDialog);
super.onSuccess(qbDialog, bundle);
@@ -207,14 +228,14 @@ public void onSuccess(QBDialog qbDialog, Bundle bundle) {
});
}
- public void loadChatHistory(QBDialog dialog, int skipPagination,
+ public void loadChatHistory(QBChatDialog dialog, int skipPagination,
final QBEntityCallback> callback) {
QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder();
customObjectRequestBuilder.setSkip(skipPagination);
customObjectRequestBuilder.setLimit(CHAT_HISTORY_ITEMS_PER_PAGE);
customObjectRequestBuilder.sortDesc(CHAT_HISTORY_ITEMS_SORT_FIELD);
- QBChatService.getDialogMessages(dialog, customObjectRequestBuilder,
+ QBRestChatService.getDialogMessages(dialog, customObjectRequestBuilder).performAsync(
new QbEntityCallbackWrapper>(callback) {
@Override
public void onSuccess(ArrayList qbChatMessages, Bundle bundle) {
@@ -225,24 +246,21 @@ public void onSuccess(ArrayList qbChatMessages, Bundle bundle) {
});
}
- public void getDialogs(QBRequestGetBuilder customObjectRequestBuilder, final QBEntityCallback> callback) {
+ public void getDialogs(QBRequestGetBuilder customObjectRequestBuilder, final QBEntityCallback> callback) {
customObjectRequestBuilder.setLimit(DIALOG_ITEMS_PER_PAGE);
- QBChatService.getChatDialogs(null, customObjectRequestBuilder,
- new QbEntityCallbackWrapper>(callback) {
+ QBRestChatService.getChatDialogs(null, customObjectRequestBuilder).performAsync(
+ new QbEntityCallbackWrapper>(callback) {
@Override
- public void onSuccess(ArrayList dialogs, Bundle args) {
- Iterator dialogIterator = dialogs.iterator();
+ public void onSuccess(ArrayList dialogs, Bundle args) {
+ Iterator dialogIterator = dialogs.iterator();
while (dialogIterator.hasNext()) {
- QBDialog dialog = dialogIterator.next();
+ QBChatDialog dialog = dialogIterator.next();
if (dialog.getType() == QBDialogType.PUBLIC_GROUP) {
dialogIterator.remove();
}
}
- for (QBDialog dialog : dialogs) {
- dialog.setId(dialog.getDialogId().hashCode());
- }
getUsersFromDialogs(dialogs, callback);
// Not calling super.onSuccess() because
// we want to load chat users before triggering callback
@@ -250,11 +268,15 @@ public void onSuccess(ArrayList dialogs, Bundle args) {
});
}
- public void getUsersFromDialog(QBDialog dialog,
+ public void getDialogById(String dialogId, final QBEntityCallback callback) {
+ QBRestChatService.getChatDialogById(dialogId).performAsync(callback);
+ }
+
+ public void getUsersFromDialog(QBChatDialog dialog,
final QBEntityCallback> callback) {
List userIds = dialog.getOccupants();
- ArrayList users = new ArrayList<>(userIds.size());
+ final ArrayList users = new ArrayList<>(userIds.size());
for (Integer id : userIds) {
users.add(QbUsersHolder.getInstance().getUserById(id));
}
@@ -267,12 +289,12 @@ public void getUsersFromDialog(QBDialog dialog,
}
QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(userIds.size(), 1);
- QBUsers.getUsersByIDs(userIds, requestBuilder,
+ QBUsers.getUsersByIDs(userIds, requestBuilder).performAsync(
new QbEntityCallbackWrapper>(callback) {
@Override
public void onSuccess(ArrayList qbUsers, Bundle bundle) {
QbUsersHolder.getInstance().putUsers(qbUsers);
- super.onSuccess(qbUsers, bundle);
+ callback.onSuccess(qbUsers, bundle);
}
});
}
@@ -283,33 +305,33 @@ public void loadFileAsAttachment(File file, QBEntityCallback callb
public void loadFileAsAttachment(File file, QBEntityCallback callback,
QBProgressCallback progressCallback) {
- QBContent.uploadFileTask(file, true, null,
+ QBContent.uploadFileTask(file, true, null, progressCallback).performAsync(
new QbEntityCallbackTwoTypeWrapper(callback) {
@Override
public void onSuccess(QBFile qbFile, Bundle bundle) {
QBAttachment attachment = new QBAttachment(QBAttachment.PHOTO_TYPE);
attachment.setId(qbFile.getId().toString());
attachment.setUrl(qbFile.getPublicUrl());
- onSuccessInMainThread(attachment, bundle);
+ callback.onSuccess(attachment, bundle);
}
- }, progressCallback);
+ });
}
- private void getUsersFromDialogs(final ArrayList dialogs,
- final QBEntityCallback> callback) {
+ private void getUsersFromDialogs(final ArrayList dialogs,
+ final QBEntityCallback> callback) {
List userIds = new ArrayList<>();
- for (QBDialog dialog : dialogs) {
+ for (QBChatDialog dialog : dialogs) {
userIds.addAll(dialog.getOccupants());
userIds.add(dialog.getLastMessageUserId());
}
QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(userIds.size(), 1);
- QBUsers.getUsersByIDs(userIds, requestBuilder,
- new QbEntityCallbackTwoTypeWrapper, ArrayList>(callback) {
+ QBUsers.getUsersByIDs(userIds, requestBuilder).performAsync(
+ new QbEntityCallbackTwoTypeWrapper, ArrayList>(callback) {
@Override
public void onSuccess(ArrayList users, Bundle params) {
QbUsersHolder.getInstance().putUsers(users);
- onSuccessInMainThread(dialogs, params);
+ callback.onSuccess(dialogs, params);
}
});
}
@@ -322,12 +344,12 @@ private void getUsersFromMessages(final ArrayList messages,
}
QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(userIds.size(), 1);
- QBUsers.getUsersByIDs(userIds, requestBuilder,
+ QBUsers.getUsersByIDs(userIds, requestBuilder).performAsync(
new QbEntityCallbackTwoTypeWrapper, ArrayList>(callback) {
@Override
public void onSuccess(ArrayList users, Bundle params) {
QbUsersHolder.getInstance().putUsers(users);
- onSuccessInMainThread(messages, params);
+ callback.onSuccess(messages, params);
}
});
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/GroupChatImpl.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/GroupChatImpl.java
deleted file mode 100644
index 4c747e4ce..000000000
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/GroupChatImpl.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.quickblox.sample.chat.utils.chat;
-
-import android.os.Bundle;
-import android.util.Log;
-
-import com.quickblox.chat.QBChatService;
-import com.quickblox.chat.QBGroupChat;
-import com.quickblox.chat.QBGroupChatManager;
-import com.quickblox.chat.listeners.QBMessageSentListener;
-import com.quickblox.chat.model.QBChatMessage;
-import com.quickblox.chat.model.QBDialog;
-import com.quickblox.core.QBEntityCallback;
-import com.quickblox.core.exception.QBResponseException;
-
-import org.jivesoftware.smack.SmackException;
-import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smackx.muc.DiscussionHistory;
-
-public class GroupChatImpl extends BaseChatImpl implements QBMessageSentListener {
- private static final String TAG = GroupChatImpl.class.getSimpleName();
-
- private QBGroupChatManager qbGroupChatManager;
-
- public GroupChatImpl(QBChatMessageListener chatMessageListener) {
- super(chatMessageListener);
- }
-
- @Override
- protected void initManagerIfNeed() {
- if (qbGroupChatManager == null) {
- qbGroupChatManager = QBChatService.getInstance().getGroupChatManager();
- }
- }
-
- public void joinGroupChat(QBDialog dialog, QBEntityCallback callback) {
- initManagerIfNeed();
- if (qbChat == null) {
- qbChat = qbGroupChatManager.createGroupChat(dialog.getRoomJid());
- }
- join(callback);
- }
-
- private void join(final QBEntityCallback callback) {
- DiscussionHistory history = new DiscussionHistory();
- history.setMaxStanzas(0);
-
- qbChat.join(history, new QBEntityCallback() {
- @Override
- public void onSuccess(final Void result, final Bundle bundle) {
- qbChat.addMessageListener(GroupChatImpl.this);
- qbChat.addMessageSentListener(GroupChatImpl.this);
-
- mainThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.onSuccess(result, bundle);
- }
- });
- Log.i(TAG, "Join successful");
- }
-
- @Override
- public void onError(final QBResponseException e) {
- mainThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.onError(e);
- }
- });
- }
- });
- }
-
- public void leaveChatRoom() {
- try {
- qbChat.leave();
- } catch (SmackException.NotConnectedException | XMPPException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void release() throws XMPPException {
- if (qbChat != null) {
- leaveChatRoom();
- qbChat.removeMessageListener(this);
- }
- }
-
- @Override
- public void processMessageSent(QBGroupChat qbGroupChat, QBChatMessage qbChatMessage) {
-
- }
-
- @Override
- public void processMessageFailed(QBGroupChat qbGroupChat, QBChatMessage qbChatMessage) {
-
- }
-}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/PrivateChatImpl.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/PrivateChatImpl.java
deleted file mode 100644
index 8a1343f08..000000000
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/PrivateChatImpl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.quickblox.sample.chat.utils.chat;
-
-import android.util.Log;
-
-import com.quickblox.chat.QBChatService;
-import com.quickblox.chat.QBPrivateChat;
-import com.quickblox.chat.QBPrivateChatManager;
-import com.quickblox.chat.listeners.QBMessageSentListener;
-import com.quickblox.chat.listeners.QBPrivateChatManagerListener;
-import com.quickblox.chat.model.QBChatMessage;
-
-public class PrivateChatImpl extends BaseChatImpl
- implements QBPrivateChatManagerListener, QBMessageSentListener {
- private static final String TAG = PrivateChatImpl.class.getSimpleName();
-
- private QBPrivateChatManager qbPrivateChatManager;
-
- public PrivateChatImpl(QBChatMessageListener chatMessageListener, Integer opponentId) {
- super(chatMessageListener);
-
- qbChat = qbPrivateChatManager.getChat(opponentId);
- if (qbChat == null) {
- qbChat = qbPrivateChatManager.createChat(opponentId, this);
- } else {
- qbChat.addMessageListener(this);
- }
- qbChat.addMessageSentListener(this);
- }
-
- @Override
- protected void initManagerIfNeed() {
- if (qbPrivateChatManager == null) {
- qbPrivateChatManager = QBChatService.getInstance().getPrivateChatManager();
- qbPrivateChatManager.addPrivateChatManagerListener(this);
- }
- }
-
- @Override
- public void release() {
- Log.i(TAG, "Release private chat");
- initManagerIfNeed();
-
- qbChat.removeMessageSentListener(this);
- qbChat.removeMessageListener(this);
- qbPrivateChatManager.removePrivateChatManagerListener(this);
- }
-
- @Override
- public void chatCreated(QBPrivateChat incomingPrivateChat, boolean createdLocally) {
- Log.i(TAG, "Private chat created: " + incomingPrivateChat.getParticipant() + ", createdLocally:" + createdLocally);
-
- if (!createdLocally) {
- qbChat = incomingPrivateChat;
- qbChat.addMessageListener(this);
- }
- }
-
- @Override
- public void processMessageSent(QBPrivateChat qbPrivateChat, QBChatMessage qbChatMessage) {
- Log.i(TAG, "processMessageSent: " + qbChatMessage.getBody());
- }
-
- @Override
- public void processMessageFailed(QBPrivateChat qbPrivateChat, QBChatMessage qbChatMessage) {
-
- }
-}
\ No newline at end of file
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/QBChatMessageListener.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/QBChatMessageListener.java
deleted file mode 100644
index 4b6ddd58b..000000000
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/QBChatMessageListener.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.quickblox.sample.chat.utils.chat;
-
-import com.quickblox.chat.QBChat;
-import com.quickblox.chat.model.QBChatMessage;
-
-public interface QBChatMessageListener {
-
- void onQBChatMessageReceived(QBChat chat, QBChatMessage message);
-
-}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbChatDialogMessageListenerImp.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbChatDialogMessageListenerImp.java
new file mode 100644
index 000000000..254cf7637
--- /dev/null
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbChatDialogMessageListenerImp.java
@@ -0,0 +1,20 @@
+package com.quickblox.sample.chat.utils.qb;
+
+import com.quickblox.chat.exception.QBChatException;
+import com.quickblox.chat.listeners.QBChatDialogMessageListener;
+import com.quickblox.chat.model.QBChatMessage;
+
+public class QbChatDialogMessageListenerImp implements QBChatDialogMessageListener{
+ public QbChatDialogMessageListenerImp() {
+ }
+
+ @Override
+ public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) {
+
+ }
+
+ @Override
+ public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) {
+
+ }
+}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java
index b04e6f3f1..0d84b1f56 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java
@@ -1,15 +1,21 @@
package com.quickblox.sample.chat.utils.qb;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
+import com.quickblox.chat.model.QBChatMessage;
+import com.quickblox.chat.model.QBDialogType;
+import com.quickblox.users.model.QBUser;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
public class QbDialogHolder {
private static QbDialogHolder instance;
- private List dialogList;
+ private Map dialogsMap;
public static synchronized QbDialogHolder getInstance() {
if (instance == null) {
@@ -19,32 +25,107 @@ public static synchronized QbDialogHolder getInstance() {
}
private QbDialogHolder() {
- dialogList = new ArrayList<>();
+ dialogsMap = new TreeMap<>();
}
- public List getDialogList() {
- return dialogList;
+ public Map getDialogs() {
+ return getSortedMap(dialogsMap);
+ }
+
+ public QBChatDialog getChatDialogById(String dialogId){
+ return dialogsMap.get(dialogId);
}
public void clear() {
- dialogList.clear();
+ dialogsMap.clear();
+ }
+
+ public void addDialog(QBChatDialog dialog) {
+ if (dialog != null) {
+ dialogsMap.put(dialog.getDialogId(), dialog);
+ }
+ }
+
+ public void addDialogs(List dialogs) {
+ for (QBChatDialog dialog : dialogs) {
+ addDialog(dialog);
+ }
}
- public void addDialogToList(QBDialog dialog) {
- if (!dialogList.contains(dialog)) {
- dialogList.add(dialog);
+ public void deleteDialogs(Collection dialogs) {
+ for (QBChatDialog dialog : dialogs) {
+ deleteDialog(dialog);
}
}
- public void addDialogs(List dialogs) {
- for (QBDialog dialog : dialogs) {
- addDialogToList(dialog);
+ public void deleteDialogs(ArrayList dialogsIds) {
+ for (String dialogId : dialogsIds) {
+ deleteDialog(dialogId);
}
}
- public void deleteDialogs(Collection dialogs) {
- for (QBDialog dialog : dialogs) {
- dialogList.remove(dialog);
+ public void deleteDialog(QBChatDialog chatDialog){
+ dialogsMap.remove(chatDialog.getDialogId());
+ }
+
+ public void deleteDialog(String dialogId){
+ dialogsMap.remove(dialogId);
+ }
+
+ public boolean hasDialogWithId(String dialogId){
+ return dialogsMap.containsKey(dialogId);
+ }
+
+ public boolean hasPrivateDialogWithUser(QBUser user){
+ return getPrivateDialogWithUser(user) != null;
+ }
+
+ public QBChatDialog getPrivateDialogWithUser(QBUser user){
+ for (QBChatDialog chatDialog : dialogsMap.values()){
+ if (QBDialogType.PRIVATE.equals(chatDialog.getType())
+ && chatDialog.getOccupants().contains(user.getId())){
+ return chatDialog;
+ }
+ }
+
+ return null;
+ }
+
+ private Map getSortedMap(Map unsortedMap){
+ Map sortedMap = new TreeMap(new LastMessageDateSentComparator(unsortedMap));
+ sortedMap.putAll(unsortedMap);
+ return sortedMap;
+ }
+
+ public void updateDialog(String dialogId, QBChatMessage qbChatMessage){
+ QBChatDialog updatedDialog = getChatDialogById(dialogId);
+ updatedDialog.setLastMessage(qbChatMessage.getBody());
+ updatedDialog.setLastMessageDateSent(qbChatMessage.getDateSent());
+ updatedDialog.setUnreadMessageCount(updatedDialog.getUnreadMessageCount() != null
+ ? updatedDialog.getUnreadMessageCount() + 1 : 1);
+ updatedDialog.setLastMessageUserId(qbChatMessage.getSenderId());
+
+ dialogsMap.put(updatedDialog.getDialogId(), updatedDialog);
+ }
+
+ static class LastMessageDateSentComparator implements Comparator {
+ Map map;
+
+ public LastMessageDateSentComparator(Map map) {
+
+ this.map = map;
+ }
+
+ public int compare(String keyA, String keyB) {
+
+ long valueA = map.get(keyA).getLastMessageDateSent();
+ long valueB = map.get(keyB).getLastMessageDateSent();
+
+ if (valueB < valueA){
+ return -1;
+ } else {
+ return 1;
+ }
}
}
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogUtils.java
index cead02319..dfa8809fa 100644
--- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogUtils.java
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogUtils.java
@@ -3,34 +3,31 @@
import android.text.TextUtils;
import android.util.Log;
-import com.quickblox.chat.model.QBDialog;
+import com.quickblox.chat.model.QBChatDialog;
+import com.quickblox.chat.model.QBChatMessage;
import com.quickblox.chat.model.QBDialogType;
+import com.quickblox.chat.utils.DialogUtils;
import com.quickblox.sample.chat.utils.chat.ChatHelper;
import com.quickblox.users.model.QBUser;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
public class QbDialogUtils {
private static final String TAG = QbDialogUtils.class.getSimpleName();
- public static QBDialog createDialog(List users) {
+
+
+ public static QBChatDialog createDialog(List users) {
QBUser currentUser = ChatHelper.getCurrentUser();
users.remove(currentUser);
- QBDialog dialogToCreate = new QBDialog();
- dialogToCreate.setName(QbDialogUtils.createChatNameFromUserList(users));
- if (users.size() == 1) {
- dialogToCreate.setType(QBDialogType.PRIVATE);
- } else {
- dialogToCreate.setType(QBDialogType.GROUP);
- }
- dialogToCreate.setOccupantsIds(new ArrayList<>(Arrays.asList(QbDialogUtils.getUserIds(users))));
- return dialogToCreate;
+ return DialogUtils.buildDialog(users.toArray(new QBUser[users.size()]));
}
- public static List getAddedUsers(QBDialog dialog, List currentUsers) {
+ public static List getAddedUsers(QBChatDialog dialog, List currentUsers) {
return getAddedUsers(getQbUsersFromQbDialog(dialog), currentUsers);
}
@@ -55,7 +52,7 @@ public static List getAddedUsers(List previousUsers, List getRemovedUsers(QBDialog dialog, List currentUsers) {
+ public static List getRemovedUsers(QBChatDialog dialog, List currentUsers) {
return getRemovedUsers(getQbUsersFromQbDialog(dialog), currentUsers);
}
@@ -80,7 +77,7 @@ public static List getRemovedUsers(List previousUsers, List users) {
}
}
- public static Integer getOpponentIdForPrivateDialog(QBDialog dialog) {
- Integer opponentId = -1;
- QBUser qbUser = ChatHelper.getCurrentUser();
- if (qbUser == null) {
- return opponentId;
- }
-
- Integer currentUserId = qbUser.getId();
-
- for (Integer userId : dialog.getOccupants()) {
- if (!userId.equals(currentUserId)) {
- opponentId = userId;
- break;
- }
- }
- return opponentId;
- }
-
public static Integer[] getUserIds(List users) {
ArrayList ids = new ArrayList<>();
for (QBUser user : users) {
@@ -124,26 +103,12 @@ public static Integer[] getUserIds(List users) {
return ids.toArray(new Integer[ids.size()]);
}
- public static String createChatNameFromUserList(List users) {
- String chatName = "";
- QBUser currentUser = ChatHelper.getCurrentUser();
- for (QBUser user : users) {
- if (user.getId().equals(currentUser.getId())) {
- continue;
- }
-
- String prefix = chatName.equals("") ? "" : ", ";
- chatName = chatName + prefix + user.getFullName();
- }
- return chatName;
- }
-
- public static String getDialogName(QBDialog dialog) {
+ public static String getDialogName(QBChatDialog dialog) {
if (dialog.getType().equals(QBDialogType.GROUP)) {
return dialog.getName();
} else {
// It's a private dialog, let's use opponent's name as chat name
- Integer opponentId = getOpponentIdForPrivateDialog(dialog);
+ Integer opponentId = dialog.getRecipientId();
QBUser user = QbUsersHolder.getInstance().getUserById(opponentId);
if (user != null) {
return TextUtils.isEmpty(user.getFullName()) ? user.getLogin() : user.getFullName();
@@ -153,7 +118,7 @@ public static String getDialogName(QBDialog dialog) {
}
}
- private static List getQbUsersFromQbDialog(QBDialog dialog) {
+ private static List getQbUsersFromQbDialog(QBChatDialog dialog) {
List previousDialogUsers = new ArrayList<>();
for (Integer id : dialog.getOccupants()) {
QBUser user = QbUsersHolder.getInstance().getUserById(id);
@@ -164,4 +129,24 @@ private static List getQbUsersFromQbDialog(QBDialog dialog) {
}
return previousDialogUsers;
}
+
+ public static List getOccupantsIdsListFromString(String occupantIds) {
+ List occupantIdsList = new ArrayList<>();
+ String[] occupantIdsArray = occupantIds.split(",");
+ for (String occupantId : occupantIdsArray) {
+ occupantIdsList.add(Integer.valueOf(occupantId));
+ }
+ return occupantIdsList;
+ }
+
+ public static String getOccupantsIdsStringFromList(Collection occupantIdsList) {
+ return TextUtils.join(",", occupantIdsList);
+ }
+
+ public static QBChatDialog buildPrivateChatDialog(String dialogId, Integer recipientId){
+ QBChatDialog chatDialog = DialogUtils.buildPrivateDialog(recipientId);
+ chatDialog.setDialogId(dialogId);
+
+ return chatDialog;
+ }
}
diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/callback/QbEntityCallbackImpl.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/callback/QbEntityCallbackImpl.java
new file mode 100644
index 000000000..a233e0631
--- /dev/null
+++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/callback/QbEntityCallbackImpl.java
@@ -0,0 +1,22 @@
+package com.quickblox.sample.chat.utils.qb.callback;
+
+import android.os.Bundle;
+
+import com.quickblox.core.QBEntityCallback;
+import com.quickblox.core.exception.QBResponseException;
+
+public class QbEntityCallbackImpl implements QBEntityCallback {
+
+ public QbEntityCallbackImpl() {
+ }
+
+ @Override
+ public void onSuccess(T result, Bundle bundle) {
+
+ }
+
+ @Override
+ public void onError(QBResponseException e) {
+
+ }
+}
diff --git a/sample-content/build.gradle b/sample-content/build.gradle
index 69db42655..23afb5800 100644
--- a/sample-content/build.gradle
+++ b/sample-content/build.gradle
@@ -35,6 +35,10 @@ android {
keyPassword "android"
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
diff --git a/sample-content/src/main/java/com/quickblox/sample/content/activities/GalleryActivity.java b/sample-content/src/main/java/com/quickblox/sample/content/activities/GalleryActivity.java
index 35403ad77..2b9103ceb 100644
--- a/sample-content/src/main/java/com/quickblox/sample/content/activities/GalleryActivity.java
+++ b/sample-content/src/main/java/com/quickblox/sample/content/activities/GalleryActivity.java
@@ -92,7 +92,7 @@ private void getFileList() {
builder.setPerPage(IMAGES_PER_PAGE);
builder.setPage(current_page++);
- QBContent.getFiles(builder, new QBEntityCallback>() {
+ QBContent.getFiles(builder).performAsync(new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList qbFiles, Bundle bundle) {
if (qbFiles.isEmpty()) {
@@ -152,7 +152,12 @@ private void uploadSelectedImage(final File imageFile) {
progressDialog.setProgressNumberFormat("%1d/%2d kB");
progressDialog.show();
- QBContent.uploadFileTask(imageFile, true, null, new QBEntityCallback() {
+ QBContent.uploadFileTask(imageFile, true, null, new QBProgressCallback() {
+ @Override
+ public void onProgressUpdate(int progress) {
+ progressDialog.setProgress((int) (onePercent * progress));
+ }
+ }).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBFile qbFile, Bundle bundle) {
DataHolder.getInstance().addQbFile(qbFile);
@@ -171,11 +176,6 @@ public void onClick(View v) {
}
});
}
- }, new QBProgressCallback() {
- @Override
- public void onProgressUpdate(int progress) {
- progressDialog.setProgress((int) (onePercent * progress));
- }
});
}
diff --git a/sample-content/src/main/java/com/quickblox/sample/content/activities/SplashActivity.java b/sample-content/src/main/java/com/quickblox/sample/content/activities/SplashActivity.java
index 06be22a00..7df2cd319 100644
--- a/sample-content/src/main/java/com/quickblox/sample/content/activities/SplashActivity.java
+++ b/sample-content/src/main/java/com/quickblox/sample/content/activities/SplashActivity.java
@@ -23,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
private void createSession() {
QBUser qbUser = new QBUser(Consts.USER_LOGIN, Consts.USER_PASSWORD);
- QBAuth.createSession(qbUser, new QBEntityCallback() {
+ QBAuth.createSession(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
proceedToTheNextActivity();
diff --git a/sample-core/build.gradle b/sample-core/build.gradle
index 15feff1d6..05ef17026 100644
--- a/sample-core/build.gradle
+++ b/sample-core/build.gradle
@@ -10,6 +10,10 @@ android {
versionCode 1
versionName "1.0"
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
diff --git a/sample-core/src/main/java/com/quickblox/sample/core/gcm/GooglePlayServicesHelper.java b/sample-core/src/main/java/com/quickblox/sample/core/gcm/GooglePlayServicesHelper.java
index 0ebfb26c8..3d6981549 100644
--- a/sample-core/src/main/java/com/quickblox/sample/core/gcm/GooglePlayServicesHelper.java
+++ b/sample-core/src/main/java/com/quickblox/sample/core/gcm/GooglePlayServicesHelper.java
@@ -114,7 +114,7 @@ protected void onPostExecute(final String gcmRegId) {
qbSubscription.setRegistrationID(gcmRegId);
qbSubscription.setEnvironment(QBEnvironment.DEVELOPMENT); // Don't forget to change QBEnvironment to PRODUCTION when releasing application
- QBPushNotifications.createSubscription(qbSubscription,
+ QBPushNotifications.createSubscription(qbSubscription).performAsync(
new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList qbSubscriptions, Bundle bundle) {
diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle
index 285bbf13e..39f7d9bae 100644
--- a/sample-custom-objects/build.gradle
+++ b/sample-custom-objects/build.gradle
@@ -35,17 +35,21 @@ android {
keyPassword "android"
}
}
+
dataBinding {
enabled = true
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar"
+ compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion"
+ compile "com.quickblox:quickblox-android-sdk-extensions:$rootProject.qbSdkVersion"
compile 'com.github.orangegangsters:swipy:1.2.2@aar'
- compile(project(":sample-core")) {
- transitive = true;
- }
+ compile(project(":sample-core"))
}
apply from: "../artifacts.gradle"
\ No newline at end of file
diff --git a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/AddNewMovieActivity.java b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/AddNewMovieActivity.java
index b02cab545..24d2f901c 100644
--- a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/AddNewMovieActivity.java
+++ b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/AddNewMovieActivity.java
@@ -7,6 +7,7 @@
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -17,10 +18,11 @@
import android.widget.Spinner;
import android.widget.Toast;
-import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
+import com.quickblox.core.server.Performer;
import com.quickblox.customobjects.QBCustomObjects;
import com.quickblox.customobjects.model.QBCustomObject;
+import com.quickblox.extensions.RxJavaPerformProcessor;
import com.quickblox.sample.core.utils.Toaster;
import com.quickblox.sample.customobjects.R;
import com.quickblox.sample.customobjects.helper.DataHolder;
@@ -31,7 +33,13 @@
import java.util.Calendar;
import java.util.List;
+import rx.Observable;
+import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
public class AddNewMovieActivity extends BaseActivity implements TextWatcher {
+ private static final String TAG = AddNewMovieActivity.class.getSimpleName();
private static final String OBJ = "\uFFFC";
private EditText titleEditText;
@@ -97,25 +105,39 @@ private void createNewMovie() {
QBCustomObject qbCustomObject = QBCustomObjectsUtils.createCustomObject(title, description, year, rating);
- QBCustomObjects.createObject(qbCustomObject, new QBEntityCallback() {
+
+ Performer performer = QBCustomObjects.createObject(qbCustomObject);
+ Observable observable =
+ performer.convertTo(RxJavaPerformProcessor.INSTANCE);
+
+ observable.subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
@Override
- public void onSuccess(QBCustomObject qbCustomObject, Bundle bundle) {
+ public void onCompleted() {
progressDialog.dismiss();
Toaster.shortToast(R.string.done);
- DataHolder.getInstance().addMovieToMap(new Movie(qbCustomObject));
finish();
}
@Override
- public void onError(QBResponseException e) {
+ public void onError(Throwable e) {
progressDialog.dismiss();
- View rootLayout = findViewById(R.id.activity_add_movie);
- showSnackbarError(rootLayout, R.string.splash_create_session_error, e, new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- createNewMovie();
- }
- });
+ if (QBCustomObjectsUtils.checkQBException(e)) {
+ View rootLayout = findViewById(R.id.activity_add_movie);
+ showSnackbarError(rootLayout, R.string.splash_create_session_error, (QBResponseException) e, new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ createNewMovie();
+ }
+ });
+ } else {
+ Log.d(TAG, "onError" + e.getMessage());
+ }
+ }
+
+ @Override
+ public void onNext(QBCustomObject qbCustomObject) {
+ DataHolder.getInstance().addMovieToMap(new Movie(qbCustomObject));
}
});
}
diff --git a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/MovieListActivity.java b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/MovieListActivity.java
index 5a73bfb7f..a1bcceb51 100644
--- a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/MovieListActivity.java
+++ b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/MovieListActivity.java
@@ -3,6 +3,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -12,22 +13,30 @@
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout;
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection;
-import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.core.request.QBRequestGetBuilder;
+import com.quickblox.core.server.Performer;
import com.quickblox.customobjects.QBCustomObjects;
import com.quickblox.customobjects.model.QBCustomObject;
+import com.quickblox.extensions.RxJavaPerformProcessor;
import com.quickblox.sample.customobjects.R;
import com.quickblox.sample.customobjects.adapter.MovieListAdapter;
-import com.quickblox.sample.customobjects.utils.Consts;
import com.quickblox.sample.customobjects.helper.DataHolder;
import com.quickblox.sample.customobjects.model.Movie;
+import com.quickblox.sample.customobjects.utils.Consts;
+import com.quickblox.sample.customobjects.utils.QBCustomObjectsUtils;
import java.util.ArrayList;
import java.util.Map;
-public class MovieListActivity extends BaseActivity implements AdapterView.OnItemClickListener {
+import rx.Observable;
+import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+public class MovieListActivity extends BaseActivity implements AdapterView.OnItemClickListener {
+ private static final String TAG = MovieListActivity.class.getSimpleName();
private static final String createDateField = "created_at";
private MovieListAdapter movieListAdapter;
@@ -109,34 +118,51 @@ private void getMovieList(boolean progress) {
}
builder.setLimit(Consts.LIMIT_RECORDS);
builder.sortDesc(createDateField);
- QBCustomObjects.getObjects(Consts.CLASS_NAME, builder, new QBEntityCallback>() {
- @Override
- public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) {
- setOnRefreshListener.setEnabled(true);
- Map movieMap = DataHolder.getInstance().getMovieMap();
- for (QBCustomObject customObject : qbCustomObjects) {
- DataHolder.getInstance().addMovieToMap(new Movie(customObject));
- }
+ Performer> performer = QBCustomObjects.getObjects(Consts.CLASS_NAME, builder);
+ Observable> observable = performer.convertTo(RxJavaPerformProcessor.INSTANCE);
- progressDialog.dismiss();
- setOnRefreshListener.setRefreshing(false);
- movieListAdapter.updateData(movieMap);
+ observable.flatMap(new Func1, Observable>() {
+ @Override
+ public Observable call(ArrayList qbCustomObjects) {
+ return Observable.from(qbCustomObjects);
}
+ }).subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe(new Observer() {
+ @Override
+ public void onCompleted() {
+ setResultParams(true);
+ Map movieMap = DataHolder.getInstance().getMovieMap();
+ movieListAdapter.updateData(movieMap);
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ setResultParams(false);
+ if (QBCustomObjectsUtils.checkQBException(e)) {
+ View rootLayout = findViewById(R.id.swipy_refresh_layout);
+ showSnackbarError(rootLayout, R.string.splash_create_session_error, (QBResponseException) e, new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getMovieList(false);
+ }
+ });
+ } else {
+ Log.d(TAG, "onError" + e.getMessage());
+ }
+ }
- @Override
- public void onError(QBResponseException e) {
- setOnRefreshListener.setEnabled(false);
- View rootLayout = findViewById(R.id.swipy_refresh_layout);
- showSnackbarError(rootLayout, R.string.splash_create_session_error, e, new View.OnClickListener() {
@Override
- public void onClick(View v) {
- getMovieList(false);
+ public void onNext(QBCustomObject customObject) {
+ DataHolder.getInstance().addMovieToMap(new Movie(customObject));
}
});
- progressDialog.dismiss();
- setOnRefreshListener.setRefreshing(false);
- }
- });
+ }
+
+ private void setResultParams(boolean enabled) {
+ setOnRefreshListener.setEnabled(enabled);
+ progressDialog.dismiss();
+ setOnRefreshListener.setRefreshing(false);
}
}
\ No newline at end of file
diff --git a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/SplashActivity.java b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/SplashActivity.java
index fabe1a5e5..c9531b2f3 100644
--- a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/SplashActivity.java
+++ b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/activities/SplashActivity.java
@@ -1,18 +1,27 @@
package com.quickblox.sample.customobjects.activities;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import com.quickblox.auth.QBAuth;
import com.quickblox.auth.model.QBSession;
-import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
+import com.quickblox.core.server.Performer;
+import com.quickblox.extensions.RxJavaPerformProcessor;
import com.quickblox.sample.core.ui.activity.CoreSplashActivity;
import com.quickblox.sample.customobjects.R;
import com.quickblox.sample.customobjects.utils.Consts;
+import com.quickblox.sample.customobjects.utils.QBCustomObjectsUtils;
import com.quickblox.users.model.QBUser;
+import rx.Observable;
+import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
public class SplashActivity extends CoreSplashActivity {
+ private static final String TAG = SplashActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -23,20 +32,35 @@ protected void onCreate(Bundle savedInstanceState) {
private void createSession() {
QBUser qbUser = new QBUser(Consts.USER_LOGIN, Consts.USER_PASSWORD);
- QBAuth.createSession(qbUser, new QBEntityCallback() {
+
+ Performer performer = QBAuth.createSession(qbUser);
+ Observable observable =
+ performer.convertTo(RxJavaPerformProcessor.INSTANCE);
+
+ observable.subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() {
@Override
- public void onSuccess(QBSession qbSession, Bundle bundle) {
- proceedToTheNextActivity();
+ public void onCompleted() {
}
@Override
- public void onError(QBResponseException e) {
- showSnackbarError(null, R.string.splash_create_session_error, e, new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- createSession();
- }
- });
+ public void onError(Throwable e) {
+ if (QBCustomObjectsUtils.checkQBException(e)) {
+ showSnackbarError(null, R.string.splash_create_session_error, (QBResponseException) e, new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ createSession();
+ }
+ });
+ } else {
+ Log.d(TAG, "onError" + e.getMessage());
+ }
+ }
+
+ @Override
+ public void onNext(QBSession qbSession) {
+ // session created
+ proceedToTheNextActivity();
}
});
}
@@ -51,4 +75,4 @@ protected void proceedToTheNextActivity() {
MovieListActivity.start(this);
finish();
}
-}
+}
\ No newline at end of file
diff --git a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/utils/QBCustomObjectsUtils.java b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/utils/QBCustomObjectsUtils.java
index 450376f51..261a24813 100644
--- a/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/utils/QBCustomObjectsUtils.java
+++ b/sample-custom-objects/src/main/java/com/quickblox/sample/customobjects/utils/QBCustomObjectsUtils.java
@@ -1,5 +1,6 @@
package com.quickblox.sample.customobjects.utils;
+import com.quickblox.core.exception.QBResponseException;
import com.quickblox.customobjects.model.QBCustomObject;
import com.quickblox.sample.customobjects.model.Movie;
@@ -29,4 +30,7 @@ public static QBCustomObject createCustomObject(String title, String description
return qbCustomObject;
}
+ public static boolean checkQBException(Throwable exception) {
+ return exception instanceof QBResponseException;
+ }
}
\ No newline at end of file
diff --git a/sample-location/build.gradle b/sample-location/build.gradle
index 80ef84ab7..f5a94c98f 100644
--- a/sample-location/build.gradle
+++ b/sample-location/build.gradle
@@ -35,10 +35,14 @@ android {
keyPassword "android"
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion@aar"
+ compile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion"
compile (project(":sample-core")) {
transitive = true;
}
diff --git a/sample-location/src/main/java/com/quickblox/sample/location/activities/MapActivity.java b/sample-location/src/main/java/com/quickblox/sample/location/activities/MapActivity.java
index 91bb49286..777a445ff 100644
--- a/sample-location/src/main/java/com/quickblox/sample/location/activities/MapActivity.java
+++ b/sample-location/src/main/java/com/quickblox/sample/location/activities/MapActivity.java
@@ -87,7 +87,7 @@ private void initLocationRequestBuilder() {
getLocationsBuilder.setPerPage(Consts.LOCATION_PER_PAGE);
getLocationsBuilder.setLastOnly();
- QBLocations.getLocations(getLocationsBuilder, new QBEntityCallback>() {
+ QBLocations.getLocations(getLocationsBuilder).performAsync( new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList qbLocations, Bundle bundle) {
// show all locations on the map
@@ -202,7 +202,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
// ================= QuickBlox ====================
// Share own location
QBLocation location = new QBLocation(lat, lng, input.getText().toString());
- QBLocations.createLocation(location, new QBEntityCallback() {
+ QBLocations.createLocation(location).performAsync( new QBEntityCallback() {
@Override
public void onSuccess(QBLocation qbLocation, Bundle bundle) {
Toaster.longToast(R.string.dlg_check_in_success);
diff --git a/sample-location/src/main/java/com/quickblox/sample/location/activities/SplashActivity.java b/sample-location/src/main/java/com/quickblox/sample/location/activities/SplashActivity.java
index 48aa2b050..26379f12f 100644
--- a/sample-location/src/main/java/com/quickblox/sample/location/activities/SplashActivity.java
+++ b/sample-location/src/main/java/com/quickblox/sample/location/activities/SplashActivity.java
@@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Create QuickBlox session
QBUser qbUser = new QBUser(Consts.USER_LOGIN, Consts.USER_PASSWORD);
- QBAuth.createSession(qbUser, new QBEntityCallback() {
+ QBAuth.createSession(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
proceedToTheNextActivity();
diff --git a/sample-pushnotifications/build.gradle b/sample-pushnotifications/build.gradle
index a370be653..4b4c5e05c 100644
--- a/sample-pushnotifications/build.gradle
+++ b/sample-pushnotifications/build.gradle
@@ -35,12 +35,14 @@ android {
keyPassword "android"
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile(project(":sample-core")) {
- transitive = true;
- }
+ compile(project(":sample-core"))
compile "com.google.android.gms:play-services-gcm:${rootProject.playServicesVersion}"
}
diff --git a/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/MessagesActivity.java b/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/MessagesActivity.java
index ceea9dfc4..80200a013 100644
--- a/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/MessagesActivity.java
+++ b/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/MessagesActivity.java
@@ -161,7 +161,7 @@ private void sendPushMessage() {
userIds.add(App.getInstance().getCurrentUserId());
qbEvent.setUserIds(userIds);
- QBPushNotifications.createEvent(qbEvent, new QBEntityCallback() {
+ QBPushNotifications.createEvent(qbEvent).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBEvent qbEvent, Bundle bundle) {
progressBar.setVisibility(View.INVISIBLE);
diff --git a/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/SplashActivity.java b/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/SplashActivity.java
index 4779f54d7..914ec375b 100644
--- a/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/SplashActivity.java
+++ b/sample-pushnotifications/src/main/java/com/quickblox/sample/pushnotifications/activities/SplashActivity.java
@@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
private void createSession() {
QBUser qbUser = new QBUser(Consts.USER_LOGIN, Consts.USER_PASSWORD);
- QBAuth.createSession(qbUser, new QBEntityCallback() {
+ QBAuth.createSession(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
App.getInstance().setCurrentUserId(qbSession.getUserId());
diff --git a/sample-users/build.gradle b/sample-users/build.gradle
index 076182d51..53265f9a1 100644
--- a/sample-users/build.gradle
+++ b/sample-users/build.gradle
@@ -39,12 +39,14 @@ android {
dataBinding {
enabled = true
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile(project(':sample-core')) {
- transitive = true;
- }
+ compile(project(':sample-core'))
compile 'com.github.orangegangsters:swipy:1.2.2@aar'
}
diff --git a/sample-users/src/main/java/com/quickblox/sample/user/activities/ShowUserActivity.java b/sample-users/src/main/java/com/quickblox/sample/user/activities/ShowUserActivity.java
index 1f5fc441c..13081b10e 100644
--- a/sample-users/src/main/java/com/quickblox/sample/user/activities/ShowUserActivity.java
+++ b/sample-users/src/main/java/com/quickblox/sample/user/activities/ShowUserActivity.java
@@ -107,7 +107,7 @@ private void updateProfile() {
qbUser.setPhone(phoneNumber);
qbUser.setTags(tagsArray);
- QBUsers.updateUser(qbUser, new QBEntityCallback() {
+ QBUsers.updateUser(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBUser user, Bundle args) {
diff --git a/sample-users/src/main/java/com/quickblox/sample/user/activities/SignInActivity.java b/sample-users/src/main/java/com/quickblox/sample/user/activities/SignInActivity.java
index bccf53079..d0e009373 100644
--- a/sample-users/src/main/java/com/quickblox/sample/user/activities/SignInActivity.java
+++ b/sample-users/src/main/java/com/quickblox/sample/user/activities/SignInActivity.java
@@ -40,7 +40,7 @@ public void signIn() {
progressDialog.show();
QBUser qbUser = new QBUser(loginEditText.getText().toString(), passwordEditText.getText().toString());
- QBUsers.signIn(qbUser, new QBEntityCallback() {
+ QBUsers.signIn(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
progressDialog.dismiss();
diff --git a/sample-users/src/main/java/com/quickblox/sample/user/activities/SignUpUserActivity.java b/sample-users/src/main/java/com/quickblox/sample/user/activities/SignUpUserActivity.java
index 41652e8cf..e1a563f54 100644
--- a/sample-users/src/main/java/com/quickblox/sample/user/activities/SignUpUserActivity.java
+++ b/sample-users/src/main/java/com/quickblox/sample/user/activities/SignUpUserActivity.java
@@ -58,7 +58,7 @@ public void signUp() {
QBUser qbUser = new QBUser();
qbUser.setLogin(login);
qbUser.setPassword(password);
- QBUsers.signUpSignInTask(qbUser, new QBEntityCallback() {
+ QBUsers.signUpSignInTask(qbUser).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
progressDialog.dismiss();
diff --git a/sample-users/src/main/java/com/quickblox/sample/user/activities/SplashActivity.java b/sample-users/src/main/java/com/quickblox/sample/user/activities/SplashActivity.java
index 62988bd94..f4545633d 100644
--- a/sample-users/src/main/java/com/quickblox/sample/user/activities/SplashActivity.java
+++ b/sample-users/src/main/java/com/quickblox/sample/user/activities/SplashActivity.java
@@ -31,7 +31,7 @@ protected void proceedToTheNextActivity() {
}
private void createSession() {
- QBAuth.createSession(new QBEntityCallback() {
+ QBAuth.createSession().performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
proceedToTheNextActivity();
diff --git a/sample-users/src/main/java/com/quickblox/sample/user/activities/UsersListActivity.java b/sample-users/src/main/java/com/quickblox/sample/user/activities/UsersListActivity.java
index 9161a7111..293b8a99c 100644
--- a/sample-users/src/main/java/com/quickblox/sample/user/activities/UsersListActivity.java
+++ b/sample-users/src/main/java/com/quickblox/sample/user/activities/UsersListActivity.java
@@ -157,7 +157,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.logout:
progressDialog.show();
- QBUsers.signOut(new QBEntityCallback() {
+ QBUsers.signOut().performAsync(new QBEntityCallback() {
@Override
public void onSuccess(Void result, Bundle bundle) {
progressDialog.dismiss();
@@ -200,7 +200,7 @@ private void getAllUsers(boolean showProgress) {
progressDialog.show();
}
- QBUsers.getUsers(qbPagedBuilder, new QBEntityCallback>() {
+ QBUsers.getUsers(qbPagedBuilder).performAsync(new QBEntityCallback>() {
@Override
public void onSuccess(ArrayList qbUsers, Bundle bundle) {
setOnRefreshListener.setEnabled(true);
diff --git a/sample-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle
index 3c154d473..be8e9c33b 100755
--- a/sample-videochat-webrtc/build.gradle
+++ b/sample-videochat-webrtc/build.gradle
@@ -42,6 +42,11 @@ android {
resValue "string", "versionName", "QuickBlox WebRTC\nBuild version " + defaultConfig.getVersionName()
signingConfig signingConfigs.debug
}
+
+ release {
+ resValue "string", "versionName", "QuickBlox WebRTC\nBuild version " + defaultConfig.getVersionName()
+ signingConfig signingConfigs.debug
+ }
}
signingConfigs {
@@ -52,18 +57,17 @@ android {
keyPassword "android"
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
- compile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion@aar") {
- transitive=true
- }
- compile "com.quickblox:quickblox-android-sdk-videochat-webrtc:$rootProject.qbSdkVersion@aar"
+ compile "com.quickblox:quickblox-android-sdk-videochat-webrtc:$rootProject.qbSdkVersion"
- compile (project(":sample-core")) {
- transitive = true;
- }
+ compile (project(":sample-core"))
compile "com.android.support:recyclerview-v7:${rootProject.recyclerviewV7Version}"
compile "com.android.support:cardview-v7:23.+"
diff --git a/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/util/QBResRequestExecutor.java b/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/util/QBResRequestExecutor.java
index 274952162..f0d4e6977 100644
--- a/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/util/QBResRequestExecutor.java
+++ b/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/util/QBResRequestExecutor.java
@@ -26,18 +26,18 @@ public class QBResRequestExecutor {
private String TAG = QBResRequestExecutor.class.getSimpleName();
public void createSession(QBEntityCallback callback) {
- QBAuth.createSession(callback);
+ QBAuth.createSession().performAsync(callback);
}
public void createSessionWithUser(final QBUser qbUser, final QBEntityCallback callback) {
- QBAuth.createSession(qbUser, callback);
+ QBAuth.createSession(qbUser).performAsync(callback);
}
public void signUpNewUser(final QBUser newQbUser, final QBEntityCallback callback) {
createSessionWithoutUser(new QBEntityCallback() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
- QBUsers.signUp(newQbUser, callback);
+ QBUsers.signUp(newQbUser).performAsync(callback);
}
@Override
@@ -48,11 +48,11 @@ public void onError(QBResponseException e) {
}
public void signInUser(final QBUser currentQbUser, final QBEntityCallback callback) {
- QBUsers.signIn(currentQbUser, callback);
+ QBUsers.signIn(currentQbUser).performAsync(callback);
}
public void deleteCurrentUser(int currentQbUserID, QBEntityCallback callback) {
- QBUsers.deleteUser(currentQbUserID, callback);
+ QBUsers.deleteUser(currentQbUserID).performAsync(callback);
}
public void loadUsersByTag(final String tag, final QBEntityCallback> callback) {
@@ -63,7 +63,7 @@ public void onSuccess(QBSession result, Bundle params) {
List tags = new LinkedList<>();
tags.add(tag);
- QBUsers.getUsersByTags(tags, requestBuilder, callback);
+ QBUsers.getUsersByTags(tags, requestBuilder).performAsync(callback);
}
});
}
@@ -72,7 +72,7 @@ public void loadUsersByIds(final Collection usersIDs, final QBEntityCal
restoreOrCreateSession(new QBEntityCallbackImpl() {
@Override
public void onSuccess(QBSession result, Bundle params) {
- QBUsers.getUsersByIDs(usersIDs, null, callback);
+ QBUsers.getUsersByIDs(usersIDs, null).performAsync(callback);
}
});
}
diff --git a/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/utils/PushNotificationSender.java b/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/utils/PushNotificationSender.java
index ecc7f6f8a..3d29fadc3 100644
--- a/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/utils/PushNotificationSender.java
+++ b/sample-videochat-webrtc/src/main/java/com/quickblox/sample/groupchatwebrtc/utils/PushNotificationSender.java
@@ -27,6 +27,6 @@ public static void sendPushMessage(ArrayList recipients, String senderN
StringifyArrayList userIds = new StringifyArrayList<>(recipients);
qbEvent.setUserIds(userIds);
- QBPushNotifications.createEvent(qbEvent, null);
+ QBPushNotifications.createEvent(qbEvent).performAsync(null);
}
}
diff --git a/settings.gradle b/settings.gradle
index 0d98ce9e7..edba2b308 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -7,4 +7,3 @@ include 'sample-pushnotifications'
include 'sample-users'
include 'sample-videochat-webrtc'
include 'snippets'
-
diff --git a/snippets/build.gradle b/snippets/build.gradle
index 7146270c9..d724270ad 100644
--- a/snippets/build.gradle
+++ b/snippets/build.gradle
@@ -41,21 +41,8 @@ android {
}
}
- productFlavors {
- // JAR
- online {
-
- }
-
- // AAR
- onlineAar {
-
- }
-
- // for development
- offlineDev {
-
- }
+ lintOptions {
+ abortOnError false
}
}
@@ -63,16 +50,6 @@ android {
dependencies {
compile(project(":sample-core"))
- // online dependencies, from maven repository, jar files
- //
- onlineCompile("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion") {
- exclude group: 'de.measite.minidns'
- exclude group: 'org.jxmpp'
- }
- onlineCompile "com.quickblox:quickblox-android-sdk-content:$rootProject.qbSdkVersion@aar"
- onlineCompile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar"
- onlineCompile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion@aar"
-
// online dependencies, from remote repository, aar files
compile "com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion"
@@ -80,15 +57,6 @@ dependencies {
compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion"
compile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion"
-// // offline dependencies, from 'SDK-android' dir, for debug
-// //
-// offlineDevCompile project(':quickblox-android-sdk-core')
-// offlineDevCompile project(':quickblox-android-sdk-chat')
-// offlineDevCompile project(':quickblox-android-sdk-content')
-// offlineDevCompile project(':quickblox-android-sdk-messages')
-// offlineDevCompile project(':quickblox-android-sdk-location')
-// offlineDevCompile project(':quickblox-android-sdk-customobjects')
-
// twitter digits
compile('com.digits.sdk.android:digits:1.9.0@aar') {
transitive = true;
diff --git a/snippets/src/main/java/com/sdk/snippets/activities/StartSnippetsActivity.java b/snippets/src/main/java/com/sdk/snippets/activities/StartSnippetsActivity.java
index 21de656c3..df696a3bc 100644
--- a/snippets/src/main/java/com/sdk/snippets/activities/StartSnippetsActivity.java
+++ b/snippets/src/main/java/com/sdk/snippets/activities/StartSnippetsActivity.java
@@ -3,6 +3,7 @@
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
+import android.view.WindowManager;
import android.widget.TabHost;
import com.sdk.snippets.R;
@@ -51,5 +52,7 @@ public void onCreate(Bundle savedInstanceState) {
tabHost.addTab(content);
tabHost.addTab(users);
tabHost.addTab(locations);
+
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
\ No newline at end of file
diff --git a/snippets/src/main/java/com/sdk/snippets/core/ApplicationConfig.java b/snippets/src/main/java/com/sdk/snippets/core/ApplicationConfig.java
index e0223ee74..b10e62743 100644
--- a/snippets/src/main/java/com/sdk/snippets/core/ApplicationConfig.java
+++ b/snippets/src/main/java/com/sdk/snippets/core/ApplicationConfig.java
@@ -97,13 +97,13 @@ private void parseJsonServers(){
useUser1 = jObject.getBoolean("use_first_user");
- // fast run mode (only for debug)
- //
- if(android.os.Build.MODEL.equals("Galaxy Nexus")){
- useUser1 = false;
- }else{
- useUser1 = true;
- }
+// // fast run mode (only for debug)
+// //
+// if(android.os.Build.MODEL.equals("Galaxy Nexus")){
+// useUser1 = false;
+// }else{
+// useUser1 = true;
+// }
} catch (Exception e) {
e.printStackTrace();
diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsAuth.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsAuth.java
index cd73c0e67..5b164e051 100644
--- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsAuth.java
+++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsAuth.java
@@ -72,7 +72,7 @@ public SnippetsAuth(Context context) {
@Override
public void execute() {
- QBAuth.createSession(new QBEntityCallback() {
+ QBAuth.createSession().performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession session, Bundle params) {
@@ -92,7 +92,7 @@ public void onError(QBResponseException e) {
public void executeAsync() {
QBSession session = null;
try {
- session = QBAuth.createSession();
+ session = QBAuth.createSession().perform();
} catch (QBResponseException e) {
setException(e);
}
@@ -114,7 +114,7 @@ public void executeAsync() {
public void execute() {
QBAuth.createSession(new QBUser(ApplicationConfig.getInstance().getTestUserLogin1(),
- ApplicationConfig.getInstance().getTestUserPassword1()), new QBEntityCallback() {
+ ApplicationConfig.getInstance().getTestUserPassword1())).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession session, Bundle args) {
Log.i(TAG, "session created, token = " + session.getToken());
@@ -141,7 +141,7 @@ public void executeAsync() {
try {
QBUser user = new QBUser(ApplicationConfig.getInstance().getTestUserLogin1(),
ApplicationConfig.getInstance().getTestUserPassword1());
- session = QBAuth.createSession(user);
+ session = QBAuth.createSession(user).perform();
} catch (QBResponseException e) {
setException(e);
}
@@ -163,7 +163,7 @@ public void execute() {
String facebookAccessToken = "AAAEra8jNdnkBABYf3ZBSAz9dgLfyK7tQNttIoaZA1cC40niR6HVS0nYuufZB0ZCn66VJcISM8DO2bcbhEahm2nW01ZAZC1YwpZB7rds37xW0wZDZD";
- QBAuth.createSessionUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null, new QBEntityCallback() {
+ QBAuth.createSessionUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null).performAsync(new QBEntityCallback() {
@Override
public void onSuccess(QBSession session, Bundle args) {
@@ -185,7 +185,7 @@ public void executeAsync() {
try {
String facebookAccessToken = "AAAEra8jNdnkBABYf3ZBSAz9dgLfyK7tQNttIoaZA1cC40niR6HVS0nYuufZB0ZCn66VJcISM8DO2bcbhEahm2nW01ZAZC1YwpZB7rds37xW0wZDZD";
- session = QBAuth.createSessionUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null);
+ session = QBAuth.createSessionUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null).perform();
} catch (QBResponseException e) {
setException(e);
}
@@ -243,7 +243,7 @@ public void success(DigitsSession session, String phoneNumber) {
if(isSync){
QBSession qbSession = null;
try {
- qbSession = QBAuth.createSessionUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization);
+ qbSession = QBAuth.createSessionUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization).perform();
} catch (QBResponseException e) {
e.printStackTrace();
}
@@ -251,7 +251,7 @@ public void success(DigitsSession session, String phoneNumber) {
Log.i(TAG, "session created: " + qbSession);
}
}else{
- QBAuth.createSessionUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization, new QBEntityCallback