Skip to content

Commit 7b4c12c

Browse files
TerehaTereha
authored andcommitted
Merge remote-tracking branch 'origin/development'
# Conflicts: # settings.gradle
2 parents 791f1c1 + ca75b4a commit 7b4c12c

File tree

61 files changed

+1592
-1333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1592
-1333
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
}
55

66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.1.3'
7+
classpath 'com.android.tools.build:gradle:2.2.0'
88
classpath 'com.google.gms:google-services:2.0.0-beta2'
99
}
1010
}
@@ -16,6 +16,7 @@ allprojects {
1616
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
1717
}
1818
}
19+
1920
}
2021

2122
ext {
@@ -31,9 +32,9 @@ ext {
3132
lintAbortOnError = false
3233

3334
// QuickBlox SDK version
34-
qbSdkVersion = '2.6.1'
35+
qbSdkVersion = '3.0'
3536

36-
versionName = "2.6.1"
37+
versionName = "3.0"
3738

3839
testRunnerVersion = "0.4.1"
3940

sample-chat/build.gradle

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1+
buildscript {
2+
repositories {
3+
maven { url 'https://maven.fabric.io/public' }
4+
}
5+
6+
dependencies {
7+
classpath 'io.fabric.tools:gradle:1.20.1'
8+
}
9+
}
10+
11+
112
apply plugin: 'com.android.application'
13+
apply plugin: 'io.fabric'
14+
15+
repositories {
16+
maven { url 'https://maven.fabric.io/public' }
17+
}
218

319
android {
420
compileSdkVersion rootProject.compileSdkVersion
@@ -9,7 +25,7 @@ android {
925
minSdkVersion rootProject.minSdkVersion
1026
targetSdkVersion rootProject.targetSdkVersion
1127
versionCode 201
12-
versionName "2.0.3"
28+
versionName "3.0"
1329
}
1430

1531
productFlavors {
@@ -29,6 +45,10 @@ android {
2945
proguardFile 'proguard-rules.pro'
3046
zipAlignEnabled false
3147
}
48+
49+
release {
50+
signingConfig signingConfigs.debug
51+
}
3252
}
3353

3454
signingConfigs {
@@ -40,6 +60,11 @@ android {
4060
}
4161
}
4262

63+
lintOptions {
64+
abortOnError false
65+
}
66+
67+
4368
}
4469

4570

@@ -52,7 +77,6 @@ dependencies {
5277
compile "com.google.android.gms:play-services-gcm:${rootProject.playServicesVersion}"
5378
compile "com.github.bumptech.glide:glide:${rootProject.glideVersion}"
5479
compile "se.emilsjolander:stickylistheaders:${rootProject.stickyListHeaders}"
55-
compile 'com.google.android.gms:play-services-gcm:8.4.0'
5680
}
5781

5882
apply from: "../artifacts.gradle"

sample-chat/fabric.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public.
2+
#Wed Mar 25 11:57:04 GMT+02:00 2015
3+
apiSecret=343e58f13448a59778de3a8f630a0bd4a03803d1ae397818fbe2e76c66d09398

sample-chat/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,9 @@
9393
<meta-data
9494
android:name="com.google.android.gms.version"
9595
android:value="@integer/google_play_services_version" />
96+
97+
<meta-data
98+
android:name="io.fabric.ApiKey"
99+
android:value="7aea78439bec41a9005c7488bb6751c5e33fe270" />
96100
</application>
97101
</manifest>
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package com.quickblox.sample.chat.managers;
2+
3+
import android.os.Bundle;
4+
import android.os.Handler;
5+
import android.os.Looper;
6+
7+
import com.quickblox.chat.QBChatService;
8+
import com.quickblox.chat.QBSystemMessagesManager;
9+
import com.quickblox.chat.model.QBChatDialog;
10+
import com.quickblox.chat.model.QBChatMessage;
11+
import com.quickblox.chat.model.QBDialogType;
12+
import com.quickblox.sample.chat.utils.chat.ChatHelper;
13+
import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
14+
import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
15+
import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackImpl;
16+
import com.quickblox.users.model.QBUser;
17+
18+
import org.jivesoftware.smack.SmackException;
19+
20+
import java.util.ArrayList;
21+
import java.util.Collection;
22+
import java.util.Collections;
23+
import java.util.Set;
24+
import java.util.concurrent.CopyOnWriteArraySet;
25+
26+
public class DialogsManager {
27+
28+
public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids";
29+
public static final String PROPERTY_DIALOG_TYPE = "dialog_type";
30+
public static final String PROPERTY_DIALOG_NAME = "dialog_name";
31+
public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type";
32+
public static final String CREATING_DIALOG = "creating_dialog";
33+
34+
private Set<ManagingDialogsCallbacks> managingDialogsCallbackListener = new CopyOnWriteArraySet<>();
35+
36+
private boolean isMessageCreatingDialog(QBChatMessage systemMessage){
37+
return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE));
38+
}
39+
40+
private QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){
41+
QBChatMessage qbChatMessage = new QBChatMessage();
42+
qbChatMessage.setDialogId(dialog.getDialogId());
43+
qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, QbDialogUtils.getOccupantsIdsStringFromList(dialog.getOccupants()));
44+
qbChatMessage.setProperty(PROPERTY_DIALOG_TYPE, String.valueOf(dialog.getType().getCode()));
45+
qbChatMessage.setProperty(PROPERTY_DIALOG_NAME, String.valueOf(dialog.getName()));
46+
qbChatMessage.setProperty(PROPERTY_NOTIFICATION_TYPE, CREATING_DIALOG);
47+
48+
return qbChatMessage;
49+
}
50+
51+
private QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChatMessage){
52+
QBChatDialog chatDialog = new QBChatDialog();
53+
chatDialog.setDialogId(qbChatMessage.getDialogId());
54+
chatDialog.setOccupantsIds(QbDialogUtils.getOccupantsIdsListFromString((String) qbChatMessage.getProperty(PROPERTY_OCCUPANTS_IDS)));
55+
chatDialog.setType(QBDialogType.parseByCode(Integer.parseInt(qbChatMessage.getProperty(PROPERTY_DIALOG_TYPE).toString())));
56+
chatDialog.setName(qbChatMessage.getProperty(PROPERTY_DIALOG_NAME).toString());
57+
chatDialog.setUnreadMessageCount(0);
58+
59+
return chatDialog;
60+
}
61+
62+
public void sendSystemMessageAboutCreatingDialog(QBSystemMessagesManager systemMessagesManager, QBChatDialog dialog) {
63+
QBChatMessage systemMessageCreatingDialog = buildSystemMessageAboutCreatingGroupDialog(dialog);
64+
65+
try {
66+
for (Integer recipientId : dialog.getOccupants()) {
67+
if (!recipientId.equals(QBChatService.getInstance().getUser().getId())) {
68+
systemMessageCreatingDialog.setRecipientId(recipientId);
69+
systemMessagesManager.sendSystemMessage(systemMessageCreatingDialog);
70+
}
71+
}
72+
} catch (SmackException.NotConnectedException e) {
73+
e.printStackTrace();
74+
}
75+
}
76+
77+
private void loadUsersFromDialog(QBChatDialog chatDialog){
78+
ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl<ArrayList<QBUser>>());
79+
}
80+
81+
public void onGlobalMessageReceived(String dialogId, QBChatMessage chatMessage){
82+
if (chatMessage.getBody() != null && chatMessage.isMarkable()) { //for excluding status messages until will be released v.3.1
83+
if (QbDialogHolder.getInstance().hasDialogWithId(dialogId)) {
84+
QbDialogHolder.getInstance().updateDialog(dialogId, chatMessage);
85+
notifyListenersDialogUpdated(dialogId);
86+
} else {
87+
ChatHelper.getInstance().getDialogById(dialogId, new QbEntityCallbackImpl<QBChatDialog>() {
88+
@Override
89+
public void onSuccess(QBChatDialog chatDialog, Bundle bundle) {
90+
loadUsersFromDialog(chatDialog);
91+
QbDialogHolder.getInstance().addDialog(chatDialog);
92+
notifyListenersNewDialogLoaded(chatDialog);
93+
}
94+
});
95+
}
96+
}
97+
}
98+
99+
public void onSystemMessageReceived(QBChatMessage systemMessage){
100+
if (isMessageCreatingDialog(systemMessage)) {
101+
QBChatDialog chatDialog = buildChatDialogFromSystemMessage(systemMessage);
102+
chatDialog.initForChat(QBChatService.getInstance());
103+
QbDialogHolder.getInstance().addDialog(chatDialog);
104+
notifyListenersDialogCreated(chatDialog);
105+
}
106+
}
107+
108+
private void notifyListenersDialogCreated(final QBChatDialog chatDialog){
109+
new Handler(Looper.getMainLooper()).post(new Runnable() {
110+
@Override
111+
public void run() {
112+
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
113+
listener.onDialogCreated(chatDialog);
114+
}
115+
}
116+
});
117+
}
118+
119+
private void notifyListenersDialogUpdated(final String dialogId){
120+
new Handler(Looper.getMainLooper()).post(new Runnable() {
121+
@Override
122+
public void run() {
123+
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
124+
listener.onDialogUpdated(dialogId);
125+
}
126+
}
127+
});
128+
}
129+
130+
private void notifyListenersNewDialogLoaded(final QBChatDialog chatDialog){
131+
new Handler(Looper.getMainLooper()).post(new Runnable() {
132+
@Override
133+
public void run() {
134+
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
135+
listener.onNewDialogLoaded(chatDialog);
136+
}
137+
}
138+
});
139+
}
140+
141+
public void addManagingDialogsCallbackListener(ManagingDialogsCallbacks listener){
142+
if (listener != null){
143+
managingDialogsCallbackListener.add(listener);
144+
}
145+
}
146+
147+
public void removeManagingDialogsCallbackListener(ManagingDialogsCallbacks listener) {
148+
managingDialogsCallbackListener.remove(listener);
149+
}
150+
151+
public Collection<ManagingDialogsCallbacks> getManagingDialogsCallbackListeners() {
152+
return Collections.unmodifiableCollection(managingDialogsCallbackListener);
153+
}
154+
155+
public interface ManagingDialogsCallbacks{
156+
157+
void onDialogCreated(QBChatDialog chatDialog);
158+
159+
void onDialogUpdated(String chatDialog);
160+
161+
void onNewDialogLoaded(QBChatDialog chatDialog);
162+
}
163+
}

0 commit comments

Comments
 (0)