Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	settings.gradle
  • Loading branch information
Tereha authored and Tereha committed Oct 7, 2016
2 parents 791f1c1 + ca75b4a commit 7b4c12c
Show file tree
Hide file tree
Showing 61 changed files with 1,592 additions and 1,333 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand All @@ -16,6 +16,7 @@ allprojects {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}

}

ext {
Expand All @@ -31,9 +32,9 @@ ext {
lintAbortOnError = false

// QuickBlox SDK version
qbSdkVersion = '2.6.1'
qbSdkVersion = '3.0'

versionName = "2.6.1"
versionName = "3.0"

testRunnerVersion = "0.4.1"

Expand Down
28 changes: 26 additions & 2 deletions sample-chat/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +25,7 @@ android {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 201
versionName "2.0.3"
versionName "3.0"
}

productFlavors {
Expand All @@ -29,6 +45,10 @@ android {
proguardFile 'proguard-rules.pro'
zipAlignEnabled false
}

release {
signingConfig signingConfigs.debug
}
}

signingConfigs {
Expand All @@ -40,6 +60,11 @@ android {
}
}

lintOptions {
abortOnError false
}


}


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

apply from: "../artifacts.gradle"
Expand Down
3 changes: 3 additions & 0 deletions sample-chat/fabric.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions sample-chat/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="7aea78439bec41a9005c7488bb6751c5e33fe270" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.quickblox.sample.chat.managers;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import com.quickblox.chat.QBChatService;
import com.quickblox.chat.QBSystemMessagesManager;
import com.quickblox.chat.model.QBChatDialog;
import com.quickblox.chat.model.QBChatMessage;
import com.quickblox.chat.model.QBDialogType;
import com.quickblox.sample.chat.utils.chat.ChatHelper;
import com.quickblox.sample.chat.utils.qb.QbDialogHolder;
import com.quickblox.sample.chat.utils.qb.QbDialogUtils;
import com.quickblox.sample.chat.utils.qb.callback.QbEntityCallbackImpl;
import com.quickblox.users.model.QBUser;

import org.jivesoftware.smack.SmackException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class DialogsManager {

public static final String PROPERTY_OCCUPANTS_IDS = "occupants_ids";
public static final String PROPERTY_DIALOG_TYPE = "dialog_type";
public static final String PROPERTY_DIALOG_NAME = "dialog_name";
public static final String PROPERTY_NOTIFICATION_TYPE = "notification_type";
public static final String CREATING_DIALOG = "creating_dialog";

private Set<ManagingDialogsCallbacks> managingDialogsCallbackListener = new CopyOnWriteArraySet<>();

private boolean isMessageCreatingDialog(QBChatMessage systemMessage){
return CREATING_DIALOG.equals(systemMessage.getProperty(PROPERTY_NOTIFICATION_TYPE));
}

private QBChatMessage buildSystemMessageAboutCreatingGroupDialog(QBChatDialog dialog){
QBChatMessage qbChatMessage = new QBChatMessage();
qbChatMessage.setDialogId(dialog.getDialogId());
qbChatMessage.setProperty(PROPERTY_OCCUPANTS_IDS, QbDialogUtils.getOccupantsIdsStringFromList(dialog.getOccupants()));
qbChatMessage.setProperty(PROPERTY_DIALOG_TYPE, String.valueOf(dialog.getType().getCode()));
qbChatMessage.setProperty(PROPERTY_DIALOG_NAME, String.valueOf(dialog.getName()));
qbChatMessage.setProperty(PROPERTY_NOTIFICATION_TYPE, CREATING_DIALOG);

return qbChatMessage;
}

private QBChatDialog buildChatDialogFromSystemMessage(QBChatMessage qbChatMessage){
QBChatDialog chatDialog = new QBChatDialog();
chatDialog.setDialogId(qbChatMessage.getDialogId());
chatDialog.setOccupantsIds(QbDialogUtils.getOccupantsIdsListFromString((String) qbChatMessage.getProperty(PROPERTY_OCCUPANTS_IDS)));
chatDialog.setType(QBDialogType.parseByCode(Integer.parseInt(qbChatMessage.getProperty(PROPERTY_DIALOG_TYPE).toString())));
chatDialog.setName(qbChatMessage.getProperty(PROPERTY_DIALOG_NAME).toString());
chatDialog.setUnreadMessageCount(0);

return chatDialog;
}

public void sendSystemMessageAboutCreatingDialog(QBSystemMessagesManager systemMessagesManager, QBChatDialog dialog) {
QBChatMessage systemMessageCreatingDialog = buildSystemMessageAboutCreatingGroupDialog(dialog);

try {
for (Integer recipientId : dialog.getOccupants()) {
if (!recipientId.equals(QBChatService.getInstance().getUser().getId())) {
systemMessageCreatingDialog.setRecipientId(recipientId);
systemMessagesManager.sendSystemMessage(systemMessageCreatingDialog);
}
}
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}

private void loadUsersFromDialog(QBChatDialog chatDialog){
ChatHelper.getInstance().getUsersFromDialog(chatDialog, new QbEntityCallbackImpl<ArrayList<QBUser>>());
}

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<QBChatDialog>() {
@Override
public void onSuccess(QBChatDialog chatDialog, Bundle bundle) {
loadUsersFromDialog(chatDialog);
QbDialogHolder.getInstance().addDialog(chatDialog);
notifyListenersNewDialogLoaded(chatDialog);
}
});
}
}
}

public void onSystemMessageReceived(QBChatMessage systemMessage){
if (isMessageCreatingDialog(systemMessage)) {
QBChatDialog chatDialog = buildChatDialogFromSystemMessage(systemMessage);
chatDialog.initForChat(QBChatService.getInstance());
QbDialogHolder.getInstance().addDialog(chatDialog);
notifyListenersDialogCreated(chatDialog);
}
}

private void notifyListenersDialogCreated(final QBChatDialog chatDialog){
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
listener.onDialogCreated(chatDialog);
}
}
});
}

private void notifyListenersDialogUpdated(final String dialogId){
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
listener.onDialogUpdated(dialogId);
}
}
});
}

private void notifyListenersNewDialogLoaded(final QBChatDialog chatDialog){
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
for (ManagingDialogsCallbacks listener : getManagingDialogsCallbackListeners()){
listener.onNewDialogLoaded(chatDialog);
}
}
});
}

public void addManagingDialogsCallbackListener(ManagingDialogsCallbacks listener){
if (listener != null){
managingDialogsCallbackListener.add(listener);
}
}

public void removeManagingDialogsCallbackListener(ManagingDialogsCallbacks listener) {
managingDialogsCallbackListener.remove(listener);
}

public Collection<ManagingDialogsCallbacks> getManagingDialogsCallbackListeners() {
return Collections.unmodifiableCollection(managingDialogsCallbackListener);
}

public interface ManagingDialogsCallbacks{

void onDialogCreated(QBChatDialog chatDialog);

void onDialogUpdated(String chatDialog);

void onNewDialogLoaded(QBChatDialog chatDialog);
}
}
Loading

0 comments on commit 7b4c12c

Please sign in to comment.