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() { + QBAuth.createSessionUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBSession qbSession, Bundle params) { Log.i(TAG, "session created: "+qbSession); @@ -288,7 +288,7 @@ private Map getAuthHeadersBySession(DigitsSession digitsSession) Snippet destroySession = new Snippet("destroy session") { @Override public void execute() { - QBAuth.deleteSession(new QBEntityCallback() { + QBAuth.deleteSession().performAsync(new QBEntityCallback() { @Override public void onSuccess(Void aVoid, Bundle bundle) { Log.i(TAG, "success"); @@ -306,7 +306,7 @@ public void onError(QBResponseException e) { @Override public void executeAsync() { try { - QBAuth.deleteSession(); + QBAuth.deleteSession().perform(); Log.i(TAG, "session destroyed "); } catch (QBResponseException e) { Log.i(TAG, "destroy fail"); @@ -325,7 +325,7 @@ public void executeAsync() { @Override public void execute() { - QBAuth.getSession(new QBEntityCallback() { + QBAuth.getSession().performAsync(new QBEntityCallback() { @Override public void onSuccess(QBSession qbSession, Bundle bundle) { Log.i(TAG, "session: " + qbSession); @@ -343,7 +343,7 @@ public void onError(QBResponseException strings) { @Override public void executeAsync() { try { - QBSession session = QBAuth.getSession(); + QBSession session = QBAuth.getSession().perform(); Log.i(TAG, "session: " + session); } catch (QBResponseException e) { Log.i(TAG, "get session fail"); diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java index a8b79a941..f713920d6 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java @@ -5,36 +5,32 @@ import android.util.Log; import com.quickblox.chat.QBChatService; -import com.quickblox.chat.QBGroupChat; -import com.quickblox.chat.QBGroupChatManager; import com.quickblox.chat.QBMessageStatusesManager; import com.quickblox.chat.QBPingManager; import com.quickblox.chat.QBPrivacyListsManager; -import com.quickblox.chat.QBPrivateChat; -import com.quickblox.chat.QBPrivateChatManager; +import com.quickblox.chat.QBRestChatService; import com.quickblox.chat.QBRoster; import com.quickblox.chat.QBSystemMessagesManager; import com.quickblox.chat.exception.QBChatException; -import com.quickblox.chat.listeners.QBGroupChatManagerListener; -import com.quickblox.chat.listeners.QBIsTypingListener; -import com.quickblox.chat.listeners.QBMessageListener; -import com.quickblox.chat.listeners.QBMessageSentListener; +import com.quickblox.chat.listeners.QBChatDialogMessageListener; +import com.quickblox.chat.listeners.QBChatDialogMessageSentListener; +import com.quickblox.chat.listeners.QBChatDialogParticipantListener; +import com.quickblox.chat.listeners.QBChatDialogTypingListener; import com.quickblox.chat.listeners.QBMessageStatusListener; -import com.quickblox.chat.listeners.QBParticipantListener; import com.quickblox.chat.listeners.QBPrivacyListListener; -import com.quickblox.chat.listeners.QBPrivateChatManagerListener; import com.quickblox.chat.listeners.QBRosterListener; import com.quickblox.chat.listeners.QBSubscriptionListener; import com.quickblox.chat.listeners.QBSystemMessageListener; 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.QBDialogCustomData; import com.quickblox.chat.model.QBDialogType; import com.quickblox.chat.model.QBPresence; import com.quickblox.chat.model.QBPrivacyList; import com.quickblox.chat.model.QBPrivacyListItem; import com.quickblox.chat.model.QBRosterEntry; +import com.quickblox.chat.utils.DialogUtils; import com.quickblox.core.QBEntityCallback; import com.quickblox.core.exception.QBResponseException; import com.quickblox.core.helper.StringifyArrayList; @@ -79,16 +75,20 @@ public class SnippetsChat extends Snippets { private QBChatService chatService; - // 1-1 Chat - // - private QBPrivateChatManager privateChatManager; - private QBPrivateChatManagerListener privateChatManagerListener; - // - private QBMessageListener privateChatMessageListener; - private QBMessageSentListener privateChatMessageSentListener; - // - private QBIsTypingListener isTypingListenerPrivate; + //Chat API 3.0 + private QBChatDialog privateChatDialog; + private QBChatDialog groupChatDialog; + + private QBChatDialogMessageListener privateChatDialogMessageListener; + private QBChatDialogMessageListener groupChatDialogMessageListener; + private QBChatDialogMessageSentListener privateChatDialogMessageSentListener; + private QBChatDialogMessageSentListener groupChatDialogMessageSentListener; + + private QBChatDialogTypingListener privateChatDialogTypingListener; + private QBChatDialogTypingListener groupChatDialogTypingListener; + + private QBChatDialogMessageListener globalChatDialogMessageListener; // Message statuses // @@ -102,16 +102,7 @@ public class SnippetsChat extends Snippets { private QBSystemMessageListener systemMessageListener; - // Group Chat - // - private QBGroupChatManager groupChatManager; - private QBGroupChatManagerListener groupChatManagerListener; - // - private QBMessageListener groupChatMessageListener; - private QBParticipantListener participantListener; - private QBMessageSentListener groupChatMessageSentListener; - // - private QBGroupChat currentChatRoom; + private QBChatDialogParticipantListener participantListener; // Roster @@ -125,7 +116,6 @@ public class SnippetsChat extends Snippets { // private QBPrivacyListsManager privacyListsManager; private QBPrivacyListListener privacyListListener; - private QBIsTypingListener isTypingListenerGroup; public SnippetsChat(final Context context) { @@ -190,8 +180,12 @@ public SnippetsChat(final Context context) { snippets.add(getDialogsSynchronous); snippets.add(getDialogsCount); snippets.add(getDialogsCountSynchronous); - snippets.add(createDialog); - snippets.add(createDialogSynchronous); + snippets.add(createGroupDialog); + snippets.add(createGroupDialogSynchronous); + + snippets.add(createPrivateDialog); + snippets.add(createPrivateDialogSynchronous); + snippets.add(updateDialog); snippets.add(updateDialogSynchronous); snippets.add(deleteDialog); @@ -235,7 +229,12 @@ public SnippetsChat(final Context context) { } private void initChatService() { + QBChatService.ConfigurationBuilder configurationBuilder = new QBChatService.ConfigurationBuilder(); + configurationBuilder.setKeepAlive(true) + .setSocketTimeout(0); + QBChatService.setConfigurationBuilder(configurationBuilder); QBChatService.setDebugEnabled(true); + QBChatService.setDefaultPacketReplyTimeout(10000); chatService = QBChatService.getInstance(); chatService.addConnectionListener(chatConnectionListener); @@ -247,27 +246,27 @@ private void initChatService() { private void initMessageSentListener() { - privateChatMessageSentListener = new QBMessageSentListener() { + privateChatDialogMessageSentListener = new QBChatDialogMessageSentListener() { @Override - public void processMessageSent(QBPrivateChat qbChat, QBChatMessage qbChatMessage) { - log("message " + qbChatMessage.getId() + " sent to " + qbChat.getParticipant()); + public void processMessageSent(String dialogId, QBChatMessage qbChatMessage) { + log("message " + qbChatMessage.getId() + " sent to dialog " + dialogId); } @Override - public void processMessageFailed(QBPrivateChat qbChat, QBChatMessage qbChatMessage) { - log("send message " + qbChatMessage.getId() + " has failed to " + qbChat.getParticipant()); + public void processMessageFailed(String dialogId, QBChatMessage qbChatMessage) { + log("send message " + qbChatMessage.getId() + " has failed to dialog " + dialogId); } }; - groupChatMessageSentListener = new QBMessageSentListener() { + groupChatDialogMessageSentListener = new QBChatDialogMessageSentListener() { @Override - public void processMessageSent(QBGroupChat qbChat, QBChatMessage qbChatMessage) { - log("message sent to group " + qbChat.getJid()); + public void processMessageSent(String dialogId, QBChatMessage qbChatMessage) { + log("message " + qbChatMessage.getId() + " sent to dialog " + dialogId); } @Override - public void processMessageFailed(QBGroupChat qbChat, QBChatMessage qbChatMessage) { - log("message sent failed to group " + qbChat.getJid()); + public void processMessageFailed(String dialogId, QBChatMessage qbChatMessage) { + log("send message " + qbChatMessage.getId() + " has failed to dialog " + dialogId); } }; } @@ -292,41 +291,41 @@ public void processMessageRead(String messageId, String dialogId, Integer userId messageStatusesManager.addMessageStatusListener(messageStatusListener); } - private void initChatPrivateAndGroupManagers() { - // Get 1-1 chat manager and listener - // - privateChatManager = chatService.getPrivateChatManager(); - // - privateChatManagerListener = new QBPrivateChatManagerListener() { + private void initGlobalMessageListener() { + globalChatDialogMessageListener = new QBChatDialogMessageListener() { @Override - public void chatCreated(final QBPrivateChat privateChat, final boolean createdLocally) { - if (!createdLocally) { - Log.i(TAG, "adding message listener to new chat"); - privateChat.addMessageListener(privateChatMessageListener); - privateChat.addMessageSentListener(privateChatMessageSentListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - } + public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { + QBRestChatService.getChatDialogById(dialogId).performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + log(chatDialog.getType().toString() + " chat with id " + chatDialog.getDialogId() + " downloaded"); + if (QBDialogType.PRIVATE.equals(chatDialog.getType())){ + privateChatDialog = chatDialog; + privateChatDialog.addMessageListener(privateChatDialogMessageListener); + privateChatDialog.addMessageSentListener(privateChatDialogMessageSentListener); + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + } else { + groupChatDialog = chatDialog; + groupChatDialog.addMessageListener(groupChatDialogMessageListener); + groupChatDialog.addMessageSentListener(groupChatDialogMessageSentListener); + groupChatDialog.addIsTypingListener(groupChatDialogTypingListener); + } + } - log("Private chat created: " + privateChat + ", createdLocally: " + createdLocally); + @Override + public void onError(QBResponseException e) { + log("Error loading dialog from global message listener: " + e); + } + }); } - }; - privateChatManager.addPrivateChatManagerListener(privateChatManagerListener); - - // Get group chat manager and listener - // - groupChatManager = chatService.getGroupChatManager(); - // - groupChatManagerListener = new QBGroupChatManagerListener() { @Override - public void chatCreated(QBGroupChat chat) { - log("Group chat created: " + chat); - currentChatRoom = chat; - currentChatRoom.addMessageListener(groupChatMessageListener); - currentChatRoom.addMessageSentListener(groupChatMessageSentListener); + public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { + log("Received error message to message listener"); } }; - groupChatManager.addGroupChatManagerListener(groupChatManagerListener); + + QBChatService.getInstance().getIncomingMessagesManager().addDialogMessageListener(globalChatDialogMessageListener); } // @@ -352,7 +351,7 @@ public void onSuccess(Void result, Bundle bundle) { log("success when login"); - initChatPrivateAndGroupManagers(); + initGlobalMessageListener(); // // Add Chat message listener initRoster(); @@ -403,7 +402,7 @@ protected void postExecute() { final Exception exc = getException(); if (exc == null) { - initChatPrivateAndGroupManagers(); + initGlobalMessageListener(); log("success when login"); @@ -579,62 +578,48 @@ public void execute() { private void initPrivateChatMessageListener() { // Create 1-1 chat is message listener // - privateChatMessageListener = new QBMessageListener() { + privateChatDialogMessageListener = new QBChatDialogMessageListener() { @Override - public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) { - log("received message: " + chatMessage.getId()); + public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) { + log("received message: " + qbChatMessage.getId()); - if (chatMessage.getSenderId().equals(chatService.getUser().getId())) { + if (qbChatMessage.getSenderId().equals(chatService.getUser().getId())) { log("Message comes here from carbons"); } - } @Override - public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage) { - log("processError: " + error.getLocalizedMessage()); + public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { + log("processError: " + e.getLocalizedMessage()); } }; } private void initIsTypingListener() { - - // Create 'is typing' listener - // - isTypingListenerPrivate = new QBIsTypingListener() { +// +// // Create 'is typing' listener +// // + groupChatDialogTypingListener = new QBChatDialogTypingListener() { @Override - public void processUserIsTyping(QBPrivateChat chat, Integer userId) { - /*if (chat instanceof QBGroupChat) { - String roomJid = ((QBGroupChat) chat).getJid(); - log("user " + userId + " is typing. Room Jid: " + roomJid); - } else {*/ - log("user " + userId + " is typing"); - //} + public void processUserIsTyping(String dialogId, Integer senderId) { + log("user " + senderId + " is typing. Group dialog id: " + dialogId); } @Override - public void processUserStopTyping(QBPrivateChat chat, Integer userId) { - /*if (chat instanceof QBGroupChat) { - String roomJid = ((QBGroupChat) chat).getJid(); - log("user " + userId + " stop typing. Room Jid: " + roomJid); - } else {*/ - log("user " + userId + " stop typing"); - //} + public void processUserStopTyping(String dialogId, Integer senderId) { + log("user " + senderId + " stop typing. Group dialog id: " + dialogId); } }; - isTypingListenerGroup = new QBIsTypingListener() { - + privateChatDialogTypingListener = new QBChatDialogTypingListener() { @Override - public void processUserIsTyping(QBGroupChat qbGroupChat, Integer userId) { - String roomJid = ((QBGroupChat) qbGroupChat).getJid(); - log("user " + userId + " is typing. Room Jid: " + roomJid); + public void processUserIsTyping(String dialogId, Integer senderId) { + log("user " + senderId + " is typing. Private dialog id: " + dialogId); } @Override - public void processUserStopTyping(QBGroupChat qbGroupChat, Integer userId) { - String roomJid = ((QBGroupChat) qbGroupChat).getJid(); - log("user " + userId + " stop typing. Room Jid: " + roomJid); + public void processUserStopTyping(String dialogId, Integer senderId) { + log("user " + senderId + " stop typing. Private dialog id: " + dialogId); } }; } @@ -658,41 +643,40 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { Snippet sendPrivateMessageExtended = new Snippet("send private message") { @Override public void execute() { - if (privateChatManager == null) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; + } else if (privateChatDialog == null){ + log("Please create private dialog first"); } - try { - // create a message - QBChatMessage chatMessage = new QBChatMessage(); - chatMessage.setBody("Hey " + new Random().nextInt()); - chatMessage.setProperty("name", "bob"); - chatMessage.setProperty("lastname", "boblast"); - chatMessage.setSaveToHistory(true); - chatMessage.setMarkable(true); + // create a message + final QBChatMessage chatMessage = new QBChatMessage(); + chatMessage.setBody("Hey " + new Random().nextInt()); + chatMessage.setProperty("name", "bob"); + chatMessage.setProperty("lastname", "boblast"); + chatMessage.setSaveToHistory(true); + chatMessage.setMarkable(true); // long time = System.currentTimeMillis()/1000; // chatMessage.setProperty("date_sent", time + ".431"); - // attach a photo - QBAttachment attachment = new QBAttachment("photo"); - attachment.setId("111"); - attachment.setUrl("www.img.com"); - chatMessage.addAttachment(attachment); - // - QBAttachment attachment2 = new QBAttachment("video"); - attachment2.setId("222"); - attachment2.setUrl("www.video.com"); - chatMessage.addAttachment(attachment2); - - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - privateChat.addMessageSentListener(privateChatMessageSentListener); - } - privateChat.sendMessage(chatMessage); + // attach a photo + QBAttachment attachment = new QBAttachment("photo"); + attachment.setId("111"); + attachment.setUrl("www.img.com"); + chatMessage.addAttachment(attachment); + // + QBAttachment attachment2 = new QBAttachment("video"); + attachment2.setId("222"); + attachment2.setUrl("www.video.com"); + chatMessage.addAttachment(attachment2); + + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog.addMessageSentListener(privateChatDialogMessageSentListener); + + try { + privateChatDialog.sendMessage(chatMessage); } catch (SmackException.NotConnectedException e) { log("send message error: " + e.getClass().getSimpleName()); } @@ -704,26 +688,19 @@ public void execute() { ////////////////////////////////////// Typing notifications ////////////////////////////////////////// // - Snippet sendIsTypingInPrivateChat = new Snippet("send is typing (private chat)") { @Override public void execute() { - if (privateChatManager == null) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - } + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + try { - privateChat.sendIsTypingNotification(); - } catch (SmackException.NotConnectedException e) { + privateChatDialog.sendIsTypingNotification(); + } catch (XMPPException | SmackException.NotConnectedException e) { log("send typing error: " + e.getClass().getSimpleName()); - } catch (XMPPException e) { - e.printStackTrace(); } } }; @@ -731,22 +708,16 @@ public void execute() { Snippet sendStopTypingInPrivateChat = new Snippet("send stop typing (private chat)") { @Override public void execute() { - if (privateChatManager == null) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - } + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + try { - privateChat.sendStopTypingNotification(); - } catch (SmackException.NotConnectedException e) { + privateChatDialog.sendStopTypingNotification(); + } catch (XMPPException | SmackException.NotConnectedException e) { log("send stop typing error: " + e.getClass().getSimpleName()); - } catch (XMPPException e) { - e.printStackTrace(); } } }; @@ -754,13 +725,13 @@ public void execute() { Snippet sendIsTypingInGroupChat = new Snippet("send is typing (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog.isJoined()) { log("Please join room first"); return; } try { - currentChatRoom.sendIsTypingNotification(); + groupChatDialog.sendIsTypingNotification(); } catch (XMPPException e) { log("send typing error: " + e.getLocalizedMessage()); } catch (SmackException.NotConnectedException e) { @@ -772,13 +743,13 @@ public void execute() { Snippet sendStopTypingInGroupChat = new Snippet("send stop typing (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog.isJoined()) { log("Please join room first"); return; } try { - currentChatRoom.sendStopTypingNotification(); + groupChatDialog.sendStopTypingNotification(); } catch (XMPPException e) { log("send typing error: " + e.getLocalizedMessage()); } catch (SmackException.NotConnectedException e) { @@ -792,29 +763,21 @@ public void execute() { /////////////////////////////////////// Read/Delivered ////////////////////////////////////////// // - Snippet readMessagePrivateChat = new Snippet("read message (private chat)") { @Override public void execute() { - if (privateChatManager == null) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - } - try { - QBChatMessage status = new QBChatMessage(); - status.setId("267477ab5612312312414124"); - status.setDialogId("267477ab5612312312414124"); + QBChatMessage status = new QBChatMessage(); + status.setId("267477ab5612312312414124"); + status.setDialogId("267477ab5612312312414124"); - privateChat.readMessage(status); - } catch (XMPPException e) { + try { + privateChatDialog.readMessage(status); + } catch (XMPPException | SmackException.NotConnectedException e) { log("read message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException e) { - log("read message error: " + e.getClass().getSimpleName()); } } }; @@ -822,25 +785,18 @@ public void execute() { Snippet deliverMessagePrivateChat = new Snippet("deliver message (private chat)") { @Override public void execute() { - if (privateChatManager == null) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - } - try { - QBChatMessage status = new QBChatMessage(); - status.setId("267477ab5612312312414124"); - status.setDialogId("267477ab5612312312414124"); + QBChatMessage status = new QBChatMessage(); + status.setId("267477ab5612312312414124"); + status.setDialogId("267477ab5612312312414124"); - privateChat.deliverMessage(status); - } catch (XMPPException e) { + try { + privateChatDialog.deliverMessage(status); + } catch (XMPPException | SmackException.NotConnectedException e) { log("deliver message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException e) { - log("deliver message error: " + e.getClass().getSimpleName()); } } }; @@ -848,7 +804,7 @@ public void execute() { Snippet readMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (!groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -859,7 +815,7 @@ public void execute() { status.setSenderId(567); status.setDialogId("267477ab5612312312414124"); - currentChatRoom.readMessage(status); + groupChatDialog.readMessage(status); } catch (XMPPException e) { log("read message error: " + e.getLocalizedMessage()); } catch (SmackException.NotConnectedException e) { @@ -871,7 +827,7 @@ public void execute() { Snippet deliverMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (!groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -882,7 +838,7 @@ public void execute() { status.setSenderId(567); status.setDialogId("267477ab5612312312414124"); - currentChatRoom.deliverMessage(status); + groupChatDialog.deliverMessage(status); } catch (XMPPException e) { log("deliver message error: " + e.getLocalizedMessage()); } catch (SmackException.NotConnectedException e) { @@ -898,24 +854,25 @@ public void execute() { private void initGroupChatMessageListener() { - groupChatMessageListener = new QBMessageListener() { + groupChatDialogMessageListener = new QBChatDialogMessageListener(){ @Override - public void processMessage(final QBGroupChat groupChat, final QBChatMessage chatMessage) { - log("group chat: " + groupChat.getDialogId() + ", processMessage: " + chatMessage); + public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) { + log("group chat: " + s + ", processMessage: " + qbChatMessage); } @Override - public void processError(final QBGroupChat groupChat, QBChatException error, QBChatMessage originMessage) { - log("Group chat: " + groupChat.getDialogId() + ", Error: " + error.getCondition().toString()); + public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { + log("Group chat: " + s + ", Error: " + e.getCondition().toString()); } }; } private void initParticipantListener() { - participantListener = new QBParticipantListener() { + + participantListener = new QBChatDialogParticipantListener() { @Override - public void processPresence(QBGroupChat groupChat, QBPresence presence) { - log("groupChat: " + groupChat.getJid() + ", presence: " + presence); + public void processPresence(String s, QBPresence qbPresence) { + log("groupChat: " + s + ", presence: " + qbPresence); } }; } @@ -923,28 +880,24 @@ public void processPresence(QBGroupChat groupChat, QBPresence presence) { Snippet joinRoom = new Snippet("join Room") { @Override public void execute() { - if (groupChatManager == null) { - log("Please login first"); + if (groupChatDialog == null) { + log("Please create group dialog first"); return; } - - DiscussionHistory history = new DiscussionHistory(); + final DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(0); - currentChatRoom = groupChatManager.createGroupChat(ApplicationConfig.getInstance().getTestRoomJid()); - log("dialog ID: " + currentChatRoom.getDialogId()); - - QBEntityCallback clbck = new QBEntityCallback() { + final QBEntityCallback clbck = new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { log("join Room success"); // add listeners - currentChatRoom.addMessageListener(groupChatMessageListener); - currentChatRoom.addParticipantListener(participantListener); - currentChatRoom.addMessageSentListener(groupChatMessageSentListener); - currentChatRoom.addIsTypingListener(isTypingListenerGroup); + groupChatDialog.addMessageListener(groupChatDialogMessageListener); + groupChatDialog.addParticipantListener(participantListener); + groupChatDialog.addMessageSentListener(groupChatDialogMessageSentListener); + groupChatDialog.addIsTypingListener(groupChatDialogTypingListener); } @Override @@ -953,34 +906,36 @@ public void onError(final QBResponseException list) { } }; - currentChatRoom.join(history, clbck); + groupChatDialog.join(history, clbck); } }; Snippet joinRoomSynchronous = new SnippetAsync("join Room (synchronous)", context) { @Override public void executeAsync() { - if (groupChatManager == null) { - log("Please login first"); + if (groupChatDialog == null) { + log("Please create group dialog first"); return; } - DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(10); - currentChatRoom = groupChatManager.createGroupChat(ApplicationConfig.getInstance().getTestRoomJid()); - try { - currentChatRoom.join(history); + groupChatDialog = QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).perform(); + log("dialog ID: " + groupChatDialog.getDialogId()); + + groupChatDialog.join(history); // add listeners - currentChatRoom.addMessageListener(groupChatMessageListener); - currentChatRoom.addParticipantListener(participantListener); - currentChatRoom.addIsTypingListener(isTypingListenerGroup); + groupChatDialog.addMessageListener(groupChatDialogMessageListener); + groupChatDialog.addParticipantListener(participantListener); + groupChatDialog.addIsTypingListener(groupChatDialogTypingListener); } catch (XMPPException | SmackException e) { setException(e); + } catch (QBResponseException e) { + log("Getting dialog error: " + e.getClass().getSimpleName()); } } @@ -988,7 +943,7 @@ public void executeAsync() { protected void postExecute() { super.postExecute(); - if (groupChatManager == null) { + if (!chatService.isLoggedIn()) { return; } @@ -1005,7 +960,10 @@ protected void postExecute() { Snippet sendMessageToRoomExtended = new Snippet("send message to room") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } @@ -1017,7 +975,7 @@ public void execute() { chatMessage.setMarkable(true); try { - currentChatRoom.sendMessage(chatMessage); + groupChatDialog.sendMessage(chatMessage); } catch (SmackException.NotConnectedException e) { log("Send message error: " + e.getClass().getSimpleName()); } catch (IllegalStateException e) { @@ -1029,10 +987,14 @@ public void execute() { Snippet sendMessageToRoomWithoutJoin = new Snippet("send message to room", "w/o join") { @Override public void execute() { - currentChatRoom = groupChatManager.createGroupChat(ApplicationConfig.getInstance().getTestRoomJid()); - currentChatRoom.addMessageListener(groupChatMessageListener); + if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } - log("currentChatRoom: " + currentChatRoom); + groupChatDialog.addMessageListener(groupChatDialogMessageListener); + + log("currentChatRoom: " + groupChatDialog); // create a message QBChatMessage chatMessage = new QBChatMessage(); @@ -1041,7 +1003,7 @@ public void execute() { chatMessage.setMarkable(true); try { - currentChatRoom.sendMessageWithoutJoin(chatMessage); + groupChatDialog.sendMessageWithoutJoin(chatMessage); } catch (SmackException.NotConnectedException e) { log("Send message error: " + e.getClass().getSimpleName()); } catch (IllegalStateException e) { @@ -1053,14 +1015,17 @@ public void execute() { Snippet getOnlineRoomUsersSynchronous = new Snippet("get online room users") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } Collection onlineRoomUsers = null; try { - onlineRoomUsers = currentChatRoom.getOnlineUsers(); + onlineRoomUsers = groupChatDialog.getOnlineUsers(); } catch (XMPPException e) { log("get online users error: " + e.getLocalizedMessage()); } @@ -1079,14 +1044,17 @@ public void execute() { Snippet leaveRoom = new SnippetAsync("leave room", context) { @Override public void executeAsync() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } try { - currentChatRoom.leave(); - currentChatRoom = null; + groupChatDialog.leave(); + groupChatDialog = null; } catch (XMPPException | SmackException.NotConnectedException e) { setException(e); } @@ -1096,7 +1064,7 @@ public void executeAsync() { protected void postExecute() { super.postExecute(); - if (currentChatRoom == null) { + if (groupChatDialog == null) { return; } @@ -1119,17 +1087,21 @@ protected void postExecute() { Snippet getDialogs = new Snippet("Get Dialogs") { @Override public void execute() { + if (!chatService.isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + log("Please login first"); + return; + } QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.setLimit(100); requestBuilder.addRule("data[class_name]", QueryRule.EQ, "Advert"); - QBChatService.getChatDialogs(null, requestBuilder, new QBEntityCallback>() { + QBRestChatService.getChatDialogs(null, requestBuilder).performAsync(new QBEntityCallback>() { @Override - public void onSuccess(ArrayList dialogs, Bundle args) { + public void onSuccess(ArrayList dialogs, Bundle args) { Log.i(TAG, "dialogs: " + dialogs); - QBDialog dialog = dialogs.get(0); + QBChatDialog dialog = dialogs.get(0); Log.i(TAG, "arr: " + dialog.getCustomData().getArray("arr")); Log.i(TAG, "bbb: " + dialog.getCustomData().getBoolean("bbb")); Log.i(TAG, "fff: " + dialog.getCustomData().getFloat("fff")); @@ -1155,19 +1127,20 @@ public void onError(QBResponseException errors) { Snippet getDialogsSynchronous = new SnippetAsync("Get Dialogs (synchronous)", context) { @Override public void executeAsync() { + if (!chatService.isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + log("Please login first"); + return; + } - Bundle bundle = new Bundle(); - // QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.setLimit(100); requestBuilder.addRule("data[class_name]", QueryRule.EQ, "Advert"); // requestBuilder.addParameter("data[class_name]", "Advert"); // - List chatDialogsList = null; + List chatDialogsList = null; try { - chatDialogsList = QBChatService.getChatDialogs(null, requestBuilder, - bundle); + chatDialogsList = QBRestChatService.getChatDialogs(null, requestBuilder).perform(); } catch (QBResponseException e) { setException(e); } @@ -1185,8 +1158,10 @@ public void execute() { // QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); // requestBuilder.all("occupants_ids", "76,58"); + + Bundle bundle = new Bundle(); // - QBChatService.getChatDialogsCount(requestBuilder, new QBEntityCallback() { + QBRestChatService.getChatDialogsCount(requestBuilder, bundle).performAsync(new QBEntityCallback() { @Override public void onSuccess(Integer integer, Bundle bundle) { Log.i(TAG, "dialogsCount: " + integer); @@ -1211,7 +1186,7 @@ public void executeAsync() { int dialogsCount = -1; try { - dialogsCount = QBChatService.getChatDialogsCount(requestBuilder, bundle); + dialogsCount = QBRestChatService.getChatDialogsCount(requestBuilder, bundle).perform(); } catch (QBResponseException e) { setException(e); } @@ -1221,10 +1196,10 @@ public void executeAsync() { }; - Snippet createDialog = new Snippet("Create Dialog") { + Snippet createGroupDialog = new Snippet("Create Group Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } @@ -1233,7 +1208,7 @@ public void execute() { occupantIdsList.add(ApplicationConfig.getInstance().getTestUserId2()); occupantIdsList.add(301); - QBDialog dialog = new QBDialog(); + QBChatDialog dialog = new QBChatDialog(); dialog.setName("Chat with Garry and John"); dialog.setPhoto("452444"); dialog.setType(QBDialogType.GROUP); @@ -1257,9 +1232,10 @@ public void execute() { dialog.setCustomData(data); - groupChatManager.createDialog(dialog, new QBEntityCallback() { + QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback() { @Override - public void onSuccess(QBDialog dialog, Bundle args) { + public void onSuccess(QBChatDialog dialog, Bundle args) { + groupChatDialog = dialog; Log.i(TAG, "dialog: " + dialog); Log.i(TAG, "arr: " + dialog.getCustomData().getArray("arr")); Log.i(TAG, "bbb: " + dialog.getCustomData().getBoolean("bbb")); @@ -1283,10 +1259,10 @@ public void onError(QBResponseException errors) { } }; - Snippet createDialogSynchronous = new SnippetAsync("Create Dialog (synchronous)", context) { + Snippet createGroupDialogSynchronous = new SnippetAsync("Create Group Dialog (synchronous)", context) { @Override public void executeAsync() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1295,7 +1271,7 @@ public void executeAsync() { occupantIdsList.add(ApplicationConfig.getInstance().getTestUserId2()); occupantIdsList.add(301); // - QBDialog dialog = new QBDialog(); + QBChatDialog dialog = new QBChatDialog(); dialog.setName("Chat with Garry and John"); dialog.setPhoto("452444"); dialog.setType(QBDialogType.GROUP); @@ -1304,26 +1280,119 @@ public void executeAsync() { HashMap data = new HashMap<>(); data.put("data[class_name]", "Advert"); data.put("data[name]", "bingo"); - dialog.setData(data); + dialog.setCustomData(new QBDialogCustomData(data)); + try { + groupChatDialog = QBRestChatService.createChatDialog(dialog).perform(); + } catch (QBResponseException e) { + setException(e); + } + + if (groupChatDialog != null) { + Log.i(TAG, "dialog: " + groupChatDialog); + } + } + }; + + Snippet createPrivateDialog = new Snippet("Create Private Dialog") { + @Override + public void execute() { + if (!chatService.isLoggedIn()) { + log("Please login first"); + return; + } + + ArrayList occupantIdsList = new ArrayList<>(); + occupantIdsList.add(ApplicationConfig.getInstance().getTestUserId2()); + + QBChatDialog dialog = new QBChatDialog(); + dialog.setPhoto("452444"); + dialog.setType(QBDialogType.PRIVATE); + dialog.setOccupantsIds(occupantIdsList); + +// HashMap data = new HashMap<>(); +// data.put("data[class_name]", "Advert"); +// data.put("data[name]", "bingo"); + final String myLocation = Double.toString(23.45454) + "," + Double.toString(0.4456); +// data.put("data[arr]", myLocation); +// dialog.setData(data); + + QBDialogCustomData data = new QBDialogCustomData("Advert"); + data.putString("name", "bingo"); + data.putArray("arr", Arrays.asList(new Double[]{1.32, 2.56})); + data.putBoolean("bbb", true); + data.putFloat("fff", 45.676f); + data.putInteger("iii", 56); + data.putDate("ddd", new Date()); + data.putLocation("loc", Arrays.asList(new Double[]{3.78, 4.87})); + + dialog.setCustomData(data); + + QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog dialog, Bundle args) { + privateChatDialog = dialog; + Log.i(TAG, "dialog: " + dialog); + Log.i(TAG, "arr: " + dialog.getCustomData().getArray("arr")); + Log.i(TAG, "bbb: " + dialog.getCustomData().getBoolean("bbb")); + Log.i(TAG, "fff: " + dialog.getCustomData().getFloat("fff")); + Log.i(TAG, "fff2: " + dialog.getCustomData().get("fff")); + Log.i(TAG, "iii: " + dialog.getCustomData().getInteger("iii")); + Log.i(TAG, "name: " + dialog.getCustomData().getString("name")); + try { + SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); + Log.i(TAG, "ddd: " + dialog.getCustomData().getDate("ddd", format)); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(QBResponseException errors) { + handleErrors(errors); + } + }); + } + }; + + Snippet createPrivateDialogSynchronous = new SnippetAsync("Create Private Dialog (synchronous)", context) { + @Override + public void executeAsync() { + if (!chatService.isLoggedIn()) { + log("Please login first"); + return; + } + + ArrayList occupantIdsList = new ArrayList<>(); + occupantIdsList.add(ApplicationConfig.getInstance().getTestUserId2()); + // + QBChatDialog dialog = new QBChatDialog(); + dialog.setPhoto("452444"); + dialog.setType(QBDialogType.PRIVATE); + dialog.setOccupantsIds(occupantIdsList); + + HashMap data = new HashMap<>(); + data.put("data[class_name]", "Advert"); + data.put("data[name]", "bingo"); + dialog.setCustomData(new QBDialogCustomData(data)); - QBDialog createdDialog = null; try { - createdDialog = groupChatManager.createDialog(dialog); + privateChatDialog = QBRestChatService.createChatDialog(dialog).perform(); } catch (QBResponseException e) { setException(e); } - if (createdDialog != null) { - Log.i(TAG, "dialog: " + createdDialog); + if (groupChatDialog != null) { + Log.i(TAG, "dialog: " + groupChatDialog); } } }; + Snippet updateDialog = new Snippet("Update Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1331,7 +1400,7 @@ public void execute() { QBRequestUpdateBuilder requestBuilder = new QBRequestUpdateBuilder(); // requestBuilder.pullAll(com.quickblox.chat.Consts.DIALOG_OCCUPANTS, 378); - QBDialog dialog = new QBDialog("56aa3d7da28f9a5b1f0000cf"); + QBChatDialog dialog = new QBChatDialog("56aa3d7da28f9a5b1f0000cf"); dialog.setName("Chat with Garry and John"); dialog.setPhoto("452444"); @@ -1346,9 +1415,9 @@ public void execute() { dialog.setCustomData(data); - groupChatManager.updateDialog(dialog, requestBuilder, new QBEntityCallback() { + QBRestChatService.updateGroupChatDialog(dialog, requestBuilder).performAsync(new QBEntityCallback() { @Override - public void onSuccess(QBDialog dialog, Bundle args) { + public void onSuccess(QBChatDialog dialog, Bundle args) { Log.i(TAG, "dialog: " + dialog); Log.i(TAG, "arr: " + dialog.getCustomData().getArray("arr")); @@ -1377,12 +1446,12 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - QBDialog dialog = new QBDialog("5444bba7535c121d3302245f"); + QBChatDialog dialog = new QBChatDialog("5444bba7535c121d3302245f"); dialog.setName("Chat with Garry and John"); dialog.setPhoto("452444"); @@ -1394,9 +1463,9 @@ public void executeAsync() { // data.put("data[title]", "bingo"); // dialog.setData(data); - QBDialog updatedDialog = null; + QBChatDialog updatedDialog = null; try { - updatedDialog = groupChatManager.updateDialog(dialog, requestBuilder); + updatedDialog = QBRestChatService.updateGroupChatDialog(dialog, requestBuilder).perform(); } catch (QBResponseException e) { setException(e); } @@ -1411,14 +1480,14 @@ public void executeAsync() { Snippet deleteDialog = new Snippet("Delete Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } String dialogID = "5444bba7535c121d3302245f"; - groupChatManager.deleteDialog(dialogID, true, new QBEntityCallback() { + QBRestChatService.deleteDialog(dialogID, true).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { Log.i(TAG, "dialog deleted"); @@ -1436,7 +1505,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { - if (groupChatManager == null) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } @@ -1444,7 +1513,7 @@ public void executeAsync() { String dialogID = "5444bbc7535c12e10f0233be"; try { - groupChatManager.deleteDialog(dialogID); + QBRestChatService.deleteDialog(dialogID, true).perform(); Log.i(TAG, "dialog deleted"); } catch (QBResponseException e) { setException(e); @@ -1456,12 +1525,12 @@ public void executeAsync() { Snippet getMessages = new Snippet("Get Messages", "with dialog id") { @Override public void execute() { - QBDialog qbDialog = new QBDialog(ApplicationConfig.getInstance().getTestDialogId()); + QBChatDialog qbDialog = new QBChatDialog(ApplicationConfig.getInstance().getTestDialogId()); QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder(); customObjectRequestBuilder.setLimit(100); - QBChatService.getDialogMessages(qbDialog, customObjectRequestBuilder, new QBEntityCallback>() { + QBRestChatService.getDialogMessages(qbDialog, customObjectRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList messages, Bundle args) { for (QBChatMessage msg : messages) { @@ -1469,7 +1538,7 @@ public void onSuccess(ArrayList messages, Bundle args) { // Deliver messages (group) // try { -// currentChatRoom.deliverMessagePrivateChat(msg); +// groupChatDialog.deliverMessage(msg); // } catch (XMPPException e) { // e.printStackTrace(); // } catch (SmackException.NotConnectedException e) { @@ -1477,12 +1546,8 @@ public void onSuccess(ArrayList messages, Bundle args) { // } // Deliver messages (private) -// QBPrivateChat privateChat = privateChatManager.getChat(msg.getRecipientId()); -// if (privateChat == null) { -// privateChat = privateChatManager.createChat(msg.getRecipientId(), privateChatMessageListener); -// } // try { -// privateChat.deliverMessage(msg); +// privateChatDialog.deliverMessage(msg); // } catch (XMPPException e) { // log("deliver message error: " + e.getLocalizedMessage()); // } catch (SmackException.NotConnectedException e) { @@ -1502,16 +1567,14 @@ public void onError(QBResponseException errors) { Snippet getMessagesSynchronous = new SnippetAsync("Get Messages (synchronous)", "with dialog id", context) { @Override public void executeAsync() { - Bundle bundle = new Bundle(); - // QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder(); customObjectRequestBuilder.setLimit(100); - QBDialog dialog = new QBDialog(ApplicationConfig.getInstance().getTestDialogId()); + QBChatDialog dialog = new QBChatDialog(ApplicationConfig.getInstance().getTestDialogId()); List dialogMessagesList = null; try { - dialogMessagesList = QBChatService.getDialogMessages(dialog, null, bundle); + dialogMessagesList = QBRestChatService.getDialogMessages(dialog, customObjectRequestBuilder).perform(); } catch (QBResponseException e) { setException(e); } @@ -1534,7 +1597,7 @@ public void execute() { String dialogId = "53cfc593efa3573ebd000017"; - QBChatService.markMessagesAsRead(dialogId, messagesIDs, new QBEntityCallback() { + QBRestChatService.markMessagesAsRead(dialogId, messagesIDs).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { Log.i(TAG, "read OK"); @@ -1556,7 +1619,7 @@ public void executeAsync() { messagesIDs.add("53cfc62fe4b05ed6d7cf17d5"); try { - QBChatService.markMessagesAsRead("53cfc593efa3573ebd000017", messagesIDs); + QBRestChatService.markMessagesAsRead("53cfc593efa3573ebd000017", messagesIDs).perform(); Log.i(TAG, "read OK"); } catch (QBResponseException e) { setException(e); @@ -1572,7 +1635,7 @@ public void execute() { add("546cc80f0eda8f2dd7ee449d"); }}; - QBChatService.deleteMessages(messagesIds, new QBEntityCallback() { + QBRestChatService.deleteMessages(messagesIds, false).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { Log.i(TAG, "deleted OK"); @@ -1595,7 +1658,7 @@ public void executeAsync() { }}; try { - QBChatService.deleteMessages(messagesIds); + QBRestChatService.deleteMessages(messagesIds, false).perform(); Log.i(TAG, "deleted OK"); } catch (QBResponseException e) { setException(e); @@ -1621,7 +1684,7 @@ public void execute() { msg.setProperty("p1", "v1"); msg.setProperty("p2", "v2"); - QBChatService.createMessage(msg, new QBEntityCallback() { + QBRestChatService.createMessage(msg, false).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBChatMessage result, Bundle params) { Log.i(TAG, "created message\n: " + result); @@ -1654,7 +1717,7 @@ public void executeAsync() { QBChatMessage createdMsg = null; try { - createdMsg = QBChatService.createMessage(msg); + createdMsg = QBRestChatService.createMessage(msg, false).perform(); } catch (QBResponseException e) { e.printStackTrace(); } diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsContent.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsContent.java index a587a7828..cd640238d 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsContent.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsContent.java @@ -97,7 +97,7 @@ public void execute() { qbfile.setPublic(false); qbfile.setContentType(ContentType.getContentType(file1)); // - QBContent.createFile(qbfile, new QBEntityCallback() { + QBContent.createFile(qbfile).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBFile file, Bundle params) { @@ -123,7 +123,7 @@ public void executeAsync() { QBFile createdFile = null; try { - createdFile = QBContent.createFile(qbfile); + createdFile = QBContent.createFile(qbfile).perform(); } catch (QBResponseException e) { setException(e); } @@ -146,7 +146,7 @@ public void execute() { QBFile qbfile = new QBFile(); qbfile.setId(212949); qbfile.setName("my Car1"); - QBContent.updateFile(qbfile, new QBEntityCallback(){ + QBContent.updateFile(qbfile).performAsync(new QBEntityCallback(){ @Override public void onSuccess(QBFile updatedFile, Bundle params) { @@ -170,7 +170,7 @@ public void executeAsync() { QBFile updatedFile = null; try { - updatedFile = QBContent.updateFile(qbfile); + updatedFile = QBContent.updateFile(qbfile).perform(); } catch (QBResponseException e) { setException(e); } @@ -210,7 +210,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { QBFile getFile = null; try { - getFile = QBContent.getFile(212949); + getFile = QBContent.getFile(212949).perform(); } catch (QBResponseException e) { setException(e); } @@ -228,7 +228,7 @@ public void executeAsync() { Snippet deleteFile = new Snippet("delete file") { @Override public void execute() { - QBContent.deleteFile(212949, new QBEntityCallback() { + QBContent.deleteFile(212949).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -247,7 +247,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBContent.deleteFile(212949); + QBContent.deleteFile(212949).perform(); Log.i(TAG, ">>> file deleted successfully"); } catch (QBResponseException e) { setException(e); @@ -264,7 +264,12 @@ public void executeAsync() { @Override public void execute() { String params = fileObjectAccess.getParams(); // will return from the server when creating file - QBContent.uploadFile(file1, params, new QBEntityCallback(){ + QBContent.uploadFile(file1, params, new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void amazonS3Response, Bundle params) { Log.i(TAG, ">>> AmazonS3Response: " + amazonS3Response); @@ -274,11 +279,6 @@ public void onSuccess(Void amazonS3Response, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -295,7 +295,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } @@ -330,7 +330,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBContent.declareFileUploaded(212951, (int) file1.length()); + QBContent.declareFileUploaded(212951, (int) file1.length()).perform(); Log.i(TAG, ">>> declare file uploaded was successful"); } catch (QBResponseException e) { setException(e); @@ -347,7 +347,7 @@ public void executeAsync() { Snippet getFileObjectAccess = new Snippet("get file object access") { @Override public void execute() { - QBContent.getFileObjectAccess(212951, new QBEntityCallback() { + QBContent.getFileObjectAccess(212951).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBFileObjectAccess fileObjectAccess, Bundle params) { @@ -367,7 +367,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { QBFileObjectAccess fileObjectAccess = null; try { - fileObjectAccess = QBContent.getFileObjectAccess(212951); + fileObjectAccess = QBContent.getFileObjectAccess(212951).perform(); } catch (QBResponseException e) { setException(e); } @@ -387,7 +387,13 @@ public void executeAsync() { Snippet downloadFileWithUID = new Snippet("download file with UID") { @Override public void execute() { - QBContent.downloadFile(FILE_UID, new QBEntityCallback() { + Bundle params = new Bundle(); + QBContent.downloadFile(FILE_UID, new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }, params).performAsync(new QBEntityCallback() { @Override public void onSuccess(InputStream inputStream, Bundle params) { @@ -399,11 +405,6 @@ public void onSuccess(InputStream inputStream, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -414,12 +415,12 @@ public void executeAsync() { InputStream inputStream = null; Bundle params = new Bundle(); try { - inputStream = QBContent.downloadFile(FILE_UID, params, new QBProgressCallback() { + inputStream = QBContent.downloadFile(FILE_UID, new QBProgressCallback() { @Override public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -436,7 +437,12 @@ public void onProgressUpdate(int progress) { public void execute() { final int fileId = 3607775; - QBContent.downloadFileById(fileId, new QBEntityCallback() { + QBContent.downloadFileById(fileId, new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback() { @Override public void onSuccess(final InputStream inputStream, Bundle params) { @@ -450,11 +456,6 @@ public void onSuccess(final InputStream inputStream, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -473,7 +474,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } @@ -498,7 +499,7 @@ public void onProgressUpdate(int progress) { public void execute() { QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(5, 2); - QBContent.getFiles(requestBuilder, new QBEntityCallback>() { + QBContent.getFiles(requestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList files, Bundle params) { @@ -520,7 +521,7 @@ public void executeAsync() { QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(10, 1); ArrayList files = null; try { - files = QBContent.getFiles(requestBuilder, params); + files = QBContent.getFiles(requestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -545,7 +546,12 @@ public void executeAsync() { public void execute() { Boolean fileIsPublic = false; - QBContent.uploadFileTask(file1, fileIsPublic, null, new QBEntityCallback() { + QBContent.uploadFileTask(file1, fileIsPublic, null, new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBFile qbFile, Bundle params) { @@ -562,11 +568,6 @@ public void onSuccess(QBFile qbFile, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -582,7 +583,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } @@ -596,24 +597,24 @@ public void onProgressUpdate(int progress) { Snippet updateFileTask = new Snippet("TASK: update file") { final int fileId = 231089; + @Override public void execute() { - QBContent.updateFileTask(file1, fileId, null, new QBEntityCallback(){ + QBContent.updateFileTask(file1, fileId, null, new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBFile qbFile, Bundle params) { - Log.i(TAG, ">>> file updated successful"+qbFile); + Log.i(TAG, ">>> file updated successful" + qbFile); } - @Override public void onError(QBResponseException errors) { - handleErrors(errors); - } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); + handleErrors(errors); } }); } @@ -632,7 +633,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsCustomObjects.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsCustomObjects.java index 473b8a9dc..ba173bf4f 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsCustomObjects.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsCustomObjects.java @@ -124,7 +124,7 @@ public SnippetsCustomObjects(Context context) { public void execute() { QBCustomObject object = new QBCustomObject("JSON", "561cbde9a28f9a520c001c35"); - QBCustomObjects.getObject(object, new QBEntityCallback(){ + QBCustomObjects.getObject(object).performAsync(new QBEntityCallback(){ @Override public void onSuccess(QBCustomObject customObject, Bundle params) { Log.i(TAG, ">>> custom object: " + customObject); @@ -151,7 +151,7 @@ public void executeAsync() { QBCustomObject getObject = null; try { - getObject = QBCustomObjects.getObject(object); + getObject = QBCustomObjects.getObject(object).perform(); } catch (QBResponseException e) { setException(e); } @@ -174,7 +174,7 @@ public void execute() { coIDs.add("53f323ab535c12567903ba43"); coIDs.add("53f32498535c12a57a03f434"); - QBCustomObjects.getObjectsByIds(MOVIE_CLASS, coIDs, new QBEntityCallback>() { + QBCustomObjects.getObjectsByIds(MOVIE_CLASS, coIDs).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList customObjects, Bundle params) { Log.i(TAG, ">>> custom objects: " + customObjects); @@ -197,7 +197,7 @@ public void executeAsync() { ArrayList getObjects = null; try { - getObjects = QBCustomObjects.getObjectsByIds(MOVIE_CLASS, coIDs); + getObjects = (ArrayList) QBCustomObjects.getObjectsByIds(MOVIE_CLASS, coIDs).perform(); } catch (QBResponseException e) { setException(e); } @@ -223,7 +223,7 @@ public void execute() { // requestBuilder.near("location", new Double[]{2.,3.}, 1000); - QBCustomObjects.getObjects(MOVIE_CLASS, requestBuilder, new QBEntityCallback>() { + QBCustomObjects.getObjects(MOVIE_CLASS, requestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList customObjects, Bundle params) { @@ -267,7 +267,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList objects = null; try { - objects = QBCustomObjects.getObjects(MOVIE_CLASS, requestBuilder, params); + objects = QBCustomObjects.getObjects(MOVIE_CLASS, requestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -292,7 +292,7 @@ public void execute() { QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.gt("rating", 1); - QBCustomObjects.countObjects(MOVIE_CLASS, requestBuilder, new QBEntityCallback() { + QBCustomObjects.countObjects(MOVIE_CLASS, requestBuilder).performAsync(new QBEntityCallback() { @Override public void onSuccess(Integer count, Bundle params) { @@ -317,7 +317,7 @@ public void executeAsync() { Integer count = null; try { - count = QBCustomObjects.countObjects(MOVIE_CLASS, requestBuilder); + count = QBCustomObjects.countObjects(MOVIE_CLASS, requestBuilder).perform(); } catch (QBResponseException e) { setException(e); } @@ -345,7 +345,7 @@ public void execute() { newRecord.putDate("ddd", new Date()); newRecord.putLocation("loc", Arrays.asList(new Double[]{3.78, 4.87})); - QBCustomObjects.createObject(newRecord, new QBEntityCallback() { + QBCustomObjects.createObject(newRecord).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObject object, Bundle params) { Log.i(TAG, ">>> created object: " + object); @@ -384,7 +384,7 @@ public void executeAsync() { QBCustomObject createdObject = null; try { - createdObject = QBCustomObjects.createObject(newRecord); + createdObject = QBCustomObjects.createObject(newRecord).perform(); } catch (QBResponseException e) { setException(e); } @@ -419,7 +419,7 @@ public void execute() { qbCustomObjectList.add(newRecord1); qbCustomObjectList.add(newRecord2); - QBCustomObjects.createObjects(qbCustomObjectList, new QBEntityCallback>() { + QBCustomObjects.createObjects(qbCustomObjectList).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList qbCustomObjects, Bundle args) { Log.i(TAG, ">>> custom object list: " + qbCustomObjects); @@ -454,7 +454,7 @@ public void executeAsync() { List createdObjects = null; try { - createdObjects = QBCustomObjects.createObjects(qbCustomObjectList); + createdObjects = QBCustomObjects.createObjects(qbCustomObjectList).perform(); } catch (QBResponseException e) { setException(e); } @@ -485,7 +485,7 @@ public void execute() { QBRequestUpdateBuilder rb = new QBRequestUpdateBuilder(); rb.pullAll("tags", "car1", "car2"); - QBCustomObjects.updateObject(record, rb, new QBEntityCallback() { + QBCustomObjects.updateObject(record, rb).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObject object, Bundle params) { Log.i(TAG, ">>> updated record: : " + object.toString()); @@ -525,7 +525,7 @@ public void executeAsync() { QBCustomObject updatedObject = null; try { - updatedObject = QBCustomObjects.updateObject(obj); + updatedObject = QBCustomObjects.updateObject(obj).perform(); } catch (QBResponseException e) { setException(e); } @@ -561,7 +561,7 @@ public void execute() { qbCustomObjectList.add(record1); qbCustomObjectList.add(record2); - QBCustomObjects.updateObjects(qbCustomObjectList, new QBEntityCallback>() { + QBCustomObjects.updateObjects(qbCustomObjectList).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList objects, Bundle params) { Log.i(TAG, ">>> updated records: " + objects.toString()); @@ -599,7 +599,7 @@ public void executeAsync() { ArrayList updatedObjects = null; Bundle params = new Bundle(); try { - updatedObjects = QBCustomObjects.updateObjects(qbCustomObjectList, params); + updatedObjects = QBCustomObjects.updateObjects(qbCustomObjectList, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -619,7 +619,7 @@ public void executeAsync() { Snippet deleteCustomObject = new Snippet("delete object") { @Override public void execute() { - QBCustomObjects.deleteObject(MOVIE_CLASS, "53f3660b6fd1dfa9c43ce5a4", new QBEntityCallback() { + QBCustomObjects.deleteObject(MOVIE_CLASS, "53f3660b6fd1dfa9c43ce5a4").performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { Log.i(TAG, ">>> custom object deleted OK"); @@ -637,7 +637,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBCustomObjects.deleteObject(MOVIE_CLASS, "561b9af7a0eb47fc1e000718"); + QBCustomObjects.deleteObject(MOVIE_CLASS, "561b9af7a0eb47fc1e000718").perform(); Log.i(TAG, ">>> custom object deleted OK"); } catch (QBResponseException e) { setException(e); @@ -658,7 +658,7 @@ public void execute() { deleteIds.add("53f36e796fd1dfa9c43ce5a6"); deleteIds.add("53f36e796fd1dfa9c43ce5a7"); - QBCustomObjects.deleteObjects(MOVIE_CLASS, deleteIds, new QBEntityCallback>() { + QBCustomObjects.deleteObjects(MOVIE_CLASS, deleteIds).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList deletedObjects, Bundle params) { @@ -687,7 +687,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList deleted = null; try { - deleted = QBCustomObjects.deleteObjects(MOVIE_CLASS, deleteIds, params); + deleted = (ArrayList) QBCustomObjects.deleteObjects(MOVIE_CLASS, deleteIds, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -711,7 +711,7 @@ public void executeAsync() { @Override public void execute() { - QBCustomObjects.getObjectPermissions(MOVIE_CLASS, "53f44e7befa3573473000002", new QBEntityCallback() { + QBCustomObjects.getObjectPermissions(MOVIE_CLASS, "53f44e7befa3573473000002").performAsync(new QBEntityCallback() { @Override public void onSuccess(QBPermissions permissions, Bundle params) { @@ -731,7 +731,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { QBPermissions permissions = null; try { - permissions = QBCustomObjects.getObjectPermissions(MOVIE_CLASS, "53f365f06fd1dfa9c43ce5a3"); + permissions = QBCustomObjects.getObjectPermissions(MOVIE_CLASS, "53f365f06fd1dfa9c43ce5a3").perform(); } catch (QBResponseException e) { setException(e); } @@ -770,7 +770,7 @@ public void execute() { permissions.setUpdatePermission(QBPermissionsLevel.OPEN_FOR_GROUPS, openPermissionsForGroups); record.setPermission(permissions); - QBCustomObjects.updateObject(record, (QBRequestUpdateBuilder) null, new QBEntityCallback() { + QBCustomObjects.updateObject(record, null).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObject object, Bundle params) { Log.i(TAG, ">>> updated record: : " + object.toString()); @@ -810,7 +810,7 @@ public void executeAsync() { QBCustomObject updatedObject = null; try { - updatedObject = QBCustomObjects.updateObject(obj); + updatedObject = QBCustomObjects.updateObject(obj).perform(); } catch (QBResponseException e) { setException(e); } @@ -849,7 +849,7 @@ public void execute() { permissions.setUpdatePermission(QBPermissionsLevel.OWNER); newRecord.setPermission(permissions); - QBCustomObjects.createObject(newRecord, new QBEntityCallback() { + QBCustomObjects.createObject(newRecord).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObject object, Bundle params) { Log.i(TAG, ">>> created object: " + object); @@ -889,7 +889,7 @@ public void executeAsync() { QBCustomObject createdObject = null; try { - createdObject = QBCustomObjects.createObject(newRecord); + createdObject = QBCustomObjects.createObject(newRecord).perform(); } catch (QBResponseException e) { setException(e); } @@ -910,7 +910,12 @@ public void executeAsync() { public void execute() { QBCustomObject qbCustomObject = new QBCustomObject(MOVIE_CLASS, "54b51dadefa3574f1600000c"); - QBCustomObjectsFiles.uploadFile(imageFile, qbCustomObject, "image", new QBEntityCallback() { + QBCustomObjectsFiles.uploadFile(imageFile, qbCustomObject, "image", new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObjectFileField uploadFileResult, Bundle params) { @@ -922,11 +927,6 @@ public void onSuccess(QBCustomObjectFileField uploadFileResult, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -943,7 +943,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } @@ -965,7 +965,12 @@ public void onProgressUpdate(int progress) { public void execute() { QBCustomObject qbCustomObject = new QBCustomObject(MOVIE_CLASS, "54b51dadefa3574f1600000c"); - QBCustomObjectsFiles.downloadFile(qbCustomObject, "image", new QBEntityCallback(){ + QBCustomObjectsFiles.downloadFile(qbCustomObject, "image", new QBProgressCallback() { + @Override + public void onProgressUpdate(int progress) { + Log.i(TAG, "progress: " + progress); + } + }).performAsync(new QBEntityCallback(){ @Override public void onSuccess(InputStream inputStream, Bundle params) { Log.i(TAG, "file downloaded"); @@ -975,11 +980,6 @@ public void onSuccess(InputStream inputStream, Bundle params) { public void onError(QBResponseException errors) { handleErrors(errors); } - }, new QBProgressCallback() { - @Override - public void onProgressUpdate(int progress) { - Log.i(TAG, "progress: " + progress); - } }); } }; @@ -997,7 +997,7 @@ public void executeAsync() { public void onProgressUpdate(int progress) { Log.i(TAG, "progress: " + progress); } - }); + }).perform(); } catch (QBResponseException e) { setException(e); } @@ -1018,7 +1018,7 @@ public void onProgressUpdate(int progress) { public void execute() { QBCustomObject qbCustomObject = new QBCustomObject(MOVIE_CLASS, "53f370cc535c1276290447d9"); - QBCustomObjectsFiles.deleteFile(qbCustomObject, "image", new QBEntityCallback() { + QBCustomObjectsFiles.deleteFile(qbCustomObject, "image").performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -1039,7 +1039,7 @@ public void executeAsync() { QBCustomObject qbCustomObject = new QBCustomObject(MOVIE_CLASS, "53f370cc535c1276290447d9"); try { - QBCustomObjectsFiles.deleteFile(qbCustomObject, "image"); + QBCustomObjectsFiles.deleteFile(qbCustomObject, "image").perform(); } catch (QBResponseException e) { setException(e); } @@ -1058,7 +1058,7 @@ public void execute() { requestGetBuilder.in("name", "The Dark Knight", "The Godfather"); QBCustomObjects.getAggregationObjects("SuperSample", - aggregationRequestBuilder, requestGetBuilder, new QBEntityCallback>() { + aggregationRequestBuilder, requestGetBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList qbAggregationItems, Bundle bundle) { Log.i(TAG, "aggregationObjects: " + qbAggregationItems); @@ -1084,7 +1084,7 @@ public void executeAsync() { requestGetBuilder.in("name", "The Dark Knight", "The Godfather"); try { ArrayList aggregationObjects = QBCustomObjects.getAggregationObjects("SuperSample", - aggregationRequestBuilder, requestGetBuilder); + aggregationRequestBuilder, requestGetBuilder).perform(); Log.i(TAG, "aggregationObjects: " + aggregationObjects); diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsLocation.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsLocation.java index 3fcfada2a..6b1207b81 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsLocation.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsLocation.java @@ -63,7 +63,7 @@ public void execute() { // final QBLocation location = new QBLocation(latitude, longitude, status); - QBLocations.createLocation(location, new QBEntityCallback() { + QBLocations.createLocation(location).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBLocation qbLocation, Bundle args) { @@ -89,7 +89,7 @@ public void executeAsync() { QBLocation locationResult = null; try { - locationResult = QBLocations.createLocation(location); + locationResult = QBLocations.createLocation(location).perform(); } catch (QBResponseException e) { setException(e); } @@ -114,18 +114,19 @@ public void execute() { // final QBLocation location = new QBLocation(latitude, longitude, status); - QBLocations.createLocation(location, new QBEntityCallback() { + QBLocations.createLocation(location, "Your friend is near!", QBEnvironment.DEVELOPMENT, 1000).performAsync( + new QBEntityCallback() { - @Override - public void onSuccess(QBLocation qbLocation, Bundle args) { - Log.i(TAG, "Location is: " + qbLocation); - } + @Override + public void onSuccess(QBLocation qbLocation, Bundle args) { + Log.i(TAG, "Location is: " + qbLocation); + } - @Override - public void onError(QBResponseException errors) { - handleErrors(errors); - } - }, "Your friend is near!", QBEnvironment.DEVELOPMENT, 1000); + @Override + public void onError(QBResponseException errors) { + handleErrors(errors); + } + }); } }; @@ -140,7 +141,7 @@ public void executeAsync() { QBLocation locationResult = null; try { - locationResult = QBLocations.createLocation(location, "Your friend is near!", QBEnvironment.DEVELOPMENT, 1000); + locationResult = QBLocations.createLocation(location, "Your friend is near!", QBEnvironment.DEVELOPMENT, 1000).perform(); } catch (QBResponseException e) { setException(e); } @@ -160,7 +161,7 @@ public void executeAsync() { @Override public void execute() { QBLocation location = new QBLocation(11308); - QBLocations.getLocation(location, new QBEntityCallback() { + QBLocations.getLocation(location).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBLocation qbLocation, Bundle args) { @@ -182,7 +183,7 @@ public void executeAsync() { QBLocation location = new QBLocation(11308); QBLocation locationResult = null; try { - locationResult = QBLocations.getLocation(location); + locationResult = QBLocations.getLocation(location).perform(); } catch (QBResponseException e) { setException(e); } @@ -206,7 +207,7 @@ public void execute() { qbLocation.setId(1141748); qbLocation.setStatus("I'am at Pizza"); - QBLocations.updateLocation(qbLocation, new QBEntityCallback() { + QBLocations.updateLocation(qbLocation).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBLocation qbLocation, Bundle args) { Log.i(TAG, "Location is: " + qbLocation); @@ -229,7 +230,7 @@ public void executeAsync() { QBLocation locationResult = null; try { - locationResult = QBLocations.updateLocation(qbLocation); + locationResult = QBLocations.updateLocation(qbLocation).perform(); } catch (QBResponseException e) { setException(e); } @@ -250,7 +251,7 @@ public void executeAsync() { public void execute() { QBLocation location = new QBLocation(1141748); - QBLocations.deleteLocation(location, new QBEntityCallback() { + QBLocations.deleteLocation(location).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -271,7 +272,7 @@ public void executeAsync() { QBLocation location = new QBLocation(1141748); try { - QBLocations.deleteLocation(location); + QBLocations.deleteLocation(location).perform(); Log.i(TAG, "Location was removed"); } catch (QBResponseException e) { setException(e); @@ -315,7 +316,9 @@ public void execute() { locationRequestBuilder.setPage(1); locationRequestBuilder.setPerPage(10); - QBLocations.getLocations(locationRequestBuilder, new QBEntityCallback>() { + Bundle bundle = new Bundle(); + + QBLocations.getLocations(locationRequestBuilder, bundle).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList locations, Bundle params) { @@ -366,7 +369,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList locations = null; try { - locations = QBLocations.getLocations(locationRequestBuilder, params); + locations = QBLocations.getLocations(locationRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -390,7 +393,7 @@ public void executeAsync() { public void execute() { int days = 2; - QBLocations.deleteObsoleteLocations(days, new QBEntityCallback() { + QBLocations.deleteObsoleteLocations(days).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -411,7 +414,7 @@ public void executeAsync() { int days = 2; try { - QBLocations.deleteObsoleteLocations(days); + QBLocations.deleteObsoleteLocations(days).perform(); Log.i(TAG, "Locations was removed"); } catch (QBResponseException e) { setException(e); diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsPushNotifications.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsPushNotifications.java index a8a7c8f73..21f5e2283 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsPushNotifications.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsPushNotifications.java @@ -82,7 +82,7 @@ public void execute() { String registrationID = "APA91bGr9AcS9Wgv4p4BkBQAg_1YrJZpfa5GMXg7LAQU0lya8gbf9Iw1360602PunkWk_NOsLS2xEK8tPeBCBfSH4fobt7zW4KVlWGjUfR3itFbVa_UreBf6c-rZ8uP_0_vxPCO65ceqgnjvQqD6j8DjLykok7VF7UBBjsMZrTIFjKwmVeJqb1o"; subscription.setRegistrationID(registrationID); - QBPushNotifications.createSubscription(subscription, new QBEntityCallback>() { + QBPushNotifications.createSubscription(subscription).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList subscriptions, Bundle args) { @@ -116,7 +116,7 @@ public void executeAsync() { ArrayList createdSubscriptions = null; try { - createdSubscriptions = QBPushNotifications.createSubscription(subscription); + createdSubscriptions = QBPushNotifications.createSubscription(subscription).perform(); } catch (QBResponseException e) { setException(e); } @@ -135,7 +135,7 @@ public void executeAsync() { Snippet getSubscriptions = new Snippet("get subscriptions") { @Override public void execute() { - QBPushNotifications.getSubscriptions(new QBEntityCallback>() { + QBPushNotifications.getSubscriptions().performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList subscriptions, Bundle args) { @@ -155,7 +155,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { ArrayList subscriptions = null; try { - subscriptions = QBPushNotifications.getSubscriptions(); + subscriptions = QBPushNotifications.getSubscriptions().perform(); } catch (QBResponseException e) { setException(e); } @@ -174,7 +174,7 @@ public void executeAsync() { Snippet deleteSubscription = new Snippet("delete subscription") { @Override public void execute() { - QBPushNotifications.deleteSubscription(1558628, new QBEntityCallback() { + QBPushNotifications.deleteSubscription(1558628).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -193,7 +193,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBPushNotifications.deleteSubscription(1558628); + QBPushNotifications.deleteSubscription(1558628).perform(); Log.i(TAG, ">>> subscription successfully deleted"); } catch (QBResponseException e) { setException(e); @@ -269,7 +269,7 @@ public void execute() { QBEvent event = buildEvent(); - QBPushNotifications.createEvent(event, new QBEntityCallback() { + QBPushNotifications.createEvent(event).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBEvent qbEvent, Bundle args) { Log.i(TAG, ">>> new event: " + qbEvent.toString()); @@ -291,7 +291,7 @@ public void executeAsync() { QBEvent createdEvent = null; try { - createdEvent = QBPushNotifications.createEvent(event); + createdEvent = QBPushNotifications.createEvent(event).perform(); } catch (QBResponseException e) { setException(e); } @@ -310,7 +310,7 @@ public void executeAsync() { Snippet getEventWithId = new Snippet("get event", "with id") { @Override public void execute() { - QBPushNotifications.getEvent(1454324, new QBEntityCallback() { + QBPushNotifications.getEvent(1454324).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBEvent qbEvent, Bundle args) { @@ -332,7 +332,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - event = QBPushNotifications.getEvent(1454324); + event = QBPushNotifications.getEvent(1454324).perform(); } catch (QBResponseException e) { setException(e); } @@ -353,7 +353,8 @@ public void executeAsync() { @Override public void execute() { QBPagedRequestBuilder requestBuilder = new QBPagedRequestBuilder(20, 1); - QBPushNotifications.getEvents(requestBuilder, new QBEntityCallback>() { + Bundle bundle = new Bundle(); + QBPushNotifications.getEvents(requestBuilder, bundle).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList events, Bundle args) { @@ -379,7 +380,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList events = null; try { - events = QBPushNotifications.getEvents(requestBuilder, params); + events = QBPushNotifications.getEvents(requestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -405,7 +406,7 @@ public void execute() { event.setId(1470629); event.setActive(true); // send it again - QBPushNotifications.updateEvent(event, new QBEntityCallback() { + QBPushNotifications.updateEvent(event).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBEvent qbEvent, Bundle args) { @@ -430,7 +431,7 @@ public void executeAsync() { QBEvent updatedEvent = null; try { - updatedEvent = QBPushNotifications.updateEvent(event); + updatedEvent = QBPushNotifications.updateEvent(event).perform(); } catch (QBResponseException e) { setException(e); } @@ -449,7 +450,7 @@ public void executeAsync() { Snippet deleteEvent = new Snippet("delete event") { @Override public void execute() { - QBPushNotifications.deleteEvent(1454324, new QBEntityCallback() { + QBPushNotifications.deleteEvent(1454324).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -468,7 +469,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBPushNotifications.deleteEvent(1454326); + QBPushNotifications.deleteEvent(1454326).perform(); Log.i(TAG, ">>> event successfully deleted"); } catch (QBResponseException e) { @@ -488,23 +489,28 @@ public void executeAsync() { public void execute() { String registrationID = "APA91bGr9AcS9Wgv4p4BkBQAg_1YrJZpfa5GMXg7LAQU0lya8gbf9Iw1360602PunkWk_NOsLS2xEK8tPeBCBfSH4fobt7zW4KVlWGjUfR3itFbVa_UreBf6c-rZ8uP_0_vxPCO65ceqgnjvQqD6j8DjLykok7VF7UBBjsMZrTIFjKwmVeJqb1o"; String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); - if(deviceId == null){ + if (deviceId == null) { deviceId = "UniversalDeviceId"; } - QBPushNotifications.subscribeToPushNotificationsTask(registrationID, deviceId, QBEnvironment.DEVELOPMENT, + QBSubscription subscription = new QBSubscription(); + subscription.setEnvironment(QBEnvironment.DEVELOPMENT); + subscription.setDeviceUdid(deviceId); + subscription.setRegistrationID(registrationID); + + QBPushNotifications.createSubscription(subscription).performAsync( new QBEntityCallback>() { - @Override - public void onSuccess(ArrayList subscriptions, Bundle args) { - Log.i(TAG, ">>> subscription created" + subscriptions.toString()); - } + @Override + public void onSuccess(ArrayList subscriptions, Bundle args) { + Log.i(TAG, ">>> subscription created" + subscriptions.toString()); + } - @Override - public void onError(QBResponseException errors) { - handleErrors(errors); - } - }); + @Override + public void onError(QBResponseException errors) { + handleErrors(errors); + } + }); } }; @@ -518,9 +524,14 @@ public void executeAsync() { deviceId = "UniversalDeviceId"; } + QBSubscription subscription = new QBSubscription(); + subscription.setEnvironment(QBEnvironment.DEVELOPMENT); + subscription.setDeviceUdid(deviceId); + subscription.setRegistrationID(registrationID); + ArrayList subscriptions = null; try { - subscriptions = QBPushNotifications.subscribeToPushNotificationsTask(registrationID, deviceId, QBEnvironment.DEVELOPMENT); + subscriptions = QBPushNotifications.createSubscription(subscription).perform(); } catch (QBResponseException e) { setException(e); } diff --git a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsUsers.java b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsUsers.java index e09c586b7..04e47e242 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsUsers.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsUsers.java @@ -150,7 +150,7 @@ public void execute() { final QBUser user = new QBUser(ApplicationConfig.getInstance().getTestUserLogin1(), ApplicationConfig.getInstance().getTestUserPassword1()); - final QBRequestCanceler canceler = QBUsers.signIn(user, new QBEntityCallback() { + QBUsers.signIn(user).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle params) { @@ -173,7 +173,7 @@ public void executeAsync() { user.setPassword(ApplicationConfig.getInstance().getTestUserPassword1()); QBUser userResult = null; try { - userResult = QBUsers.signIn(user); + userResult = QBUsers.signIn(user).perform(); } catch (QBResponseException e) { setException(e); } @@ -193,11 +193,10 @@ public void executeAsync() { @Override public void execute() { - final QBUser user = new QBUser(); - user.setEmail("test987@test.com"); - user.setPassword("testpassword"); + String email = "test987@test.com"; + String password = "testpassword"; - QBUsers.signIn(user, new QBEntityCallback() { + QBUsers.signInByEmail(email, password).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { Log.i(TAG, ">>> User was successfully signed in, " + user); @@ -214,12 +213,12 @@ public void onError(QBResponseException errors) { Snippet signInUserWithEmailSynchronous = new SnippetAsync("sign in user (synchronous)", "with email", context) { @Override public void executeAsync() { - QBUser user = new QBUser(); - user.setEmail("test987@test.com"); - user.setPassword("testpassword"); + String email = "test987@test.com"; + String password = "testpassword"; + QBUser userResult = null; try { - userResult = QBUsers.signIn(user); + userResult = QBUsers.signInByEmail(email, password).perform(); } catch (QBResponseException e) { setException(e); } @@ -240,7 +239,7 @@ public void executeAsync() { public void execute() { String facebookAccessToken = "AAAEra8jNdnkBABYf3ZBSAz9dgLfyK7tQNttIoaZA1cC40niR6HVS0nYuufZB0ZCn66VJcISM8DO2bcbhEahm2nW01ZAZC1YwpZB7rds37xW0wZDZD"; - QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null, new QBEntityCallback() { + QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { Log.i(TAG, ">>> User was successfully signed in, " + user); @@ -264,7 +263,7 @@ public void executeAsync() { QBUser userResult = null; try { - userResult = QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null); + userResult = QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null).perform(); } catch (QBResponseException e) { setException(e); } @@ -319,28 +318,29 @@ public void success(DigitsSession session, String phoneNumber) { String xAuthServiceProvider = authHeaders.get("X-Auth-Service-Provider"); String xVerifyCredentialsAuthorization = authHeaders.get("X-Verify-Credentials-Authorization"); - if(isSync){ + if (isSync) { QBUser user = null; try { - user = QBUsers.signInUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization); + user = QBUsers.signInUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization).perform(); } catch (QBResponseException e) { e.printStackTrace(); } - if(session != null){ + if (session != null) { Log.i(TAG, "user: " + user); } - }else{ - QBUsers.signInUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization, new QBEntityCallbackImpl() { - @Override - public void onSuccess(QBUser user, Bundle params) { - Log.i(TAG, "user: "+user); - } - - @Override - public void onError(QBResponseException errors) { - handleErrors(errors); - } - }); + } else { + QBUsers.signInUsingTwitterDigits(xAuthServiceProvider, xVerifyCredentialsAuthorization).performAsync( + new QBEntityCallback() { + @Override + public void onSuccess(QBUser user, Bundle params) { + Log.i(TAG, "user: " + user); + } + + @Override + public void onError(QBResponseException errors) { + handleErrors(errors); + } + }); } } @@ -367,7 +367,7 @@ private Map getAuthHeadersBySession(DigitsSession digitsSession) Snippet signOut = new Snippet("sign out") { @Override public void execute() { - QBUsers.signOut(new QBEntityCallback(){ + QBUsers.signOut().performAsync(new QBEntityCallback(){ @Override public void onSuccess(Void result, Bundle bundle) { @@ -386,7 +386,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { try { - QBUsers.signOut(); + QBUsers.signOut().perform(); } catch (QBResponseException e) { setException(e); } @@ -419,7 +419,7 @@ public void execute() { user.setTags(tags); user.setWebsite("website.com"); - QBUsers.signUp(user, new QBEntityCallback() { + QBUsers.signUp(user).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { Log.i(TAG, ">>> User was successfully signed up, " + user); @@ -454,7 +454,7 @@ public void executeAsync() { user.setWebsite("website.com"); QBUser qbUserResult = null; try { - qbUserResult = QBUsers.signUp(user); + qbUserResult = QBUsers.signUp(user).perform(); } catch (QBResponseException e) { setException(e); } @@ -489,7 +489,7 @@ public void execute() { user.setTags(tags); user.setWebsite("website.com"); - QBUsers.signUpSignInTask(user, new QBEntityCallback() { + QBUsers.signUpSignInTask(user).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { Log.i(TAG, ">>> User was successfully signed up and signed in, " + user); @@ -525,7 +525,7 @@ public void executeAsync() { QBUser userResult = null; try { - userResult = QBUsers.signUpSignInTask(user); + userResult = QBUsers.signUpSignInTask(user).perform(); } catch (QBResponseException e) { setException(e); } @@ -551,13 +551,13 @@ public void execute() { // user.setFullName("galog"); // user.setPhone("+123123123"); // user.setCustomData("my new custom data"); -// StringifyArrayQBResponseException tags = new StringifyArrayQBResponseException(); -// tags.add("man"); -// user.setTags(tags); + StringifyArrayList tags = new StringifyArrayList(); + tags.add("man"); + user.setTags(tags); // user.setWebsite("google.com"); // user.setFileId(-1); - QBUsers.updateUser(user, new QBEntityCallback(){ + QBUsers.updateUser(user).performAsync(new QBEntityCallback(){ @Override public void onSuccess(QBUser user, Bundle args) { Log.i(TAG, ">>> User: " + user); @@ -582,7 +582,7 @@ public void executeAsync() { QBUser userResult = null; try { - userResult = QBUsers.updateUser(user); + userResult = QBUsers.updateUser(user).perform(); } catch (QBResponseException e) { setException(e); } @@ -600,7 +600,7 @@ public void executeAsync() { public void execute() { int userId = 562; - QBUsers.deleteUser(userId, new QBEntityCallback() { + QBUsers.deleteUser(userId).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -622,7 +622,7 @@ public void executeAsync() { int userId = 562; try { - QBUsers.deleteUser(userId); + QBUsers.deleteUser(userId).perform(); } catch (QBResponseException e) { setException(e); } @@ -638,7 +638,7 @@ public void executeAsync() { Snippet deleteUserByExternalId = new Snippet("delete user", "by external id") { @Override public void execute() { - QBUsers.deleteByExternalId("568965444", new QBEntityCallback() { + QBUsers.deleteByExternalId("568965444").performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -658,7 +658,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { try { - QBUsers.deleteByExternalId("568965444"); + QBUsers.deleteByExternalId("568965444").perform(); } catch (QBResponseException e) { setException(e); } @@ -674,7 +674,7 @@ public void executeAsync() { Snippet resetPassword = new Snippet("reset password") { @Override public void execute() { - QBUsers.resetPassword("test987@test.com", new QBEntityCallback() { + QBUsers.resetPassword("test987@test.com").performAsync(new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { @@ -694,7 +694,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { try { - QBUsers.resetPassword("test987@test.com"); + QBUsers.resetPassword("test987@test.com").perform(); } catch (QBResponseException e) { setException(e); } @@ -715,7 +715,9 @@ public void execute() { pagedRequestBuilder.setPage(1); pagedRequestBuilder.setPerPage(5); - QBUsers.getUsers(pagedRequestBuilder, new QBEntityCallback>() { + Bundle bundle = new Bundle(); + + QBUsers.getUsers(pagedRequestBuilder, bundle).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { @@ -747,7 +749,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList users = null; try { - users = QBUsers.getUsers(pagedRequestBuilder, params); + users = QBUsers.getUsers(pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -779,7 +781,9 @@ public void execute() { usersIds.add(379); usersIds.add(380); - QBUsers.getUsersByIDs(usersIds, pagedRequestBuilder, new QBEntityCallback>() { + Bundle bundle = new Bundle(); + + QBUsers.getUsersByIDs(usersIds, pagedRequestBuilder, bundle).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -813,7 +817,7 @@ public void executeAsync() { Bundle params = new Bundle(); ArrayList users = null; try { - users = QBUsers.getUsersByIDs(usersIds, pagedRequestBuilder, params); + users = QBUsers.getUsersByIDs(usersIds, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -844,7 +848,9 @@ public void execute() { usersLogins.add("igorquickblox2"); usersLogins.add("john"); - QBUsers.getUsersByLogins(usersLogins, pagedRequestBuilder, new QBEntityCallback>() { + Bundle params = new Bundle(); + + QBUsers.getUsersByLogins(usersLogins, pagedRequestBuilder, params).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -877,7 +883,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByLogins(usersLogins, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByLogins(usersLogins, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -908,7 +914,7 @@ public void execute() { usersEmails.add("asd@ffg.fgg"); usersEmails.add("ghh@ggh.vbb"); - QBUsers.getUsersByEmails(usersEmails, pagedRequestBuilder, new QBEntityCallback>() { + QBUsers.getUsersByEmails(usersEmails, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -941,7 +947,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByEmails(usersEmails, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByEmails(usersEmails, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -972,7 +978,7 @@ public void execute() { usersPhones.add("980028312"); usersPhones.add("765172323"); - QBUsers.getUsersByPhoneNumbers(usersPhones, pagedRequestBuilder, new QBEntityCallback>() { + QBUsers.getUsersByPhoneNumbers(usersPhones, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1005,7 +1011,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByPhoneNumbers(usersPhones, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByPhoneNumbers(usersPhones, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -1036,7 +1042,7 @@ public void execute() { pagedRequestBuilder.setPage(1); pagedRequestBuilder.setPerPage(10); - QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder, new QBEntityCallback>() { + QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1068,7 +1074,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -1099,7 +1105,7 @@ public void execute() { pagedRequestBuilder.setPage(1); pagedRequestBuilder.setPerPage(10); - QBUsers.getUsersByTwitterId(twitterIDs, pagedRequestBuilder, new QBEntityCallback>() { + QBUsers.getUsersByTwitterId(twitterIDs, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1131,7 +1137,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByTwitterId(twitterIDs, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByTwitterId(twitterIDs, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -1161,7 +1167,7 @@ public void execute() { pagedRequestBuilder.setPage(1); pagedRequestBuilder.setPerPage(10); - QBUsers.getUsersByTwitterDigitsId(twitterDigitsIDs, pagedRequestBuilder, new QBEntityCallbackImpl>() { + QBUsers.getUsersByTwitterDigitsId(twitterDigitsIDs, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1192,7 +1198,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByTwitterDigitsId(twitterDigitsIDs, pagedRequestBuilder, params); + users = QBUsers.getUsersByTwitterDigitsId(twitterDigitsIDs, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { handleErrors(e); } @@ -1223,7 +1229,7 @@ public void execute() { pagedRequestBuilder.setPage(1); pagedRequestBuilder.setPerPage(10); - QBUsers.getUsersByTags(userTags, pagedRequestBuilder, new QBEntityCallback>() { + QBUsers.getUsersByTags(userTags, pagedRequestBuilder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1255,7 +1261,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByTags(userTags, pagedRequestBuilder, params); + users = (ArrayList) QBUsers.getUsersByTags(userTags, pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -1279,7 +1285,7 @@ public void executeAsync() { @Override public void execute() { String fullName = "bob"; - QBUsers.getUsersByFullName(fullName, null, new QBEntityCallback>() { + QBUsers.getUsersByFullName(fullName, null).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList users, Bundle params) { Log.i(TAG, ">>> Users: " + users.toString()); @@ -1308,7 +1314,7 @@ public void executeAsync() { ArrayList users = null; try { - users = QBUsers.getUsersByFullName("bob", pagedRequestBuilder, params); + users = QBUsers.getUsersByFullName("bob", pagedRequestBuilder, params).perform(); } catch (QBResponseException e) { setException(e); } @@ -1331,7 +1337,7 @@ public void executeAsync() { Snippet getUserById = new Snippet("get user", "by id") { @Override public void execute() { - QBUsers.getUser(53779, new QBEntityCallback() { + QBUsers.getUser(53779).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1350,7 +1356,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUser(53779); + user = QBUsers.getUser(53779).perform(); } catch (QBResponseException e) { setException(e); } @@ -1371,7 +1377,7 @@ public void executeAsync() { @Override public void execute() { String login = "testuser"; - QBUsers.getUserByLogin(login, new QBEntityCallback() { + QBUsers.getUserByLogin(login).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1392,7 +1398,7 @@ public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUserByLogin(login); + user = QBUsers.getUserByLogin(login).perform(); } catch (QBResponseException e) { setException(e); } @@ -1413,7 +1419,7 @@ public void executeAsync() { @Override public void execute() { String twitterId = "56802037340"; - QBUsers.getUserByTwitterId(twitterId, new QBEntityCallback() { + QBUsers.getUserByTwitterId(twitterId).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1434,7 +1440,7 @@ public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUserByTwitterId(twitterId); + user = QBUsers.getUserByTwitterId(twitterId).perform(); } catch (QBResponseException e) { setException(e); } @@ -1455,7 +1461,7 @@ public void executeAsync() { @Override public void execute() { String twitterDigitsId = "3533173695"; - QBUsers.getUserByTwitterDigitsId(twitterDigitsId, new QBEntityCallbackImpl() { + QBUsers.getUserByTwitterDigitsId(twitterDigitsId).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1464,7 +1470,6 @@ public void onSuccess(QBUser user, Bundle args) { @Override public void onError(QBResponseException errors) { - super.onError(errors); } }); } @@ -1477,7 +1482,7 @@ public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUserByTwitterDigitsId(twitterDigitsId); + user = QBUsers.getUserByTwitterDigitsId(twitterDigitsId).perform(); } catch (QBResponseException e) { setException(e); } @@ -1498,7 +1503,7 @@ public void executeAsync() { @Override public void execute() { String facebookId = "100003123141430"; - QBUsers.getUserByFacebookId(facebookId, new QBEntityCallback() { + QBUsers.getUserByFacebookId(facebookId).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1518,7 +1523,7 @@ public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUserByFacebookId(facebookId); + user = QBUsers.getUserByFacebookId(facebookId).perform(); } catch (QBResponseException e) { setException(e); } @@ -1539,7 +1544,7 @@ public void executeAsync() { @Override public void execute() { String email = "test123@test.com"; - QBUsers.getUserByEmail(email, new QBEntityCallback() { + QBUsers.getUserByEmail(email).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1559,7 +1564,7 @@ public void onError(QBResponseException errors) { public void executeAsync() { String email = "test123@test.com"; try { - userByEmail = QBUsers.getUserByEmail(email); + userByEmail = QBUsers.getUserByEmail(email).perform(); } catch (QBResponseException e) { setException(e); } @@ -1584,7 +1589,7 @@ protected void postExecute() { @Override public void execute() { String externalId = "123145235"; - QBUsers.getUserByExternalId(externalId, new QBEntityCallback() { + QBUsers.getUserByExternalId(externalId).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBUser user, Bundle args) { @@ -1604,7 +1609,7 @@ public void executeAsync() { QBUser user = null; try { - user = QBUsers.getUserByExternalId(externalId); + user = QBUsers.getUserByExternalId(externalId).perform(); } catch (QBResponseException e) { setException(e); } diff --git a/snippets/src/main/res/raw/servers.json b/snippets/src/main/res/raw/servers.json index 2cd3d8f12..0189d2fe5 100644 --- a/snippets/src/main/res/raw/servers.json +++ b/snippets/src/main/res/raw/servers.json @@ -1,19 +1,20 @@ { "servers":{ "production": { - "app_id": 92, + "app_id": "92", "auth_key": "wJHdOcQSxXQGWx5", "auth_secret": "BTFsj7Rtt27DAmT", - "account_key": "rz2sXxBt5xgSxGjALDW6", - "api_domain": "https://api.quickblox.com", + "api_domain": "api.quickblox.com", "chat_domain": "chat.quickblox.com", - "test_user_id1": 5179218, - "test_user_login1": "igorquickblox711", - "test_user_password1": "igorquickblox711", - "test_user_id2": 5179221, - "test_user_login2": "igorquickblox712", - "test_user_password2": "igorquickblox712", - "dialog_id": "561cffc2a28f9a97ec0001d9" + "bucket_name": "qbprod", + "test_user_id1": 11109547, + "test_user_login1": "supersample-ios2", + "test_user_password1": "supersample-ios2", + "test_user_id2": 11108871, + "test_user_login2": "supersample-ios1", + "test_user_password2": "supersample-ios1", +// "dialog_id": "561cffc2a28f9a97ec0001d9" + "dialog_id": "56f3fac3a0eb4786ae00003f" } }, "active": "production",