From 3fa0c9ea669837aac2074eb15fe46409f4c2d1cf Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 3 Mar 2016 16:48:00 +0200 Subject: [PATCH 01/55] introduced 2.5.1 sdk version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c1b5011d4..a702be431 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ allprojects { // QuickBlox SDK version // -ext.qbSdkVersion = '2.5' +ext.qbSdkVersion = '2.5.1' // // From 8be1a6cf50151262e5c0a157572135a69c6737e2 Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Fri, 25 Mar 2016 18:46:51 +0200 Subject: [PATCH 02/55] adopt build.gradle --- build.gradle | 4 +- sample-chat/build.gradle | 6 +-- sample-content/build.gradle | 4 +- sample-custom-objects/build.gradle | 4 +- sample-location/build.gradle | 4 +- sample-messages/build.gradle | 4 +- sample-users/build.gradle | 2 +- sample-videochat-webrtc/build.gradle | 6 +-- settings.gradle | 28 +++++------ snippets/build.gradle | 42 ++++++++-------- snippets/res/raw/servers.json | 50 ++++--------------- .../sdk/snippets/modules/SnippetsChat.java | 2 +- 12 files changed, 64 insertions(+), 92 deletions(-) diff --git a/build.gradle b/build.gradle index c1b5011d4..7eefc3afd 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ allprojects { // QuickBlox SDK version // -ext.qbSdkVersion = '2.5' +ext.versionName = '2.5.1' // // @@ -38,6 +38,8 @@ ext.playServiceGCMVersion = "8.3.0" ext.sourceCompatibility = JavaVersion.VERSION_1_7 ext.targetCompatibility = JavaVersion.VERSION_1_7 +ext.testRunnerVersion = "0.4.1" + ext.lintAbortOnError = false task wrapper(type: Wrapper) { diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 7d67d0542..95593f632 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -27,11 +27,11 @@ dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion@aar") { + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile("com.quickblox:quickblox-android-sdk-chat:$rootProject.versionName@aar") { transitive=true } - compile "com.quickblox:quickblox-android-sdk-messages:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-messages:$rootProject.versionName@aar" compile 'com.navercorp.pulltorefresh:library:3.2.3@aar' compile('vc908.stickers:stickerfactory:0.2.2@aar') { diff --git a/sample-content/build.gradle b/sample-content/build.gradle index 39b87d6cd..db84c8866 100644 --- a/sample-content/build.gradle +++ b/sample-content/build.gradle @@ -26,8 +26,8 @@ dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile "com.quickblox:quickblox-android-sdk-content:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile "com.quickblox:quickblox-android-sdk-content:$rootProject.versionName@aar" compile "com.android.support:appcompat-v7:$rootProject.appCompatVersion" compile "com.nostra13.universalimageloader:universal-image-loader:1.9.0" diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle index cb008e087..ecd4a09c2 100644 --- a/sample-custom-objects/build.gradle +++ b/sample-custom-objects/build.gradle @@ -21,8 +21,8 @@ android { dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.versionName@aar" compile "com.android.support:appcompat-v7:$rootProject.appCompatVersion" } diff --git a/sample-location/build.gradle b/sample-location/build.gradle index 70f78e4f4..dc75feaf2 100644 --- a/sample-location/build.gradle +++ b/sample-location/build.gradle @@ -22,8 +22,8 @@ dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile "com.quickblox:quickblox-android-sdk-location:$rootProject.versionName@aar" compile "com.google.android.gms:play-services-location:8.4.0" compile "com.android.support:appcompat-v7:$rootProject.appCompatVersion" diff --git a/sample-messages/build.gradle b/sample-messages/build.gradle index c8a134af4..c96bdc9a5 100644 --- a/sample-messages/build.gradle +++ b/sample-messages/build.gradle @@ -22,8 +22,8 @@ dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile "com.quickblox:quickblox-android-sdk-messages:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile "com.quickblox:quickblox-android-sdk-messages:$rootProject.versionName@aar" compile "com.google.android.gms:play-services-gcm:$rootProject.playServiceGCMVersion" compile "com.android.support:support-v4:$rootProject.androidSupportVersion" diff --git a/sample-users/build.gradle b/sample-users/build.gradle index 35811d023..535562252 100644 --- a/sample-users/build.gradle +++ b/sample-users/build.gradle @@ -37,7 +37,7 @@ android { dependencies { // online dependencies, from maven repository, jar files // - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" compile "com.android.support:appcompat-v7:$rootProject.appCompatVersion" diff --git a/sample-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle index 02557d80d..5c49745d5 100755 --- a/sample-videochat-webrtc/build.gradle +++ b/sample-videochat-webrtc/build.gradle @@ -36,11 +36,11 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - compile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion@aar") { + compile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + compile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.versionName@aar") { transitive=true } - compile "com.quickblox:quickblox-android-sdk-videochat-webrtc:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-videochat-webrtc:$rootProject.versionName@aar" compile "com.android.support:appcompat-v7:$rootProject.appCompatVersion" compile 'com.android.support:recyclerview-v7:23.1.1' diff --git a/settings.gradle b/settings.gradle index 1a064218f..5b353d7dc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,19 +8,19 @@ include 'sample-chat' include 'sample-videochat-webrtc' -//// for development purpose -//// -//include ':quickblox-android-sdk-chat' -//project(':quickblox-android-sdk-chat').projectDir = new File('../SDK-android/quickblox-android-sdk-chat') -//include ':quickblox-android-sdk-core' -//project(':quickblox-android-sdk-core').projectDir = new File('../SDK-android/quickblox-android-sdk-core') -//include ':quickblox-android-sdk-content' -//project(':quickblox-android-sdk-content').projectDir = new File('../SDK-android/quickblox-android-sdk-content') -//include ':quickblox-android-sdk-messages' -//project(':quickblox-android-sdk-messages').projectDir = new File('../SDK-android/quickblox-android-sdk-messages') -//include ':quickblox-android-sdk-location' -//project(':quickblox-android-sdk-location').projectDir = new File('../SDK-android/quickblox-android-sdk-location') -//include ':quickblox-android-sdk-customobjects' -//project(':quickblox-android-sdk-customobjects').projectDir = new File('../SDK-android/quickblox-android-sdk-customobjects') +// for development purpose +// +include ':quickblox-android-sdk-chat' +project(':quickblox-android-sdk-chat').projectDir = new File('../SDK-android/quickblox-android-sdk-chat') +include ':quickblox-android-sdk-core' +project(':quickblox-android-sdk-core').projectDir = new File('../SDK-android/quickblox-android-sdk-core') +include ':quickblox-android-sdk-content' +project(':quickblox-android-sdk-content').projectDir = new File('../SDK-android/quickblox-android-sdk-content') +include ':quickblox-android-sdk-messages' +project(':quickblox-android-sdk-messages').projectDir = new File('../SDK-android/quickblox-android-sdk-messages') +include ':quickblox-android-sdk-location' +project(':quickblox-android-sdk-location').projectDir = new File('../SDK-android/quickblox-android-sdk-location') +include ':quickblox-android-sdk-customobjects' +project(':quickblox-android-sdk-customobjects').projectDir = new File('../SDK-android/quickblox-android-sdk-customobjects') //include ':quickblox-android-sdk-videochat-webrtc' //project(':quickblox-android-sdk-videochat-webrtc').projectDir = new File('../SDK-android/quickblox-android-sdk-videochat-webrtc') diff --git a/snippets/build.gradle b/snippets/build.gradle index 7faa2e888..5ff3b0866 100644 --- a/snippets/build.gradle +++ b/snippets/build.gradle @@ -56,36 +56,36 @@ dependencies { // online dependencies, from maven repository, jar files // - onlineCompile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion" - onlineCompile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion") { + onlineCompile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName" + onlineCompile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.versionName") { exclude group: 'de.measite.minidns' exclude group: 'org.jxmpp' } - onlineCompile "com.quickblox:quickblox-android-sdk-content:$rootProject.qbSdkVersion" - onlineCompile "com.quickblox:quickblox-android-sdk-messages:$rootProject.qbSdkVersion" - onlineCompile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion" - onlineCompile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion" + onlineCompile "com.quickblox:quickblox-android-sdk-content:$rootProject.versionName" + onlineCompile "com.quickblox:quickblox-android-sdk-messages:$rootProject.versionName" + onlineCompile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.versionName" + onlineCompile "com.quickblox:quickblox-android-sdk-location:$rootProject.versionName" // online dependencies, from remote repository, aar files // - onlineAarCompile "com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion@aar" - onlineAarCompile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion@aar"){ + onlineAarCompile "com.quickblox:quickblox-android-sdk-core:$rootProject.versionName@aar" + onlineAarCompile ("com.quickblox:quickblox-android-sdk-chat:$rootProject.versionName@aar"){ transitive=true } - onlineAarCompile "com.quickblox:quickblox-android-sdk-content:$rootProject.qbSdkVersion@aar" - onlineAarCompile "com.quickblox:quickblox-android-sdk-messages:$rootProject.qbSdkVersion@aar" - onlineAarCompile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar" - onlineAarCompile "com.quickblox:quickblox-android-sdk-location:$rootProject.qbSdkVersion@aar" - -// // 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') + onlineAarCompile "com.quickblox:quickblox-android-sdk-content:$rootProject.versionName@aar" + onlineAarCompile "com.quickblox:quickblox-android-sdk-messages:$rootProject.versionName@aar" + onlineAarCompile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.versionName@aar" + onlineAarCompile "com.quickblox:quickblox-android-sdk-location:$rootProject.versionName@aar" + + // 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') { diff --git a/snippets/res/raw/servers.json b/snippets/res/raw/servers.json index c453e5846..09e0e04f4 100644 --- a/snippets/res/raw/servers.json +++ b/snippets/res/raw/servers.json @@ -1,51 +1,21 @@ { "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", + "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" - }, - "dekhdekh": { - "app_id": 1, - "auth_key": "L-DWNzHvUrcVYMW", - "auth_secret": "S2sYOsNC4GEFKYK", - "account_key": "", - "api_domain": "https://qbapi.dekhdekh.com", - "chat_domain": "qbchat.dekhdekh.com", - "test_user_id1": 15, - "test_user_login1": "test1", - "test_user_password1": "11111111", - "test_user_id2": 16, - "test_user_login2": "test2", - "test_user_password2": "11111111", - "dialog_id": "..." - }, - "stage1": { - "app_id": 1, - "auth_key": "zUZXVVatAhfGjZB", - "auth_secret": "wqPafgpvOr-mC4u", - "account_key": "", - "api_domain": "https://apistage1.quickblox.com", - "chat_domain": "chatstage1.quickblox.com", - "test_user_id1": 2, - "test_user_login1": "igorquickblox711", - "test_user_password1": "igorquickblox711", - "test_user_id2": 3, - "test_user_login2": "igorquickblox712", - "test_user_password2": "igorquickblox712", - "dialog_id": "..." } }, "active": "production", - "use_first_user": false + "use_first_user": true } \ No newline at end of file diff --git a/snippets/src/com/sdk/snippets/modules/SnippetsChat.java b/snippets/src/com/sdk/snippets/modules/SnippetsChat.java index 981d25aa7..a0591fbad 100644 --- a/snippets/src/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/com/sdk/snippets/modules/SnippetsChat.java @@ -585,7 +585,7 @@ private void initPrivateChatMessageListener(){ privateChatMessageListener = new QBMessageListener() { @Override public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) { - log("received message: " + chatMessage.getId()); + log("received message: " + chatMessage.getBody() + ", date_sent: " + chatMessage.getDateSent()); if(chatMessage.getSenderId().equals(chatService.getUser().getId())){ log("Message comes here from carbons"); From 614796c495f4499bd9188144d16a2c321d655205 Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Wed, 30 Mar 2016 18:15:27 +0300 Subject: [PATCH 03/55] updated config --- settings.gradle | 2 -- snippets/res/raw/servers.json | 19 +++++++++++++++++-- .../activities/StartSnippetsActivity.java | 3 +++ .../sdk/snippets/core/ApplicationConfig.java | 14 +++++++------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/settings.gradle b/settings.gradle index 5b353d7dc..e0e17214a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,5 +22,3 @@ include ':quickblox-android-sdk-location' project(':quickblox-android-sdk-location').projectDir = new File('../SDK-android/quickblox-android-sdk-location') include ':quickblox-android-sdk-customobjects' project(':quickblox-android-sdk-customobjects').projectDir = new File('../SDK-android/quickblox-android-sdk-customobjects') -//include ':quickblox-android-sdk-videochat-webrtc' -//project(':quickblox-android-sdk-videochat-webrtc').projectDir = new File('../SDK-android/quickblox-android-sdk-videochat-webrtc') diff --git a/snippets/res/raw/servers.json b/snippets/res/raw/servers.json index 09e0e04f4..b25d2af3f 100644 --- a/snippets/res/raw/servers.json +++ b/snippets/res/raw/servers.json @@ -14,8 +14,23 @@ "test_user_login2": "supersample-ios1", "test_user_password2": "supersample-ios1", "dialog_id": "561cffc2a28f9a97ec0001d9" + }, "stage8": { + "app_id": "2", + "auth_key": "KZDRDAgj6w-Fz5V", + "auth_secret": "V4rArqPLZz-NFPM", + "api_domain": "https://apistage8.quickblox.com", + "chat_domain": "chatstage8.quickblox.com", + "test_user_id1": 4, + "test_user_email1": "", + "test_user_login1": "igorquickbloxI1", + "test_user_password1": "igorquickbloxI1", + "test_user_id2": 6, + "test_user_login2": "igorquickbloxI3", + "test_user_password2": "igorquickbloxI3", + "test_user_email2": "", + "dialog_id": "56f9580317d7a5472b000002" } }, - "active": "production", - "use_first_user": true + "active": "stage8", + "use_first_user": false } \ No newline at end of file diff --git a/snippets/src/com/sdk/snippets/activities/StartSnippetsActivity.java b/snippets/src/com/sdk/snippets/activities/StartSnippetsActivity.java index 21de656c3..df696a3bc 100644 --- a/snippets/src/com/sdk/snippets/activities/StartSnippetsActivity.java +++ b/snippets/src/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/com/sdk/snippets/core/ApplicationConfig.java b/snippets/src/com/sdk/snippets/core/ApplicationConfig.java index e0223ee74..b10e62743 100644 --- a/snippets/src/com/sdk/snippets/core/ApplicationConfig.java +++ b/snippets/src/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(); From a2f46ec93ced9d170b502493d8be27861a4bdfe7 Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Thu, 31 Mar 2016 13:18:38 +0300 Subject: [PATCH 04/55] updated servers.json --- snippets/res/raw/servers.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/res/raw/servers.json b/snippets/res/raw/servers.json index b25d2af3f..1d3da95e4 100644 --- a/snippets/res/raw/servers.json +++ b/snippets/res/raw/servers.json @@ -28,7 +28,7 @@ "test_user_login2": "igorquickbloxI3", "test_user_password2": "igorquickbloxI3", "test_user_email2": "", - "dialog_id": "56f9580317d7a5472b000002" + "dialog_id": "56fcd9ca17d7a55f03000010" } }, "active": "stage8", From 77036a62063cc382e265ab79e8c9d3b2172c3de5 Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Fri, 15 Apr 2016 11:07:26 +0300 Subject: [PATCH 05/55] added chat mesages unread request --- snippets/res/raw/servers.json | 2 +- .../sdk/snippets/modules/SnippetsChat.java | 88 ++++++++++++++++--- .../sdk/snippets/modules/SnippetsUsers.java | 6 +- 3 files changed, 79 insertions(+), 17 deletions(-) diff --git a/snippets/res/raw/servers.json b/snippets/res/raw/servers.json index 1d3da95e4..c76238646 100644 --- a/snippets/res/raw/servers.json +++ b/snippets/res/raw/servers.json @@ -31,6 +31,6 @@ "dialog_id": "56fcd9ca17d7a55f03000010" } }, - "active": "stage8", + "active": "production", "use_first_user": false } \ No newline at end of file diff --git a/snippets/src/com/sdk/snippets/modules/SnippetsChat.java b/snippets/src/com/sdk/snippets/modules/SnippetsChat.java index a0591fbad..c5a3d38af 100644 --- a/snippets/src/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/com/sdk/snippets/modules/SnippetsChat.java @@ -209,6 +209,9 @@ public SnippetsChat(final Context context) { snippets.add(createMessage); snippets.add(createMessageSynchronous); // + snippets.add(getTotalUnreadMessages); + snippets.add(getTotalUnreadMessagesSynchronous); + // // snippets.add(sendPresence); snippets.add(getRosterUsers); @@ -1110,25 +1113,31 @@ public void execute() { QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.setLimit(100); - requestBuilder.addRule("data[class_name]", QueryRule.EQ, "Advert"); +// requestBuilder.addRule("data[class_name]", QueryRule.EQ, "Advert"); QBChatService.getChatDialogs(null, requestBuilder, new QBEntityCallback>() { @Override public void onSuccess(ArrayList dialogs, Bundle args) { Log.i(TAG, "dialogs: " + dialogs); - QBDialog 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")); - 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(); + QBDialog dialog = dialogs.get(5); + if(dialog != null) { + QBDialogCustomData customData = dialog.getCustomData(); + if(customData != null) { + Log.i(TAG, "arr: " + customData.getArray("arr")); + Log.i(TAG, "bbb: " + customData.getBoolean("bbb")); + Log.i(TAG, "fff: " + customData.getFloat("fff")); + Log.i(TAG, "fff2: " + customData.get("fff")); + Log.i(TAG, "iii: " + customData.getInteger("iii")); + Log.i(TAG, "name: " + customData.getString("name")); + Log.i(TAG, "loc: " + customData.getLocation("loc")); + try { + SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); + Log.i(TAG, "ddd: " + customData.getDate("ddd", format)); + } catch (ParseException e) { + e.printStackTrace(); + } + } } } @@ -1653,6 +1662,59 @@ public void executeAsync() { }; + // + ////////////////////////////////////////// Total unread ///////////////////////////////////////// + // + + + Snippet getTotalUnreadMessages = new Snippet("Get total unread Messages") { + @Override + public void execute() { + Set dialogsIds = new HashSet() {{ + add("56f3fac3a0eb4786ae00003f"); add("56f3f546a28f9affc0000033"); + }}; + + QBChatService.getTotalUnreadMessagesCount(dialogsIds, new QBEntityCallback() { + @Override + public void onSuccess(Integer total, Bundle params) { + Log.i(TAG, "total unread messages: " + total); + Log.i(TAG, "params: " + params); + } + + @Override + public void onError(QBResponseException responseException) { + handleErrors(responseException); + } + }); + } + }; + + Snippet getTotalUnreadMessagesSynchronous = new SnippetAsync("Get total unread Messages (synchronous)", context) { + @Override + public void executeAsync() { + Set dialogsIds = new HashSet() {{ + add("56f3fac3a0eb4786ae00003f"); add("56f3f546a28f9affc0000033"); + }}; + + Integer total = null; + Bundle bundle = new Bundle(); + try { + total = QBChatService.getTotalUnreadMessagesCount(dialogsIds, bundle); + } catch (QBResponseException e) { + e.printStackTrace(); + } + + if(total != null){ + Log.i(TAG, "total unread messages: " + total); + Log.i(TAG, "params: " + bundle); + } + + } + }; + + + + // ///////////////////////////////////////////// Roster ///////////////////////////////////////////// // diff --git a/snippets/src/com/sdk/snippets/modules/SnippetsUsers.java b/snippets/src/com/sdk/snippets/modules/SnippetsUsers.java index e09c586b7..1a80805c5 100644 --- a/snippets/src/com/sdk/snippets/modules/SnippetsUsers.java +++ b/snippets/src/com/sdk/snippets/modules/SnippetsUsers.java @@ -551,9 +551,9 @@ 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); From ed6cc13e8b34c827bab49f522a6e9a3ed5f953a9 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 16 Sep 2016 19:02:35 +0300 Subject: [PATCH 06/55] after updating SDK to 3.0 --- build.gradle | 2 +- .../sample/chat/ui/activity/ChatActivity.java | 18 +++--- .../chat/ui/activity/ChatInfoActivity.java | 8 +-- .../chat/ui/activity/DialogsActivity.java | 16 ++--- .../chat/ui/activity/LoginActivity.java | 2 +- .../chat/ui/activity/SelectUsersActivity.java | 8 +-- .../chat/ui/activity/SplashActivity.java | 2 +- .../chat/ui/adapter/DialogsAdapter.java | 10 +-- .../sample/chat/utils/chat/ChatHelper.java | 64 +++++++++---------- .../sample/chat/utils/chat/GroupChatImpl.java | 4 +- .../sample/chat/utils/qb/QbDialogHolder.java | 16 ++--- .../sample/chat/utils/qb/QbDialogUtils.java | 18 +++--- .../content/activities/GalleryActivity.java | 14 ++-- .../content/activities/SplashActivity.java | 2 +- .../core/gcm/GooglePlayServicesHelper.java | 2 +- .../activities/AddNewMovieActivity.java | 2 +- .../activities/MovieListActivity.java | 2 +- .../activities/SplashActivity.java | 2 +- .../activities/MessagesActivity.java | 2 +- .../activities/SplashActivity.java | 2 +- .../user/activities/ShowUserActivity.java | 2 +- .../user/activities/SignInActivity.java | 2 +- .../user/activities/SignUpUserActivity.java | 2 +- .../user/activities/SplashActivity.java | 2 +- .../user/activities/UsersListActivity.java | 4 +- .../util/QBResRequestExecutor.java | 14 ++-- .../utils/PushNotificationSender.java | 2 +- 27 files changed, 112 insertions(+), 112 deletions(-) diff --git a/build.gradle b/build.gradle index 1f05d8679..e26ded0ed 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { lintAbortOnError = false // QuickBlox SDK version - qbSdkVersion = '2.6.1' + qbSdkVersion = '3.0' // Dependency versions playServicesVersion = '8.4.0' 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..9f7bfbb1a 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 @@ -18,7 +18,7 @@ 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; @@ -75,12 +75,12 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener private ConnectionListener chatConnectionListener; private Chat chat; - private QBDialog qbDialog; + private QBChatDialog qbDialog; private ArrayList chatMessageIds; private ArrayList unShownMessages; private int skipPagination = 0; - 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, ChatActivity.class); intent.putExtra(ChatActivity.EXTRA_DIALOG, dialog); activity.startActivityForResult(intent, code); @@ -91,7 +91,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); - qbDialog = (QBDialog) getIntent().getSerializableExtra(EXTRA_DIALOG); + qbDialog = (QBChatDialog) getIntent().getSerializableExtra(EXTRA_DIALOG); chatMessageIds = new ArrayList<>(); initChatConnectionListener(); @@ -110,7 +110,7 @@ public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistent protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (qbDialog == null) { - qbDialog = (QBDialog) savedInstanceState.getSerializable(EXTRA_DIALOG); + qbDialog = (QBChatDialog) savedInstanceState.getSerializable(EXTRA_DIALOG); } } @@ -197,9 +197,9 @@ private void sendReadMessageId() { private void leaveGroupChat() { ((GroupChatImpl) chat).leaveChatRoom(); ProgressDialogFragment.show(getSupportFragmentManager()); - ChatHelper.getInstance().leaveDialog(qbDialog, new QBEntityCallback() { + ChatHelper.getInstance().leaveDialog(qbDialog, new QBEntityCallback() { @Override - public void onSuccess(QBDialog qbDialog, Bundle bundle) { + public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { ProgressDialogFragment.hide(getSupportFragmentManager()); finish(); } @@ -406,9 +406,9 @@ private void releaseChat() { private void updateDialog(final ArrayList selectedUsers) { ChatHelper.getInstance().updateDialogUsers(qbDialog, selectedUsers, - new QBEntityCallback() { + new QBEntityCallback() { @Override - public void onSuccess(QBDialog dialog, Bundle args) { + public void onSuccess(QBChatDialog dialog, Bundle args) { qbDialog = dialog; loadDialogUsers(); } 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..43f1b7117 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 @@ -32,7 +32,7 @@ import com.quickblox.chat.listeners.QBMessageListener; import com.quickblox.chat.listeners.QBPrivateChatManagerListener; 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; @@ -329,7 +329,7 @@ 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); } else { @@ -340,7 +340,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; @@ -398,9 +398,9 @@ private void unregisterQbChatListeners() { 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); ProgressDialogFragment.hide(getSupportFragmentManager()); @@ -434,9 +434,9 @@ private void loadDialogsFromQb(final boolean silentUpdate, final boolean clearDi 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) { progressBar.setVisibility(View.GONE); setOnRefreshListener.setRefreshing(false); @@ -494,7 +494,7 @@ public void onDestroyActionMode(ActionMode mode) { } private void deleteSelectedDialogs() { - final Collection selectedDialogs = dialogsAdapter.getSelectedItems(); + final Collection selectedDialogs = dialogsAdapter.getSelectedItems(); ChatHelper.getInstance().deleteDialogs(selectedDialogs, new QBEntityCallback() { @Override public void onSuccess(Void aVoid, Bundle bundle) { 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/DialogsAdapter.java b/sample-chat/src/main/java/com/quickblox/sample/chat/ui/adapter/DialogsAdapter.java index ed2bb5532..afb327374 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,7 +7,7 @@ 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.qb.QbDialogUtils; @@ -17,9 +17,9 @@ import java.util.List; -public class DialogsAdapter extends BaseSelectableListAdapter { +public class DialogsAdapter extends BaseSelectableListAdapter { - public DialogsAdapter(Context context, List dialogs) { + public DialogsAdapter(Context context, List dialogs) { super(context, dialogs); } @@ -41,7 +41,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); @@ -71,7 +71,7 @@ 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; 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..c53793cba 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 @@ -8,7 +8,7 @@ import com.quickblox.chat.QBChatService; 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.content.QBContent; import com.quickblox.content.model.QBFile; @@ -83,7 +83,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()); @@ -122,11 +122,11 @@ public boolean logout() { } public void createDialogWithSelectedUsers(final List users, - final QBEntityCallback callback) { + final QBEntityCallback callback) { QBChatService.getInstance().getGroupChatManager().createDialog(QbDialogUtils.createDialog(users), - new QbEntityCallbackWrapper(callback) { + new QbEntityCallbackWrapper(callback) { @Override - public void onSuccess(QBDialog dialog, Bundle args) { + public void onSuccess(QBChatDialog dialog, Bundle args) { QbUsersHolder.getInstance().putUsers(users); super.onSuccess(dialog, args); } @@ -134,8 +134,8 @@ public void onSuccess(QBDialog dialog, Bundle args) { ); } - public void deleteDialogs(Collection dialogs, QBEntityCallback callback) { - for (QBDialog dialog : dialogs) { + public void deleteDialogs(Collection dialogs, QBEntityCallback callback) { + for (QBChatDialog dialog : dialogs) { deleteDialog(dialog, new QBEntityCallback() { @Override public void onSuccess(Void aVoid, Bundle bundle) { @@ -150,7 +150,7 @@ public void onError(QBResponseException e) { callback.onSuccess(null, null); } - public void deleteDialog(QBDialog qbDialog, QBEntityCallback callback) { + public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) { if (qbDialog.getType() == QBDialogType.GROUP) { QBChatService.getInstance().getGroupChatManager().deleteDialog(qbDialog.getDialogId(), true, new QbEntityCallbackWrapper(callback)); @@ -163,22 +163,22 @@ public void deleteDialog(QBDialog qbDialog, QBEntityCallback callback) { } } - public void leaveDialog(QBDialog qbDialog, QBEntityCallback callback) { + public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder(); qbRequestBuilder.pullAll("occupants_ids", SharedPreferencesUtil.getQbUser().getId()); QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, - new QbEntityCallbackWrapper(callback) { + new QbEntityCallbackWrapper(callback) { @Override - public void onSuccess(QBDialog qbDialog, Bundle bundle) { + public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { super.onSuccess(qbDialog, bundle); } }); } - 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); @@ -197,9 +197,9 @@ public void updateDialogUsers(QBDialog qbDialog, qbDialog.setName(QbDialogUtils.createChatNameFromUserList(newQbDialogUsersList)); QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, - new QbEntityCallbackWrapper(callback) { + 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,7 +207,7 @@ 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); @@ -225,22 +225,22 @@ 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) { + 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) { + for (QBChatDialog dialog : dialogs) { dialog.setId(dialog.getDialogId().hashCode()); } getUsersFromDialogs(dialogs, callback); @@ -250,7 +250,7 @@ public void onSuccess(ArrayList dialogs, Bundle args) { }); } - public void getUsersFromDialog(QBDialog dialog, + public void getUsersFromDialog(QBChatDialog dialog, final QBEntityCallback> callback) { List userIds = dialog.getOccupants(); @@ -267,7 +267,7 @@ 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) { @@ -283,7 +283,7 @@ 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) { @@ -292,20 +292,20 @@ public void onSuccess(QBFile qbFile, Bundle bundle) { attachment.setUrl(qbFile.getPublicUrl()); onSuccessInMainThread(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); @@ -322,7 +322,7 @@ 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) { 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 index 4c747e4ce..fb8747049 100644 --- 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 @@ -8,7 +8,7 @@ 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.chat.model.QBChatDialog; import com.quickblox.core.QBEntityCallback; import com.quickblox.core.exception.QBResponseException; @@ -32,7 +32,7 @@ protected void initManagerIfNeed() { } } - public void joinGroupChat(QBDialog dialog, QBEntityCallback callback) { + public void joinGroupChat(QBChatDialog dialog, QBEntityCallback callback) { initManagerIfNeed(); if (qbChat == null) { qbChat = qbGroupChatManager.createGroupChat(dialog.getRoomJid()); 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..71cf4afbf 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,6 +1,6 @@ package com.quickblox.sample.chat.utils.qb; -import com.quickblox.chat.model.QBDialog; +import com.quickblox.chat.model.QBChatDialog; import java.util.ArrayList; import java.util.Collection; @@ -9,7 +9,7 @@ public class QbDialogHolder { private static QbDialogHolder instance; - private List dialogList; + private List dialogList; public static synchronized QbDialogHolder getInstance() { if (instance == null) { @@ -22,7 +22,7 @@ private QbDialogHolder() { dialogList = new ArrayList<>(); } - public List getDialogList() { + public List getDialogList() { return dialogList; } @@ -30,20 +30,20 @@ public void clear() { dialogList.clear(); } - public void addDialogToList(QBDialog dialog) { + public void addDialogToList(QBChatDialog dialog) { if (!dialogList.contains(dialog)) { dialogList.add(dialog); } } - public void addDialogs(List dialogs) { - for (QBDialog dialog : dialogs) { + public void addDialogs(List dialogs) { + for (QBChatDialog dialog : dialogs) { addDialogToList(dialog); } } - public void deleteDialogs(Collection dialogs) { - for (QBDialog dialog : dialogs) { + public void deleteDialogs(Collection dialogs) { + for (QBChatDialog dialog : dialogs) { dialogList.remove(dialog); } } 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..231539c67 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,7 +3,7 @@ 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.QBDialogType; import com.quickblox.sample.chat.utils.chat.ChatHelper; import com.quickblox.users.model.QBUser; @@ -15,11 +15,11 @@ 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(); + QBChatDialog dialogToCreate = new QBChatDialog(); dialogToCreate.setName(QbDialogUtils.createChatNameFromUserList(users)); if (users.size() == 1) { dialogToCreate.setType(QBDialogType.PRIVATE); @@ -30,7 +30,7 @@ public static QBDialog createDialog(List users) { return dialogToCreate; } - public static List getAddedUsers(QBDialog dialog, List currentUsers) { + public static List getAddedUsers(QBChatDialog dialog, List currentUsers) { return getAddedUsers(getQbUsersFromQbDialog(dialog), currentUsers); } @@ -55,7 +55,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 +80,7 @@ public static List getRemovedUsers(List previousUsers, List users) { } } - public static Integer getOpponentIdForPrivateDialog(QBDialog dialog) { + public static Integer getOpponentIdForPrivateDialog(QBChatDialog dialog) { Integer opponentId = -1; QBUser qbUser = ChatHelper.getCurrentUser(); if (qbUser == null) { @@ -138,7 +138,7 @@ public static String createChatNameFromUserList(List users) { return chatName; } - public static String getDialogName(QBDialog dialog) { + public static String getDialogName(QBChatDialog dialog) { if (dialog.getType().equals(QBDialogType.GROUP)) { return dialog.getName(); } else { @@ -153,7 +153,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); 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/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/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..0044ef812 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 @@ -97,7 +97,7 @@ private void createNewMovie() { QBCustomObject qbCustomObject = QBCustomObjectsUtils.createCustomObject(title, description, year, rating); - QBCustomObjects.createObject(qbCustomObject, new QBEntityCallback() { + QBCustomObjects.createObject(qbCustomObject).performAsync(new QBEntityCallback() { @Override public void onSuccess(QBCustomObject qbCustomObject, Bundle bundle) { progressDialog.dismiss(); 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..6d92c3460 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 @@ -109,7 +109,7 @@ private void getMovieList(boolean progress) { } builder.setLimit(Consts.LIMIT_RECORDS); builder.sortDesc(createDateField); - QBCustomObjects.getObjects(Consts.CLASS_NAME, builder, new QBEntityCallback>() { + QBCustomObjects.getObjects(Consts.CLASS_NAME, builder).performAsync(new QBEntityCallback>() { @Override public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) { setOnRefreshListener.setEnabled(true); 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..0ff9efa5c 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 @@ -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-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/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/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); } } From f6eaaa2286b5973f7b414f305e06e85bb696716c Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 20 Sep 2016 11:54:01 +0300 Subject: [PATCH 07/55] - adapted code of ChatHelper.java to new version QB SDK (3.0) --- .../sample/chat/utils/chat/ChatHelper.java | 97 ++++++++++++++++--- 1 file changed, 82 insertions(+), 15 deletions(-) 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 c53793cba..dfeada66b 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,12 @@ 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.QBChatDialog; import com.quickblox.chat.model.QBDialogType; +import com.quickblox.chat.utils.DialogUtils; import com.quickblox.content.QBContent; import com.quickblox.content.model.QBFile; import com.quickblox.core.LogLevel; @@ -123,15 +125,25 @@ public boolean logout() { public void createDialogWithSelectedUsers(final List users, final QBEntityCallback callback) { - QBChatService.getInstance().getGroupChatManager().createDialog(QbDialogUtils.createDialog(users), + + QBRestChatService.createChatDialog(QbDialogUtils.createDialog(users)).performAsync( new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { QbUsersHolder.getInstance().putUsers(users); super.onSuccess(dialog, args); } - } - ); + }); + +// QBChatService.getInstance().getGroupChatManager().createDialog(QbDialogUtils.createDialog(users), +// new QbEntityCallbackWrapper(callback) { +// @Override +// public void onSuccess(QBChatDialog dialog, Bundle args) { +// QbUsersHolder.getInstance().putUsers(users); +// super.onSuccess(dialog, args); +// } +// } +// ); } public void deleteDialogs(Collection dialogs, QBEntityCallback callback) { @@ -151,23 +163,37 @@ public void onError(QBResponseException e) { } public void deleteDialog(QBChatDialog 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) { + if (qbDialog.getType() == QBDialogType.PUBLIC_GROUP){ Toaster.shortToast(R.string.public_group_chat_cannot_be_deleted); + } else { + QBRestChatService.deleteDialog(qbDialog.getDialogId(), true) + .performAsync(new QbEntityCallbackWrapper(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 leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder(); qbRequestBuilder.pullAll("occupants_ids", SharedPreferencesUtil.getQbUser().getId()); - QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, +// QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, +// new QbEntityCallbackWrapper(callback) { +// @Override +// public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { +// super.onSuccess(qbDialog, bundle); +// } +// }); + + QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { @@ -196,7 +222,17 @@ public void updateDialogUsers(QBChatDialog qbDialog, } qbDialog.setName(QbDialogUtils.createChatNameFromUserList(newQbDialogUsersList)); - QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, +// QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, +// new QbEntityCallbackWrapper(callback) { +// @Override +// public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { +// QbUsersHolder.getInstance().putUsers(newQbDialogUsersList); +// QbDialogUtils.logDialogUsers(qbDialog); +// super.onSuccess(qbDialog, bundle); +// } +// }); + + QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { @@ -214,7 +250,17 @@ public void loadChatHistory(QBChatDialog dialog, int skipPagination, customObjectRequestBuilder.setLimit(CHAT_HISTORY_ITEMS_PER_PAGE); customObjectRequestBuilder.sortDesc(CHAT_HISTORY_ITEMS_SORT_FIELD); - QBChatService.getDialogMessages(dialog, customObjectRequestBuilder, +// QBChatService.getDialogMessages(dialog, customObjectRequestBuilder, +// new QbEntityCallbackWrapper>(callback) { +// @Override +// public void onSuccess(ArrayList qbChatMessages, Bundle bundle) { +// getUsersFromMessages(qbChatMessages, callback); +//// Not calling super.onSuccess() because +//// we're want to load chat users before triggering the callback +// } +// }); +// + QBRestChatService.getDialogMessages(dialog, customObjectRequestBuilder).performAsync( new QbEntityCallbackWrapper>(callback) { @Override public void onSuccess(ArrayList qbChatMessages, Bundle bundle) { @@ -228,7 +274,7 @@ public void onSuccess(ArrayList qbChatMessages, Bundle bundle) { public void getDialogs(QBRequestGetBuilder customObjectRequestBuilder, final QBEntityCallback> callback) { customObjectRequestBuilder.setLimit(DIALOG_ITEMS_PER_PAGE); - QBChatService.getChatDialogs(null, customObjectRequestBuilder, + QBRestChatService.getChatDialogs(null, customObjectRequestBuilder).performAsync( new QbEntityCallbackWrapper>(callback) { @Override public void onSuccess(ArrayList dialogs, Bundle args) { @@ -248,6 +294,27 @@ public void onSuccess(ArrayList dialogs, Bundle args) { // we want to load chat users before triggering callback } }); + +// QBChatService.getChatDialogs(null, customObjectRequestBuilder, +// new QbEntityCallbackWrapper>(callback) { +// @Override +// public void onSuccess(ArrayList dialogs, Bundle args) { +// Iterator dialogIterator = dialogs.iterator(); +// while (dialogIterator.hasNext()) { +// QBChatDialog dialog = dialogIterator.next(); +// if (dialog.getType() == QBDialogType.PUBLIC_GROUP) { +// dialogIterator.remove(); +// } +// } +// +// for (QBChatDialog dialog : dialogs) { +// dialog.setId(dialog.getDialogId().hashCode()); +// } +// getUsersFromDialogs(dialogs, callback); +// // Not calling super.onSuccess() because +// // we want to load chat users before triggering callback +// } +// }); } public void getUsersFromDialog(QBChatDialog dialog, From f77f3a782d34041200c92cf37f672f432d926c41 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 20 Sep 2016 13:07:57 +0300 Subject: [PATCH 08/55] - cleanup gradle settings --- settings.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/settings.gradle b/settings.gradle index d08cba23f..edba2b308 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,6 +7,3 @@ include 'sample-pushnotifications' include 'sample-users' include 'sample-videochat-webrtc' include 'snippets' - -apply from: "sdk-settings.gradle" - From c8cd6ff71152039dfb11c2d6bca4f40cc0e383b7 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 20 Sep 2016 19:25:43 +0300 Subject: [PATCH 09/55] - rewritted code for REST request for new SDK logic --- .../chat/ui/activity/DialogsActivity.java | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) 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 43f1b7117..7147f3384 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 @@ -28,6 +28,7 @@ import com.quickblox.chat.QBPrivateChat; import com.quickblox.chat.QBPrivateChatManager; import com.quickblox.chat.exception.QBChatException; +import com.quickblox.chat.listeners.QBChatDialogMessageListener; import com.quickblox.chat.listeners.QBGroupChatManagerListener; import com.quickblox.chat.listeners.QBMessageListener; import com.quickblox.chat.listeners.QBPrivateChatManagerListener; @@ -147,9 +148,9 @@ protected void onPause() { protected void onDestroy() { super.onDestroy(); - if (isAppSessionActive) { - unregisterQbChatListeners(); - } +// if (isAppSessionActive) { +// unregisterQbChatListeners(); +// } } @Override @@ -185,7 +186,7 @@ public void onSessionCreated(boolean success) { setActionBarTitle(getString(R.string.dialogs_logged_in_as, currentUser.getFullName())); } - registerQbChatListeners(); +// registerQbChatListeners(); if (QbDialogHolder.getInstance().getDialogList().size() > 0) { loadDialogsFromQb(true, true); } else { @@ -372,29 +373,43 @@ public void processError(QBPrivateChat privateChat, QBChatException error, QBCha } }; - private void registerQbChatListeners() { - QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); - QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); - if (privateChatManager != null) { - privateChatManager.addPrivateChatManagerListener(privateChatManagerListener); - } - if (groupChatManager != null) { - groupChatManager.addGroupChatManagerListener(groupChatManagerListener); - } - } + QBChatDialogMessageListener messageListener = new QBChatDialogMessageListener() { + @Override + public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { - private void unregisterQbChatListeners() { - QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); - QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); - if (privateChatManager != null) { - privateChatManager.removePrivateChatManagerListener(privateChatManagerListener); } - if (groupChatManager != null) { - groupChatManager.removeGroupChatManagerListener(groupChatManagerListener); + @Override + public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { + } - } + }; + + +// private void registerQbChatListeners() { +// QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); +// QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); +// if (privateChatManager != null) { +// privateChatManager.addPrivateChatManagerListener(privateChatManagerListener); +// } +// +// if (groupChatManager != null) { +// groupChatManager.addGroupChatManagerListener(groupChatManagerListener); +// } +// } +// +// private void unregisterQbChatListeners() { +// QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); +// QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); +// if (privateChatManager != null) { +// privateChatManager.removePrivateChatManagerListener(privateChatManagerListener); +// } +// +// if (groupChatManager != null) { +// groupChatManager.removeGroupChatManagerListener(groupChatManagerListener); +// } +// } private void createDialog(final ArrayList selectedUsers) { ChatHelper.getInstance().createDialogWithSelectedUsers(selectedUsers, From 6b715f5f04ef5d1c3b1fc6e809d8ecaed5d6b02d Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 22 Sep 2016 19:31:14 +0300 Subject: [PATCH 10/55] - implement new chat logic (by sdk 3.0) (need fix some bags) --- sample-chat/build.gradle | 2 +- .../sample/chat/ui/activity/ChatActivity.java | 116 +++++++++-------- .../chat/ui/activity/DialogsActivity.java | 119 +++++++----------- .../sample/chat/utils/CollectionUtils.java | 19 +++ .../sample/chat/utils/chat/BaseChatImpl.java | 65 ---------- .../sample/chat/utils/chat/Chat.java | 13 -- .../sample/chat/utils/chat/ChatHelper.java | 105 ++++------------ .../sample/chat/utils/chat/GroupChatImpl.java | 99 --------------- .../chat/utils/chat/PrivateChatImpl.java | 67 ---------- .../utils/chat/QBChatMessageListener.java | 10 -- .../sample/chat/utils/qb/QbDialogHolder.java | 27 ++-- 11 files changed, 171 insertions(+), 471 deletions(-) create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/BaseChatImpl.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/Chat.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/GroupChatImpl.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/PrivateChatImpl.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/QBChatMessageListener.java diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 7116c3642..9c266720f 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion versionCode 201 - versionName "2.0.3" + versionName "3.0" } productFlavors { 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 9f7bfbb1a..5ab7dd37a 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,7 +15,9 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; -import com.quickblox.chat.QBChat; +import com.quickblox.chat.QBChatService; +import com.quickblox.chat.exception.QBChatException; +import com.quickblox.chat.listeners.QBChatDialogMessageListener; import com.quickblox.chat.model.QBAttachment; import com.quickblox.chat.model.QBChatMessage; import com.quickblox.chat.model.QBChatDialog; @@ -26,12 +28,9 @@ 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.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; @@ -43,6 +42,7 @@ 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; @@ -57,7 +57,6 @@ 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"; @@ -74,15 +73,14 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener private AttachmentPreviewAdapter attachmentPreviewAdapter; private ConnectionListener chatConnectionListener; - private Chat chat; - private QBChatDialog qbDialog; + private QBChatDialog qbChatDialog; private ArrayList chatMessageIds; private ArrayList unShownMessages; private int skipPagination = 0; - public static void startForResult(Activity activity, int code, QBChatDialog 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,7 +89,9 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); - qbDialog = (QBChatDialog) getIntent().getSerializableExtra(EXTRA_DIALOG); + qbChatDialog = QbDialogHolder.getInstance().getChatDialogById( + getIntent().getStringExtra(EXTRA_DIALOG_ID)); + chatMessageIds = new ArrayList<>(); initChatConnectionListener(); @@ -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 = (QBChatDialog) savedInstanceState.getSerializable(EXTRA_DIALOG); + if (qbChatDialog == null) { + qbChatDialog = QbDialogHolder.getInstance().getChatDialogById(savedInstanceState.getString(EXTRA_DIALOG_ID)); } } @@ -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: @@ -190,14 +190,14 @@ public boolean onOptionsItemSelected(MenuItem item) { private void sendReadMessageId() { 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(); + leaveGroupChatRoom(); ProgressDialogFragment.show(getSupportFragmentManager()); - ChatHelper.getInstance().leaveDialog(qbDialog, new QBEntityCallback() { + ChatHelper.getInstance().leaveDialog(qbChatDialog, new QBEntityCallback() { @Override public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { ProgressDialogFragment.hide(getSupportFragmentManager()); @@ -331,9 +331,10 @@ private void sendChatMessage(String text, QBAttachment attachment) { chatMessage.setDateSent(System.currentTimeMillis() / 1000); try { - chat.sendMessage(chatMessage); + qbChatDialog.sendMessage(chatMessage); - if (qbDialog.getType() == QBDialogType.PRIVATE) { + if (qbChatDialog.getType() == QBDialogType.PRIVATE) { + Log.d(TAG, "showMessage from method sendChatMessage"); showMessage(chatMessage); } @@ -342,27 +343,31 @@ 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"); + } catch (IllegalStateException e) { + Log.w(TAG, e); + Toaster.shortToast("You're still joining a group chat, please wait a bit"); } } private void initChat() { - switch (qbDialog.getType()) { + qbChatDialog.initForChat(QBChatService.getInstance()); + qbChatDialog.addMessageListener(chatMessageListener); + + 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 +375,10 @@ private void initChat() { private void joinGroupChat() { progressBar.setVisibility(View.VISIBLE); + DiscussionHistory history = new DiscussionHistory(); + history.setMaxStanzas(0); - ((GroupChatImpl) chat).joinGroupChat(qbDialog, new QBEntityCallback() { + qbChatDialog.join(history, new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle b) { if (snackbar != null) { @@ -389,27 +396,30 @@ public void onError(QBResponseException e) { } private void leaveGroupChatRoom() { - if (chat != null) { - ((GroupChatImpl) chat).leaveChatRoom(); + if (qbChatDialog != null) { + try { + qbChatDialog.leave(); + } catch (SmackException.NotConnectedException | XMPPException e) { + e.printStackTrace(); + } } } private void releaseChat() { - try { - if (chat != null) { - chat.release(); + if (qbChatDialog != null) { + qbChatDialog.removeMessageListrener(chatMessageListener); + if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType())){ + leaveGroupChatRoom(); } - } catch (XMPPException e) { - Log.e(TAG, "Failed to release chat", e); } } private void updateDialog(final ArrayList selectedUsers) { - ChatHelper.getInstance().updateDialogUsers(qbDialog, selectedUsers, + ChatHelper.getInstance().updateDialogUsers(qbChatDialog, selectedUsers, new QBEntityCallback() { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { - qbDialog = dialog; + qbChatDialog = dialog; loadDialogUsers(); } @@ -428,7 +438,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 +459,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,7 +469,7 @@ 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, @@ -526,7 +536,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); @@ -553,7 +563,7 @@ public void connectionClosedOnError(final Exception e) { super.connectionClosedOnError(e); // Leave active room if we're in Group Chat - if (qbDialog.getType() == QBDialogType.GROUP) { + if (qbChatDialog.getType() == QBDialogType.GROUP) { runOnUiThread(new Runnable() { @Override public void run() { @@ -568,7 +578,7 @@ public void reconnectionSuccessful() { super.reconnectionSuccessful(); skipPagination = 0; chatAdapter = null; - switch (qbDialog.getType()) { + switch (qbChatDialog.getType()) { case PRIVATE: runOnUiThread(new Runnable() { @Override @@ -591,11 +601,17 @@ public void run() { }; } - private QBChatMessageListener chatMessageListener = new QBChatMessageListener() { + private QBChatDialogMessageListener chatMessageListener = new QBChatDialogMessageListener() { @Override - public void onQBChatMessageReceived(QBChat chat, QBChatMessage message) { - chatMessageIds.add(message.getId()); - showMessage(message); + public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { + chatMessageIds.add(qbChatMessage.getId()); + Log.d(TAG, "showMessage from listener"); + showMessage(qbChatMessage); + } + + @Override + public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { + } }; } 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 7147f3384..dee82118a 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,15 +23,10 @@ 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.QBRestChatService; import com.quickblox.chat.exception.QBChatException; import com.quickblox.chat.listeners.QBChatDialogMessageListener; -import com.quickblox.chat.listeners.QBGroupChatManagerListener; -import com.quickblox.chat.listeners.QBMessageListener; -import com.quickblox.chat.listeners.QBPrivateChatManagerListener; import com.quickblox.chat.model.QBChatMessage; import com.quickblox.chat.model.QBChatDialog; import com.quickblox.core.QBEntityCallback; @@ -40,6 +35,7 @@ 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.CollectionUtils; import com.quickblox.sample.chat.utils.Consts; import com.quickblox.sample.chat.utils.SharedPreferencesUtil; import com.quickblox.sample.chat.utils.chat.ChatHelper; @@ -74,14 +70,13 @@ public class DialogsActivity extends BaseActivity { private BroadcastReceiver pushBroadcastReceiver; private GooglePlayServicesHelper googlePlayServicesHelper; private DialogsAdapter dialogsAdapter; + private QBChatDialogMessageListener chatServiceMessagesListener; 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 @@ -96,21 +91,29 @@ protected void onCreate(Bundle savedInstanceState) { pushBroadcastReceiver = new PushBroadcastReceiver(); - privateChatManagerListener = new QBPrivateChatManagerListener() { + chatServiceMessagesListener = new QBChatDialogMessageListener(){ + @Override - public void chatCreated(QBPrivateChat qbPrivateChat, boolean createdLocally) { - if (!createdLocally) { - qbPrivateChat.addMessageListener(privateChatMessageListener); + public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { + Log.d(TAG, "new incoming message dialog id = "+ dialogId + " message id = " + qbChatMessage.getId()); + if (QbDialogHolder.getInstance().getChatDialogById(dialogId) == null){ + Log.d(TAG, "dialogsAdapter not have this dialog"); + requestBuilder.setSkip(skipRecords = 0); + if (isActivityForeground) { + loadDialogsFromQbInUiThread(true); + } + } else { + Log.d(TAG, "dialogsAdapter not have this dialog"); + dialogsAdapter.notifyDataSetChanged(); } } - }; - groupChatManagerListener = new QBGroupChatManagerListener() { + @Override - public void chatCreated(QBGroupChat qbGroupChat) { - requestBuilder.setSkip(skipRecords = 0); - loadDialogsFromQbInUiThread(true); + public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { + } }; +// chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { @Override @@ -148,9 +151,9 @@ protected void onPause() { protected void onDestroy() { super.onDestroy(); -// if (isAppSessionActive) { -// unregisterQbChatListeners(); -// } + if (isAppSessionActive) { + unregisterQbChatListeners(); + } } @Override @@ -186,8 +189,8 @@ public void onSessionCreated(boolean success) { setActionBarTitle(getString(R.string.dialogs_logged_in_as, currentUser.getFullName())); } -// registerQbChatListeners(); - if (QbDialogHolder.getInstance().getDialogList().size() > 0) { + registerQbChatListeners(); + if (QbDialogHolder.getInstance().getDialogsMap().size() > 0) { loadDialogsFromQb(true, true); } else { loadDialogsFromQb(); @@ -280,7 +283,7 @@ public void onClick(View v) { private void markMessagesRead(StringifyArrayList messagesIds, String dialogId) { if (messagesIds.size() > 0) { - QBChatService.markMessagesAsRead(dialogId, messagesIds, new QBEntityCallback() { + QBRestChatService.markMessagesAsRead(dialogId, messagesIds).performAsync(new QBEntityCallback() { @Override public void onSuccess(Void aVoid, Bundle bundle) { isProcessingResultInProgress = false; @@ -317,7 +320,8 @@ 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, + CollectionUtils.convertMapToList(QbDialogHolder.getInstance().getDialogsMap())); TextView listHeader = (TextView) LayoutInflater.from(this) .inflate(R.layout.include_list_hint_header, dialogsListView, false); @@ -332,7 +336,7 @@ private void initUi() { public void onItemClick(AdapterView parent, View view, int position, long id) { QBChatDialog selectedDialog = (QBChatDialog) parent.getItemAtPosition(position); if (currentActionMode == null) { - ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, selectedDialog); + ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, selectedDialog.getDialogId()); } else { dialogsAdapter.toggleSelection(selectedDialog); } @@ -358,58 +362,19 @@ 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); - } + private void registerQbChatListeners() { + QBIncomingMessagesManager incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager(); + if (incomingMessagesManager != null) { + incomingMessagesManager.addDialogMessageListener(chatServiceMessagesListener); } + } - @Override - public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage) { - - } - }; - - - QBChatDialogMessageListener messageListener = new QBChatDialogMessageListener() { - @Override - public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { - - } - - @Override - public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { - + private void unregisterQbChatListeners() { + QBIncomingMessagesManager incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager(); + if (incomingMessagesManager != null) { + incomingMessagesManager.removeDialogMessageListrener(chatServiceMessagesListener); } - }; - - -// private void registerQbChatListeners() { -// QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); -// QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); -// if (privateChatManager != null) { -// privateChatManager.addPrivateChatManagerListener(privateChatManagerListener); -// } -// -// if (groupChatManager != null) { -// groupChatManager.addGroupChatManagerListener(groupChatManagerListener); -// } -// } -// -// private void unregisterQbChatListeners() { -// QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); -// QBGroupChatManager groupChatManager = QBChatService.getInstance().getGroupChatManager(); -// if (privateChatManager != null) { -// privateChatManager.removePrivateChatManagerListener(privateChatManagerListener); -// } -// -// if (groupChatManager != null) { -// groupChatManager.removeGroupChatManagerListener(groupChatManagerListener); -// } -// } + } private void createDialog(final ArrayList selectedUsers) { ChatHelper.getInstance().createDialogWithSelectedUsers(selectedUsers, @@ -417,7 +382,7 @@ private void createDialog(final ArrayList selectedUsers) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; - ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, dialog); + ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } @@ -459,7 +424,7 @@ public void onSuccess(ArrayList dialogs, Bundle bundle) { QbDialogHolder.getInstance().clear(); } QbDialogHolder.getInstance().addDialogs(dialogs); - dialogsAdapter.notifyDataSetChanged(); + dialogsAdapter.addList(CollectionUtils.convertMapToList(QbDialogHolder.getInstance().getDialogsMap())); } @Override diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java new file mode 100644 index 000000000..61fdf6ae6 --- /dev/null +++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java @@ -0,0 +1,19 @@ +package com.quickblox.sample.chat.utils; + +import com.quickblox.chat.model.QBChatDialog; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class CollectionUtils { + + public static List convertMapToList(Map incomeMap){ + List list = new ArrayList<>(); + for (String key : incomeMap.keySet()){ + list.add(incomeMap.get(key)); + } + + return list; + } +} 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 dfeada66b..4c70446ec 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 @@ -1,6 +1,8 @@ package com.quickblox.sample.chat.utils.chat; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import com.quickblox.auth.QBAuth; @@ -24,6 +26,7 @@ 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; @@ -56,6 +59,8 @@ public class ChatHelper { private QBChatService qbChatService; + public static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); + public static synchronized ChatHelper getInstance() { if (instance == null) { QBSettings.getInstance().setLogLevel(LogLevel.DEBUG); @@ -96,7 +101,12 @@ public void onSuccess(QBSession session, Bundle args) { private void loginToChat(final QBUser user, final QBEntityCallback callback) { if (qbChatService.isLoggedIn()) { - callback.onSuccess(null, null); + MAIN_HANDLER.post(new Runnable() { + @Override + public void run() { + callback.onSuccess(null, null); + } + }); return; } @@ -130,23 +140,14 @@ public void createDialogWithSelectedUsers(final List users, new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { + QbDialogHolder.getInstance().addDialogToMap(dialog); QbUsersHolder.getInstance().putUsers(users); super.onSuccess(dialog, args); } }); - -// QBChatService.getInstance().getGroupChatManager().createDialog(QbDialogUtils.createDialog(users), -// new QbEntityCallbackWrapper(callback) { -// @Override -// public void onSuccess(QBChatDialog dialog, Bundle args) { -// QbUsersHolder.getInstance().putUsers(users); -// super.onSuccess(dialog, args); -// } -// } -// ); } - public void deleteDialogs(Collection dialogs, QBEntityCallback callback) { + public void deleteDialogs(Collection dialogs, final QBEntityCallback callback) { for (QBChatDialog dialog : dialogs) { deleteDialog(dialog, new QBEntityCallback() { @Override @@ -159,7 +160,12 @@ public void onError(QBResponseException e) { }); } - callback.onSuccess(null, null); + MAIN_HANDLER.post(new Runnable() { + @Override + public void run() { + callback.onSuccess(null, null); + } + }); } public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) { @@ -169,30 +175,12 @@ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) QBRestChatService.deleteDialog(qbDialog.getDialogId(), true) .performAsync(new QbEntityCallbackWrapper(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 leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder(); qbRequestBuilder.pullAll("occupants_ids", SharedPreferencesUtil.getQbUser().getId()); -// QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, -// new QbEntityCallbackWrapper(callback) { -// @Override -// public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { -// super.onSuccess(qbDialog, bundle); -// } -// }); - QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { @Override @@ -222,16 +210,6 @@ public void updateDialogUsers(QBChatDialog qbDialog, } qbDialog.setName(QbDialogUtils.createChatNameFromUserList(newQbDialogUsersList)); -// QBChatService.getInstance().getGroupChatManager().updateDialog(qbDialog, qbRequestBuilder, -// new QbEntityCallbackWrapper(callback) { -// @Override -// public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { -// QbUsersHolder.getInstance().putUsers(newQbDialogUsersList); -// QbDialogUtils.logDialogUsers(qbDialog); -// super.onSuccess(qbDialog, bundle); -// } -// }); - QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { @Override @@ -250,16 +228,6 @@ public void loadChatHistory(QBChatDialog dialog, int skipPagination, customObjectRequestBuilder.setLimit(CHAT_HISTORY_ITEMS_PER_PAGE); customObjectRequestBuilder.sortDesc(CHAT_HISTORY_ITEMS_SORT_FIELD); -// QBChatService.getDialogMessages(dialog, customObjectRequestBuilder, -// new QbEntityCallbackWrapper>(callback) { -// @Override -// public void onSuccess(ArrayList qbChatMessages, Bundle bundle) { -// getUsersFromMessages(qbChatMessages, callback); -//// Not calling super.onSuccess() because -//// we're want to load chat users before triggering the callback -// } -// }); -// QBRestChatService.getDialogMessages(dialog, customObjectRequestBuilder).performAsync( new QbEntityCallbackWrapper>(callback) { @Override @@ -286,42 +254,18 @@ public void onSuccess(ArrayList dialogs, Bundle args) { } } - for (QBChatDialog dialog : dialogs) { - dialog.setId(dialog.getDialogId().hashCode()); - } getUsersFromDialogs(dialogs, callback); // Not calling super.onSuccess() because // we want to load chat users before triggering callback } }); - -// QBChatService.getChatDialogs(null, customObjectRequestBuilder, -// new QbEntityCallbackWrapper>(callback) { -// @Override -// public void onSuccess(ArrayList dialogs, Bundle args) { -// Iterator dialogIterator = dialogs.iterator(); -// while (dialogIterator.hasNext()) { -// QBChatDialog dialog = dialogIterator.next(); -// if (dialog.getType() == QBDialogType.PUBLIC_GROUP) { -// dialogIterator.remove(); -// } -// } -// -// for (QBChatDialog dialog : dialogs) { -// dialog.setId(dialog.getDialogId().hashCode()); -// } -// getUsersFromDialogs(dialogs, callback); -// // Not calling super.onSuccess() because -// // we want to load chat users before triggering 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)); } @@ -329,7 +273,12 @@ public void getUsersFromDialog(QBChatDialog dialog, // If we already have all users in memory // there is no need to make REST requests to QB if (userIds.size() == users.size()) { - callback.onSuccess(users, null); + MAIN_HANDLER.post(new Runnable() { + @Override + public void run() { + callback.onSuccess(users, null); + } + }); return; } @@ -339,7 +288,7 @@ public void getUsersFromDialog(QBChatDialog dialog, @Override public void onSuccess(ArrayList qbUsers, Bundle bundle) { QbUsersHolder.getInstance().putUsers(qbUsers); - super.onSuccess(qbUsers, bundle); + onSuccessInMainThread(qbUsers, bundle); } }); } 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 fb8747049..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.QBChatDialog; -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(QBChatDialog 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/QbDialogHolder.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java index 71cf4afbf..bda859f84 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 @@ -2,14 +2,15 @@ import com.quickblox.chat.model.QBChatDialog; -import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class QbDialogHolder { private static QbDialogHolder instance; - private List dialogList; + private Map dialogsMap; public static synchronized QbDialogHolder getInstance() { if (instance == null) { @@ -19,32 +20,36 @@ public static synchronized QbDialogHolder getInstance() { } private QbDialogHolder() { - dialogList = new ArrayList<>(); + dialogsMap = new HashMap<>(); } - public List getDialogList() { - return dialogList; + public Map getDialogsMap() { + return dialogsMap; + } + + public QBChatDialog getChatDialogById(String dialogId){ + return dialogsMap.get(dialogId); } public void clear() { - dialogList.clear(); + dialogsMap.clear(); } - public void addDialogToList(QBChatDialog dialog) { - if (!dialogList.contains(dialog)) { - dialogList.add(dialog); + public void addDialogToMap(QBChatDialog dialog) { + if (dialog != null) { + dialogsMap.put(dialog.getDialogId(), dialog); } } public void addDialogs(List dialogs) { for (QBChatDialog dialog : dialogs) { - addDialogToList(dialog); + addDialogToMap(dialog); } } public void deleteDialogs(Collection dialogs) { for (QBChatDialog dialog : dialogs) { - dialogList.remove(dialog); + dialogsMap.remove(dialog.getDialogId()); } } } From 76981bcc36f1f41c992ccec428c9e2fbe7456f60 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 23 Sep 2016 19:12:09 +0300 Subject: [PATCH 11/55] begin make Rx --- sample-custom-objects/build.gradle | 1 + .../activities/MovieListActivity.java | 51 ++++++++++++++----- .../activities/SplashActivity.java | 31 ++++++++--- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle index 285bbf13e..689809ca6 100644 --- a/sample-custom-objects/build.gradle +++ b/sample-custom-objects/build.gradle @@ -43,6 +43,7 @@ android { dependencies { compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar" compile 'com.github.orangegangsters:swipy:1.2.2@aar' + compile "com.quickblox:quickblox-android-sdk-extensions:3.0" compile(project(":sample-core")) { transitive = true; } 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 6d92c3460..46b5a6db9 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 @@ -15,8 +15,10 @@ 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; @@ -26,6 +28,11 @@ import java.util.ArrayList; import java.util.Map; +import rx.Observable; +import rx.Observer; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + public class MovieListActivity extends BaseActivity implements AdapterView.OnItemClickListener { private static final String createDateField = "created_at"; @@ -109,9 +116,31 @@ private void getMovieList(boolean progress) { } builder.setLimit(Consts.LIMIT_RECORDS); builder.sortDesc(createDateField); - QBCustomObjects.getObjects(Consts.CLASS_NAME, builder).performAsync(new QBEntityCallback>() { + + Performer> performer = QBCustomObjects.getObjects(Consts.CLASS_NAME, builder); + Observable> observable = performer.convertTo(RxJavaPerformProcessor.INSTANCE); + observable.subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer>() { @Override - public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) { + public void onCompleted() { + } + + @Override + public void onError(Throwable e) { + setOnRefreshListener.setEnabled(false); + 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); + } + }); + progressDialog.dismiss(); + setOnRefreshListener.setRefreshing(false); + } + + @Override + public void onNext(ArrayList qbCustomObjects) { setOnRefreshListener.setEnabled(true); Map movieMap = DataHolder.getInstance().getMovieMap(); @@ -123,19 +152,17 @@ public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) setOnRefreshListener.setRefreshing(false); movieListAdapter.updateData(movieMap); } + }); + + QBCustomObjects.getObjects(Consts.CLASS_NAME, builder).performAsync(new QBEntityCallback>() { + @Override + public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) { + + } @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); - } - }); - progressDialog.dismiss(); - setOnRefreshListener.setRefreshing(false); + } }); } 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 0ff9efa5c..5c83a183a 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 @@ -5,13 +5,19 @@ 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.users.model.QBUser; +import rx.Observable; +import rx.Observer; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + public class SplashActivity extends CoreSplashActivity { @Override @@ -23,21 +29,32 @@ protected void onCreate(Bundle savedInstanceState) { private void createSession() { QBUser qbUser = new QBUser(Consts.USER_LOGIN, Consts.USER_PASSWORD); - QBAuth.createSession(qbUser).performAsync(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() { + public void onError(Throwable e) { + showSnackbarError(null, R.string.splash_create_session_error, (QBResponseException)e, new View.OnClickListener() { @Override public void onClick(View v) { createSession(); } }); } + + @Override + public void onNext(QBSession qbSession) { + // session created + proceedToTheNextActivity(); + } }); } @@ -51,4 +68,4 @@ protected void proceedToTheNextActivity() { MovieListActivity.start(this); finish(); } -} +} \ No newline at end of file From d64fb03799c04cf631351de4d172d5c63e6ff19f Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 26 Sep 2016 12:41:37 +0300 Subject: [PATCH 12/55] add Performer at AddNewMovieActivity --- .../activities/AddNewMovieActivity.java | 34 ++++++++++++++----- .../activities/MovieListActivity.java | 12 ------- 2 files changed, 25 insertions(+), 21 deletions(-) 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 0044ef812..611a05406 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 @@ -17,10 +17,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,6 +32,11 @@ 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 OBJ = "\uFFFC"; @@ -97,26 +103,36 @@ private void createNewMovie() { QBCustomObject qbCustomObject = QBCustomObjectsUtils.createCustomObject(title, description, year, rating); - QBCustomObjects.createObject(qbCustomObject).performAsync(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) { - progressDialog.dismiss(); - Toaster.shortToast(R.string.done); - DataHolder.getInstance().addMovieToMap(new Movie(qbCustomObject)); - finish(); + public void onCompleted() { } @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() { + showSnackbarError(rootLayout, R.string.splash_create_session_error, (QBResponseException)e, new View.OnClickListener() { @Override public void onClick(View v) { createNewMovie(); } }); } + + @Override + public void onNext(QBCustomObject qbCustomObject) { + progressDialog.dismiss(); + Toaster.shortToast(R.string.done); + DataHolder.getInstance().addMovieToMap(new Movie(qbCustomObject)); + finish(); + } }); } 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 46b5a6db9..ef4c405d8 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 @@ -153,17 +153,5 @@ public void onNext(ArrayList qbCustomObjects) { movieListAdapter.updateData(movieMap); } }); - - QBCustomObjects.getObjects(Consts.CLASS_NAME, builder).performAsync(new QBEntityCallback>() { - @Override - public void onSuccess(ArrayList qbCustomObjects, Bundle bundle) { - - } - - @Override - public void onError(QBResponseException e) { - - } - }); } } \ No newline at end of file From 7fc993961ebc3c1e687f642202745ecf3971a203 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 27 Sep 2016 11:25:19 +0300 Subject: [PATCH 13/55] add Observable.from in MovieListActivity --- sample-custom-objects/build.gradle | 2 +- .../activities/AddNewMovieActivity.java | 6 +- .../activities/MovieListActivity.java | 64 ++++++++++--------- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle index 689809ca6..ae4791263 100644 --- a/sample-custom-objects/build.gradle +++ b/sample-custom-objects/build.gradle @@ -41,7 +41,7 @@ android { } dependencies { - compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion@aar" + compile "com.quickblox:quickblox-android-sdk-customobjects:$rootProject.qbSdkVersion" compile 'com.github.orangegangsters:swipy:1.2.2@aar' compile "com.quickblox:quickblox-android-sdk-extensions:3.0" compile(project(":sample-core")) { 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 611a05406..60d70c0a2 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 @@ -112,6 +112,9 @@ private void createNewMovie() { .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer() { @Override public void onCompleted() { + progressDialog.dismiss(); + Toaster.shortToast(R.string.done); + finish(); } @Override @@ -128,10 +131,7 @@ public void onClick(View v) { @Override public void onNext(QBCustomObject qbCustomObject) { - progressDialog.dismiss(); - Toaster.shortToast(R.string.done); DataHolder.getInstance().addMovieToMap(new Movie(qbCustomObject)); - finish(); } }); } 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 ef4c405d8..2b8ce6e44 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 @@ -12,7 +12,6 @@ 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; @@ -21,9 +20,9 @@ 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 java.util.ArrayList; import java.util.Map; @@ -31,6 +30,7 @@ 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 { @@ -119,39 +119,43 @@ private void getMovieList(boolean progress) { Performer> performer = QBCustomObjects.getObjects(Consts.CLASS_NAME, builder); Observable> observable = performer.convertTo(RxJavaPerformProcessor.INSTANCE); - observable.subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer>() { - @Override - public void onCompleted() { - } + observable.flatMap(new Func1, Observable>() { @Override - public void onError(Throwable e) { - setOnRefreshListener.setEnabled(false); - View rootLayout = findViewById(R.id.swipy_refresh_layout); - showSnackbarError(rootLayout, R.string.splash_create_session_error, (QBResponseException)e, new View.OnClickListener() { + public Observable call(ArrayList qbCustomObjects) { + return Observable.from(qbCustomObjects); + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { @Override - public void onClick(View v) { - getMovieList(false); + public void onCompleted() { + Map movieMap = DataHolder.getInstance().getMovieMap(); + setOnRefreshListener.setEnabled(true); + progressDialog.dismiss(); + setOnRefreshListener.setRefreshing(false); + movieListAdapter.updateData(movieMap); } - }); - progressDialog.dismiss(); - setOnRefreshListener.setRefreshing(false); - } - - @Override - public void onNext(ArrayList qbCustomObjects) { - setOnRefreshListener.setEnabled(true); - Map movieMap = DataHolder.getInstance().getMovieMap(); - for (QBCustomObject customObject : qbCustomObjects) { - DataHolder.getInstance().addMovieToMap(new Movie(customObject)); - } + @Override + public void onError(Throwable e) { + setOnRefreshListener.setEnabled(false); + 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); + } + }); + progressDialog.dismiss(); + setOnRefreshListener.setRefreshing(false); + } - progressDialog.dismiss(); - setOnRefreshListener.setRefreshing(false); - movieListAdapter.updateData(movieMap); - } - }); + @Override + public void onNext(QBCustomObject customObject) { + DataHolder.getInstance().addMovieToMap(new Movie(customObject)); + } + }); } } \ No newline at end of file From 4dcdbf8b7ab4163cff1964d3f3f85898a354d8d1 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 27 Sep 2016 14:10:33 +0300 Subject: [PATCH 14/55] minor fix MovieListActivity --- sample-custom-objects/build.gradle | 2 +- .../activities/MovieListActivity.java | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle index ae4791263..9e9a8dcbe 100644 --- a/sample-custom-objects/build.gradle +++ b/sample-custom-objects/build.gradle @@ -42,8 +42,8 @@ android { dependencies { 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 "com.quickblox:quickblox-android-sdk-extensions:3.0" compile(project(":sample-core")) { transitive = true; } 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 2b8ce6e44..5deacbd4f 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 @@ -125,22 +125,19 @@ private void getMovieList(boolean progress) { public Observable call(ArrayList qbCustomObjects) { return Observable.from(qbCustomObjects); } - }) - .subscribeOn(Schedulers.io()) + }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer() { @Override public void onCompleted() { + setResultParams(true); Map movieMap = DataHolder.getInstance().getMovieMap(); - setOnRefreshListener.setEnabled(true); - progressDialog.dismiss(); - setOnRefreshListener.setRefreshing(false); movieListAdapter.updateData(movieMap); } @Override public void onError(Throwable e) { - setOnRefreshListener.setEnabled(false); + setResultParams(false); View rootLayout = findViewById(R.id.swipy_refresh_layout); showSnackbarError(rootLayout, R.string.splash_create_session_error, (QBResponseException) e, new View.OnClickListener() { @Override @@ -148,8 +145,6 @@ public void onClick(View v) { getMovieList(false); } }); - progressDialog.dismiss(); - setOnRefreshListener.setRefreshing(false); } @Override @@ -158,4 +153,10 @@ public void onNext(QBCustomObject customObject) { } }); } + + private void setResultParams(boolean enabled) { + setOnRefreshListener.setEnabled(enabled); + progressDialog.dismiss(); + setOnRefreshListener.setRefreshing(false); + } } \ No newline at end of file From 0c75dfa1fa0b335ef2b36abcdd61418db1f70574 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 27 Sep 2016 15:40:50 +0300 Subject: [PATCH 15/55] - added system notification for creating group dialogs; --- .../sample/chat/ui/activity/ChatActivity.java | 40 +++-- .../chat/ui/activity/DialogsActivity.java | 148 ++++++++++++++---- .../sample/chat/utils/chat/ChatHelper.java | 86 ++++++++-- .../sample/chat/utils/qb/QbDialogHolder.java | 14 ++ .../sample/chat/utils/qb/QbDialogUtils.java | 48 ++++++ 5 files changed, 270 insertions(+), 66 deletions(-) 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 5ab7dd37a..2400d27b2 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,7 +15,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; -import com.quickblox.chat.QBChatService; import com.quickblox.chat.exception.QBChatException; import com.quickblox.chat.listeners.QBChatDialogMessageListener; import com.quickblox.chat.model.QBAttachment; @@ -41,8 +40,6 @@ 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; @@ -77,6 +74,7 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener private ArrayList chatMessageIds; private ArrayList unShownMessages; private int skipPagination = 0; + private ChatMessageListener chatMessageListener; public static void startForResult(Activity activity, int code, String dialogId) { Intent intent = new Intent(activity, ChatActivity.class); @@ -91,8 +89,12 @@ public void onCreate(Bundle savedInstanceState) { qbChatDialog = QbDialogHolder.getInstance().getChatDialogById( getIntent().getStringExtra(EXTRA_DIALOG_ID)); + chatMessageListener = new ChatMessageListener(); + + qbChatDialog.addMessageListener(chatMessageListener); chatMessageIds = new ArrayList<>(); + initChatConnectionListener(); initViews(); @@ -195,7 +197,7 @@ private void sendReadMessageId() { } private void leaveGroupChat() { - leaveGroupChatRoom(); + leaveGroupDialog(); ProgressDialogFragment.show(getSupportFragmentManager()); ChatHelper.getInstance().leaveDialog(qbChatDialog, new QBEntityCallback() { @Override @@ -353,8 +355,7 @@ private void sendChatMessage(String text, QBAttachment attachment) { } private void initChat() { - qbChatDialog.initForChat(QBChatService.getInstance()); - qbChatDialog.addMessageListener(chatMessageListener); +// qbChatDialog.initForChat(QBChatService.getInstance()); switch (qbChatDialog.getType()) { case GROUP: @@ -375,10 +376,7 @@ private void initChat() { private void joinGroupChat() { progressBar.setVisibility(View.VISIBLE); - DiscussionHistory history = new DiscussionHistory(); - history.setMaxStanzas(0); - - qbChatDialog.join(history, new QBEntityCallback() { + ChatHelper.getInstance().join(qbChatDialog, new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle b) { if (snackbar != null) { @@ -395,13 +393,9 @@ public void onError(QBResponseException e) { }); } - private void leaveGroupChatRoom() { + private void leaveGroupDialog() { if (qbChatDialog != null) { - try { - qbChatDialog.leave(); - } catch (SmackException.NotConnectedException | XMPPException e) { - e.printStackTrace(); - } + ChatHelper.getInstance().leave(qbChatDialog); } } @@ -409,7 +403,7 @@ private void releaseChat() { if (qbChatDialog != null) { qbChatDialog.removeMessageListrener(chatMessageListener); if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType())){ - leaveGroupChatRoom(); + leaveGroupDialog(); } } } @@ -567,7 +561,7 @@ public void connectionClosedOnError(final Exception e) { runOnUiThread(new Runnable() { @Override public void run() { - leaveGroupChatRoom(); + leaveGroupDialog(); } }); } @@ -601,17 +595,19 @@ public void run() { }; } - private QBChatDialogMessageListener chatMessageListener = new QBChatDialogMessageListener() { + public class ChatMessageListener implements QBChatDialogMessageListener { + @Override - public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { + public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) { chatMessageIds.add(qbChatMessage.getId()); Log.d(TAG, "showMessage from listener"); + Log.d(TAG, "qbDialoh have listeners: " + qbChatDialog.getMessageListeners().size()); showMessage(qbChatMessage); } @Override - public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { + public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { } - }; + } } 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 dee82118a..342818855 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 @@ -25,8 +25,10 @@ import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBIncomingMessagesManager; import com.quickblox.chat.QBRestChatService; +import com.quickblox.chat.QBSystemMessagesManager; import com.quickblox.chat.exception.QBChatException; import com.quickblox.chat.listeners.QBChatDialogMessageListener; +import com.quickblox.chat.listeners.QBSystemMessageListener; import com.quickblox.chat.model.QBChatMessage; import com.quickblox.chat.model.QBChatDialog; import com.quickblox.core.QBEntityCallback; @@ -40,14 +42,17 @@ import com.quickblox.sample.chat.utils.SharedPreferencesUtil; 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.VerboseQbChatConnectionListener; 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.Toaster; import com.quickblox.sample.core.utils.constant.GcmConsts; import com.quickblox.users.model.QBUser; import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.SmackException; import java.util.ArrayList; import java.util.Collection; @@ -71,6 +76,9 @@ public class DialogsActivity extends BaseActivity { private GooglePlayServicesHelper googlePlayServicesHelper; private DialogsAdapter dialogsAdapter; private QBChatDialogMessageListener chatServiceMessagesListener; + private SystemMessagesListener systemMessagesListener; + private QBSystemMessagesManager systemMessagesManager; + private QBIncomingMessagesManager incomingMessagesManager; public static void start(Context context) { Intent intent = new Intent(context, DialogsActivity.class); @@ -91,29 +99,10 @@ protected void onCreate(Bundle savedInstanceState) { pushBroadcastReceiver = new PushBroadcastReceiver(); - chatServiceMessagesListener = new QBChatDialogMessageListener(){ + chatServiceMessagesListener = new AllDialogsMessageListener(); - @Override - public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { - Log.d(TAG, "new incoming message dialog id = "+ dialogId + " message id = " + qbChatMessage.getId()); - if (QbDialogHolder.getInstance().getChatDialogById(dialogId) == null){ - Log.d(TAG, "dialogsAdapter not have this dialog"); - requestBuilder.setSkip(skipRecords = 0); - if (isActivityForeground) { - loadDialogsFromQbInUiThread(true); - } - } else { - Log.d(TAG, "dialogsAdapter not have this dialog"); - dialogsAdapter.notifyDataSetChanged(); - } - } + systemMessagesListener = new SystemMessagesListener(); - @Override - public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { - - } - }; -// chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { @Override @@ -363,17 +352,26 @@ public void onRefresh(SwipyRefreshLayoutDirection direction) { } private void registerQbChatListeners() { - QBIncomingMessagesManager incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager(); + incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager(); + systemMessagesManager = QBChatService.getInstance().getSystemMessagesManager(); + if (incomingMessagesManager != null) { incomingMessagesManager.addDialogMessageListener(chatServiceMessagesListener); } + + if (systemMessagesManager != null){ + systemMessagesManager.addSystemMessageListener(systemMessagesListener); + } } private void unregisterQbChatListeners() { - QBIncomingMessagesManager incomingMessagesManager = QBChatService.getInstance().getIncomingMessagesManager(); if (incomingMessagesManager != null) { incomingMessagesManager.removeDialogMessageListrener(chatServiceMessagesListener); } + + if (systemMessagesManager != null){ + systemMessagesManager.removeSystemMessageListener(systemMessagesListener); + } } private void createDialog(final ArrayList selectedUsers) { @@ -382,6 +380,7 @@ private void createDialog(final ArrayList selectedUsers) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; + sendSystemMessageAboutCreatingDialog(dialog); ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } @@ -396,6 +395,21 @@ public void onError(QBResponseException e) { ); } + private void sendSystemMessageAboutCreatingDialog(QBChatDialog dialog) { + QBChatMessage systemMessageCreatingDialog = QbDialogUtils.createSystemMessageAboutCreatingGroupDialog(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 loadDialogsFromQb() { loadDialogsFromQb(false, true); } @@ -436,6 +450,26 @@ public void onError(QBResponseException e) { }); } + private void loadUsersFromDialog(QBChatDialog chatDialog){ + ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QBEntityCallback>() { + @Override + public void onSuccess(ArrayList qbUsers, Bundle bundle) { + + } + + @Override + public void onError(QBResponseException e) { + + } + }); + } + + private void removeDialogsFromAdapter(Collection selectedDialogs) { + for (QBChatDialog chatDialog : selectedDialogs){ + dialogsAdapter.remove(chatDialog); + } + } + private class DeleteActionModeCallback implements ActionMode.Callback { public DeleteActionModeCallback() { @@ -475,10 +509,11 @@ public void onDestroyActionMode(ActionMode mode) { private void deleteSelectedDialogs() { final Collection selectedDialogs = dialogsAdapter.getSelectedItems(); - ChatHelper.getInstance().deleteDialogs(selectedDialogs, new QBEntityCallback() { + 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); + removeDialogsFromAdapter(selectedDialogs); } @Override @@ -500,8 +535,65 @@ 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); - loadDialogsFromQb(true, true); + Log.e(TAG, "Received broadcast " + intent.getAction() + " with data: " + message); +// loadDialogsFromQb(true, true); + } + } + + private class SystemMessagesListener implements QBSystemMessageListener { + @Override + public void processMessage(final QBChatMessage qbChatMessage) { + Log.d(TAG, "Received system message"); + if (qbChatMessage.getProperty(QbDialogUtils.PROPERTY_NOTIFICATION_TYPE).equals(QbDialogUtils.CREATING_DIALOG)){ + Log.d(TAG, "Received system message about creating dialog by id " + qbChatMessage.getDialogId()); + final QBChatDialog newGroupDialog = QbDialogUtils.buildChatDialogFromSystemMessage(qbChatMessage); + QbDialogHolder.getInstance().addDialogToMap(newGroupDialog); + runOnUiThread(new Runnable() { + @Override + public void run() { + Toaster.shortToast("Received system message about creating dialog by id " + qbChatMessage.getDialogId()); + dialogsAdapter.add(newGroupDialog); + } + }); + } + } + + @Override + public void processError(QBChatException e, QBChatMessage qbChatMessage) { + + } + } + + private class AllDialogsMessageListener implements QBChatDialogMessageListener{ + + @Override + public void processMessage(final String dialogId, final QBChatMessage qbChatMessage, Integer integer) { + Log.d(TAG, "new incoming message dialog id = " + dialogId + " message id = " + qbChatMessage.getId()); + if (!QbDialogHolder.getInstance().hadDialogWithId(dialogId)) { + Log.d(TAG, "dialogsAdapter not have this dialog"); + ChatHelper.getInstance().getDialogById(dialogId, new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + QbDialogHolder.getInstance().addDialogToMap(chatDialog); + dialogsAdapter.add(chatDialog); + loadUsersFromDialog(chatDialog); + } + + @Override + public void onError(QBResponseException e) { + + } + }); + } else { + Log.d(TAG, "dialogsAdapter has this dialog"); + dialogsAdapter.notifyDataSetChanged(); + } + + } + + @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/chat/ChatHelper.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/chat/ChatHelper.java index 4c70446ec..c3df202d5 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 @@ -4,6 +4,7 @@ import android.os.Handler; import android.os.Looper; import android.util.Log; +import android.view.View; import com.quickblox.auth.QBAuth; import com.quickblox.auth.model.QBSession; @@ -13,14 +14,17 @@ import com.quickblox.chat.model.QBChatMessage; 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; import com.quickblox.core.QBEntityCallback; +import com.quickblox.core.QBEntityCallbackImpl; 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; @@ -37,6 +41,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; @@ -123,6 +129,41 @@ public void onError(QBResponseException e) { }); } + public void join(QBChatDialog chatDialog, final QBEntityCallback callback){ + DiscussionHistory history = new DiscussionHistory(); + history.setMaxStanzas(0); + + chatDialog.join(history, new QBEntityCallback() { + @Override + public void onSuccess(final Void result, final Bundle b) { + MAIN_HANDLER.post(new Runnable() { + @Override + public void run() { + callback.onSuccess(result, b); + } + }); + } + + @Override + public void onError(final QBResponseException e) { + MAIN_HANDLER.post(new Runnable() { + @Override + public void run() { + callback.onError(e); + } + }); + } + }); + } + + public void leave(QBChatDialog chatDialog){ + try { + chatDialog.leave(); + } catch (SmackException.NotConnectedException | XMPPException e) { + e.printStackTrace(); + } + } + public boolean logout() { try { qbChatService.logout(); @@ -147,23 +188,21 @@ public void onSuccess(QBChatDialog dialog, Bundle args) { }); } - public void deleteDialogs(Collection dialogs, final QBEntityCallback callback) { - for (QBChatDialog 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()); } - MAIN_HANDLER.post(new Runnable() { + QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(new QBEntityCallback>() { @Override - public void run() { - callback.onSuccess(null, null); + public void onSuccess(ArrayList removedDialogsIds, Bundle bundle) { + callback.onSuccess(removedDialogsIds, bundle); + } + + @Override + public void onError(QBResponseException e) { + } }); } @@ -178,8 +217,8 @@ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) } public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { - QBRequestUpdateBuilder qbRequestBuilder = new QBRequestUpdateBuilder(); - qbRequestBuilder.pullAll("occupants_ids", SharedPreferencesUtil.getQbUser().getId()); + QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder(); + qbRequestBuilder.removeUsers(SharedPreferencesUtil.getQbUser().getId()); QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { @@ -261,6 +300,21 @@ public void onSuccess(ArrayList dialogs, Bundle args) { }); } + public void getDialogById(String dialogId, final QBEntityCallback callback) { + QBRestChatService.getChatDialogById(dialogId).performAsync( + new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + callback.onSuccess(chatDialog, bundle); + } + + @Override + public void onError(QBResponseException e) { + callback.onError(e); + } + }); + } + public void getUsersFromDialog(QBChatDialog dialog, final QBEntityCallback> callback) { List userIds = dialog.getOccupants(); 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 bda859f84..6799d01ef 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,7 +1,10 @@ package com.quickblox.sample.chat.utils.qb; +import android.util.Log; + import com.quickblox.chat.model.QBChatDialog; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -20,6 +23,7 @@ public static synchronized QbDialogHolder getInstance() { } private QbDialogHolder() { + Log.d("two_messages", "QbDialogHolder.newInstance"); dialogsMap = new HashMap<>(); } @@ -52,4 +56,14 @@ public void deleteDialogs(Collection dialogs) { dialogsMap.remove(dialog.getDialogId()); } } + + public void deleteDialogs(ArrayList dialogsIds) { + for (String dialogId : dialogsIds) { + dialogsMap.remove(dialogId); + } + } + + public boolean hadDialogWithId(String dialogId){ + return dialogsMap.containsKey(dialogId); + } } 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 231539c67..658abacc3 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 @@ -4,17 +4,26 @@ import android.util.Log; 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 final String PROPERTY_OCCUPANTS_IDS = "occupants_ids"; + public static final String PROPERTY_DIALOG_TYPE = "dialog_type"; + public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type"; + public static final String CREATING_DIALOG = "creating_dialog"; + + public static QBChatDialog createDialog(List users) { QBUser currentUser = ChatHelper.getCurrentUser(); users.remove(currentUser); @@ -164,4 +173,43 @@ private static List getQbUsersFromQbDialog(QBChatDialog dialog) { } return previousDialogUsers; } + + public static QBChatMessage createSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){ + QBChatMessage qbChatMessage = new QBChatMessage(); + qbChatMessage.setDialogId(dialog.getDialogId()); + qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, getOccupantsIdsStringFromList(dialog.getOccupants())); + qbChatMessage.setProperty(PROPERTY_DIALOG_TYPE, String.valueOf(dialog.getType().getCode())); + qbChatMessage.setProperty(PROPERTY_NOTIFICATION_TYPE, CREATING_DIALOG); + + return qbChatMessage; + } + + public static 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()))); + + return chatDialog; + } + + 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 createPrivateChatDialog(String dialogId, Integer recipientId){ + QBChatDialog chatDialog = DialogUtils.buildPrivateDialog(recipientId); + chatDialog.setDialogId(dialogId); + + return chatDialog; + } } From f08a79ef9b665ca364c8d237ad6bacb01c22e356 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 27 Sep 2016 16:04:37 +0300 Subject: [PATCH 16/55] add checkQBException --- .../activities/AddNewMovieActivity.java | 20 +++++++++++------ .../activities/MovieListActivity.java | 22 ++++++++++++------- .../activities/SplashActivity.java | 19 +++++++++++----- .../utils/QBCustomObjectsUtils.java | 4 ++++ 4 files changed, 44 insertions(+), 21 deletions(-) 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 60d70c0a2..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; @@ -38,6 +39,7 @@ 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; @@ -120,13 +122,17 @@ public void onCompleted() { @Override public void onError(Throwable e) { progressDialog.dismiss(); - 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(); - } - }); + 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 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 5deacbd4f..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; @@ -23,6 +24,7 @@ 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; @@ -34,7 +36,7 @@ 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; @@ -138,13 +140,17 @@ public void onCompleted() { @Override public void onError(Throwable e) { setResultParams(false); - 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); - } - }); + 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 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 5c83a183a..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,6 +1,7 @@ package com.quickblox.sample.customobjects.activities; import android.os.Bundle; +import android.util.Log; import android.view.View; import com.quickblox.auth.QBAuth; @@ -11,6 +12,7 @@ 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; @@ -19,6 +21,7 @@ import rx.schedulers.Schedulers; public class SplashActivity extends CoreSplashActivity { + private static final String TAG = SplashActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -42,12 +45,16 @@ public void onCompleted() { @Override public void onError(Throwable e) { - showSnackbarError(null, R.string.splash_create_session_error, (QBResponseException)e, new View.OnClickListener() { - @Override - public void onClick(View v) { - createSession(); - } - }); + 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 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 From e558e547a9ed55f8fafb8a40c6dd51d6b6729e5b Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 27 Sep 2016 16:28:19 +0300 Subject: [PATCH 17/55] - reviewed method for updating dialog --- .../com/quickblox/sample/chat/utils/chat/ChatHelper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 c3df202d5..f53dd4474 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 @@ -3,6 +3,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.support.v4.content.res.TypedArrayUtils; import android.util.Log; import android.view.View; @@ -46,6 +47,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -240,12 +242,12 @@ public void updateDialogUsers(QBChatDialog 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)); From 28f55be9f4d5a9fca4b52ac5dfc2292b2bb69e20 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 27 Sep 2016 19:27:18 +0300 Subject: [PATCH 18/55] - reviewed REST requests for returning result to main thread --- .../sample/chat/utils/chat/ChatHelper.java | 36 +++++-------------- 1 file changed, 8 insertions(+), 28 deletions(-) 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 f53dd4474..d4d0a8ba4 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 @@ -109,12 +109,7 @@ public void onSuccess(QBSession session, Bundle args) { private void loginToChat(final QBUser user, final QBEntityCallback callback) { if (qbChatService.isLoggedIn()) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - callback.onSuccess(null, null); - } - }); + callback.onSuccess(null, null); return; } @@ -135,25 +130,15 @@ public void join(QBChatDialog chatDialog, final QBEntityCallback callback) DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(0); - chatDialog.join(history, new QBEntityCallback() { + chatDialog.join(history, new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(final Void result, final Bundle b) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - callback.onSuccess(result, b); - } - }); + onSuccessInMainThread(result, b); } @Override public void onError(final QBResponseException e) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - callback.onError(e); - } - }); + onErrorInMainThread(e); } }); } @@ -196,15 +181,15 @@ public void deleteDialogs(Collection dialogs, final QBEntityCallba dialogsIds.add(dialog.getDialogId()); } - QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(new QBEntityCallback>() { + QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(new QbEntityCallbackWrapper>(callback) { @Override public void onSuccess(ArrayList removedDialogsIds, Bundle bundle) { - callback.onSuccess(removedDialogsIds, bundle); + onSuccessInMainThread(removedDialogsIds, bundle); } @Override public void onError(QBResponseException e) { - + onErrorInMainThread(e); } }); } @@ -329,12 +314,7 @@ public void getUsersFromDialog(QBChatDialog dialog, // If we already have all users in memory // there is no need to make REST requests to QB if (userIds.size() == users.size()) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - callback.onSuccess(users, null); - } - }); + callback.onSuccess(users, null); return; } From 4149e943b6b0c8f26e43457c0282eeb2f42f8395 Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 28 Sep 2016 20:05:51 +0300 Subject: [PATCH 19/55] - fixed lead's flaws (not all); --- .../sample/chat/ui/activity/ChatActivity.java | 25 +-- .../chat/ui/activity/DialogsActivity.java | 161 ++++++------------ .../sample/chat/ui/adapter/ChatAdapter.java | 28 ++- .../sample/chat/utils/CollectionUtils.java | 19 --- .../sample/chat/utils/chat/ChatHelper.java | 47 ++--- .../sample/chat/utils/qb/QbDialogHolder.java | 37 +++- .../sample/chat/utils/qb/QbDialogUtils.java | 14 +- .../qb/callback/QbEntityCallbackImpl.java | 22 +++ 8 files changed, 158 insertions(+), 195 deletions(-) delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/callback/QbEntityCallbackImpl.java 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 2400d27b2..71a4f6c3c 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 @@ -131,7 +131,7 @@ protected void onPause() { @Override public void onBackPressed() { releaseChat(); - sendReadMessageId(); + sendDialogId(); super.onBackPressed(); } @@ -189,9 +189,8 @@ 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, qbChatDialog.getDialogId()); setResult(RESULT_OK, result); } @@ -336,7 +335,6 @@ private void sendChatMessage(String text, QBAttachment attachment) { qbChatDialog.sendMessage(chatMessage); if (qbChatDialog.getType() == QBDialogType.PRIVATE) { - Log.d(TAG, "showMessage from method sendChatMessage"); showMessage(chatMessage); } @@ -355,8 +353,6 @@ private void sendChatMessage(String text, QBAttachment attachment) { } private void initChat() { -// qbChatDialog.initForChat(QBChatService.getInstance()); - switch (qbChatDialog.getType()) { case GROUP: case PUBLIC_GROUP: @@ -394,20 +390,15 @@ public void onError(QBResponseException e) { } private void leaveGroupDialog() { - if (qbChatDialog != null) { - ChatHelper.getInstance().leave(qbChatDialog); - } + ChatHelper.getInstance().leave(qbChatDialog); } private void releaseChat() { - if (qbChatDialog != null) { - qbChatDialog.removeMessageListrener(chatMessageListener); - if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType())){ - leaveGroupDialog(); - } + qbChatDialog.removeMessageListrener(chatMessageListener); + if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType())) { + leaveGroupDialog(); } } - private void updateDialog(final ArrayList selectedUsers) { ChatHelper.getInstance().updateDialogUsers(qbChatDialog, selectedUsers, new QBEntityCallback() { @@ -470,7 +461,7 @@ public void onSuccess(ArrayList messages, Bundle args) { // 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() { @@ -600,8 +591,6 @@ public class ChatMessageListener implements QBChatDialogMessageListener { @Override public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) { chatMessageIds.add(qbChatMessage.getId()); - Log.d(TAG, "showMessage from listener"); - Log.d(TAG, "qbDialoh have listeners: " + qbChatDialog.getMessageListeners().size()); showMessage(qbChatMessage); } 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 342818855..e932d3238 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 @@ -24,7 +24,6 @@ import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBIncomingMessagesManager; -import com.quickblox.chat.QBRestChatService; import com.quickblox.chat.QBSystemMessagesManager; import com.quickblox.chat.exception.QBChatException; import com.quickblox.chat.listeners.QBChatDialogMessageListener; @@ -33,21 +32,19 @@ 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.CollectionUtils; import com.quickblox.sample.chat.utils.Consts; import com.quickblox.sample.chat.utils.SharedPreferencesUtil; 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.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.Toaster; import com.quickblox.sample.core.utils.constant.GcmConsts; import com.quickblox.users.model.QBUser; @@ -60,7 +57,7 @@ public class DialogsActivity extends BaseActivity { 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; @@ -69,13 +66,12 @@ 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 chatServiceMessagesListener; + private QBChatDialogMessageListener allDialogsMessagesListener; private SystemMessagesListener systemMessagesListener; private QBSystemMessagesManager systemMessagesManager; private QBIncomingMessagesManager incomingMessagesManager; @@ -99,9 +95,10 @@ protected void onCreate(Bundle savedInstanceState) { pushBroadcastReceiver = new PushBroadcastReceiver(); - chatServiceMessagesListener = new AllDialogsMessageListener(); - - systemMessagesListener = new SystemMessagesListener(); + if (isAppSessionActive) { + allDialogsMessagesListener = new AllDialogsMessageListener(); + systemMessagesListener = new SystemMessagesListener(); + } chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { @@ -121,7 +118,6 @@ public void reconnectionSuccessful() { protected void onResume() { super.onResume(); ChatHelper.getInstance().addConnectionListener(chatConnectionListener); - isActivityForeground = true; googlePlayServicesHelper.checkPlayServicesAvailable(this); LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver, @@ -132,7 +128,6 @@ protected void onResume() { protected void onPause() { super.onPause(); ChatHelper.getInstance().removeConnectionListener(chatConnectionListener); - isActivityForeground = false; LocalBroadcastManager.getInstance(this).unregisterReceiver(pushBroadcastReceiver); } @@ -179,7 +174,7 @@ public void onSessionCreated(boolean success) { } registerQbChatListeners(); - if (QbDialogHolder.getInstance().getDialogsMap().size() > 0) { + if (QbDialogHolder.getInstance().getDialogs().size() > 0) { loadDialogsFromQb(true, true); } else { loadDialogsFromQb(); @@ -199,16 +194,16 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { .getSerializableExtra(SelectUsersActivity.EXTRA_QB_USERS); createDialog(selectedUsers); - } else if (requestCode == REQUEST_MARK_READ) { + } 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); + ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl(){ + @Override + public void onSuccess(QBChatDialog result, Bundle bundle) { + QbDialogHolder.getInstance().addDialog(result); + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + } + }); } else { isProcessingResultInProgress = false; updateDialogsList(); @@ -231,18 +226,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) { @@ -270,26 +271,6 @@ public void onClick(View v) { }); } - private void markMessagesRead(StringifyArrayList messagesIds, String dialogId) { - if (messagesIds.size() > 0) { - QBRestChatService.markMessagesAsRead(dialogId, messagesIds).performAsync(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); @@ -309,8 +290,7 @@ private void initUi() { fab = _findViewById(R.id.fab_dialogs_new_chat); setOnRefreshListener = _findViewById(R.id.swipy_refresh_layout); - dialogsAdapter = new DialogsAdapter(this, - CollectionUtils.convertMapToList(QbDialogHolder.getInstance().getDialogsMap())); + 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); @@ -325,7 +305,7 @@ private void initUi() { public void onItemClick(AdapterView parent, View view, int position, long id) { QBChatDialog selectedDialog = (QBChatDialog) parent.getItemAtPosition(position); if (currentActionMode == null) { - ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, selectedDialog.getDialogId()); + ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, selectedDialog.getDialogId()); } else { dialogsAdapter.toggleSelection(selectedDialog); } @@ -356,17 +336,19 @@ private void registerQbChatListeners() { systemMessagesManager = QBChatService.getInstance().getSystemMessagesManager(); if (incomingMessagesManager != null) { - incomingMessagesManager.addDialogMessageListener(chatServiceMessagesListener); + incomingMessagesManager.addDialogMessageListener(allDialogsMessagesListener != null + ? allDialogsMessagesListener : new AllDialogsMessageListener()); } if (systemMessagesManager != null){ - systemMessagesManager.addSystemMessageListener(systemMessagesListener); + systemMessagesManager.addSystemMessageListener(systemMessagesListener != null + ? systemMessagesListener : new SystemMessagesListener()); } } private void unregisterQbChatListeners() { if (incomingMessagesManager != null) { - incomingMessagesManager.removeDialogMessageListrener(chatServiceMessagesListener); + incomingMessagesManager.removeDialogMessageListrener(allDialogsMessagesListener); } if (systemMessagesManager != null){ @@ -381,7 +363,7 @@ private void createDialog(final ArrayList selectedUsers) { public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; sendSystemMessageAboutCreatingDialog(dialog); - ChatActivity.startForResult(DialogsActivity.this, REQUEST_MARK_READ, dialog.getDialogId()); + ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } @@ -438,7 +420,7 @@ public void onSuccess(ArrayList dialogs, Bundle bundle) { QbDialogHolder.getInstance().clear(); } QbDialogHolder.getInstance().addDialogs(dialogs); - dialogsAdapter.addList(CollectionUtils.convertMapToList(QbDialogHolder.getInstance().getDialogsMap())); + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); } @Override @@ -451,23 +433,7 @@ public void onError(QBResponseException e) { } private void loadUsersFromDialog(QBChatDialog chatDialog){ - ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QBEntityCallback>() { - @Override - public void onSuccess(ArrayList qbUsers, Bundle bundle) { - - } - - @Override - public void onError(QBResponseException e) { - - } - }); - } - - private void removeDialogsFromAdapter(Collection selectedDialogs) { - for (QBChatDialog chatDialog : selectedDialogs){ - dialogsAdapter.remove(chatDialog); - } + ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl>()); } private class DeleteActionModeCallback implements ActionMode.Callback { @@ -513,7 +479,7 @@ private void deleteSelectedDialogs() { @Override public void onSuccess(ArrayList dialogsIds, Bundle bundle) { QbDialogHolder.getInstance().deleteDialogs(dialogsIds); - removeDialogsFromAdapter(selectedDialogs); + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); } @Override @@ -535,24 +501,21 @@ 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.e(TAG, "Received broadcast " + intent.getAction() + " with data: " + message); -// loadDialogsFromQb(true, true); + Log.v(TAG, "Received broadcast " + intent.getAction() + " with data: " + message); + loadDialogsFromQb(true, true); } } private class SystemMessagesListener implements QBSystemMessageListener { @Override public void processMessage(final QBChatMessage qbChatMessage) { - Log.d(TAG, "Received system message"); - if (qbChatMessage.getProperty(QbDialogUtils.PROPERTY_NOTIFICATION_TYPE).equals(QbDialogUtils.CREATING_DIALOG)){ - Log.d(TAG, "Received system message about creating dialog by id " + qbChatMessage.getDialogId()); + if (QbDialogUtils.CREATING_DIALOG.equals(qbChatMessage.getProperty(QbDialogUtils.PROPERTY_NOTIFICATION_TYPE))){ final QBChatDialog newGroupDialog = QbDialogUtils.buildChatDialogFromSystemMessage(qbChatMessage); - QbDialogHolder.getInstance().addDialogToMap(newGroupDialog); + QbDialogHolder.getInstance().addDialog(newGroupDialog); runOnUiThread(new Runnable() { @Override public void run() { - Toaster.shortToast("Received system message about creating dialog by id " + qbChatMessage.getDialogId()); - dialogsAdapter.add(newGroupDialog); + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); } }); } @@ -565,35 +528,23 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { } private class AllDialogsMessageListener implements QBChatDialogMessageListener{ - @Override public void processMessage(final String dialogId, final QBChatMessage qbChatMessage, Integer integer) { - Log.d(TAG, "new incoming message dialog id = " + dialogId + " message id = " + qbChatMessage.getId()); - if (!QbDialogHolder.getInstance().hadDialogWithId(dialogId)) { - Log.d(TAG, "dialogsAdapter not have this dialog"); - ChatHelper.getInstance().getDialogById(dialogId, new QBEntityCallback() { + ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl() { @Override public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - QbDialogHolder.getInstance().addDialogToMap(chatDialog); - dialogsAdapter.add(chatDialog); - loadUsersFromDialog(chatDialog); - } - - @Override - public void onError(QBResponseException e) { + if (!QbDialogHolder.getInstance().hadDialogWithId(dialogId)) { + loadUsersFromDialog(chatDialog); + } + QbDialogHolder.getInstance().addDialog(chatDialog); + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); } }); - } else { - Log.d(TAG, "dialogsAdapter has this dialog"); - dialogsAdapter.notifyDataSetChanged(); - } - } @Override public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { - } } } 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..fe9c72ce4 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 @@ -16,7 +16,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 +31,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 +41,14 @@ public class ChatAdapter extends BaseListAdapter implements StickyListHeadersAdapter { + 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 +107,10 @@ public boolean onLongClick(View v) { }); holder.messageInfoTextView.setVisibility(View.GONE); + if (isIncoming(chatMessage) && !isRead(chatMessage)){ + readMessage(chatMessage); + } + downloadMore(position); return convertView; @@ -266,6 +277,21 @@ 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 e) { + e.printStackTrace(); + } catch (SmackException.NotConnectedException e) { + e.printStackTrace(); + } + } + private static class HeaderViewHolder { public TextView dateTextView; } diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java deleted file mode 100644 index 61fdf6ae6..000000000 --- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/CollectionUtils.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.quickblox.sample.chat.utils; - -import com.quickblox.chat.model.QBChatDialog; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class CollectionUtils { - - public static List convertMapToList(Map incomeMap){ - List list = new ArrayList<>(); - for (String key : incomeMap.keySet()){ - list.add(incomeMap.get(key)); - } - - return list; - } -} 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 d4d0a8ba4..fbd984be1 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 @@ -3,9 +3,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.support.v4.content.res.TypedArrayUtils; import android.util.Log; -import android.view.View; import com.quickblox.auth.QBAuth; import com.quickblox.auth.model.QBSession; @@ -16,19 +14,16 @@ 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; import com.quickblox.core.QBEntityCallback; -import com.quickblox.core.QBEntityCallbackImpl; 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; @@ -47,7 +42,6 @@ import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -57,23 +51,22 @@ 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 = 5*60*1000; public static final int DIALOG_ITEMS_PER_PAGE = 100; public static final int CHAT_HISTORY_ITEMS_PER_PAGE = 50; private static final String CHAT_HISTORY_ITEMS_SORT_FIELD = "date_sent"; + private static final String DIALOGS_ITEMS_SORT_FIELD = "last_message_date_sent"; private static ChatHelper instance; private QBChatService qbChatService; - public static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); - 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; @@ -88,6 +81,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); } @@ -151,14 +153,8 @@ public void leave(QBChatDialog chatDialog){ } } - public boolean logout() { - try { - qbChatService.logout(); - return true; - } catch (SmackException.NotConnectedException e) { - e.printStackTrace(); - } - return false; + public void logout(final QBEntityCallback callback) { + qbChatService.logout(callback); } public void createDialogWithSelectedUsers(final List users, @@ -168,7 +164,7 @@ public void createDialogWithSelectedUsers(final List users, new QbEntityCallbackWrapper(callback) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { - QbDialogHolder.getInstance().addDialogToMap(dialog); + QbDialogHolder.getInstance().addDialog(dialog); QbUsersHolder.getInstance().putUsers(users); super.onSuccess(dialog, args); } @@ -288,18 +284,7 @@ public void onSuccess(ArrayList dialogs, Bundle args) { } public void getDialogById(String dialogId, final QBEntityCallback callback) { - QBRestChatService.getChatDialogById(dialogId).performAsync( - new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - callback.onSuccess(chatDialog, bundle); - } - - @Override - public void onError(QBResponseException e) { - callback.onError(e); - } - }); + QBRestChatService.getChatDialogById(dialogId).performAsync(callback); } public void getUsersFromDialog(QBChatDialog dialog, 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 6799d01ef..a7d95ea07 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,14 +1,13 @@ package com.quickblox.sample.chat.utils.qb; -import android.util.Log; - import com.quickblox.chat.model.QBChatDialog; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.TreeMap; public class QbDialogHolder { @@ -23,12 +22,11 @@ public static synchronized QbDialogHolder getInstance() { } private QbDialogHolder() { - Log.d("two_messages", "QbDialogHolder.newInstance"); - dialogsMap = new HashMap<>(); + dialogsMap = new TreeMap<>(); } - public Map getDialogsMap() { - return dialogsMap; + public Map getDialogs() { + return getSortedMap(dialogsMap); } public QBChatDialog getChatDialogById(String dialogId){ @@ -39,7 +37,7 @@ public void clear() { dialogsMap.clear(); } - public void addDialogToMap(QBChatDialog dialog) { + public void addDialog(QBChatDialog dialog) { if (dialog != null) { dialogsMap.put(dialog.getDialogId(), dialog); } @@ -47,7 +45,7 @@ public void addDialogToMap(QBChatDialog dialog) { public void addDialogs(List dialogs) { for (QBChatDialog dialog : dialogs) { - addDialogToMap(dialog); + addDialog(dialog); } } @@ -66,4 +64,25 @@ public void deleteDialogs(ArrayList dialogsIds) { public boolean hadDialogWithId(String dialogId){ return dialogsMap.containsKey(dialogId); } + + private Map getSortedMap(Map unsortedMap){ + Map sortedMap = new TreeMap(new ValueComparator(unsortedMap)); + sortedMap.putAll(unsortedMap); + return sortedMap; + } + + class ValueComparator implements Comparator { + Map map; + + public ValueComparator(Map map) { + + this.map = map; + } + + public int compare(String keyA, String keyB) { + Comparable valueA = map.get(keyA).getLastMessageDateSent(); + Comparable valueB = map.get(keyB).getLastMessageDateSent(); + return valueB.compareTo(valueA); + } + } } 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 658abacc3..e9599daae 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 @@ -134,17 +134,7 @@ public static Integer[] getUserIds(List users) { } 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; + return DialogUtils.createChatNameFromUserList(users.toArray(new QBUser[users.size()])); } public static String getDialogName(QBChatDialog dialog) { @@ -206,7 +196,7 @@ public static String getOccupantsIdsStringFromList(Collection occupantI return TextUtils.join(",", occupantIdsList); } - public static QBChatDialog createPrivateChatDialog(String dialogId, Integer recipientId){ + public static QBChatDialog buildPrivateChatDialog(String dialogId, Integer recipientId){ QBChatDialog chatDialog = DialogUtils.buildPrivateDialog(recipientId); chatDialog.setDialogId(dialogId); 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) { + + } +} From 9d1f886bb2d207f041e3ad4aab0d62fc62ef0c5c Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 29 Sep 2016 13:44:04 +0300 Subject: [PATCH 20/55] - fixed lead's flaws; --- .../sample/chat/ui/activity/ChatActivity.java | 12 ---- .../chat/ui/activity/DialogsActivity.java | 61 +++++++++---------- .../chat/utils/SystemMessagesUtils.java | 56 +++++++++++++++++ .../sample/chat/utils/chat/ChatHelper.java | 2 +- .../sample/chat/utils/qb/QbDialogHolder.java | 6 +- .../sample/chat/utils/qb/QbDialogUtils.java | 23 ------- 6 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java 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 71a4f6c3c..0f0606438 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 @@ -56,7 +56,6 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener 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; @@ -196,7 +195,6 @@ private void sendDialogId() { } private void leaveGroupChat() { - leaveGroupDialog(); ProgressDialogFragment.show(getSupportFragmentManager()); ChatHelper.getInstance().leaveDialog(qbChatDialog, new QBEntityCallback() { @Override @@ -546,16 +544,6 @@ private void initChatConnectionListener() { @Override public void connectionClosedOnError(final Exception e) { super.connectionClosedOnError(e); - - // Leave active room if we're in Group Chat - if (qbChatDialog.getType() == QBDialogType.GROUP) { - runOnUiThread(new Runnable() { - @Override - public void run() { - leaveGroupDialog(); - } - }); - } } @Override 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 e932d3238..6a92c0626 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 @@ -37,9 +37,9 @@ 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.utils.SystemMessagesUtils; 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.VerboseQbChatConnectionListener; import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackImpl; import com.quickblox.sample.core.gcm.GooglePlayServicesHelper; @@ -49,7 +49,6 @@ import com.quickblox.users.model.QBUser; import org.jivesoftware.smack.ConnectionListener; -import org.jivesoftware.smack.SmackException; import java.util.ArrayList; import java.util.Collection; @@ -197,13 +196,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } else if (requestCode == REQUEST_DIALOG_ID_FOR_UPDATE) { if (data != null) { String dialogId = data.getStringExtra(ChatActivity.EXTRA_DIALOG_ID); - ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl(){ - @Override - public void onSuccess(QBChatDialog result, Bundle bundle) { - QbDialogHolder.getInstance().addDialog(result); - dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); - } - }); + loadUpdatedDialog(dialogId); } else { isProcessingResultInProgress = false; updateDialogsList(); @@ -214,6 +207,22 @@ public void onSuccess(QBChatDialog result, Bundle bundle) { } } + 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); @@ -362,7 +371,7 @@ private void createDialog(final ArrayList selectedUsers) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; - sendSystemMessageAboutCreatingDialog(dialog); + SystemMessagesUtils.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog); ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } @@ -377,21 +386,6 @@ public void onError(QBResponseException e) { ); } - private void sendSystemMessageAboutCreatingDialog(QBChatDialog dialog) { - QBChatMessage systemMessageCreatingDialog = QbDialogUtils.createSystemMessageAboutCreatingGroupDialog(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 loadDialogsFromQb() { loadDialogsFromQb(false, true); } @@ -420,7 +414,7 @@ public void onSuccess(ArrayList dialogs, Bundle bundle) { QbDialogHolder.getInstance().clear(); } QbDialogHolder.getInstance().addDialogs(dialogs); - dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + updateDialogsAdapter(); } @Override @@ -436,6 +430,10 @@ private void loadUsersFromDialog(QBChatDialog chatDialog){ ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl>()); } + private void updateDialogsAdapter(){ + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + } + private class DeleteActionModeCallback implements ActionMode.Callback { public DeleteActionModeCallback() { @@ -479,7 +477,7 @@ private void deleteSelectedDialogs() { @Override public void onSuccess(ArrayList dialogsIds, Bundle bundle) { QbDialogHolder.getInstance().deleteDialogs(dialogsIds); - dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + updateDialogsAdapter(); } @Override @@ -509,13 +507,12 @@ public void onReceive(Context context, Intent intent) { private class SystemMessagesListener implements QBSystemMessageListener { @Override public void processMessage(final QBChatMessage qbChatMessage) { - if (QbDialogUtils.CREATING_DIALOG.equals(qbChatMessage.getProperty(QbDialogUtils.PROPERTY_NOTIFICATION_TYPE))){ - final QBChatDialog newGroupDialog = QbDialogUtils.buildChatDialogFromSystemMessage(qbChatMessage); - QbDialogHolder.getInstance().addDialog(newGroupDialog); + if (SystemMessagesUtils.isMessageCreatingDialog(qbChatMessage)) { + QbDialogHolder.getInstance().addDialog(SystemMessagesUtils.buildChatDialogFromSystemMessage(qbChatMessage)); runOnUiThread(new Runnable() { @Override public void run() { - dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + updateDialogsAdapter(); } }); } @@ -538,7 +535,7 @@ public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { } QbDialogHolder.getInstance().addDialog(chatDialog); - dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); + updateDialogsAdapter(); } }); } diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java new file mode 100644 index 000000000..157733125 --- /dev/null +++ b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java @@ -0,0 +1,56 @@ +package com.quickblox.sample.chat.utils; + +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.qb.QbDialogUtils; + +import org.jivesoftware.smack.SmackException; + +public class SystemMessagesUtils { + + public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids"; + public static final String PROPERTY_DIALOG_TYPE = "dialog_type"; + public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type"; + public static final String CREATING_DIALOG = "creating_dialog"; + + public static boolean isMessageCreatingDialog(QBChatMessage systemMessage){ + return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE)); + } + + public static 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_NOTIFICATION_TYPE, CREATING_DIALOG); + + return qbChatMessage; + } + + public static 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()))); + + return chatDialog; + } + + public static 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(); + } + } +} 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 fbd984be1..12e1f7d55 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 @@ -56,7 +56,6 @@ public class ChatHelper { public static final int DIALOG_ITEMS_PER_PAGE = 100; public static final int CHAT_HISTORY_ITEMS_PER_PAGE = 50; private static final String CHAT_HISTORY_ITEMS_SORT_FIELD = "date_sent"; - private static final String DIALOGS_ITEMS_SORT_FIELD = "last_message_date_sent"; private static ChatHelper instance; @@ -200,6 +199,7 @@ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) } public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { + leave(qbDialog); QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder(); qbRequestBuilder.removeUsers(SharedPreferencesUtil.getQbUser().getId()); 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 a7d95ea07..620f5ab92 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 @@ -66,15 +66,15 @@ public boolean hadDialogWithId(String dialogId){ } private Map getSortedMap(Map unsortedMap){ - Map sortedMap = new TreeMap(new ValueComparator(unsortedMap)); + Map sortedMap = new TreeMap(new LastMessageDateSentComparator(unsortedMap)); sortedMap.putAll(unsortedMap); return sortedMap; } - class ValueComparator implements Comparator { + class LastMessageDateSentComparator implements Comparator { Map map; - public ValueComparator(Map map) { + public LastMessageDateSentComparator(Map map) { this.map = map; } 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 e9599daae..20cd8f1e2 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 @@ -18,10 +18,6 @@ public class QbDialogUtils { private static final String TAG = QbDialogUtils.class.getSimpleName(); - public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids"; - public static final String PROPERTY_DIALOG_TYPE = "dialog_type"; - public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type"; - public static final String CREATING_DIALOG = "creating_dialog"; public static QBChatDialog createDialog(List users) { @@ -164,25 +160,6 @@ private static List getQbUsersFromQbDialog(QBChatDialog dialog) { return previousDialogUsers; } - public static QBChatMessage createSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){ - QBChatMessage qbChatMessage = new QBChatMessage(); - qbChatMessage.setDialogId(dialog.getDialogId()); - qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, getOccupantsIdsStringFromList(dialog.getOccupants())); - qbChatMessage.setProperty(PROPERTY_DIALOG_TYPE, String.valueOf(dialog.getType().getCode())); - qbChatMessage.setProperty(PROPERTY_NOTIFICATION_TYPE, CREATING_DIALOG); - - return qbChatMessage; - } - - public static 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()))); - - return chatDialog; - } - public static List getOccupantsIdsListFromString(String occupantIds) { List occupantIdsList = new ArrayList<>(); String[] occupantIdsArray = occupantIds.split(","); From 55c4df71b4a9191a2085400bdfd4f1c56a1a55ee Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 29 Sep 2016 19:28:53 +0300 Subject: [PATCH 21/55] - fixed lead's flaws; --- .../sample/chat/managers/DialogsManager.java | 158 ++++++++++++++++++ .../sample/chat/ui/activity/ChatActivity.java | 33 ++-- .../chat/ui/activity/DialogsActivity.java | 67 ++++---- .../sample/chat/ui/adapter/ChatAdapter.java | 8 +- .../chat/utils/SystemMessagesUtils.java | 56 ------- .../sample/chat/utils/chat/ChatHelper.java | 21 ++- .../qb/QbChatDialogMessageListenerImp.java | 20 +++ .../sample/chat/utils/qb/QbDialogHolder.java | 15 +- .../sample/chat/utils/qb/QbDialogUtils.java | 26 +-- 9 files changed, 255 insertions(+), 149 deletions(-) create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/managers/DialogsManager.java delete mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbChatDialogMessageListenerImp.java 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..a95b42057 --- /dev/null +++ b/sample-chat/src/main/java/com/quickblox/sample/chat/managers/DialogsManager.java @@ -0,0 +1,158 @@ +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_NOTIFICATION_TYPE = "notification_type"; + public static final String CREATING_DIALOG = "creating_dialog"; + + private Set magingDialogsCallbackListener = new CopyOnWriteArraySet<>(); + + public static boolean isMessageCreatingDialog(QBChatMessage systemMessage){ + return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE)); + } + + public static 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_NOTIFICATION_TYPE, CREATING_DIALOG); + + return qbChatMessage; + } + + public static 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()))); + + return chatDialog; + } + + public static 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); + QbDialogHolder.getInstance().addDialog(chatDialog); + notifyListenersDialogCreated(buildChatDialogFromSystemMessage(systemMessage)); + } + } + + 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 addMagingDialogsCallbackListener(ManagingDialogsCallbacks listener){ + if (listener != null){ + magingDialogsCallbackListener.add(listener); + } + } + + public void removeMagingDialogsCallbackListener(ManagingDialogsCallbacks listener) { + magingDialogsCallbackListener.remove(listener); + } + + public Collection getManagingDialogsCallbackListeners() { + return Collections.unmodifiableCollection(magingDialogsCallbackListener); + } + + 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 0f0606438..058bdfedc 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 @@ -29,6 +29,7 @@ import com.quickblox.sample.chat.ui.widget.AttachmentPreviewAdapterView; import com.quickblox.sample.chat.utils.chat.ChatHelper; 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; @@ -40,6 +41,7 @@ import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.XMPPException; import java.io.File; import java.util.ArrayList; @@ -70,7 +72,6 @@ public class ChatActivity extends BaseActivity implements OnImagePickedListener private ConnectionListener chatConnectionListener; private QBChatDialog qbChatDialog; - private ArrayList chatMessageIds; private ArrayList unShownMessages; private int skipPagination = 0; private ChatMessageListener chatMessageListener; @@ -92,8 +93,6 @@ public void onCreate(Bundle savedInstanceState) { qbChatDialog.addMessageListener(chatMessageListener); - chatMessageIds = new ArrayList<>(); - initChatConnectionListener(); initViews(); @@ -328,11 +327,16 @@ 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"); + } try { qbChatDialog.sendMessage(chatMessage); - if (qbChatDialog.getType() == QBDialogType.PRIVATE) { + if (QBDialogType.PRIVATE.equals(qbChatDialog.getType())) { showMessage(chatMessage); } @@ -346,7 +350,6 @@ private void sendChatMessage(String text, QBAttachment attachment) { 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"); } } @@ -388,7 +391,11 @@ public void onError(QBResponseException e) { } private void leaveGroupDialog() { - ChatHelper.getInstance().leave(qbChatDialog); + try { + ChatHelper.getInstance().leave(qbChatDialog); + } catch (XMPPException | SmackException.NotConnectedException e) { + Log.w(TAG, e); + } } private void releaseChat() { @@ -541,11 +548,6 @@ public void onClick(View v) { private void initChatConnectionListener() { chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { - @Override - public void connectionClosedOnError(final Exception e) { - super.connectionClosedOnError(e); - } - @Override public void reconnectionSuccessful() { super.reconnectionSuccessful(); @@ -574,17 +576,10 @@ public void run() { }; } - public class ChatMessageListener implements QBChatDialogMessageListener { - + public class ChatMessageListener extends QbChatDialogMessageListenerImp { @Override public void processMessage(String s, QBChatMessage qbChatMessage, Integer integer) { - chatMessageIds.add(qbChatMessage.getId()); showMessage(qbChatMessage); } - - @Override - public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { - - } } } 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 6a92c0626..52ca34377 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 @@ -37,8 +37,9 @@ 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.utils.SystemMessagesUtils; +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; @@ -53,7 +54,7 @@ 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_DIALOG_ID_FOR_UPDATE = 165; @@ -74,6 +75,7 @@ public class DialogsActivity extends BaseActivity { 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); @@ -99,6 +101,8 @@ protected void onCreate(Bundle savedInstanceState) { systemMessagesListener = new SystemMessagesListener(); } + dialogsManager = new DialogsManager(); + chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { @Override @@ -208,7 +212,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } private void loadUpdatedDialog(String dialogId) { - ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl(){ + ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl() { @Override public void onSuccess(QBChatDialog result, Bundle bundle) { isProcessingResultInProgress = false; @@ -349,10 +353,12 @@ private void registerQbChatListeners() { ? allDialogsMessagesListener : new AllDialogsMessageListener()); } - if (systemMessagesManager != null){ + if (systemMessagesManager != null) { systemMessagesManager.addSystemMessageListener(systemMessagesListener != null ? systemMessagesListener : new SystemMessagesListener()); } + + dialogsManager.addMagingDialogsCallbackListener(this); } private void unregisterQbChatListeners() { @@ -360,9 +366,11 @@ private void unregisterQbChatListeners() { incomingMessagesManager.removeDialogMessageListrener(allDialogsMessagesListener); } - if (systemMessagesManager != null){ + if (systemMessagesManager != null) { systemMessagesManager.removeSystemMessageListener(systemMessagesListener); } + + dialogsManager.removeMagingDialogsCallbackListener(this); } private void createDialog(final ArrayList selectedUsers) { @@ -371,7 +379,7 @@ private void createDialog(final ArrayList selectedUsers) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; - SystemMessagesUtils.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog); + DialogsManager.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog); ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } @@ -426,12 +434,23 @@ public void onError(QBResponseException e) { }); } - private void loadUsersFromDialog(QBChatDialog chatDialog){ - ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl>()); + private void updateDialogsAdapter() { + dialogsAdapter.updateList(new ArrayList<>(QbDialogHolder.getInstance().getDialogs().values())); } - 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 { @@ -507,15 +526,7 @@ public void onReceive(Context context, Intent intent) { private class SystemMessagesListener implements QBSystemMessageListener { @Override public void processMessage(final QBChatMessage qbChatMessage) { - if (SystemMessagesUtils.isMessageCreatingDialog(qbChatMessage)) { - QbDialogHolder.getInstance().addDialog(SystemMessagesUtils.buildChatDialogFromSystemMessage(qbChatMessage)); - runOnUiThread(new Runnable() { - @Override - public void run() { - updateDialogsAdapter(); - } - }); - } + dialogsManager.onSystemMessageReceived(qbChatMessage); } @Override @@ -524,24 +535,10 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { } } - private class AllDialogsMessageListener implements QBChatDialogMessageListener{ + private class AllDialogsMessageListener extends QbChatDialogMessageListenerImp { @Override public void processMessage(final String dialogId, final QBChatMessage qbChatMessage, Integer integer) { - ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - if (!QbDialogHolder.getInstance().hadDialogWithId(dialogId)) { - loadUsersFromDialog(chatDialog); - } - - QbDialogHolder.getInstance().addDialog(chatDialog); - updateDialogsAdapter(); - } - }); - } - - @Override - public void processError(String s, QBChatException e, QBChatMessage qbChatMessage, Integer integer) { + dialogsManager.onGlobalMessageReceived(dialogId, qbChatMessage); } } } 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 fe9c72ce4..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; @@ -41,6 +42,7 @@ 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; @@ -285,10 +287,8 @@ private boolean isRead(QBChatMessage chatMessage){ private void readMessage(QBChatMessage chatMessage){ try { chatDialog.readMessage(chatMessage); - } catch (XMPPException e) { - e.printStackTrace(); - } catch (SmackException.NotConnectedException e) { - e.printStackTrace(); + } catch (XMPPException | SmackException.NotConnectedException e) { + Log.w(TAG, e); } } diff --git a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java deleted file mode 100644 index 157733125..000000000 --- a/sample-chat/src/main/java/com/quickblox/sample/chat/utils/SystemMessagesUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.quickblox.sample.chat.utils; - -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.qb.QbDialogUtils; - -import org.jivesoftware.smack.SmackException; - -public class SystemMessagesUtils { - - public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids"; - public static final String PROPERTY_DIALOG_TYPE = "dialog_type"; - public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type"; - public static final String CREATING_DIALOG = "creating_dialog"; - - public static boolean isMessageCreatingDialog(QBChatMessage systemMessage){ - return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE)); - } - - public static 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_NOTIFICATION_TYPE, CREATING_DIALOG); - - return qbChatMessage; - } - - public static 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()))); - - return chatDialog; - } - - public static 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(); - } - } -} 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 12e1f7d55..c16f2d0cb 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 @@ -14,6 +14,7 @@ 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; @@ -51,7 +52,7 @@ public class ChatHelper { private static final String TAG = ChatHelper.class.getSimpleName(); - private static final int CHAT_SOCKET_TIMEOUT = 5*60*1000; + private static final int CHAT_SOCKET_TIMEOUT = 5*60; public static final int DIALOG_ITEMS_PER_PAGE = 100; public static final int CHAT_HISTORY_ITEMS_PER_PAGE = 50; @@ -144,12 +145,8 @@ public void onError(final QBResponseException e) { }); } - public void leave(QBChatDialog chatDialog){ - try { - chatDialog.leave(); - } catch (SmackException.NotConnectedException | XMPPException e) { - e.printStackTrace(); - } + public void leave(QBChatDialog chatDialog) throws XMPPException, SmackException.NotConnectedException { + chatDialog.leave(); } public void logout(final QBEntityCallback callback) { @@ -199,7 +196,12 @@ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) } public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { - leave(qbDialog); + try { + leave(qbDialog); + } catch (XMPPException | SmackException.NotConnectedException e) { + callback.onError(new QBResponseException(e.getMessage())); + } + QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder(); qbRequestBuilder.removeUsers(SharedPreferencesUtil.getQbUser().getId()); @@ -230,7 +232,8 @@ public void updateDialogUsers(QBChatDialog qbDialog, if (!removedUsers.isEmpty()) { qbRequestBuilder.removeUsers(removedUsers.toArray(new QBUser[removedUsers.size()])); } - qbDialog.setName(QbDialogUtils.createChatNameFromUserList(newQbDialogUsersList)); + qbDialog.setName(DialogUtils.createChatNameFromUserList( + newQbDialogUsersList.toArray(new QBUser[newQbDialogUsersList.size()]))); QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( new QbEntityCallbackWrapper(callback) { 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 620f5ab92..cfcf267da 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,6 +1,7 @@ package com.quickblox.sample.chat.utils.qb; import com.quickblox.chat.model.QBChatDialog; +import com.quickblox.chat.model.QBChatMessage; import java.util.ArrayList; import java.util.Collection; @@ -61,7 +62,7 @@ public void deleteDialogs(ArrayList dialogsIds) { } } - public boolean hadDialogWithId(String dialogId){ + public boolean hasDialogWithId(String dialogId){ return dialogsMap.containsKey(dialogId); } @@ -71,7 +72,17 @@ private Map getSortedMap(Map unsort return sortedMap; } - class LastMessageDateSentComparator implements Comparator { + public void updateDialog(String dialogId, QBChatMessage qbChatMessage){ + QBChatDialog updatedDialog = getChatDialogById(dialogId); + updatedDialog.setLastMessage(qbChatMessage.getBody()); + updatedDialog.setLastMessageDateSent(qbChatMessage.getDateSent()); + updatedDialog.setUnreadMessageCount(updatedDialog.getUnreadMessageCount() + 1); + updatedDialog.setLastMessageUserId(qbChatMessage.getSenderId()); + + dialogsMap.put(updatedDialog.getDialogId(), updatedDialog); + } + + static class LastMessageDateSentComparator implements Comparator { Map map; public LastMessageDateSentComparator(Map map) { 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 20cd8f1e2..8dacd6819 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 @@ -25,7 +25,7 @@ public static QBChatDialog createDialog(List users) { users.remove(currentUser); QBChatDialog dialogToCreate = new QBChatDialog(); - dialogToCreate.setName(QbDialogUtils.createChatNameFromUserList(users)); + dialogToCreate.setName(DialogUtils.createChatNameFromUserList(users.toArray(new QBUser[users.size()]))); if (users.size() == 1) { dialogToCreate.setType(QBDialogType.PRIVATE); } else { @@ -103,24 +103,6 @@ private static void logUsersByIds(List users) { } } - public static Integer getOpponentIdForPrivateDialog(QBChatDialog 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) { @@ -129,16 +111,12 @@ public static Integer[] getUserIds(List users) { return ids.toArray(new Integer[ids.size()]); } - public static String createChatNameFromUserList(List users) { - return DialogUtils.createChatNameFromUserList(users.toArray(new QBUser[users.size()])); - } - 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(); From f2e74df8d496b92c0a56b288fe097543456899c6 Mon Sep 17 00:00:00 2001 From: Tereha Date: Fri, 30 Sep 2016 11:28:03 +0300 Subject: [PATCH 22/55] - fixed lead's flaws; --- .../sample/chat/managers/DialogsManager.java | 12 +++++++++--- .../sample/chat/ui/activity/DialogsActivity.java | 10 ++++++---- .../sample/chat/utils/qb/QbDialogHolder.java | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) 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 index a95b42057..bcada198f 100644 --- 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 @@ -3,6 +3,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.util.Log; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBSystemMessagesManager; @@ -27,6 +28,7 @@ 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"; @@ -41,6 +43,7 @@ public static QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDia 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; @@ -51,6 +54,8 @@ public static QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChat 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; } @@ -95,8 +100,9 @@ public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { public void onSystemMessageReceived(QBChatMessage systemMessage){ if (isMessageCreatingDialog(systemMessage)) { QBChatDialog chatDialog = buildChatDialogFromSystemMessage(systemMessage); + chatDialog.initForChat(QBChatService.getInstance()); QbDialogHolder.getInstance().addDialog(chatDialog); - notifyListenersDialogCreated(buildChatDialogFromSystemMessage(systemMessage)); + notifyListenersDialogCreated(chatDialog); } } @@ -133,13 +139,13 @@ public void run() { }); } - public void addMagingDialogsCallbackListener(ManagingDialogsCallbacks listener){ + public void addManagingDialogsCallbackListener(ManagingDialogsCallbacks listener){ if (listener != null){ magingDialogsCallbackListener.add(listener); } } - public void removeMagingDialogsCallbackListener(ManagingDialogsCallbacks listener) { + public void removeManagingDialogsCallbackListener(ManagingDialogsCallbacks listener) { magingDialogsCallbackListener.remove(listener); } 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 52ca34377..3271e99d0 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 @@ -358,7 +358,7 @@ private void registerQbChatListeners() { ? systemMessagesListener : new SystemMessagesListener()); } - dialogsManager.addMagingDialogsCallbackListener(this); + dialogsManager.addManagingDialogsCallbackListener(this); } private void unregisterQbChatListeners() { @@ -370,7 +370,7 @@ private void unregisterQbChatListeners() { systemMessagesManager.removeSystemMessageListener(systemMessagesListener); } - dialogsManager.removeMagingDialogsCallbackListener(this); + dialogsManager.removeManagingDialogsCallbackListener(this); } private void createDialog(final ArrayList selectedUsers) { @@ -537,8 +537,10 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { private class AllDialogsMessageListener extends QbChatDialogMessageListenerImp { @Override - public void processMessage(final String dialogId, final QBChatMessage qbChatMessage, Integer integer) { - dialogsManager.onGlobalMessageReceived(dialogId, qbChatMessage); + 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/utils/qb/QbDialogHolder.java b/sample-chat/src/main/java/com/quickblox/sample/chat/utils/qb/QbDialogHolder.java index cfcf267da..d86b98de0 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 @@ -76,7 +76,8 @@ public void updateDialog(String dialogId, QBChatMessage qbChatMessage){ QBChatDialog updatedDialog = getChatDialogById(dialogId); updatedDialog.setLastMessage(qbChatMessage.getBody()); updatedDialog.setLastMessageDateSent(qbChatMessage.getDateSent()); - updatedDialog.setUnreadMessageCount(updatedDialog.getUnreadMessageCount() + 1); + updatedDialog.setUnreadMessageCount(updatedDialog.getUnreadMessageCount() != null + ? updatedDialog.getUnreadMessageCount() + 1 : 1); updatedDialog.setLastMessageUserId(qbChatMessage.getSenderId()); dialogsMap.put(updatedDialog.getDialogId(), updatedDialog); From bc1319e309506f5447417fa60d7518b06b1c65c7 Mon Sep 17 00:00:00 2001 From: Tereha Date: Fri, 30 Sep 2016 11:56:19 +0300 Subject: [PATCH 23/55] - fixed comparator issue (before was deleted all dialogs without messages) --- .../sample/chat/utils/qb/QbDialogHolder.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 d86b98de0..c92a13307 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 @@ -92,9 +92,15 @@ public LastMessageDateSentComparator(Map map) { } public int compare(String keyA, String keyB) { - Comparable valueA = map.get(keyA).getLastMessageDateSent(); - Comparable valueB = map.get(keyB).getLastMessageDateSent(); - return valueB.compareTo(valueA); + + long valueA = map.get(keyA).getLastMessageDateSent(); + long valueB = map.get(keyB).getLastMessageDateSent(); + + if (valueB < valueA){ + return -1; + } else { + return 1; + } } } } From bc09bddfffa1ced24e5ed3aac104320f258ed794 Mon Sep 17 00:00:00 2001 From: Tereha Date: Fri, 30 Sep 2016 14:07:48 +0300 Subject: [PATCH 24/55] - refactoring DialogsManager.java --- .../sample/chat/managers/DialogsManager.java | 17 ++++++++--------- .../chat/ui/activity/DialogsActivity.java | 2 +- .../sample/chat/utils/chat/ChatHelper.java | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) 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 index bcada198f..819cf0f63 100644 --- 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 @@ -3,7 +3,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.util.Log; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBSystemMessagesManager; @@ -32,13 +31,13 @@ public class DialogsManager { public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type"; public static final String CREATING_DIALOG = "creating_dialog"; - private Set magingDialogsCallbackListener = new CopyOnWriteArraySet<>(); + private Set managingDialogsCallbackListener = new CopyOnWriteArraySet<>(); - public static boolean isMessageCreatingDialog(QBChatMessage systemMessage){ + private boolean isMessageCreatingDialog(QBChatMessage systemMessage){ return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE)); } - public static QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){ + private QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){ QBChatMessage qbChatMessage = new QBChatMessage(); qbChatMessage.setDialogId(dialog.getDialogId()); qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, QbDialogUtils.getOccupantsIdsStringFromList(dialog.getOccupants())); @@ -49,7 +48,7 @@ public static QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDia return qbChatMessage; } - public static QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChatMessage){ + private QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChatMessage){ QBChatDialog chatDialog = new QBChatDialog(); chatDialog.setDialogId(qbChatMessage.getDialogId()); chatDialog.setOccupantsIds(QbDialogUtils.getOccupantsIdsListFromString((String) qbChatMessage.getProperty(PROPERTY_OCCUPANTS_IDS))); @@ -60,7 +59,7 @@ public static QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChat return chatDialog; } - public static void sendSystemMessageAboutCreatingDialog(QBSystemMessagesManager systemMessagesManager, QBChatDialog dialog) { + public void sendSystemMessageAboutCreatingDialog(QBSystemMessagesManager systemMessagesManager, QBChatDialog dialog) { QBChatMessage systemMessageCreatingDialog = buildSystemMessageAboutCreatingGroupDialog(dialog); try { @@ -141,16 +140,16 @@ public void run() { public void addManagingDialogsCallbackListener(ManagingDialogsCallbacks listener){ if (listener != null){ - magingDialogsCallbackListener.add(listener); + managingDialogsCallbackListener.add(listener); } } public void removeManagingDialogsCallbackListener(ManagingDialogsCallbacks listener) { - magingDialogsCallbackListener.remove(listener); + managingDialogsCallbackListener.remove(listener); } public Collection getManagingDialogsCallbackListeners() { - return Collections.unmodifiableCollection(magingDialogsCallbackListener); + return Collections.unmodifiableCollection(managingDialogsCallbackListener); } public interface ManagingDialogsCallbacks{ 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 3271e99d0..5be5690a3 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 @@ -379,7 +379,7 @@ private void createDialog(final ArrayList selectedUsers) { @Override public void onSuccess(QBChatDialog dialog, Bundle args) { isProcessingResultInProgress = false; - DialogsManager.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog); + dialogsManager.sendSystemMessageAboutCreatingDialog(systemMessagesManager, dialog); ChatActivity.startForResult(DialogsActivity.this, REQUEST_DIALOG_ID_FOR_UPDATE, dialog.getDialogId()); ProgressDialogFragment.hide(getSupportFragmentManager()); } 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 c16f2d0cb..f233dbe5d 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 @@ -52,7 +52,7 @@ public class ChatHelper { private static final String TAG = ChatHelper.class.getSimpleName(); - private static final int CHAT_SOCKET_TIMEOUT = 5*60; + 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; From 1f7c7e38495dd0dbc3f03cbbf84a6303eabcedfe Mon Sep 17 00:00:00 2001 From: vfite Date: Fri, 30 Sep 2016 17:49:12 +0300 Subject: [PATCH 25/55] updated build script --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 3fda7a4b4..7fd32f1d6 100644 --- a/build.gradle +++ b/build.gradle @@ -19,11 +19,11 @@ allprojects { } ext { - compileSdkVersion = 23 - buildToolsVersion = "23.0.2" + compileSdkVersion = 22 + buildToolsVersion = "22.0.1" minSdkVersion = 14 - targetSdkVersion = 23 + targetSdkVersion = 22 sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 From 0bc36f6b7db0aea8638dee2588312894868645b2 Mon Sep 17 00:00:00 2001 From: Tereha Date: Fri, 30 Sep 2016 17:54:46 +0300 Subject: [PATCH 26/55] - fixed lead flaws; --- .../sample/chat/ui/activity/ChatActivity.java | 11 ++++--- .../sample/chat/utils/chat/ChatHelper.java | 30 ++++--------------- .../sample/chat/utils/qb/QbDialogUtils.java | 10 +------ 3 files changed, 12 insertions(+), 39 deletions(-) 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 058bdfedc..a9aa729f9 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,8 +15,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; -import com.quickblox.chat.exception.QBChatException; -import com.quickblox.chat.listeners.QBChatDialogMessageListener; import com.quickblox.chat.model.QBAttachment; import com.quickblox.chat.model.QBChatMessage; import com.quickblox.chat.model.QBChatDialog; @@ -87,6 +85,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); + Log.v("ChatHelper", "onCreate ChatActivity on Thread ID = " + Thread.currentThread().getId()); + qbChatDialog = QbDialogHolder.getInstance().getChatDialogById( getIntent().getStringExtra(EXTRA_DIALOG_ID)); chatMessageListener = new ChatMessageListener(); @@ -195,7 +195,7 @@ private void sendDialogId() { private void leaveGroupChat() { ProgressDialogFragment.show(getSupportFragmentManager()); - ChatHelper.getInstance().leaveDialog(qbChatDialog, new QBEntityCallback() { + ChatHelper.getInstance().exitFromDialog(qbChatDialog, new QBEntityCallback() { @Override public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { ProgressDialogFragment.hide(getSupportFragmentManager()); @@ -331,6 +331,7 @@ private void sendChatMessage(String text, QBAttachment attachment) { if (!QBDialogType.PRIVATE.equals(qbChatDialog.getType()) && !qbChatDialog.isJoined()){ Toaster.shortToast("You're still joining a group chat, please wait a bit"); + return; } try { @@ -348,8 +349,6 @@ private void sendChatMessage(String text, QBAttachment attachment) { } 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); } } @@ -392,7 +391,7 @@ public void onError(QBResponseException e) { private void leaveGroupDialog() { try { - ChatHelper.getInstance().leave(qbChatDialog); + ChatHelper.getInstance().leaveChatDialog(qbChatDialog); } catch (XMPPException | SmackException.NotConnectedException e) { Log.w(TAG, e); } 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 f233dbe5d..d149b2314 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 @@ -1,8 +1,6 @@ package com.quickblox.sample.chat.utils.chat; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; import android.util.Log; import com.quickblox.auth.QBAuth; @@ -145,7 +143,7 @@ public void onError(final QBResponseException e) { }); } - public void leave(QBChatDialog chatDialog) throws XMPPException, SmackException.NotConnectedException { + public void leaveChatDialog(QBChatDialog chatDialog) throws XMPPException, SmackException.NotConnectedException { chatDialog.leave(); } @@ -169,21 +167,11 @@ public void onSuccess(QBChatDialog dialog, Bundle args) { public void deleteDialogs(Collection dialogs, final QBEntityCallback> callback) { StringifyArrayList dialogsIds = new StringifyArrayList<>(); - for (QBChatDialog dialog : dialogs){ + for (QBChatDialog dialog : dialogs) { dialogsIds.add(dialog.getDialogId()); } - QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(new QbEntityCallbackWrapper>(callback) { - @Override - public void onSuccess(ArrayList removedDialogsIds, Bundle bundle) { - onSuccessInMainThread(removedDialogsIds, bundle); - } - - @Override - public void onError(QBResponseException e) { - onErrorInMainThread(e); - } - }); + QBRestChatService.deleteDialogs(dialogsIds, false, null).performAsync(callback); } public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) { @@ -195,9 +183,9 @@ public void deleteDialog(QBChatDialog qbDialog, QBEntityCallback callback) } } - public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback callback) { + public void exitFromDialog(QBChatDialog qbDialog, QBEntityCallback callback) { try { - leave(qbDialog); + leaveChatDialog(qbDialog); } catch (XMPPException | SmackException.NotConnectedException e) { callback.onError(new QBResponseException(e.getMessage())); } @@ -205,13 +193,7 @@ public void leaveDialog(QBChatDialog qbDialog, QBEntityCallback ca QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder(); qbRequestBuilder.removeUsers(SharedPreferencesUtil.getQbUser().getId()); - QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync( - new QbEntityCallbackWrapper(callback) { - @Override - public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { - super.onSuccess(qbDialog, bundle); - } - }); + QBRestChatService.updateGroupChatDialog(qbDialog, qbRequestBuilder).performAsync(callback); } public void updateDialogUsers(QBChatDialog qbDialog, 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 8dacd6819..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 @@ -24,15 +24,7 @@ public static QBChatDialog createDialog(List users) { QBUser currentUser = ChatHelper.getCurrentUser(); users.remove(currentUser); - QBChatDialog dialogToCreate = new QBChatDialog(); - dialogToCreate.setName(DialogUtils.createChatNameFromUserList(users.toArray(new QBUser[users.size()]))); - 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(QBChatDialog dialog, List currentUsers) { From b1c42100c42297d2bda3eedd71260b026dad0a51 Mon Sep 17 00:00:00 2001 From: tatanka987 Date: Sun, 2 Oct 2016 22:39:42 +0300 Subject: [PATCH 27/55] - reviewed result callbacks for sending result to main thread --- .../com/quickblox/sample/chat/utils/chat/ChatHelper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 d149b2314..1b88dc204 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 @@ -294,7 +294,7 @@ public void getUsersFromDialog(QBChatDialog dialog, @Override public void onSuccess(ArrayList qbUsers, Bundle bundle) { QbUsersHolder.getInstance().putUsers(qbUsers); - onSuccessInMainThread(qbUsers, bundle); + callback.onSuccess(qbUsers, bundle); } }); } @@ -312,7 +312,7 @@ 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); } }); } @@ -331,7 +331,7 @@ private void getUsersFromDialogs(final ArrayList dialogs, @Override public void onSuccess(ArrayList users, Bundle params) { QbUsersHolder.getInstance().putUsers(users); - onSuccessInMainThread(dialogs, params); + callback.onSuccess(dialogs, params); } }); } @@ -349,7 +349,7 @@ private void getUsersFromMessages(final ArrayList messages, @Override public void onSuccess(ArrayList users, Bundle params) { QbUsersHolder.getInstance().putUsers(users); - onSuccessInMainThread(messages, params); + callback.onSuccess(messages, params); } }); } From a22c60a7fc05cdd11930368531e492e1d305d7e7 Mon Sep 17 00:00:00 2001 From: Tereha Date: Mon, 3 Oct 2016 14:02:54 +0300 Subject: [PATCH 28/55] - removed excess loading all dialogs; --- .../chat/ui/activity/DialogsActivity.java | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) 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 5be5690a3..9065a3ebd 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 @@ -82,8 +82,6 @@ public static void start(Context context) { context.startActivity(intent); } - private ConnectionListener chatConnectionListener; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -103,24 +101,12 @@ protected void onCreate(Bundle savedInstanceState) { dialogsManager = new DialogsManager(); - chatConnectionListener = new VerboseQbChatConnectionListener(getSnackbarAnchorView()) { - - @Override - public void reconnectionSuccessful() { - super.reconnectionSuccessful(); - - requestBuilder.setSkip(skipRecords = 0); - loadDialogsFromQbInUiThread(true); - } - }; - initUi(); } @Override protected void onResume() { super.onResume(); - ChatHelper.getInstance().addConnectionListener(chatConnectionListener); googlePlayServicesHelper.checkPlayServicesAvailable(this); LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver, @@ -130,7 +116,6 @@ protected void onResume() { @Override protected void onPause() { super.onPause(); - ChatHelper.getInstance().removeConnectionListener(chatConnectionListener); LocalBroadcastManager.getInstance(this).unregisterReceiver(pushBroadcastReceiver); } @@ -180,7 +165,7 @@ public void onSessionCreated(boolean success) { if (QbDialogHolder.getInstance().getDialogs().size() > 0) { loadDialogsFromQb(true, true); } else { - loadDialogsFromQb(); + loadDialogsFromQb(false, true); } } } @@ -206,8 +191,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { updateDialogsList(); } } - } else { - updateDialogsList(); } } @@ -394,19 +377,6 @@ 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) { if (!silentUpdate) { progressBar.setVisibility(View.VISIBLE); From b4d70270976d7095e60f246e33d0989c31b1cfbc Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 17:13:43 +0300 Subject: [PATCH 29/55] updated build script --- build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 6aaa10284..994e5fee3 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' } } @@ -19,11 +19,11 @@ allprojects { } ext { - compileSdkVersion = 22 - buildToolsVersion = "22.0.1" + compileSdkVersion = 23 + buildToolsVersion = "23.0.2" minSdkVersion = 14 - targetSdkVersion = 22 + targetSdkVersion = 23 sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 From 98777b1b8f8fa0c6624292fc497348f9529af52a Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 17:36:21 +0300 Subject: [PATCH 30/55] updated build script --- build.gradle | 4 ++-- sample-chat/build.gradle | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 994e5fee3..207ab41cd 100644 --- a/build.gradle +++ b/build.gradle @@ -39,12 +39,12 @@ ext { // Dependency versions - playServicesVersion = '8.4.0' + playServicesVersion = '8.1.0' supportV4Version = '23.1.1' appcompatV7Version = '23.1.1' recyclerviewV7Version = '23.2.1' supportAnnotationsVersion = '23.1.1' - designVersion = '23.1.1' + designVersion = '24.1.1' uilVersion = '1.9.0' glideVersion = '3.6.1' diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 9c266720f..b93f3144d 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -52,7 +52,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" From 2a512224af4deb9e7eabfa13c64702f98ed9ee3a Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 17:45:37 +0300 Subject: [PATCH 31/55] added ignoring lint --- sample-chat/build.gradle | 4 ++++ sample-content/build.gradle | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index b93f3144d..1c8100f61 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -40,6 +40,10 @@ android { } } + lintOptions { + abortOnError false + } + } 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 { From 08ee231e2bdd18d13465210477172f79f369253b Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 17:49:25 +0300 Subject: [PATCH 32/55] added ignoring lint for core module --- sample-core/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) 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 { From 083e9695c56911b9e9024ac12733c823760a057b Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 18:00:57 +0300 Subject: [PATCH 33/55] fixed errors for building --- sample-location/build.gradle | 2 +- .../sample/location/activities/MapActivity.java | 4 ++-- .../sample/location/activities/SplashActivity.java | 2 +- sample-videochat-webrtc/build.gradle | 9 ++------- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sample-location/build.gradle b/sample-location/build.gradle index 80ef84ab7..47c073443 100644 --- a/sample-location/build.gradle +++ b/sample-location/build.gradle @@ -38,7 +38,7 @@ android { } 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-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle index 3c154d473..cd3f36264 100755 --- a/sample-videochat-webrtc/build.gradle +++ b/sample-videochat-webrtc/build.gradle @@ -56,14 +56,9 @@ android { 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.+" From 56cab89dc648aa68f364eac7d7a489685ac900d1 Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 18:12:27 +0300 Subject: [PATCH 34/55] fixed errors for building --- sample-custom-objects/build.gradle | 9 ++++++--- sample-location/build.gradle | 4 ++++ sample-videochat-webrtc/build.gradle | 4 ++++ snippets/build.gradle | 23 ++++------------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/sample-custom-objects/build.gradle b/sample-custom-objects/build.gradle index 9e9a8dcbe..39f7d9bae 100644 --- a/sample-custom-objects/build.gradle +++ b/sample-custom-objects/build.gradle @@ -35,18 +35,21 @@ android { keyPassword "android" } } + dataBinding { enabled = true } + + lintOptions { + abortOnError false + } } dependencies { 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-location/build.gradle b/sample-location/build.gradle index 47c073443..f5a94c98f 100644 --- a/sample-location/build.gradle +++ b/sample-location/build.gradle @@ -35,6 +35,10 @@ android { keyPassword "android" } } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/sample-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle index cd3f36264..d49bf98a2 100755 --- a/sample-videochat-webrtc/build.gradle +++ b/sample-videochat-webrtc/build.gradle @@ -52,6 +52,10 @@ android { keyPassword "android" } } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/snippets/build.gradle b/snippets/build.gradle index 7146270c9..a01689f57 100644 --- a/snippets/build.gradle +++ b/snippets/build.gradle @@ -58,21 +58,15 @@ android { } } + lintOptions { + abortOnError false + } + } 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 +74,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; From 5821ef7cfdf2fb9c9ff32757b8bf6906819b95a0 Mon Sep 17 00:00:00 2001 From: vfite Date: Mon, 3 Oct 2016 18:17:44 +0300 Subject: [PATCH 35/55] fixed errors for building --- sample-pushnotifications/build.gradle | 8 +++++--- sample-users/build.gradle | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) 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-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' } From 5bb2db60f11fcf4d128fe581fe6635c613e22a87 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 4 Oct 2016 11:56:52 +0300 Subject: [PATCH 36/55] - changed compileSdkVersion, targetSdkVersion to 23, changed app's version name to 3.0 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 6aaa10284..70b2efdd0 100644 --- a/build.gradle +++ b/build.gradle @@ -19,11 +19,11 @@ allprojects { } ext { - compileSdkVersion = 22 + compileSdkVersion = 23 buildToolsVersion = "22.0.1" minSdkVersion = 14 - targetSdkVersion = 22 + targetSdkVersion = 23 sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 @@ -33,7 +33,7 @@ ext { // QuickBlox SDK version qbSdkVersion = '3.0' - versionName = "2.6.1" + versionName = "3.0" testRunnerVersion = "0.4.1" From c0bdd9133e50abf4b21a11d96ce96408fe5efdf1 Mon Sep 17 00:00:00 2001 From: Tereha Date: Tue, 4 Oct 2016 20:01:48 +0300 Subject: [PATCH 37/55] - adapted code for working with new SDK API v.3.0 --- .../sdk/snippets/modules/SnippetsAuth.java | 24 +- .../sdk/snippets/modules/SnippetsChat.java | 444 +++++++++--------- .../sdk/snippets/modules/SnippetsContent.java | 103 ++-- .../modules/SnippetsCustomObjects.java | 88 ++-- .../snippets/modules/SnippetsLocation.java | 49 +- .../modules/SnippetsPushNotifications.java | 67 +-- .../sdk/snippets/modules/SnippetsUsers.java | 157 ++++--- 7 files changed, 472 insertions(+), 460 deletions(-) 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..bcbfdf3b0 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java @@ -4,37 +4,36 @@ import android.os.Bundle; import android.util.Log; +import com.quickblox.auth.QBAuth; 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.QBChatDialogMessageListener; +import com.quickblox.chat.listeners.QBChatDialogMessageSentListener; +import com.quickblox.chat.listeners.QBChatDialogParticipantListener; +import com.quickblox.chat.listeners.QBChatDialogTypingListener; import com.quickblox.chat.listeners.QBMessageListener; -import com.quickblox.chat.listeners.QBMessageSentListener; 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 +78,21 @@ 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 chatDialog; + 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 +106,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 +120,6 @@ public class SnippetsChat extends Snippets { // private QBPrivacyListsManager privacyListsManager; private QBPrivacyListListener privacyListListener; - private QBIsTypingListener isTypingListenerGroup; public SnippetsChat(final Context context) { @@ -247,27 +241,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 +286,37 @@ 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) { + try { + chatDialog = QBRestChatService.getChatDialogById(dialogId).perform(); + log(chatDialog.getType().toString() + "chat with id " + chatDialog.getDialogId() + " downloaded"); + } catch (QBResponseException e) { + e.printStackTrace(); } - log("Private chat created: " + privateChat + ", createdLocally: " + createdLocally); + 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); + } } - }; - 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) { + } }; - groupChatManager.addGroupChatManagerListener(groupChatManagerListener); + + QBChatService.getInstance().getIncomingMessagesManager().addDialogMessageListener(globalChatDialogMessageListener); } // @@ -352,7 +342,7 @@ public void onSuccess(Void result, Bundle bundle) { log("success when login"); - initChatPrivateAndGroupManagers(); + initGlobalMessageListener(); // // Add Chat message listener initRoster(); @@ -403,7 +393,7 @@ protected void postExecute() { final Exception exc = getException(); if (exc == null) { - initChatPrivateAndGroupManagers(); + initGlobalMessageListener(); log("success when login"); @@ -579,62 +569,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,7 +634,7 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { Snippet sendPrivateMessageExtended = new Snippet("send private message") { @Override public void execute() { - if (privateChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -686,15 +662,19 @@ public void execute() { 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); + QBChatDialog privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); + + if (privateChatDialog != null) { + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog.addMessageSentListener(privateChatDialogMessageSentListener); } - privateChat.sendMessage(chatMessage); + + privateChatDialog.sendMessage(chatMessage); } catch (SmackException.NotConnectedException e) { log("send message error: " + e.getClass().getSimpleName()); + } catch (QBResponseException e) { + log("getting private chat dialog error: " + e.getClass().getSimpleName()); + e.printStackTrace(); } } }; @@ -708,19 +688,20 @@ public void execute() { Snippet sendIsTypingInPrivateChat = new Snippet("send is typing (private chat)") { @Override public void execute() { - if (privateChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - } + QBChatDialog privateChatDialog = null; try { - privateChat.sendIsTypingNotification(); - } catch (SmackException.NotConnectedException e) { + privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog( + ApplicationConfig.getInstance().getTestUserId2())).perform(); + if (privateChatDialog != null) { + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog.sendIsTypingNotification(); + } + } catch (QBResponseException | SmackException.NotConnectedException e) { log("send typing error: " + e.getClass().getSimpleName()); } catch (XMPPException e) { e.printStackTrace(); @@ -731,19 +712,20 @@ public void execute() { Snippet sendStopTypingInPrivateChat = new Snippet("send stop typing (private chat)") { @Override public void execute() { - if (privateChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - privateChat.addIsTypingListener(isTypingListenerPrivate); - } + QBChatDialog privateChatDialog = null; try { - privateChat.sendStopTypingNotification(); - } catch (SmackException.NotConnectedException e) { + privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog( + ApplicationConfig.getInstance().getTestUserId2())).perform(); + if (privateChatDialog != null) { + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog.sendStopTypingNotification(); + } + } catch (QBResponseException | SmackException.NotConnectedException e) { log("send stop typing error: " + e.getClass().getSimpleName()); } catch (XMPPException e) { e.printStackTrace(); @@ -754,13 +736,13 @@ public void execute() { Snippet sendIsTypingInGroupChat = new Snippet("send is typing (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { 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 +754,13 @@ public void execute() { Snippet sendStopTypingInGroupChat = new Snippet("send stop typing (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { log("Please join room first"); return; } try { - currentChatRoom.sendStopTypingNotification(); + groupChatDialog.sendStopTypingNotification(); } catch (XMPPException e) { log("send typing error: " + e.getLocalizedMessage()); } catch (SmackException.NotConnectedException e) { @@ -796,24 +778,23 @@ public void execute() { Snippet readMessagePrivateChat = new Snippet("read message (private chat)") { @Override public void execute() { - if (privateChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - } + QBChatDialog privateChatDialog = null; try { + privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); + QBChatMessage status = new QBChatMessage(); status.setId("267477ab5612312312414124"); status.setDialogId("267477ab5612312312414124"); - privateChat.readMessage(status); + privateChatDialog.readMessage(status); } catch (XMPPException e) { log("read message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException e) { + } catch (SmackException.NotConnectedException | QBResponseException e) { log("read message error: " + e.getClass().getSimpleName()); } } @@ -822,24 +803,25 @@ public void execute() { Snippet deliverMessagePrivateChat = new Snippet("deliver message (private chat)") { @Override public void execute() { - if (privateChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - QBPrivateChat privateChat = privateChatManager.getChat(ApplicationConfig.getInstance().getTestUserId2()); - if (privateChat == null) { - privateChat = privateChatManager.createChat(ApplicationConfig.getInstance().getTestUserId2(), privateChatMessageListener); - } + QBChatDialog privateChatDialog = null; + try { + privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); + + QBChatMessage status = new QBChatMessage(); status.setId("267477ab5612312312414124"); status.setDialogId("267477ab5612312312414124"); - privateChat.deliverMessage(status); + privateChatDialog.deliverMessage(status); } catch (XMPPException e) { log("deliver message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException e) { + } catch (SmackException.NotConnectedException | QBResponseException e) { log("deliver message error: " + e.getClass().getSimpleName()); } } @@ -848,7 +830,7 @@ public void execute() { Snippet readMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { log("Please join room first"); return; } @@ -859,7 +841,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 +853,7 @@ public void execute() { Snippet deliverMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { log("Please join room first"); return; } @@ -882,7 +864,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 +880,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,17 +906,20 @@ public void processPresence(QBGroupChat groupChat, QBPresence presence) { Snippet joinRoom = new Snippet("join Room") { @Override public void execute() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } - DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(0); - currentChatRoom = groupChatManager.createGroupChat(ApplicationConfig.getInstance().getTestRoomJid()); - log("dialog ID: " + currentChatRoom.getDialogId()); + try { + groupChatDialog = QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).perform(); + log("dialog ID: " + groupChatDialog.getDialogId()); + } catch (QBResponseException e) { + log("Getting dialog error: " + e.getClass().getSimpleName()); + } QBEntityCallback clbck = new QBEntityCallback() { @Override @@ -941,10 +927,10 @@ 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,14 +939,14 @@ 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) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -969,18 +955,21 @@ public void executeAsync() { 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 +977,7 @@ public void executeAsync() { protected void postExecute() { super.postExecute(); - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { return; } @@ -1005,7 +994,7 @@ protected void postExecute() { Snippet sendMessageToRoomExtended = new Snippet("send message to room") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { log("Please join room first"); return; } @@ -1017,7 +1006,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 +1018,16 @@ 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); - log("currentChatRoom: " + currentChatRoom); + try { + groupChatDialog = QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).perform(); + } catch (QBResponseException e) { + log("Getting dialog error: " + e.getClass().getSimpleName()); + } + + groupChatDialog.addMessageListener(groupChatDialogMessageListener); + + log("currentChatRoom: " + groupChatDialog); // create a message QBChatMessage chatMessage = new QBChatMessage(); @@ -1041,7 +1036,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 +1048,14 @@ public void execute() { Snippet getOnlineRoomUsersSynchronous = new Snippet("get online room users") { @Override public void execute() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { 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 +1074,14 @@ public void execute() { Snippet leaveRoom = new SnippetAsync("leave room", context) { @Override public void executeAsync() { - if (currentChatRoom == null) { + if (groupChatDialog == null) { log("Please join room first"); return; } try { - currentChatRoom.leave(); - currentChatRoom = null; + groupChatDialog.leave(); + groupChatDialog = null; } catch (XMPPException | SmackException.NotConnectedException e) { setException(e); } @@ -1096,7 +1091,7 @@ public void executeAsync() { protected void postExecute() { super.postExecute(); - if (currentChatRoom == null) { + if (groupChatDialog == null) { return; } @@ -1124,12 +1119,12 @@ public void execute() { 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")); @@ -1156,18 +1151,15 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { - 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 +1177,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 +1205,7 @@ public void executeAsync() { int dialogsCount = -1; try { - dialogsCount = QBChatService.getChatDialogsCount(requestBuilder, bundle); + dialogsCount = QBRestChatService.getChatDialogsCount(requestBuilder, bundle).perform(); } catch (QBResponseException e) { setException(e); } @@ -1224,7 +1218,7 @@ public void executeAsync() { Snippet createDialog = new Snippet("Create Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1233,7 +1227,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 +1251,9 @@ 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) { Log.i(TAG, "dialog: " + dialog); Log.i(TAG, "arr: " + dialog.getCustomData().getArray("arr")); Log.i(TAG, "bbb: " + dialog.getCustomData().getBoolean("bbb")); @@ -1286,7 +1280,7 @@ public void onError(QBResponseException errors) { Snippet createDialogSynchronous = new SnippetAsync("Create Dialog (synchronous)", context) { @Override public void executeAsync() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1295,7 +1289,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,12 +1298,12 @@ 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)); - QBDialog createdDialog = null; + QBChatDialog createdDialog = null; try { - createdDialog = groupChatManager.createDialog(dialog); + createdDialog = QBRestChatService.createChatDialog(dialog).perform(); } catch (QBResponseException e) { setException(e); } @@ -1323,7 +1317,7 @@ public void executeAsync() { Snippet updateDialog = new Snippet("Update Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1331,7 +1325,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 +1340,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 +1371,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 +1388,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 +1405,14 @@ public void executeAsync() { Snippet deleteDialog = new Snippet("Delete Dialog") { @Override public void execute() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().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 +1430,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { - if (groupChatManager == null) { + if (!QBChatService.getInstance().isLoggedIn()) { log("Please login first"); return; } @@ -1444,7 +1438,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 +1450,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) { @@ -1502,16 +1496,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 +1526,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 +1548,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 +1564,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 +1587,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 +1613,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 +1646,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 1a80805c5..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); } @@ -557,7 +557,7 @@ public void execute() { // 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); } From c8ce2493ca8b9723ef1284a9b0a090dcf8e5f28a Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 5 Oct 2016 10:55:44 +0300 Subject: [PATCH 38/55] - fixed ANDSAMPLES-331 --- .../sample/chat/ui/activity/ChatActivity.java | 1 + .../sample/chat/ui/activity/DialogsActivity.java | 2 ++ .../sample/chat/utils/qb/QbDialogHolder.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) 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 a9aa729f9..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 @@ -199,6 +199,7 @@ private void leaveGroupChat() { @Override public void onSuccess(QBChatDialog qbDialog, Bundle bundle) { ProgressDialogFragment.hide(getSupportFragmentManager()); + QbDialogHolder.getInstance().deleteDialog(qbDialog); finish(); } 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 9065a3ebd..65a6fc2a9 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 @@ -191,6 +191,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { updateDialogsList(); } } + } else { + updateDialogsAdapter(); } } 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 c92a13307..db5f022cc 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 @@ -52,16 +52,24 @@ public void addDialogs(List dialogs) { public void deleteDialogs(Collection dialogs) { for (QBChatDialog dialog : dialogs) { - dialogsMap.remove(dialog.getDialogId()); + deleteDialog(dialog); } } public void deleteDialogs(ArrayList dialogsIds) { for (String dialogId : dialogsIds) { - dialogsMap.remove(dialogId); + deleteDialog(dialogId); } } + 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); } From 09bb942868522133431f5f83fc980266e85cea33 Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 5 Oct 2016 12:05:18 +0300 Subject: [PATCH 39/55] - fixed ANDSAMPLES-328 --- .../chat/ui/adapter/DialogsAdapter.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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 afb327374..a4bfde4d9 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 @@ -19,6 +19,9 @@ public class DialogsAdapter extends BaseSelectableListAdapter { + private final String NULL_TEXT = "null"; + private final String EMPTY_STRING = ""; + public DialogsAdapter(Context context, List dialogs) { super(context, dialogs); } @@ -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) { @@ -74,7 +73,22 @@ public View getView(int position, View convertView, ViewGroup parent) { private boolean isLastMessageAttachment(QBChatDialog dialog) { String lastMessage = dialog.getLastMessage(); Integer lastMessageSenderId = dialog.getLastMessageUserId(); - return TextUtils.isEmpty(lastMessage) && lastMessageSenderId != null; + return (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 textIsNull(chatDialog.getLastMessage()) ? EMPTY_STRING : chatDialog.getLastMessage(); + } + + return EMPTY_STRING; + } + + //temp fix before fixing in SDK + private boolean textIsNull(String text){ + return NULL_TEXT.equals(text); } private static class ViewHolder { From d152eedbef07e7ae3c372b344c8df2a09f571a2f Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 5 Oct 2016 16:09:48 +0300 Subject: [PATCH 40/55] - fixed ANDSAMPLES-334 --- .../chat/ui/activity/DialogsActivity.java | 21 ++++++++++++++----- .../sample/chat/utils/chat/ChatHelper.java | 2 +- .../sample/chat/utils/qb/QbDialogHolder.java | 17 +++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) 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 65a6fc2a9..a8cdc66aa 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 @@ -41,7 +41,6 @@ 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; @@ -49,8 +48,6 @@ 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; @@ -177,11 +174,18 @@ 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); + if (isTryCreateExistingPrivateDialog(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) { String dialogId = data.getStringExtra(ChatActivity.EXTRA_DIALOG_ID); @@ -196,6 +200,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } + private boolean isTryCreateExistingPrivateDialog(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 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 1b88dc204..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 @@ -178,7 +178,7 @@ 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(), true) + QBRestChatService.deleteDialog(qbDialog.getDialogId(), false) .performAsync(new QbEntityCallbackWrapper(callback)); } } 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 db5f022cc..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 @@ -2,6 +2,8 @@ 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; @@ -74,6 +76,21 @@ 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); From 57c21697c96a596f9c5aeba8db5d39a71e8a1399 Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 5 Oct 2016 16:19:42 +0300 Subject: [PATCH 41/55] - changed version of designVersion to 23.1.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 41efb5688..b233e06b6 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ ext { appcompatV7Version = '23.1.1' recyclerviewV7Version = '23.2.1' supportAnnotationsVersion = '23.1.1' - designVersion = '24.1.1' + designVersion = '23.1.1' uilVersion = '1.9.0' glideVersion = '3.6.1' From a1c6ce9b857c9d97c78794693e08f561dd9c4dc8 Mon Sep 17 00:00:00 2001 From: Tereha Date: Wed, 5 Oct 2016 16:21:45 +0300 Subject: [PATCH 42/55] - fixed ANDSAMPLES-333 --- .../com/quickblox/sample/chat/ui/activity/DialogsActivity.java | 1 + 1 file changed, 1 insertion(+) 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 a8cdc66aa..f6e1e062e 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 @@ -502,6 +502,7 @@ public void onReceive(Context context, Intent intent) { // Get extra data included in the Intent String message = intent.getStringExtra(GcmConsts.EXTRA_GCM_MESSAGE); Log.v(TAG, "Received broadcast " + intent.getAction() + " with data: " + message); + requestBuilder.setSkip(skipRecords = 0); loadDialogsFromQb(true, true); } } From 411f8bde13032afd6e0c2ecfc74b7b9a3528d3ee Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 10:52:37 +0300 Subject: [PATCH 43/55] fixed errors for building --- build.gradle | 2 +- snippets/build.gradle | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 41efb5688..b233e06b6 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ ext { appcompatV7Version = '23.1.1' recyclerviewV7Version = '23.2.1' supportAnnotationsVersion = '23.1.1' - designVersion = '24.1.1' + designVersion = '23.1.1' uilVersion = '1.9.0' glideVersion = '3.6.1' diff --git a/snippets/build.gradle b/snippets/build.gradle index a01689f57..d724270ad 100644 --- a/snippets/build.gradle +++ b/snippets/build.gradle @@ -41,23 +41,6 @@ android { } } - productFlavors { - // JAR - online { - - } - - // AAR - onlineAar { - - } - - // for development - offlineDev { - - } - } - lintOptions { abortOnError false } From 180d3413aa8cdcbb35f53efd8a59a141380e2ef3 Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 6 Oct 2016 11:15:39 +0300 Subject: [PATCH 44/55] - fixed ANDSAMPLES-341 --- .../com/quickblox/sample/chat/ui/activity/DialogsActivity.java | 3 +++ 1 file changed, 3 insertions(+) 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 f6e1e062e..ba940b30f 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 @@ -391,6 +391,7 @@ public void onError(QBResponseException e) { } private void loadDialogsFromQb(final boolean silentUpdate, final boolean clearDialogHolder) { + isProcessingResultInProgress = true; if (!silentUpdate) { progressBar.setVisibility(View.VISIBLE); } @@ -398,6 +399,7 @@ private void loadDialogsFromQb(final boolean silentUpdate, final boolean clearDi ChatHelper.getInstance().getDialogs(requestBuilder, new QBEntityCallback>() { @Override public void onSuccess(ArrayList dialogs, Bundle bundle) { + isProcessingResultInProgress = false; progressBar.setVisibility(View.GONE); setOnRefreshListener.setRefreshing(false); @@ -410,6 +412,7 @@ public void onSuccess(ArrayList dialogs, Bundle bundle) { @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(); From 8c1168da10d4b4d7e2d5cb0df03240b0d9a69200 Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 6 Oct 2016 17:01:09 +0300 Subject: [PATCH 45/55] - code refactoring --- .../sdk/snippets/modules/SnippetsChat.java | 209 +++++++++++------- snippets/src/main/res/raw/servers.json | 3 +- 2 files changed, 127 insertions(+), 85 deletions(-) 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 bcbfdf3b0..723c2a74f 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java @@ -5,6 +5,7 @@ import android.util.Log; import com.quickblox.auth.QBAuth; +import com.quickblox.chat.JIDHelper; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBMessageStatusesManager; import com.quickblox.chat.QBPingManager; @@ -229,7 +230,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); @@ -290,29 +296,33 @@ private void initGlobalMessageListener() { globalChatDialogMessageListener = new QBChatDialogMessageListener() { @Override public void processMessage(String dialogId, QBChatMessage qbChatMessage, Integer senderId) { - try { - chatDialog = QBRestChatService.getChatDialogById(dialogId).perform(); - log(chatDialog.getType().toString() + "chat with id " + chatDialog.getDialogId() + " downloaded"); - } catch (QBResponseException e) { - e.printStackTrace(); - } + 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); + } + } - 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); - } + @Override + public void onError(QBResponseException e) { + log("Error loading dialog " + chatDialog.getDialogId() + " from global message listener"); + } + }); } @Override public void processError(String dialogId, QBChatException e, QBChatMessage qbChatMessage, Integer senderId) { - + log("Received error message to message listener"); } }; @@ -634,48 +644,54 @@ public void processError(QBChatException e, QBChatMessage qbChatMessage) { Snippet sendPrivateMessageExtended = new Snippet("send private message") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } - 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); + // 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); - QBChatDialog privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); + final QBChatDialog[] privateChatDialog = new QBChatDialog[1]; - if (privateChatDialog != null) { - privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); - privateChatDialog.addMessageSentListener(privateChatDialogMessageSentListener); + QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + privateChatDialog[0] = chatDialog; + privateChatDialog[0].addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog[0].addMessageSentListener(privateChatDialogMessageSentListener); + + try { + privateChatDialog[0].sendMessage(chatMessage); + } catch (SmackException.NotConnectedException e) { + log("send message error: " + e.getClass().getSimpleName()); + } } - privateChatDialog.sendMessage(chatMessage); - } catch (SmackException.NotConnectedException e) { - log("send message error: " + e.getClass().getSimpleName()); - } catch (QBResponseException e) { - log("getting private chat dialog error: " + e.getClass().getSimpleName()); - e.printStackTrace(); - } + @Override + public void onError(QBResponseException e) { + + } + }); } }; @@ -688,24 +704,29 @@ public void execute() { Snippet sendIsTypingInPrivateChat = new Snippet("send is typing (private chat)") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } - QBChatDialog privateChatDialog = null; - try { - privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog( - ApplicationConfig.getInstance().getTestUserId2())).perform(); - if (privateChatDialog != null) { - privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); - privateChatDialog.sendIsTypingNotification(); + QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + chatDialog.addIsTypingListener(privateChatDialogTypingListener); + + try { + chatDialog.sendIsTypingNotification(); + log("typing notification was sent"); + } catch (XMPPException | SmackException.NotConnectedException e) { + log("send typing error: " + e.getClass().getSimpleName()); + } } - } catch (QBResponseException | SmackException.NotConnectedException e) { - log("send typing error: " + e.getClass().getSimpleName()); - } catch (XMPPException e) { - e.printStackTrace(); - } + + @Override + public void onError(QBResponseException e) { + log("Error getting dialog " + e.getClass().getSimpleName()); + } + }); } }; @@ -717,19 +738,23 @@ public void execute() { return; } - QBChatDialog privateChatDialog = null; - try { - privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog( - ApplicationConfig.getInstance().getTestUserId2())).perform(); - if (privateChatDialog != null) { - privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); - privateChatDialog.sendStopTypingNotification(); + QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + chatDialog.addIsTypingListener(privateChatDialogTypingListener); + try { + chatDialog.sendStopTypingNotification(); + log("stop typing notification was sent"); + } catch (XMPPException | SmackException.NotConnectedException e) { + log("send stop typing error: " + e.getClass().getSimpleName()); + } } - } catch (QBResponseException | SmackException.NotConnectedException e) { - log("send stop typing error: " + e.getClass().getSimpleName()); - } catch (XMPPException e) { - e.printStackTrace(); - } + + @Override + public void onError(QBResponseException e) { + log("Error getting dialog " + e.getClass().getSimpleName()); + } + }); } }; @@ -906,22 +931,15 @@ public void processPresence(String s, QBPresence qbPresence) { Snippet joinRoom = new Snippet("join Room") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } - DiscussionHistory history = new DiscussionHistory(); + final DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(0); - try { - groupChatDialog = QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).perform(); - log("dialog ID: " + groupChatDialog.getDialogId()); - } catch (QBResponseException e) { - log("Getting dialog error: " + e.getClass().getSimpleName()); - } - - QBEntityCallback clbck = new QBEntityCallback() { + final QBEntityCallback clbck = new QBEntityCallback() { @Override public void onSuccess(Void result, Bundle bundle) { log("join Room success"); @@ -939,7 +957,22 @@ public void onError(final QBResponseException list) { } }; - groupChatDialog.join(history, clbck); + ArrayList occupantsIds = new ArrayList<>(); + occupantsIds.add(ApplicationConfig.getInstance().getTestUserId2()); + + QBRestChatService.createChatDialog(DialogUtils.buildDialog("Snippets dialog name", QBDialogType.GROUP, occupantsIds)) + .performAsync(new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { + groupChatDialog = chatDialog; + groupChatDialog.join(history, clbck); + } + + @Override + public void onError(QBResponseException e) { + log("Loading dialog for join error: " + e.getClass().getSimpleName()); + } + }); } }; @@ -1114,6 +1147,10 @@ protected void postExecute() { Snippet getDialogs = new Snippet("Get Dialogs") { @Override public void execute() { + if (!QBChatService.getInstance().isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + log("Please login first"); + return; + } QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.setLimit(100); @@ -1150,6 +1187,10 @@ public void onError(QBResponseException errors) { Snippet getDialogsSynchronous = new SnippetAsync("Get Dialogs (synchronous)", context) { @Override public void executeAsync() { + if (!QBChatService.getInstance().isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + log("Please login first"); + return; + } QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder(); requestBuilder.setLimit(100); diff --git a/snippets/src/main/res/raw/servers.json b/snippets/src/main/res/raw/servers.json index c213555c9..0189d2fe5 100644 --- a/snippets/src/main/res/raw/servers.json +++ b/snippets/src/main/res/raw/servers.json @@ -13,7 +13,8 @@ "test_user_id2": 11108871, "test_user_login2": "supersample-ios1", "test_user_password2": "supersample-ios1", - "dialog_id": "561cffc2a28f9a97ec0001d9" +// "dialog_id": "561cffc2a28f9a97ec0001d9" + "dialog_id": "56f3fac3a0eb4786ae00003f" } }, "active": "production", From f6e1fd8509993e4d8316ebdbadbb5dc6afcf4aaa Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 17:05:57 +0300 Subject: [PATCH 46/55] fixed errors for building --- sample-videochat-webrtc/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sample-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle index d49bf98a2..ceae13f5d 100755 --- a/sample-videochat-webrtc/build.gradle +++ b/sample-videochat-webrtc/build.gradle @@ -42,6 +42,10 @@ android { resValue "string", "versionName", "QuickBlox WebRTC\nBuild version " + defaultConfig.getVersionName() signingConfig signingConfigs.debug } + + release { + resValue "string", "versionName", "QuickBlox WebRTC\nBuild version " + defaultConfig.getVersionName() + } } signingConfigs { From 6cf4c4e4a2f15c08457b4369a8327334f70049db Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 6 Oct 2016 17:12:05 +0300 Subject: [PATCH 47/55] - fixed lead's flaws --- .../sample/chat/ui/activity/DialogsActivity.java | 4 ++-- .../sample/chat/ui/adapter/DialogsAdapter.java | 13 ++++--------- .../quickblox/sample/chat/utils/StringUtils.java | 9 +++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 sample-chat/src/main/java/com/quickblox/sample/chat/utils/StringUtils.java 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 ba940b30f..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 @@ -177,7 +177,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { ArrayList selectedUsers = (ArrayList) data .getSerializableExtra(SelectUsersActivity.EXTRA_QB_USERS); - if (isTryCreateExistingPrivateDialog(selectedUsers)){ + if (isPrivateDialogExist(selectedUsers)){ selectedUsers.remove(ChatHelper.getCurrentUser()); QBChatDialog existingPrivateDialog = QbDialogHolder.getInstance().getPrivateDialogWithUser(selectedUsers.get(0)); isProcessingResultInProgress = false; @@ -200,7 +200,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } - private boolean isTryCreateExistingPrivateDialog(ArrayList allSelectedUsers){ + private boolean isPrivateDialogExist(ArrayList allSelectedUsers){ ArrayList selectedUsers = new ArrayList<>(); selectedUsers.addAll(allSelectedUsers); selectedUsers.remove(ChatHelper.getCurrentUser()); 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 a4bfde4d9..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 @@ -10,6 +10,7 @@ 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; @@ -19,8 +20,7 @@ public class DialogsAdapter extends BaseSelectableListAdapter { - private final String NULL_TEXT = "null"; - private final String EMPTY_STRING = ""; + private static final String EMPTY_STRING = ""; public DialogsAdapter(Context context, List dialogs) { super(context, dialogs); @@ -73,24 +73,19 @@ public View getView(int position, View convertView, ViewGroup parent) { private boolean isLastMessageAttachment(QBChatDialog dialog) { String lastMessage = dialog.getLastMessage(); Integer lastMessageSenderId = dialog.getLastMessageUserId(); - return (textIsNull(lastMessage) || 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 textIsNull(chatDialog.getLastMessage()) ? EMPTY_STRING : chatDialog.getLastMessage(); + return StringUtils.textIsNull(chatDialog.getLastMessage()) ? EMPTY_STRING : chatDialog.getLastMessage(); } return EMPTY_STRING; } - //temp fix before fixing in SDK - private boolean textIsNull(String text){ - return NULL_TEXT.equals(text); - } - private static class ViewHolder { ViewGroup rootLayout; ImageView dialogImageView; 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); + } +} From 31ddacf9031db3c2ebc55705ed6e1922ddbc8ff9 Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 17:13:33 +0300 Subject: [PATCH 48/55] fixed errors for building --- sample-videochat-webrtc/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/sample-videochat-webrtc/build.gradle b/sample-videochat-webrtc/build.gradle index ceae13f5d..be8e9c33b 100755 --- a/sample-videochat-webrtc/build.gradle +++ b/sample-videochat-webrtc/build.gradle @@ -45,6 +45,7 @@ android { release { resValue "string", "versionName", "QuickBlox WebRTC\nBuild version " + defaultConfig.getVersionName() + signingConfig signingConfigs.debug } } From 8a85f4b8093bf07657fa3f66fd892743d17b0151 Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 17:46:36 +0300 Subject: [PATCH 49/55] fixed errors for building --- sample-chat/build.gradle | 20 ++++++++++++++++++++ sample-chat/src/main/AndroidManifest.xml | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 1c8100f61..41aef1c94 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 @@ -29,6 +45,10 @@ android { proguardFile 'proguard-rules.pro' zipAlignEnabled false } + + release { + signingConfig signingConfigs.debug + } } signingConfigs { 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 @@ + + From 0c2001a43875c0f065fbed098589ca0a32efc9ff Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 17:54:15 +0300 Subject: [PATCH 50/55] fixed errors for building --- sample-chat/fabric.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 sample-chat/fabric.properties 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 From ef1bc1298eb41e8492722a9df7d1255c238c30b8 Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 18:34:26 +0300 Subject: [PATCH 51/55] fixed errors for building --- sample-chat/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 41aef1c94..1a5d412b0 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -64,6 +64,10 @@ android { abortOnError false } + crashlytics { + manifestPath = '/src/main/AndroidManifest.xml' + } + } From ffb699b72baaecc1abcdf8893044f78966b57eab Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 18:38:10 +0300 Subject: [PATCH 52/55] fixed errors for building --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index b233e06b6..895e3896f 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,10 @@ allprojects { url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/" } } + + crashlytics { + manifestPath = '/src/main/AndroidManifest.xml' + } } ext { From 3099465c95cf0ca0a357a347f5114688f06cf7b3 Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 18:40:50 +0300 Subject: [PATCH 53/55] fixed errors for building --- build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.gradle b/build.gradle index 895e3896f..1ce7ac317 100644 --- a/build.gradle +++ b/build.gradle @@ -17,9 +17,6 @@ allprojects { } } - crashlytics { - manifestPath = '/src/main/AndroidManifest.xml' - } } ext { From 505a52ae9d6ff5c4cd14617fe9d6d365862df164 Mon Sep 17 00:00:00 2001 From: vfite Date: Thu, 6 Oct 2016 18:43:29 +0300 Subject: [PATCH 54/55] fixed errors for building --- sample-chat/build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/sample-chat/build.gradle b/sample-chat/build.gradle index 1a5d412b0..b5deb52d6 100644 --- a/sample-chat/build.gradle +++ b/sample-chat/build.gradle @@ -64,9 +64,6 @@ android { abortOnError false } - crashlytics { - manifestPath = '/src/main/AndroidManifest.xml' - } } From d2c64289401861470b6e9367a8df9a15fa3067a7 Mon Sep 17 00:00:00 2001 From: Tereha Date: Thu, 6 Oct 2016 18:50:32 +0300 Subject: [PATCH 55/55] - reviewed SnippetsChat.java for adaptation to new chat API --- .../sdk/snippets/modules/SnippetsChat.java | 318 ++++++++++-------- 1 file changed, 174 insertions(+), 144 deletions(-) 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 723c2a74f..f713920d6 100644 --- a/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java +++ b/snippets/src/main/java/com/sdk/snippets/modules/SnippetsChat.java @@ -4,13 +4,10 @@ import android.os.Bundle; import android.util.Log; -import com.quickblox.auth.QBAuth; -import com.quickblox.chat.JIDHelper; import com.quickblox.chat.QBChatService; import com.quickblox.chat.QBMessageStatusesManager; import com.quickblox.chat.QBPingManager; import com.quickblox.chat.QBPrivacyListsManager; -import com.quickblox.chat.QBPrivateChat; import com.quickblox.chat.QBRestChatService; import com.quickblox.chat.QBRoster; import com.quickblox.chat.QBSystemMessagesManager; @@ -19,7 +16,6 @@ import com.quickblox.chat.listeners.QBChatDialogMessageSentListener; import com.quickblox.chat.listeners.QBChatDialogParticipantListener; import com.quickblox.chat.listeners.QBChatDialogTypingListener; -import com.quickblox.chat.listeners.QBMessageListener; import com.quickblox.chat.listeners.QBMessageStatusListener; import com.quickblox.chat.listeners.QBPrivacyListListener; import com.quickblox.chat.listeners.QBRosterListener; @@ -80,7 +76,6 @@ public class SnippetsChat extends Snippets { //Chat API 3.0 - private QBChatDialog chatDialog; private QBChatDialog privateChatDialog; private QBChatDialog groupChatDialog; @@ -185,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); @@ -315,7 +314,7 @@ public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { @Override public void onError(QBResponseException e) { - log("Error loading dialog " + chatDialog.getDialogId() + " from global message listener"); + log("Error loading dialog from global message listener: " + e); } }); } @@ -647,6 +646,8 @@ public void execute() { if (!chatService.isLoggedIn()) { log("Please login first"); return; + } else if (privateChatDialog == null){ + log("Please create private dialog first"); } // create a message @@ -671,27 +672,14 @@ public void execute() { attachment2.setUrl("www.video.com"); chatMessage.addAttachment(attachment2); - final QBChatDialog[] privateChatDialog = new QBChatDialog[1]; - - QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - privateChatDialog[0] = chatDialog; - privateChatDialog[0].addIsTypingListener(privateChatDialogTypingListener); - privateChatDialog[0].addMessageSentListener(privateChatDialogMessageSentListener); + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); + privateChatDialog.addMessageSentListener(privateChatDialogMessageSentListener); - try { - privateChatDialog[0].sendMessage(chatMessage); - } catch (SmackException.NotConnectedException e) { - log("send message error: " + e.getClass().getSimpleName()); - } - } - - @Override - public void onError(QBResponseException e) { - - } - }); + try { + privateChatDialog.sendMessage(chatMessage); + } catch (SmackException.NotConnectedException e) { + log("send message error: " + e.getClass().getSimpleName()); + } } }; @@ -700,68 +688,44 @@ public void onError(QBResponseException e) { ////////////////////////////////////// Typing notifications ////////////////////////////////////////// // - Snippet sendIsTypingInPrivateChat = new Snippet("send is typing (private chat)") { @Override public void execute() { - if (!chatService.isLoggedIn()) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - chatDialog.addIsTypingListener(privateChatDialogTypingListener); - - try { - chatDialog.sendIsTypingNotification(); - log("typing notification was sent"); - } catch (XMPPException | SmackException.NotConnectedException e) { - log("send typing error: " + e.getClass().getSimpleName()); - } - } + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); - @Override - public void onError(QBResponseException e) { - log("Error getting dialog " + e.getClass().getSimpleName()); - } - }); + try { + privateChatDialog.sendIsTypingNotification(); + } catch (XMPPException | SmackException.NotConnectedException e) { + log("send typing error: " + e.getClass().getSimpleName()); + } } }; Snippet sendStopTypingInPrivateChat = new Snippet("send stop typing (private chat)") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).performAsync(new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - chatDialog.addIsTypingListener(privateChatDialogTypingListener); - try { - chatDialog.sendStopTypingNotification(); - log("stop typing notification was sent"); - } catch (XMPPException | SmackException.NotConnectedException e) { - log("send stop typing error: " + e.getClass().getSimpleName()); - } - } + privateChatDialog.addIsTypingListener(privateChatDialogTypingListener); - @Override - public void onError(QBResponseException e) { - log("Error getting dialog " + e.getClass().getSimpleName()); - } - }); + try { + privateChatDialog.sendStopTypingNotification(); + } catch (XMPPException | SmackException.NotConnectedException e) { + log("send stop typing error: " + e.getClass().getSimpleName()); + } } }; Snippet sendIsTypingInGroupChat = new Snippet("send is typing (group chat)") { @Override public void execute() { - if (groupChatDialog == null) { + if (groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -779,7 +743,7 @@ public void execute() { Snippet sendStopTypingInGroupChat = new Snippet("send stop typing (group chat)") { @Override public void execute() { - if (groupChatDialog == null) { + if (groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -799,28 +763,21 @@ public void execute() { /////////////////////////////////////// Read/Delivered ////////////////////////////////////////// // - Snippet readMessagePrivateChat = new Snippet("read message (private chat)") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBChatDialog privateChatDialog = null; - try { - privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); - - QBChatMessage status = new QBChatMessage(); - status.setId("267477ab5612312312414124"); - status.setDialogId("267477ab5612312312414124"); + QBChatMessage status = new QBChatMessage(); + status.setId("267477ab5612312312414124"); + status.setDialogId("267477ab5612312312414124"); + try { privateChatDialog.readMessage(status); - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NotConnectedException e) { log("read message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException | QBResponseException e) { - log("read message error: " + e.getClass().getSimpleName()); } } }; @@ -828,26 +785,18 @@ public void execute() { Snippet deliverMessagePrivateChat = new Snippet("deliver message (private chat)") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { - log("Please login first"); - return; + if (privateChatDialog == null){ + log("Please create private dialog first"); } - QBChatDialog privateChatDialog = null; + QBChatMessage status = new QBChatMessage(); + status.setId("267477ab5612312312414124"); + status.setDialogId("267477ab5612312312414124"); try { - privateChatDialog = QBRestChatService.createChatDialog(DialogUtils.buildPrivateDialog(ApplicationConfig.getInstance().getTestUserId2())).perform(); - - - QBChatMessage status = new QBChatMessage(); - status.setId("267477ab5612312312414124"); - status.setDialogId("267477ab5612312312414124"); - privateChatDialog.deliverMessage(status); - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NotConnectedException e) { log("deliver message error: " + e.getLocalizedMessage()); - } catch (SmackException.NotConnectedException | QBResponseException e) { - log("deliver message error: " + e.getClass().getSimpleName()); } } }; @@ -855,7 +804,7 @@ public void execute() { Snippet readMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (groupChatDialog == null) { + if (!groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -878,7 +827,7 @@ public void execute() { Snippet deliverMessageGroupChat = new Snippet("deliver message (group chat)") { @Override public void execute() { - if (groupChatDialog == null) { + if (!groupChatDialog.isJoined()) { log("Please join room first"); return; } @@ -931,8 +880,8 @@ public void processPresence(String s, QBPresence qbPresence) { Snippet joinRoom = new Snippet("join Room") { @Override public void execute() { - if (!chatService.isLoggedIn()) { - log("Please login first"); + if (groupChatDialog == null) { + log("Please create group dialog first"); return; } @@ -957,34 +906,18 @@ public void onError(final QBResponseException list) { } }; - ArrayList occupantsIds = new ArrayList<>(); - occupantsIds.add(ApplicationConfig.getInstance().getTestUserId2()); - - QBRestChatService.createChatDialog(DialogUtils.buildDialog("Snippets dialog name", QBDialogType.GROUP, occupantsIds)) - .performAsync(new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog chatDialog, Bundle bundle) { - groupChatDialog = chatDialog; - groupChatDialog.join(history, clbck); - } - - @Override - public void onError(QBResponseException e) { - log("Loading dialog for join error: " + e.getClass().getSimpleName()); - } - }); + groupChatDialog.join(history, clbck); } }; Snippet joinRoomSynchronous = new SnippetAsync("join Room (synchronous)", context) { @Override public void executeAsync() { - if (!QBChatService.getInstance().isLoggedIn()) { - log("Please login first"); + if (groupChatDialog == null) { + log("Please create group dialog first"); return; } - DiscussionHistory history = new DiscussionHistory(); history.setMaxStanzas(10); @@ -1010,7 +943,7 @@ public void executeAsync() { protected void postExecute() { super.postExecute(); - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { return; } @@ -1028,6 +961,9 @@ protected void postExecute() { @Override public void execute() { if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } @@ -1051,11 +987,9 @@ public void execute() { Snippet sendMessageToRoomWithoutJoin = new Snippet("send message to room", "w/o join") { @Override public void execute() { - - try { - groupChatDialog = QBRestChatService.getChatDialogById(ApplicationConfig.getInstance().getTestDialogId()).perform(); - } catch (QBResponseException e) { - log("Getting dialog error: " + e.getClass().getSimpleName()); + if (groupChatDialog == null) { + log("Please create group dialog first"); + return; } groupChatDialog.addMessageListener(groupChatDialogMessageListener); @@ -1082,6 +1016,9 @@ public void execute() { @Override public void execute() { if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } @@ -1108,6 +1045,9 @@ public void execute() { @Override public void executeAsync() { if (groupChatDialog == null) { + log("Please create group dialog first"); + return; + } else if (!groupChatDialog.isJoined()){ log("Please join room first"); return; } @@ -1147,7 +1087,7 @@ protected void postExecute() { Snippet getDialogs = new Snippet("Get Dialogs") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + if (!chatService.isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 log("Please login first"); return; } @@ -1187,7 +1127,7 @@ public void onError(QBResponseException errors) { Snippet getDialogsSynchronous = new SnippetAsync("Get Dialogs (synchronous)", context) { @Override public void executeAsync() { - if (!QBChatService.getInstance().isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 + if (!chatService.isLoggedIn()){ //TODO VT need delete after fix QBANDRSDK-526 log("Please login first"); return; } @@ -1256,10 +1196,10 @@ public void executeAsync() { }; - Snippet createDialog = new Snippet("Create Dialog") { + Snippet createGroupDialog = new Snippet("Create Group Dialog") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } @@ -1295,6 +1235,7 @@ public void execute() { QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback() { @Override 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")); @@ -1318,7 +1259,7 @@ 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 (!QBChatService.getInstance().isLoggedIn()) { @@ -1341,20 +1282,113 @@ public void executeAsync() { data.put("data[name]", "bingo"); 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)); - QBChatDialog createdDialog = null; try { - createdDialog = QBRestChatService.createChatDialog(dialog).perform(); + 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() { @@ -1446,7 +1480,7 @@ public void executeAsync() { Snippet deleteDialog = new Snippet("Delete Dialog") { @Override public void execute() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } @@ -1471,7 +1505,7 @@ public void onError(QBResponseException errors) { @Override public void executeAsync() { - if (!QBChatService.getInstance().isLoggedIn()) { + if (!chatService.isLoggedIn()) { log("Please login first"); return; } @@ -1504,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) { @@ -1512,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) {