diff --git a/README.md b/README.md index d2c7534f..0483dd17 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # Mobile Messaging SDK for Android -[![Download](https://api.bintray.com/packages/infobip/maven/infobip-mobile-messaging-android-sdk/images/download.svg)](https://bintray.com/infobip/maven/infobip-mobile-messaging-android-sdk/_latestVersion) -[![License](https://img.shields.io/github/license/infobip/mobile-messaging-sdk-android.svg?label=License)](https://github.com/infobip/mobile-messaging-sdk-android/blob/master/LICENSE) +[![Download](https://api.bintray.com/packages/infobip/maven/infobip-mobile-messaging-huawei-sdk/images/download.svg)](https://bintray.com/infobip/maven/infobip-mobile-messaging-huawei-sdk/_latestVersion) +[![License](https://img.shields.io/github/license/infobip/mobile-messaging-sdk-huawei.svg?label=License)](https://github.com/infobip/mobile-messaging-sdk-huawei/blob/master/LICENSE) -Mobile Messaging SDK is designed and developed to easily enable push notification channel in your mobile application. In almost no time of implementation you get push notification in your application and access to the features of Infobip Mobile Apps Messaging. The document describes library integration steps. Additional information can be found in our Wiki. +Mobile Messaging SDK is designed and developed to easily enable push notification channel in your mobile application. In almost no time of implementation you get push notification in your application and access to the features of Infobip Mobile Apps Messaging. The document describes library integration steps. Additional information can be found in our Wiki. ## Requirements - Android Studio -- API Level: 14 (Android 4.0 - Ice Cream Sandwich) +- API Level: 19 (Android 4.4 - KitKat) +- [AppGallery](https://huaweimobileservices.com/appgallery/) ## Quick start guide @@ -17,22 +18,21 @@ Mobile Messaging SDK is designed and developed to easily enable push notificatio ```groovy dependencies { ... - implementation ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-sdk:2.4.0@aar') { + implementation ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-huawei-sdk:1.0.0@aar') { transitive = true } } ``` - Gradle dependencies -3. Add `Firebase Sender ID` and Infobip `Application Code` obtained in step 1 to `values/strings.xml` + +3. Add `HMS App ID` and Infobip `Application Code` obtained in step 1 to `values/strings.xml` ```groovy - SENDER ID + SENDER ID APPLICATION CODE ... ``` - String resources - Do not add `google_app_id` if you're using Google Services Gradle Plugin and `google-services.json`. + 4. Add code to `MainActivity#onCreate` ```java @@ -57,12 +57,11 @@ Mobile Messaging SDK is designed and developed to easily enable push notificatio > ### Notes > 1. All required manifest components are merged to application manifest automatically by manifest merger. Please include push-related components to manifest manually if manifest merger was disabled. -> 2. MobileMessaging library has geofencing service disabled by default. In order to opt-in the service, follow this guide. -> 3. Keep in mind that some proprietary android versions may restrict network traffic for your app. It may in turn affect delivery of push notifications. +> 2. Keep in mind that some proprietary android versions may restrict network traffic for your app. It may in turn affect delivery of push notifications.
-| If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue. | +| If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue. | |---| diff --git a/build.gradle b/build.gradle index 4f506219..99a01fd3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,6 @@ buildscript { } repositories { - jcenter() maven { url 'https://oss.jfrog.org/artifactory/plugins-release' credentials { @@ -13,13 +12,13 @@ buildscript { password = "${artifactoryPassword}" } } - maven { - url 'https://maven.google.com/' - name 'Google' - } + google() + jcenter() + // huawei maven + maven { url 'http://developer.huawei.com/repo/' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:3.6.2' classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.7' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } @@ -32,23 +31,20 @@ plugins { } ext { - mm_minSdkVersion = 14 + mm_minSdkVersion = 17 mm_compileSdkVersion = 28 mm_targetSdkVersion = 28 mm_buildToolsVersion = "28.0.3" mm_supportLibrariesVersion = "28.0.0" - mm_firebaseMessagingVersion = "17.6.0" - mm_gcmVersion = "16.1.0" - mm_gmsLocationVersion = "16.0.0" + mm_apiVersion = "3.0.4" } allprojects { repositories { + google() jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } + // huawei maven + maven { url 'http://developer.huawei.com/repo/' } } } @@ -104,7 +100,7 @@ task updateVersionInReadme { def readmeFile = new File('README.md') def text = readmeFile.text readmeFile.withWriter { w -> - w << text.replaceFirst('infobip-mobile-messaging-android-sdk:\\d+\\.\\d+\\.\\S+@aar', "infobip-mobile-messaging-android-sdk:$version@aar") + w << text.replaceFirst('infobip-mobile-messaging-huawei-sdk:\\d+\\.\\d+\\.\\S+@aar', "infobip-mobile-messaging-huawei-sdk:$version@aar") } } } diff --git a/gradle.properties b/gradle.properties index 1ea3d9c1..73954474 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,5 +17,5 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -version=2.5.0-SNAPSHOT +version=1.1.0-SNAPSHOT group=org.infobip.mobile.messaging.api diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2133a23c..3b46f6ea 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 16 17:44:32 CEST 2019 +#Tue Mar 31 11:01:47 MSK 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/TestBase.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/TestBase.java deleted file mode 100644 index 76f12983..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/TestBase.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import android.content.Intent; -import android.os.Bundle; -import android.support.annotation.NonNull; - -import org.infobip.mobile.messaging.BroadcastParameter; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.repository.MJSONObject; -import org.json.JSONException; -import org.mockito.ArgumentMatcher; -import org.skyscreamer.jsonassert.JSONAssert; - -import java.util.Objects; -import java.util.Set; - -import static junit.framework.Assert.assertEquals; -import static org.infobip.mobile.messaging.UserMapper.toJson; -import static org.mockito.Matchers.argThat; - -/** - * @author sslavin - * @since 10/10/2017. - */ - -public abstract class TestBase { - - protected Intent eqIntentWith(final ChatEvent action, final Bundle givenBundle) { - return argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - Intent intent = (Intent) argument; - return checkEquals(intent.getExtras(), givenBundle) - && action.getKey().equals(intent.getAction()); - } - }); - } - - @NonNull - protected Bundle givenBundle() { - Bundle bundle = new Bundle(); - bundle.putString("key", "value"); - return bundle; - } - - @NonNull - protected ChatMessage givenChatMessage() { - return new ChatMessage( - "messageId", - "body", - "chatId", - 1L, - 2L, - 3L, - "category", - "contentUrl", - givenChatParticipant(), - org.infobip.mobile.messaging.Message.Status.UNKNOWN, - MJSONObject.create("{'key':'value'}"), - true); - } - - @NonNull - protected ChatParticipant givenChatParticipant() { - return new ChatParticipant( - "participantId", - "firstName", - "lastName", - "middleName", - "email@email.com", - "1234567", - MJSONObject.create("{'key':'value'}")); - } - - protected Intent givenIntentWithUserData(User user) { - return new Intent(org.infobip.mobile.messaging.Event.USER_UPDATED.getKey()) - .putExtra(BroadcastParameter.EXTRA_USER, toJson(user)); - } - - protected void assertMessageEquals(ChatMessage expected, ChatMessage actual) throws JSONException { - assertEquals(expected.getId(), actual.getId()); - assertEquals(expected.getBody(), actual.getBody()); - assertEquals(expected.getChatId(), actual.getChatId()); - assertEquals(expected.getCreatedAt(), actual.getCreatedAt()); - assertEquals(expected.getReceivedAt(), actual.getReceivedAt()); - assertEquals(expected.getReadAt(), actual.getReadAt()); - assertParticipantEquals(expected.getAuthor(), actual.getAuthor()); - assertEquals(expected.getStatus(), actual.getStatus()); - JSONAssert.assertEquals(expected.getCustomData(), actual.getCustomData(), true); - } - - // region internal methods - - private void assertParticipantEquals(ChatParticipant expected, ChatParticipant actual) throws JSONException { - assertEquals(expected.getId(), actual.getId()); - assertEquals(expected.getFirstName(), actual.getFirstName()); - assertEquals(expected.getLastName(), actual.getLastName()); - assertEquals(expected.getMiddleName(), actual.getMiddleName()); - assertEquals(expected.getEmail(), actual.getEmail()); - assertEquals(expected.getGsm(), actual.getGsm()); - JSONAssert.assertEquals(expected.getCustomData(), actual.getCustomData(), true); - } - - private boolean checkEquals(Bundle first, Bundle second) { - Set aks = first.keySet(); - Set bks = second.keySet(); - - if (!aks.containsAll(bks)) { - return false; - } - - for (String key : aks) { - if (!Objects.equals(first.get(key), second.get(key))) { - return false; - } - } - - return true; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImplTest.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImplTest.java deleted file mode 100644 index 5634ebf9..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImplTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.infobip.mobile.messaging.chat.broadcast; - -import android.content.Context; -import android.os.Bundle; -import android.support.test.runner.AndroidJUnit4; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.ChatEvent; -import org.infobip.mobile.messaging.chat.MobileChat; -import org.infobip.mobile.messaging.chat.TestBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -/** - * @author sslavin - * @since 10/10/2017. - */ -@RunWith(AndroidJUnit4.class) -public class ChatBroadcasterImplTest extends TestBase { - - private Context contextMock; - private LocalBroadcastManagerWrapper localBroadcastManagerWrapperMock; - private ChatBundleMapper chatBundleMapperMock; - private ChatBroadcasterImpl implementation; - - @Before - public void before() { - chatBundleMapperMock = mock(ChatBundleMapper.class); - contextMock = mock(Context.class); - localBroadcastManagerWrapperMock = mock(LocalBroadcastManagerWrapper.class); - - implementation = new ChatBroadcasterImpl(contextMock, localBroadcastManagerWrapperMock, chatBundleMapperMock); - } - - @Test - public void should_call_mapper_and_broadcast_event_on_message_received() throws Exception { - ChatMessage givenMessage = givenChatMessage(); - final Bundle givenBundle = givenBundle(); - given(chatBundleMapperMock.chatMessageToBundle(any(ChatMessage.class))).willReturn(givenBundle); - - implementation.chatMessageReceived(givenMessage); - - then(chatBundleMapperMock).should(times(1)).chatMessageToBundle(eq(givenMessage)); - then(contextMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_RECEIVED, givenBundle)); - then(localBroadcastManagerWrapperMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_RECEIVED, givenBundle)); - } - - @Test - public void should_call_mapper_and_broadcast_event_on_message_sent() throws Exception { - ChatMessage givenMessage = givenChatMessage(); - final Bundle givenBundle = givenBundle(); - given(chatBundleMapperMock.chatMessageToBundle(any(ChatMessage.class))).willReturn(givenBundle); - - implementation.chatMessageSent(givenMessage); - - then(chatBundleMapperMock).should(times(1)).chatMessageToBundle(eq(givenMessage)); - then(contextMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_SENT, givenBundle)); - then(localBroadcastManagerWrapperMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_SENT, givenBundle)); - } - - @Test - public void should_call_mapper_and_broadcast_event_on_message_tapped() throws Exception { - ChatMessage givenMessage = givenChatMessage(); - final Bundle givenBundle = givenBundle(); - given(chatBundleMapperMock.chatMessageToBundle(any(ChatMessage.class))).willReturn(givenBundle); - - implementation.chatMessageTapped(givenMessage); - - then(chatBundleMapperMock).should(times(1)).chatMessageToBundle(eq(givenMessage)); - then(contextMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_TAPPED, givenBundle)); - then(localBroadcastManagerWrapperMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_TAPPED, givenBundle)); - } - - @Test - public void should_call_mapper_and_broadcast_event_on_action_tapped() throws Exception { - ChatMessage givenMessage = givenChatMessage(); - String givenActionId = "actionId"; - final Bundle givenBundle = givenBundle(); - Bundle givenBundleWithAction = new Bundle(givenBundle); - givenBundleWithAction.putString(MobileChat.EXTRA_ACTION_ID, givenActionId); - given(chatBundleMapperMock.chatMessageToBundle(any(ChatMessage.class))).willReturn(givenBundle); - - implementation.chatMessageViewActionTapped(givenMessage, givenActionId); - - then(chatBundleMapperMock).should(times(1)).chatMessageToBundle(eq(givenMessage)); - then(contextMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_VIEW_ACTION_TAPPED, givenBundleWithAction)); - then(localBroadcastManagerWrapperMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_MESSAGE_VIEW_ACTION_TAPPED, givenBundleWithAction)); - } - - @Test - public void should_call_mapper_and_broadcast_event_on_user_info_synchronized() throws Exception { - ChatParticipant givenParticipant = givenChatParticipant(); - final Bundle givenBundle = givenBundle(); - given(chatBundleMapperMock.chatParticipantToBundle(any(ChatParticipant.class))).willReturn(givenBundle); - - implementation.userInfoSynchronized(givenParticipant); - - then(chatBundleMapperMock).should(times(1)).chatParticipantToBundle(eq(givenParticipant)); - then(contextMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_USER_INFO_SYNCHRONIZED, givenBundle)); - then(localBroadcastManagerWrapperMock).should(times(1)).sendBroadcast(eqIntentWith(ChatEvent.CHAT_USER_INFO_SYNCHRONIZED, givenBundle)); - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImplTest.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImplTest.java deleted file mode 100644 index 7395b94c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImplTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.support.test.runner.AndroidJUnit4; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.TestBase; -import org.infobip.mobile.messaging.chat.repository.Message; -import org.infobip.mobile.messaging.chat.repository.MessageRepository; -import org.infobip.mobile.messaging.chat.repository.Participant; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepository; -import org.infobip.mobile.messaging.chat.repository.RepositoryMapper; -import org.json.JSONException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.assertEquals; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -/** - * @author sslavin - * @since 17/10/2017. - */ -@RunWith(AndroidJUnit4.class) -public class ChatMessageStorageImplTest extends TestBase { - - private ChatMessageStorageImpl chatMessageStorage; - private MessageRepository messageRepository; - private RepositoryMapper repositoryMapper; - - @Before - public void before() { - messageRepository = mock(MessageRepository.class); - repositoryMapper = mock(RepositoryMapper.class); - chatMessageStorage = new ChatMessageStorageImpl(messageRepository, mock(ParticipantRepository.class), repositoryMapper); - } - - @Test - public void should_find_all_messages_and_participants_in_repository() throws JSONException { - ChatMessage givenMessage = givenChatMessage(); - given(messageRepository.findAll()).willReturn(givenRepositoryMessages()); - given(repositoryMapper.chatMessageFromDbMessageAndParticipant(any(Message.class), any(Participant.class))) - .willReturn(givenMessage); - - List actualMessages = chatMessageStorage.findAllMessages(); - - assertEquals(1, actualMessages.size()); - assertMessageEquals(givenMessage, actualMessages.get(0)); - } - - @Test - public void should_count_all_messages_in_repository() { - long givenCount = 10; - given(messageRepository.countAll()).willReturn(givenCount); - - long actualCount = chatMessageStorage.countAllMessages(); - - assertEquals(givenCount, actualCount); - } - - @Test - public void should_find_one_message_in_repository() throws JSONException { - ChatMessage givenMessage = givenChatMessage(); - String givenMessageId = "messageId"; - given(messageRepository.findOne(anyString())).willReturn(givenRepositoryMessage()); - given(repositoryMapper.chatMessageFromDbMessageAndParticipant(any(Message.class), any(Participant.class))) - .willReturn(givenMessage); - - ChatMessage actualMessage = chatMessageStorage.findMessage(givenMessageId); - - then(messageRepository).should(times(1)).findOne(eq(givenMessageId)); - assertMessageEquals(givenMessage, actualMessage); - } - - @Test - public void should_delete_by_id() { - String givenId = "messageId"; - - chatMessageStorage.delete(givenId); - - then(messageRepository).should(times(1)).remove(eq("messageId")); - } - - @Test - public void should_delete_all() { - chatMessageStorage.deleteAll(); - - then(messageRepository).should(times(1)).clear(); - } - - // region private methods - - private List givenRepositoryMessages() { - return new ArrayList() {{ - add(givenRepositoryMessage()); - }}; - } - - private Message givenRepositoryMessage() { - return new Message(); - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiverTest.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiverTest.java deleted file mode 100644 index ff9b4bd5..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiverTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.content.Context; -import android.content.Intent; -import android.support.test.runner.AndroidJUnit4; - -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.TestBase; -import org.infobip.mobile.messaging.chat.broadcast.ChatBroadcaster; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -/** - * @author sslavin - * @since 10/10/2017. - */ -@RunWith(AndroidJUnit4.class) -public class CoreBroadcastReceiverTest extends TestBase { - - private CoreBroadcastReceiver coreBroadcastReceiver; - - private Context context; - private ChatBroadcaster chatBroadcaster; - private ObjectMapper objectMapper; - private UserProfileManager userProfileManager; - - @Before - public void before() { - chatBroadcaster = mock(ChatBroadcaster.class); - objectMapper = mock(ObjectMapper.class); - userProfileManager = mock(UserProfileManager.class); - context = mock(Context.class); - coreBroadcastReceiver = new CoreBroadcastReceiver(chatBroadcaster, objectMapper, userProfileManager); - } - - @Test - public void should_resend_user_data_broadcast() { - - ChatParticipant givenParticipant = givenChatParticipant(); - User givenUser = givenUserData(givenParticipant); - Intent givenIntent = givenIntentWithUserData(givenUser); - given(objectMapper.fromUserData(any(User.class))).willReturn(givenParticipant); - - coreBroadcastReceiver.onReceive(context, givenIntent); - - then(userProfileManager).should(times(1)).save(givenParticipant); - then(chatBroadcaster).should(times(1)).userInfoSynchronized(givenParticipant); - } - - // region internal methods - - private User givenUserData(ChatParticipant chatParticipant) { - return new ObjectMapper().toUserData(chatParticipant); - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ObjectMapperTest.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ObjectMapperTest.java deleted file mode 100644 index 12449084..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/ObjectMapperTest.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.support.test.runner.AndroidJUnit4; - -import org.infobip.mobile.messaging.CustomAttributeValue; -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.repository.MJSONObject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; - -import java.util.HashMap; - -import static junit.framework.Assert.assertEquals; - -/** - * @author sslavin - * @since 10/10/2017. - */ -@RunWith(AndroidJUnit4.class) -public class ObjectMapperTest { - - private ObjectMapper objectMapper = new ObjectMapper(); - - @Test - public void should_map_push_message_to_chat_message() throws Exception { - Message givenMessage = new Message( - "messageId", - "title", - "body", - "sound", - true, - "icon", - true, - "category", - "from", - 123L, - 456L, - 789L, - MJSONObject.create() - .add("chatId", "chatId") - .add("sender", "senderId") - .add("senderFirstName", "firstName") - .add("senderLastName", "lastName") - .add("senderMiddleName", "middleName") - .add("senderEmail", "sender@email.com") - .add("senderGsm", "senderGsm") - .add("senderData", MJSONObject.create().add("key", "value")) - .add("someKey", "someValue") - .add("isChat", true), - "{'key2':'value2'}", - "destination", - Message.Status.ERROR, - "statusMessage", - "contentUrl", - null - ); - - ChatMessage message = objectMapper.fromBaseMessage(givenMessage, true); - assertEquals(givenMessage.getMessageId(), message.getId()); - assertEquals(givenMessage.getBody(), message.getBody()); - assertEquals(789L, message.getCreatedAt()); - assertEquals(123L, message.getReceivedAt()); - assertEquals(456L, message.getReadAt()); - assertEquals("chatId", message.getChatId()); - assertEquals("category", message.getCategory()); - assertEquals("contentUrl", message.getContentUrl()); - assertEquals(Message.Status.ERROR, message.getStatus()); - JSONAssert.assertEquals(MJSONObject.create().add("someKey", "someValue"), message.getCustomData(), true); - - ChatParticipant participant = message.getAuthor(); - assertEquals("senderId", participant.getId()); - assertEquals("firstName", participant.getFirstName()); - assertEquals("lastName", participant.getLastName()); - assertEquals("firstName lastName", participant.getUserName()); - assertEquals("middleName", participant.getMiddleName()); - assertEquals("sender@email.com", participant.getEmail()); - assertEquals("senderGsm", participant.getGsm()); - JSONAssert.assertEquals(MJSONObject.create().add("key", "value"), participant.getCustomData(), true); - } - - @Test - public void should_map_chat_message_to_push_message() throws Exception { - ChatParticipant givenParticipant = new ChatParticipant( - "participantId", - "firstName", - "lastName", - "middleName", - "participant@email.com", - "gsm", - MJSONObject.create().add("key", "value")); - - ChatMessage givenChatMessage = new ChatMessage( - "messageId", - "body", - "chatId", - 123L, - 456L, - 789L, - "category", - "contentUrl", - givenParticipant, - Message.Status.SUCCESS, - MJSONObject.create().add("key", "value"), - true); - - Message message = objectMapper.toBaseMessage(givenChatMessage); - assertEquals(givenChatMessage.getId(), message.getMessageId()); - assertEquals(givenChatMessage.getBody(), message.getBody()); - assertEquals(givenChatMessage.getChatId(), message.getCustomPayload().getString("chatId")); - assertEquals(givenChatMessage.getCreatedAt(), message.getSentTimestamp()); - assertEquals(givenChatMessage.getReceivedAt(), message.getReceivedTimestamp()); - assertEquals(givenChatMessage.getReadAt(), message.getSeenTimestamp()); - assertEquals(givenChatMessage.getStatus(), message.getStatus()); - assertEquals(givenChatMessage.getCategory(), message.getCategory()); - assertEquals(givenChatMessage.getContentUrl(), message.getContentUrl()); - assertEquals("value", message.getCustomPayload().getString("key")); - - assertEquals("participantId", message.getCustomPayload().getString("sender")); - assertEquals("firstName", message.getCustomPayload().getString("senderFirstName")); - assertEquals("lastName", message.getCustomPayload().getString("senderLastName")); - assertEquals("middleName", message.getCustomPayload().getString("senderMiddleName")); - assertEquals("participant@email.com", message.getCustomPayload().getString("senderEmail")); - assertEquals("gsm", message.getCustomPayload().getString("senderGsm")); - assertEquals(true, message.getCustomPayload().getBoolean("isChat")); - assertEquals("{\"key\":\"value\"}", message.getCustomPayload().getString("senderData")); - } - - @Test - public void should_map_user_data_to_participant() throws Exception { - User givenUser = new User() {{ - setExternalUserId("userId"); - setFirstName("firstName"); - setLastName("lastName"); - setMiddleName("middleName"); -// setEmail("email@email.com"); -// setMsisdn("msisdn"); - setCustomAttributes(new HashMap() {{ - put("chatCustomData", new CustomAttributeValue( - MJSONObject.create().add("key", "value").toString())); - }}); - }}; - - ChatParticipant participant = objectMapper.fromUserData(givenUser); - assertEquals("userId", participant.getId()); - assertEquals("firstName", participant.getFirstName()); - assertEquals("lastName", participant.getLastName()); - assertEquals("middleName", participant.getMiddleName()); -// assertEquals("email@email.com", participant.getEmail()); -// assertEquals("msisdn", participant.getGsm()); - JSONAssert.assertEquals(MJSONObject.create().add("key", "value"), participant.getCustomData(), false); - } - - @Test - public void should_map_participant_to_user_data() throws Exception { - ChatParticipant givenParticipant = new ChatParticipant( - "participantId", - "firstName", - "lastName", - "middleName", - null, - null, - MJSONObject.create().add("key", "value")); - - User user = objectMapper.toUserData(givenParticipant); - - assertEquals("participantId", user.getExternalUserId()); - assertEquals("firstName", user.getFirstName()); - assertEquals("lastName", user.getLastName()); - assertEquals("middleName", user.getMiddleName()); -// assertEquals("participant@email.com", user.getEmail()); -// assertEquals("gsm", user.getMsisdn()); - assertEquals("{\"key\":\"value\"}", user.getCustomAttributes().get("chatCustomData").stringValue()); - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/UserProfileManagerTest.java b/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/UserProfileManagerTest.java deleted file mode 100644 index ca2e8a4e..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/androidTest/java/org/infobip/mobile/messaging/chat/core/UserProfileManagerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.content.SharedPreferences; -import android.support.test.runner.AndroidJUnit4; - -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.TestBase; -import org.infobip.mobile.messaging.chat.repository.Participant; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepository; -import org.infobip.mobile.messaging.chat.repository.RepositoryMapper; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; -import static org.mockito.BDDMockito.then; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author sslavin - * @since 10/10/2017. - */ -@RunWith(AndroidJUnit4.class) -public class UserProfileManagerTest extends TestBase { - - private UserProfileManager userProfileManager; - private ParticipantRepository participantRepository; - private RepositoryMapper repositoryMapper; - private SharedPreferences sharedPreferences; - private SharedPreferences.Editor editor; - private String pushRegistrationId; - - @Before - public void before() { - participantRepository = mock(ParticipantRepository.class); - repositoryMapper = mock(RepositoryMapper.class); - sharedPreferences = mock(SharedPreferences.class); - editor = mock(SharedPreferences.Editor.class); - pushRegistrationId = "d1aca8ed-c9d3-426f-a9e7-b10a1a43c864"; - - when(sharedPreferences.edit()).thenReturn(editor); - when(editor.putString(anyString(), anyString())).thenReturn(editor); - - userProfileManager = new UserProfileManager(participantRepository, repositoryMapper, sharedPreferences, pushRegistrationId); - } - - @Test - public void should_save_participant_to_db_and_id_to_preferences() { - ChatParticipant givenChatParticipant = givenChatParticipant(); - Participant givenParticipant = givenParticipant(givenChatParticipant); - when(repositoryMapper.dbParticipantFromChatParticipant(any(ChatParticipant.class))).thenReturn(givenParticipant); - - userProfileManager.save(givenChatParticipant); - - verify(participantRepository, times(1)).upsert(givenParticipant); - then(editor.putString(eq("org.infobip.mobile.messaging.chat.PARTICIPANT_ID_TAG"), eq(givenChatParticipant.getId()))).should(times(1)); - } - - @Test - public void should_determine_if_message_is_from_local_user() throws Exception { - Message givenMessage = givenPushMessageFromUser("localId"); - when(sharedPreferences.getString(eq("org.infobip.mobile.messaging.chat.PARTICIPANT_ID_TAG"), anyString())).thenReturn("localId"); - - assertTrue(userProfileManager.isUsersMessage(givenMessage)); - } - - @Test - public void should_fallback_to_push_reg_id_as_user_id_if_no_user_info_provided() { - when(sharedPreferences.getString(eq("org.infobip.mobile.messaging.chat.PARTICIPANT_ID_TAG"), anyString())).thenReturn(null); - - assertEquals(pushRegistrationId, userProfileManager.get().getId()); - } - - // region internal methods - - private Participant givenParticipant(final ChatParticipant chatParticipant) { - return new Participant(){{ - id = chatParticipant.getId(); - }}; - } - - private Message givenPushMessageFromUser(String userId) throws JSONException { - Message message = new Message(); - message.setCustomPayload(new JSONObject().putOpt("sender", userId)); - return message; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/AndroidManifest.xml b/infobip-mobile-messaging-android-chat-sdk/src/main/AndroidManifest.xml deleted file mode 100644 index 3eab4b6b..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/AndroidManifest.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatEvent.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatEvent.java deleted file mode 100644 index a515606a..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatEvent.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -/** - * Contains all chat-related events produced by the library. - * - * @author sslavin - * @since 06/10/2017. - */ - -public enum ChatEvent { - - /** - * Triggered when chat message is received from the server. - *
-     * {@code
-     * ChatMessage message = ChatMessage.createFrom(intent);
-     * }
-     * 
- */ - CHAT_MESSAGE_RECEIVED("org.infobip.mobile.messaging.chat.CHAT_MESSAGE_RECEIVED"), - - /** - * Triggered when chat message is successfully sent to the server. - *
-     * {@code
-     * ChatMessage message = ChatMessage.createFrom(intent);
-     * }
-     * 
- */ - CHAT_MESSAGE_SENT("org.infobip.mobile.messaging.chat.CHAT_MESSAGE_SENT"), - - /** - * Triggered when chat message is tapped. - *
-     * {@code
-     * ChatMessage message = ChatMessage.createFrom(intent);
-     * }
-     * 
- */ - CHAT_MESSAGE_TAPPED("org.infobip.mobile.messaging.chat.CHAT_MESSAGE_TAPPED"), - - /** - * Triggered when action tapped inside chat view. - *
-     * {@code
-     * ChatMessage message = ChatMessage.createFrom(intent);
-     * String actionId = intent.getStringExtra(MobileChat.EXTRA_ACTION_ID);
-     * }
-     * 
- */ - CHAT_MESSAGE_VIEW_ACTION_TAPPED("org.infobip.mobile.messaging.chat.CHAT_MESSAGE_VIEW_ACTION_TAPPED"), - - /** - * Triggered when information of current user is saved on server. - *
-     * {@code
-     * ChatParticipant info = ChatParticipant.createFrom(intent);
-     * }
-     * 
- */ - CHAT_USER_INFO_SYNCHRONIZED("org.infobip.mobile.messaging.chat.CHAT_USER_INFO_SYNCHRONIZED"); - - private final String key; - - ChatEvent(String key) { - this.key = key; - } - - public String getKey() { - return key; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessage.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessage.java deleted file mode 100644 index bdbc5af6..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessage.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import android.content.Intent; -import android.support.annotation.NonNull; - -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.chat.broadcast.ChatBundleMapper; -import org.infobip.mobile.messaging.platform.Time; -import org.json.JSONObject; - -import java.util.UUID; - -/** - * One simple message from chat - * - * @author sslavin - * @since 05/10/2017. - */ - -@SuppressWarnings({"unused", "WeakerAccess"}) -public class ChatMessage implements Comparable { - /** - * Unique message id - */ - private String id; - - /** - * Message text - */ - private String body; - - /** - * ID of a chat which this message belongs to - */ - private String chatId; - - /** - * Date when this message was created - */ - private long createdAt; - - /** - * Date when this message was received - */ - private long receivedAt; - - /** - * Date when this message was seen - */ - private long readAt; - - /** - * Message category for actionable notifications - */ - private String category; - - /** - * Url for media content provided with message - */ - private String contentUrl; - - /** - * Author of this message - */ - private ChatParticipant author; - - /** - * Current status of message - */ - private Message.Status status; - - /** - * Any custom data attached to message - */ - private JSONObject customData; - - /** - * Flag that indicates that message belongs to current user - */ - private boolean isYours; - - /** - * Creates message based on provided intent - * - * @param intent intent with data - * @return message object - */ - public static ChatMessage createFrom(@NonNull Intent intent) { - return mapper.chatMessageFromBundle(intent.getExtras()); - } - - @Override - public int compareTo(@NonNull ChatMessage o) { - if (createdAt != 0 && o.createdAt != 0) { - return (int) Math.signum(createdAt - o.createdAt); - } - return (int) Math.signum(receivedAt - o.receivedAt); - } - - // region Boilerplate code - - private final static ChatBundleMapper mapper = new ChatBundleMapper(); - - public ChatMessage(String id, String body, String chatId, long createdAt, long receivedAt, long readAt, String category, String contentUrl, ChatParticipant author, Message.Status status, JSONObject customData, boolean isYours) { - this.id = id; - this.body = body; - this.chatId = chatId; - this.createdAt = createdAt; - this.receivedAt = receivedAt; - this.readAt = readAt; - this.category = category; - this.contentUrl = contentUrl; - this.author = author; - this.status = status; - this.customData = customData; - this.isYours = isYours; - } - - public ChatMessage() { - this(UUID.randomUUID().toString(), - null, - null, - Time.now(), - 0, - 0, - null, - null, - null, - Message.Status.UNKNOWN, - null, - false); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public String getChatId() { - return chatId; - } - - public void setChatId(String chatId) { - this.chatId = chatId; - } - - public long getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(long createdAt) { - this.createdAt = createdAt; - } - - public long getReceivedAt() { - return receivedAt; - } - - public void setReceivedAt(long receivedAt) { - this.receivedAt = receivedAt; - } - - public long getReadAt() { - return readAt; - } - - public void setReadAt(long readAt) { - this.readAt = readAt; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public String getContentUrl() { - return contentUrl; - } - - public void setContentUrl(String contentUrl) { - this.contentUrl = contentUrl; - } - - public ChatParticipant getAuthor() { - return author; - } - - public void setAuthor(ChatParticipant author) { - this.author = author; - } - - public Message.Status getStatus() { - return status; - } - - public void setStatus(Message.Status status) { - this.status = status; - } - - public JSONObject getCustomData() { - return customData; - } - - public void setCustomData(JSONObject customData) { - this.customData = customData; - } - - public boolean isYours() { - return isYours; - } - - public void setYours(boolean isYours) { - this.isYours = isYours; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessageStorage.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessageStorage.java deleted file mode 100644 index 00b54be1..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatMessageStorage.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import java.util.List; - -/** - * Set of interfaces to access chat messages stored on a device - * - * @author sslavin - * @since 17/10/2017. - */ - -public interface ChatMessageStorage { - - /** - * Set of callback methods for chat message storage - */ - interface Listener { - /** - * Called when new message is added to the storage. - * Invoked after {@link ChatMessageStorage#save(ChatMessage)}} for new message. - * @param message new message - */ - void onNew(ChatMessage message); - - /** - * Called when message is updated. - * Invoked after {@link ChatMessageStorage#save(ChatMessage)}}. - * @param message message that was updated in storage - */ - void onUpdated(ChatMessage message); - - /** - * Called when messages are deleted in storage. - * Invoked after {@link ChatMessageStorage#delete(String)}. - * Is not invoked after {@link ChatMessageStorage#deleteAll()}}. - * @param messageId ids of messages that were deleted - */ - void onDeleted(String messageId); - - /** - * Called when all messages are deleted in message storage. - * Invoked after {@link ChatMessageStorage#deleteAll()}}. - */ - void onAllDeleted(); - } - - /** - * Returnes all received chat messages - * @return list if messages - */ - List findAllMessages(); - - /** - * Returns number of messages stored locally - * @return number of messages - */ - long countAllMessages(); - - /** - * Returns number of all unread messages stored locally - * @return number of messages - */ - long countAllUnreadMessages(); - - /** - * Returns message based on id - * @param id id of message - * @return chat message - */ - ChatMessage findMessage(String id); - - /** - * Saves message to storage - * @param message message ot save - */ - void save(ChatMessage message); - - /** - * Deletes message by id - * @param id id of message - */ - void delete(String id); - - /** - * Deletes all messages - */ - void deleteAll(); - - /** - * Registers listener for message storage updates - * @param listener listener callback - */ - void registerListener(Listener listener); - - /** - * Unregisters listener from message storage updates - * @param listener listener callback - */ - void unregisterListener(Listener listener); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatParticipant.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatParticipant.java deleted file mode 100644 index 4fe654fa..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/ChatParticipant.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import android.text.TextUtils; - -import org.json.JSONObject; - -/** - * A simple participant of a chat - * - * @author sslavin - * @since 05/10/2017. - */ - -@SuppressWarnings({"WeakerAccess", "unused"}) -public class ChatParticipant { - /** - * Unique ID of a participant - */ - private String id; - - /** - * First name - */ - private String firstName; - - /** - * Last name - */ - private String lastName; - - /** - * Middle name - */ - private String middleName; - - /** - * Email - */ - private String email; - - /** - * GSM - */ - private String gsm; - - /** - * Any custom data that can be attached to a participant - */ - private JSONObject customData; - - // region Boilerplate code - - public ChatParticipant(String id, String firstName, String lastName, String middleName, String email, String gsm, JSONObject customData) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - this.middleName = middleName; - this.email = email; - this.gsm = gsm; - this.customData = customData; - } - - public ChatParticipant(String id) { - this(id, null, null, null, null, null, null); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getUserName() { - String userName; - if (!TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(lastName)) { - userName = firstName.trim() + " " + lastName.trim(); - } else { - userName = !TextUtils.isEmpty(firstName) ? firstName.trim() - : !TextUtils.isEmpty(lastName) ? lastName.trim() : ""; - } - - return userName.trim(); - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getGsm() { - return gsm; - } - - public void setGsm(String gsm) { - this.gsm = gsm; - } - - public JSONObject getCustomData() { - return customData; - } - - public void setCustomData(JSONObject customData) { - this.customData = customData; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChat.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChat.java deleted file mode 100644 index 4606e4ab..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChat.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import android.content.Context; - -import org.infobip.mobile.messaging.MobileMessaging; -import org.infobip.mobile.messaging.MobileMessagingCore; -import org.infobip.mobile.messaging.chat.core.MobileChatImpl; -import org.json.JSONObject; - -/** - * Main interface for chat communication - * - * @author sslavin - * @since 05/10/2017. - */ -@SuppressWarnings("unused") -public abstract class MobileChat { - - /** - * @see ChatEvent#CHAT_MESSAGE_VIEW_ACTION_TAPPED - */ - public static final String EXTRA_ACTION_ID = "org.infobip.mobile.messaging.chat.EXTRA_ACTION_ID"; - - /** - * Returns unstance of chat api - * @param context android context - * @return instance of chat api - */ - public static MobileChat getInstance(Context context) { - return MobileMessagingCore.getInstance(context).getMessageHandlerModule(MobileChatImpl.class); - } - - /** - * Sends message to chat - * @param text text of message - */ - public abstract void sendMessage(String text); - - /** - * Sends message to chat - * @param text text of message - * @param customData any custom data attached to message - */ - public abstract void sendMessage(String text, JSONObject customData); - - /** - * Sends message to chat - * @param text text of message - * @param listener callback that receives the result - */ - public abstract void sendMessage(String text, MobileMessaging.ResultListener listener); - - /** - * Sends message to chat - * @param text text of message - * @param customData any custom data attached to message - * @param listener callback that receives the result - */ - public abstract void sendMessage(String text, JSONObject customData, MobileMessaging.ResultListener listener); - - /** - * Marks chat message as read - * @param id message id - */ - public abstract void markMessageRead(String id); - - /** - * Marks all stored messages as read - */ - public abstract void markAllMessagesRead(); - - /** - * Sets user info for current user - * @param info participant information - */ - public abstract void setUserInfo(ChatParticipant info); - - /** - * Sets user info for current user - * @param info participant information - * @param listener callback that receives the result of operation - */ - public abstract void setUserInfo(ChatParticipant info, MobileMessaging.ResultListener listener); - - /** - * Returns user profile cached locally - * @return user profile - */ - public abstract ChatParticipant getUserInfo(); - - /** - * Fetches current profile from server - * (prefer {@link #getUserInfo()} if user profile is changed only on mobile) - * @param listener callback that receives user profile - */ - public abstract void fetchUserInfo(MobileMessaging.ResultListener listener); - - /** - * Fetches current profile from server and caches it in library - * (prefer {@link #getUserInfo()} if user profile is changed only on mobile) - */ - public abstract void fetchUserInfo(); - - /** - * Returns message storage to access messages stored on a device - * @return chat message storage - */ - public abstract ChatMessageStorage getChatMessageStorage(); - - /** - * Creates chat view activity. - * @see MobileChatView#show() - * @return chat view object - */ - public abstract MobileChatView chatView(); - - /** - * Sets which activities to start when user taps on chat notification. Last one in array will be show, others will be put to task stack. - *

Library will also provide appropriate message together with intent, use following code to retrieve the message:

- * *
-     * {@code
-     * ChatMessage message = ChatMessage.createFrom(intent);
-     * }
-     * 
- * @param activityClasses array of activities to put into task stack when message is tapped - */ - public abstract void setActivitiesToStartOnMessageTap(Class... activityClasses); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChatView.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChatView.java deleted file mode 100644 index 0f435be3..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/MobileChatView.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.infobip.mobile.messaging.chat; - -import org.infobip.mobile.messaging.interactive.NotificationCategory; - -/** - * @author sslavin - * @since 19/11/2017. - */ - -public interface MobileChatView { - - /** - * Will register action categories in chat view. All messages containing these categories will also have buttons for corresponding actions. - * @param categories categories to register - * @return view - */ - MobileChatView withActionCategories(NotificationCategory... categories); - - /** - * Call this method to show the view - */ - void show(); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcaster.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcaster.java deleted file mode 100644 index fc2339e9..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcaster.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.infobip.mobile.messaging.chat.broadcast; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public interface ChatBroadcaster { - - /** - * Sends broadcast when chat message is received - * - * @param message message to send broadcast for - */ - void chatMessageReceived(ChatMessage message); - - /** - * Sends broadcast when chat message is sent out - * - * @param message message to send broadcast for - */ - void chatMessageSent(ChatMessage message); - - /** - * Sends broadcast when chat message is tapped - * - * @param message message to send broadcast for - */ - void chatMessageTapped(ChatMessage message); - - /** - * Sends broadcast when action tapped - * - * @param message message to send broadcast for - * @param actionId tapped action id - */ - void chatMessageViewActionTapped(ChatMessage message, String actionId); - - /** - * Sends broadcast when user information is saved on server - * - * @param participant user information - */ - void userInfoSynchronized(ChatParticipant participant); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImpl.java deleted file mode 100644 index 1719c616..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBroadcasterImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.infobip.mobile.messaging.chat.broadcast; - -import android.content.Context; -import android.content.Intent; -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.ChatEvent; -import org.infobip.mobile.messaging.chat.MobileChat; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class ChatBroadcasterImpl implements ChatBroadcaster { - - private final Context context; - private final LocalBroadcastManagerWrapper localBroadcastManagerWrapper; - private final ChatBundleMapper mapper; - - public ChatBroadcasterImpl(Context context) { - this.context = context; - this.localBroadcastManagerWrapper = new LocalBroadcastManagerWrapper(context); - this.mapper = new ChatBundleMapper(); - } - - @VisibleForTesting - ChatBroadcasterImpl(Context context, LocalBroadcastManagerWrapper localBroadcastManagerWrapper, ChatBundleMapper mapper) { - this.context = context; - this.localBroadcastManagerWrapper = localBroadcastManagerWrapper; - this.mapper = mapper; - } - - @Override - public void chatMessageReceived(ChatMessage message) { - sendIntent(prepareIntent(ChatEvent.CHAT_MESSAGE_RECEIVED) - .putExtras(mapper.chatMessageToBundle(message))); - } - - @Override - public void chatMessageSent(ChatMessage message) { - sendIntent(prepareIntent(ChatEvent.CHAT_MESSAGE_SENT) - .putExtras(mapper.chatMessageToBundle(message))); - } - - @Override - public void chatMessageTapped(ChatMessage message) { - sendIntent(prepareIntent(ChatEvent.CHAT_MESSAGE_TAPPED) - .putExtras(mapper.chatMessageToBundle(message))); - } - - @Override - public void chatMessageViewActionTapped(ChatMessage message, String actionId) { - sendIntent(prepareIntent(ChatEvent.CHAT_MESSAGE_VIEW_ACTION_TAPPED) - .putExtras(mapper.chatMessageToBundle(message)) - .putExtra(MobileChat.EXTRA_ACTION_ID, actionId)); - } - - @Override - public void userInfoSynchronized(ChatParticipant info) { - sendIntent(prepareIntent(ChatEvent.CHAT_USER_INFO_SYNCHRONIZED) - .putExtras(mapper.chatParticipantToBundle(info))); - } - - // region private methods - - private Intent prepareIntent(ChatEvent event) { - return prepareIntent(event.getKey()); - } - - private Intent prepareIntent(String event) { - return new Intent(event) - .setPackage(context.getPackageName()); - } - - private void sendIntent(Intent intent) { - context.sendBroadcast(intent); - localBroadcastManagerWrapper.sendBroadcast(intent); - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBundleMapper.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBundleMapper.java deleted file mode 100644 index 5f438723..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/ChatBundleMapper.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.infobip.mobile.messaging.chat.broadcast; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.dal.bundle.BundleMapper; - -import static android.support.annotation.VisibleForTesting.PACKAGE_PRIVATE; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class ChatBundleMapper extends BundleMapper { - - private static final String BUNDLED_MESSAGE_TAG = ChatBundleMapper.class.getName() + ".message"; - private static final String BUNDLED_PARTICIPANT_TAG = ChatBundleMapper.class.getName() + ".participant"; - - /** - * Converts chat message to bundle - * @param message chat message - * @return resulting bundle - */ - @NonNull - public Bundle chatMessageToBundle(@NonNull ChatMessage message) { - return objectToBundle(message, BUNDLED_MESSAGE_TAG); - } - - /** - * Converts bundle to chat message - * @param bundle bundle with data - * @return chat message - */ - @Nullable - public ChatMessage chatMessageFromBundle(Bundle bundle) { - return objectFromBundle(bundle, BUNDLED_MESSAGE_TAG, ChatMessage.class); - } - - /** - * Converts chat participant to bundle - * @param participant participant information - * @return resuting bundle - */ - @NonNull - @VisibleForTesting(otherwise = PACKAGE_PRIVATE) - public Bundle chatParticipantToBundle(@NonNull ChatParticipant participant) { - return objectToBundle(participant, BUNDLED_PARTICIPANT_TAG); - } - - /** - * Converts bundle to chat participant - * @param bundle bundle with data - * @return chat participant - */ - @Nullable - public ChatParticipant chatParticipantFromBundle(Bundle bundle) { - return objectFromBundle(bundle, BUNDLED_PARTICIPANT_TAG, ChatParticipant.class); - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/LocalBroadcastManagerWrapper.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/LocalBroadcastManagerWrapper.java deleted file mode 100644 index b33400af..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/broadcast/LocalBroadcastManagerWrapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.infobip.mobile.messaging.chat.broadcast; - -import android.content.Context; -import android.content.Intent; -import android.support.v4.content.LocalBroadcastManager; - -/** - * Needed for proper testing - * - * @author sslavin - * @since 10/10/2017. - */ - - -public class LocalBroadcastManagerWrapper { - - private final LocalBroadcastManager localBroadcastManager; - - public LocalBroadcastManagerWrapper(Context context) { - localBroadcastManager = LocalBroadcastManager.getInstance(context); - } - - public void sendBroadcast(Intent intent) { - localBroadcastManager.sendBroadcast(intent); - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImpl.java deleted file mode 100644 index 1af1887a..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ChatMessageStorageImpl.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.text.TextUtils; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatMessageStorage; -import org.infobip.mobile.messaging.chat.repository.Message; -import org.infobip.mobile.messaging.chat.repository.MessageRepository; -import org.infobip.mobile.messaging.chat.repository.Participant; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepository; -import org.infobip.mobile.messaging.chat.repository.RepositoryMapper; -import org.infobip.mobile.messaging.dal.sqlite.PrimaryKeyViolationException; -import org.infobip.mobile.messaging.mobile.common.MAsyncTask; -import org.infobip.mobile.messaging.platform.Time; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author sslavin - * @since 17/10/2017. - */ - -public class ChatMessageStorageImpl implements ChatMessageStorage { - - private final MessageRepository messageRepository; - private final ParticipantRepository participantRepository; - private final RepositoryMapper repositoryMapper; - private final Set listeners = new HashSet<>(); - - ChatMessageStorageImpl(MessageRepository messageRepository, ParticipantRepository participantRepository, RepositoryMapper repositoryMapper) { - this.messageRepository = messageRepository; - this.participantRepository = participantRepository; - this.repositoryMapper = repositoryMapper; - } - - @Override - public List findAllMessages() { - List repositoryMessages = messageRepository.findAll(); - List chatMessages = new ArrayList<>(repositoryMessages.size()); - for (Message message : repositoryMessages) { - chatMessages.add(repositoryMapper.chatMessageFromDbMessageAndParticipant(message, participantRepository.findAuthor(message))); - } - return chatMessages; - } - - @Override - public long countAllMessages() { - return messageRepository.countAll(); - } - - @Override - public long countAllUnreadMessages() { - return messageRepository.countAllUnread(); - } - - @Override - public ChatMessage findMessage(String id) { - Message message = messageRepository.findOne(id); - if (message == null) { - return null; - } - - Participant participant = participantRepository.findAuthor(message); - return repositoryMapper.chatMessageFromDbMessageAndParticipant(message, participant); - } - - @Override - public void save(ChatMessage message) { - - if (message.getAuthor() != null && !TextUtils.isEmpty(message.getAuthor().getId())) { - Participant participant = repositoryMapper.dbParticipantFromChatParticipant(message.getAuthor()); - participantRepository.upsert(participant); - } - - Message repositoryMessage = repositoryMapper.dbMessageFromChatMessage(message); - try { - messageRepository.insert(repositoryMessage); - invokeOnNew(message); - } catch (PrimaryKeyViolationException e) { - messageRepository.upsert(repositoryMessage); - invokeOnUpdated(message); - } - } - - @Override - public void delete(String id) { - messageRepository.remove(id); - invokeOnDeleted(id); - } - - @Override - public void deleteAll() { - messageRepository.clear(); - invokeOnAllDeleted(); - } - - @Override - public void registerListener(Listener listener) { - listeners.add(listener); - } - - @Override - public void unregisterListener(Listener listener) { - listeners.remove(listener); - } - - void markRead(String messageId) { - Message message = messageRepository.markRead(messageId, Time.now()); - if (message == null) { - return; - } - - Participant participant = participantRepository.findAuthor(message); - invokeOnUpdated(repositoryMapper.chatMessageFromDbMessageAndParticipant(message, participant)); - } - - Set markAllRead() { - Set ids = messageRepository.markAllMessagesRead(Time.now()); - for (String id : ids) { - markRead(id); - } - return ids; - } - - // region private methods - - private void invokeOnNew(final ChatMessage message) { - invokeOnUiThread(new Runnable() { - @Override - public void run() { - for (Listener listener : listeners) { - listener.onNew(message); - } - } - }); - } - - private void invokeOnUpdated(final ChatMessage message) { - invokeOnUiThread(new Runnable() { - @Override - public void run() { - for (Listener listener : listeners) { - listener.onUpdated(message); - } - } - }); - } - - private void invokeOnDeleted(final String id) { - invokeOnUiThread(new Runnable() { - @Override - public void run() { - for (Listener listener : listeners) { - listener.onDeleted(id); - } - } - }); - } - - private void invokeOnAllDeleted() { - invokeOnUiThread(new Runnable() { - @Override - public void run() { - for (Listener listener : listeners) { - listener.onAllDeleted(); - } - } - }); - } - - private void invokeOnUiThread(final Runnable runnable) { - new MAsyncTask() { - - @Override - public Void run(Void[] objects) { - return null; - } - - @Override - public void after(Void o) { - runnable.run(); - } - }.execute(); - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiver.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiver.java deleted file mode 100644 index 20aba19f..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/CoreBroadcastReceiver.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.Event; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.broadcast.ChatBroadcaster; -import org.infobip.mobile.messaging.chat.broadcast.ChatBroadcasterImpl; - -/** - * @author sslavin - * @since 10/10/2017. - */ - -public class CoreBroadcastReceiver extends BroadcastReceiver { - - private ChatBroadcaster broadcaster; - private final ObjectMapper mapper; - private UserProfileManager userProfileManager; - - @SuppressWarnings("unused") - public CoreBroadcastReceiver() { - this.mapper = new ObjectMapper(); - } - - @VisibleForTesting - public CoreBroadcastReceiver(ChatBroadcaster broadcaster, ObjectMapper mapper, UserProfileManager userProfileManager) { - this.broadcaster = broadcaster; - this.mapper = mapper; - this.userProfileManager = userProfileManager; - } - - @Override - public void onReceive(Context context, Intent intent) { - if (intent == null) { - return; - } - - if (!Event.USER_UPDATED.getKey().equals(intent.getAction())) { - return; - } - - User user = User.createFrom(intent.getExtras()); - if (user != null) { - ChatParticipant participant = mapper.fromUserData(user); - userProfileManager(context).save(participant); - broadcaster(context).userInfoSynchronized(participant); - } - } - - // region private methods - - private ChatBroadcaster broadcaster(Context context) { - if (broadcaster == null) { - broadcaster = new ChatBroadcasterImpl(context); - } - return broadcaster; - } - - private UserProfileManager userProfileManager(Context context) { - if (userProfileManager == null) { - userProfileManager = new UserProfileManager(context); - } - return userProfileManager; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/MobileChatImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/MobileChatImpl.java deleted file mode 100644 index 4ed0881a..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/MobileChatImpl.java +++ /dev/null @@ -1,347 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.TaskStackBuilder; - -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.MessageHandlerModule; -import org.infobip.mobile.messaging.MobileMessaging; -import org.infobip.mobile.messaging.MobileMessagingCore; -import org.infobip.mobile.messaging.NotificationSettings; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatMessageStorage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.MobileChat; -import org.infobip.mobile.messaging.chat.broadcast.ChatBroadcaster; -import org.infobip.mobile.messaging.chat.broadcast.ChatBroadcasterImpl; -import org.infobip.mobile.messaging.chat.broadcast.ChatBundleMapper; -import org.infobip.mobile.messaging.chat.properties.MobileChatProperty; -import org.infobip.mobile.messaging.chat.properties.PropertyHelper; -import org.infobip.mobile.messaging.chat.repository.MessageRepositoryImpl; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepositoryImpl; -import org.infobip.mobile.messaging.chat.repository.RepositoryMapper; -import org.infobip.mobile.messaging.interactive.MobileInteractive; -import org.infobip.mobile.messaging.interactive.NotificationAction; -import org.infobip.mobile.messaging.mobile.MobileMessagingError; -import org.infobip.mobile.messaging.mobile.Result; -import org.infobip.mobile.messaging.platform.Time; -import org.json.JSONObject; - -import java.util.Set; - -import static org.infobip.mobile.messaging.chat.ChatEvent.CHAT_MESSAGE_TAPPED; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class MobileChatImpl extends MobileChat implements MessageHandlerModule { - - private Context context; - private MobileMessagingCore mobileMessagingCore; - private MobileInteractive mobileInteractive; - private final ObjectMapper objectMapper = new ObjectMapper(); - private final RepositoryMapper repositoryMapper = new RepositoryMapper(); - private final ChatBundleMapper bundleMapper = new ChatBundleMapper(); - private ChatBroadcaster broadcaster; - private UserProfileManager userProfileManager; - private ChatMessageStorageImpl chatMessageStorage; - private MobileChatViewImpl mobileChatView; - private PropertyHelper propertyHelper; - private ParticipantRepositoryImpl participantRepository; - - @Override - public void init(Context appContext) { - this.context = appContext; - } - - @Override - public boolean handleMessage(Message message) { - if (!isChatMessage(message)) { - return false; - } - - ChatMessage chatMessage = objectMapper.fromBaseMessage(message, userProfileManager().isUsersMessage(message)); - chatMessageStorage().save(chatMessage); - broadcaster().chatMessageReceived(chatMessage); - mobileMessagingCore().getNotificationHandler().displayNotification(message); - return true; - } - - @Override - public boolean messageTapped(Message message) { - if (!isChatMessage(message)) { - return false; - } - - ChatMessage chatMessage = objectMapper.fromBaseMessage(message, userProfileManager().isUsersMessage(message)); - broadcaster().chatMessageTapped(chatMessage); - doCoreTappedActions(chatMessage); - return true; - } - - @Override - public void sendMessage(String text) { - sendChatMessage(text, null, null); - } - - @Override - public void sendMessage(String text, JSONObject customData) { - sendChatMessage(text, customData, null); - } - - @Override - public void sendMessage(String text, MobileMessaging.ResultListener listener) { - sendChatMessage(text, null, listener); - } - - @Override - public void sendMessage(String text, JSONObject customData, MobileMessaging.ResultListener listener) { - sendChatMessage(text, customData, listener); - } - - @Override - public void markMessageRead(String id) { - chatMessageStorage().markRead(id); - mobileMessagingCore().setMessagesSeenDontStore(id); - } - - @Override - public void markAllMessagesRead() { - Set ids = chatMessageStorage().markAllRead(); - mobileMessagingCore().setMessagesSeenDontStore(ids.toArray(new String[0])); - } - - @Override - public void setUserInfo(ChatParticipant info) { - setChatUserInfo(info, null); - } - - @Override - public void setUserInfo(ChatParticipant info, MobileMessaging.ResultListener listener) { - setChatUserInfo(info, listener); - } - - @Override - public ChatParticipant getUserInfo() { - return userProfileManager().get(); - } - - @Override - public void fetchUserInfo() { - fetchUserInfo(null); - } - - @Override - public void fetchUserInfo(final MobileMessaging.ResultListener listener) { - mobileMessagingCore().fetchUser(new MobileMessaging.ResultListener() { - @Override - public void onResult(Result result) { - if (listener == null) { - return; - } - - if (result.getData() == null) { - listener.onResult(new Result(MobileMessagingError.createFrom(new RuntimeException()))); - return; - } - - listener.onResult(new Result<>(objectMapper.fromUserData(result.getData()), result.getError())); - } - }); - } - - @Override - public ChatMessageStorage getChatMessageStorage() { - return chatMessageStorage(); - } - - @Override - public MobileChatViewImpl chatView() { - if (mobileChatView == null) { - mobileChatView = new MobileChatViewImpl(context); - } - return mobileChatView; - } - - @Override - public void setActivitiesToStartOnMessageTap(Class... activityClasses) { - propertyHelper().saveClasses(MobileChatProperty.ON_MESSAGE_TAP_ACTIVITY_CLASSES, activityClasses); - } - - // region private methods - - private void sendChatMessage(String text, JSONObject customData, final MobileMessaging.ResultListener listener) { - final ChatMessage message = new ChatMessage(); - message.setBody(text); - message.setAuthor(userProfileManager().get()); - message.setCustomData(customData); - message.setReceivedAt(Time.now()); - message.setYours(true); - chatMessageStorage().save(message); - Message baseMessage = objectMapper.toBaseMessage(message); - mobileMessagingCore().sendMessagesDontStore(new MobileMessaging.ResultListener() { - @Override - public void onResult(Result result) { - if (listener == null) { - return; - } - - Message[] messages = result.getData(); - if (messages == null || messages.length == 0) { - listener.onResult(new Result(MobileMessagingError.createFrom(new RuntimeException()))); - return; - } - - ChatMessage sentMessage = objectMapper.fromBaseMessage(messages[0], userProfileManager().isUsersMessage(messages[0])); - chatMessageStorage().save(sentMessage); - - broadcaster().chatMessageSent(sentMessage); - listener.onResult(new Result<>(sentMessage, result.getError())); - } - }, baseMessage); - } - - private void setChatUserInfo(ChatParticipant info, final MobileMessaging.ResultListener listener) { - userProfileManager().save(info); - User user = objectMapper.toUserData(info); - mobileMessagingCore().saveUser(user, new MobileMessaging.ResultListener() { - @Override - public void onResult(Result result) { - if (listener == null) { - return; - } - - if (result == null) { - listener.onResult(new Result(MobileMessagingError.createFrom(new RuntimeException()))); - return; - } - - ChatParticipant participant = objectMapper.fromUserData(result.getData()); - userProfileManager.save(participant); - broadcaster().userInfoSynchronized(participant); - listener.onResult(new Result<>(participant, result.getError())); - } - }); - } - - private static boolean isChatMessage(Message message) { - return message.getCustomPayload() != null && - message.getCustomPayload().optBoolean("isChat", false); - } - - synchronized private MobileMessagingCore mobileMessagingCore() { - if (mobileMessagingCore == null) { - mobileMessagingCore = MobileMessagingCore.getInstance(context); - } - return mobileMessagingCore; - } - - synchronized private ChatBroadcaster broadcaster() { - if (broadcaster == null) { - broadcaster = new ChatBroadcasterImpl(context); - } - return broadcaster; - } - - synchronized private UserProfileManager userProfileManager() { - if (userProfileManager == null) { - userProfileManager = new UserProfileManager(context); - } - return userProfileManager; - } - - synchronized private ChatMessageStorageImpl chatMessageStorage() { - if (chatMessageStorage == null) { - chatMessageStorage = new ChatMessageStorageImpl(new MessageRepositoryImpl(context), participantRepository(), repositoryMapper); - } - return chatMessageStorage; - } - - synchronized private ParticipantRepositoryImpl participantRepository() { - if (participantRepository == null) { - participantRepository = new ParticipantRepositoryImpl(context); - } - return participantRepository; - } - - synchronized private MobileInteractive mobileInteractive() { - if (mobileInteractive == null) { - mobileInteractive = MobileInteractive.getInstance(context); - } - return mobileInteractive; - } - - synchronized private PropertyHelper propertyHelper() { - if (propertyHelper == null) { - propertyHelper = new PropertyHelper(context); - } - return propertyHelper; - } - - @Override - public void applicationInForeground() { - // do nothing - } - - @Override - public void cleanup() { - chatMessageStorage().deleteAll(); - participantRepository().clear(); - propertyHelper().remove(MobileChatProperty.USER_NAME_DIALOG_SHOWN); - } - - @Override - public void depersonalize() { - chatMessageStorage().deleteAll(); - participantRepository().clear(); - propertyHelper().remove(MobileChatProperty.USER_NAME_DIALOG_SHOWN); - } - - public void processTappedAction(ChatMessage chatMessage, NotificationAction action) { - broadcaster().chatMessageViewActionTapped(chatMessage, action.getId()); - mobileInteractive().triggerSdkActionsFor(action, objectMapper.toBaseMessage(chatMessage)); - } - - @NonNull - private TaskStackBuilder stackBuilderForNotificationTap(ChatMessage message) { - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - Bundle messageBundle = bundleMapper.chatMessageToBundle(message); - Class[] classes = propertyHelper().findClasses(MobileChatProperty.ON_MESSAGE_TAP_ACTIVITY_CLASSES); - if (classes != null) { - for (Class cls : classes) { - stackBuilder.addNextIntent(new Intent(context, cls) - .setAction(CHAT_MESSAGE_TAPPED.getKey()) - .putExtras(messageBundle)); - } - } - - NotificationSettings notificationSettings = mobileMessagingCore().getNotificationSettings(); - if (stackBuilder.getIntentCount() == 0 && notificationSettings != null && notificationSettings.getCallbackActivity() != null) { - stackBuilder.addNextIntent(new Intent(context, notificationSettings.getCallbackActivity()) - .setAction(CHAT_MESSAGE_TAPPED.getKey()) - .putExtras(messageBundle)); - } - - return stackBuilder; - } - - private void doCoreTappedActions(ChatMessage chatMessage) { - NotificationSettings notificationSettings = mobileMessagingCore().getNotificationSettings(); - if (notificationSettings != null && notificationSettings.markSeenOnTap()) { - markMessageRead(chatMessage.getId()); - } - - TaskStackBuilder stackBuilder = stackBuilderForNotificationTap(chatMessage); - if (stackBuilder.getIntentCount() != 0) { - stackBuilder.startActivities(); - } - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ObjectMapper.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ObjectMapper.java deleted file mode 100644 index 5846e03c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/ObjectMapper.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.CustomAttributeValue; -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.repository.MJSONObject; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.Map; - -import static android.support.annotation.VisibleForTesting.PACKAGE_PRIVATE; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -@VisibleForTesting(otherwise = PACKAGE_PRIVATE) -public class ObjectMapper { - - public ChatMessage fromBaseMessage(Message message, boolean isYours) { - JSONObject originalData = message.getCustomPayload(); - JSONObject data = MJSONObject.copy(message.getCustomPayload(), "chatId", "sender", "senderFirstName", - "senderLastName", "senderMiddleName", "senderEmail", "senderGsm", "senderData", "isChat"); - return new ChatMessage( - message.getMessageId(), - message.getBody(), - originalData.optString("chatId", null), - message.getSentTimestamp(), - message.getReceivedTimestamp(), - message.getSeenTimestamp(), - message.getCategory(), - message.getContentUrl(), - new ChatParticipant( - originalData.optString("sender", null), - originalData.optString("senderFirstName", null), - originalData.optString("senderLastName", null), - originalData.optString("senderMiddleName", null), - originalData.optString("senderEmail", null), - originalData.optString("senderGsm", null), - MJSONObject.create(originalData.optString("senderData", null))), - message.getStatus(), - data, - isYours - ); - } - - public Message toBaseMessage(ChatMessage message) { - MJSONObject customData = MJSONObject.copy(message.getCustomData()); - if (customData == null) customData = MJSONObject.create(); - if (message.getAuthor() != null) { - ChatParticipant author = message.getAuthor(); - customData - .add("sender", author.getId()) - .add("senderFirstName", author.getFirstName()) - .add("senderLastName", author.getLastName()) - .add("senderMiddleName", author.getMiddleName()) - .add("senderEmail", author.getEmail()) - .add("senderGsm", author.getGsm()) - .add("senderData", author.getCustomData() == null ? null : author.getCustomData().toString()) - .add("isChat", true); - } - customData.add("chatId", message.getChatId()); - return new Message( - message.getId(), - null, - message.getBody(), - null, - true, - null, - false, - message.getCategory(), - null, - message.getReceivedAt(), - message.getReadAt(), - message.getCreatedAt(), - customData, - null, - null, - message.getStatus(), - null, - message.getContentUrl(), - null, - 0); - } - - public ChatParticipant fromUserData(User user) { - MJSONObject data = null; - Map customData = user.getCustomAttributes(); - if (customData != null) { - CustomAttributeValue value = customData.get("chatCustomData"); - if (value != null) { - data = MJSONObject.create(value.stringValue()); - } - } - return new ChatParticipant( - user.getExternalUserId(), - user.getFirstName(), - user.getLastName(), - user.getMiddleName(), - null, - null, - data); - } - - public User toUserData(ChatParticipant participant) { - Map customData = new HashMap<>(); - if (participant.getCustomData() != null) { - customData.put("chatCustomData", new CustomAttributeValue(participant.getCustomData().toString())); - } - User user = new User(); - user.setExternalUserId(participant.getId()); - user.setFirstName(participant.getFirstName()); - user.setLastName(participant.getLastName()); - user.setMiddleName(participant.getMiddleName()); -// user.setEmail(participant.getEmail()); -// user.setMsisdn(participant.getGsm()); - user.setCustomAttributes(customData); - return user; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/UserProfileManager.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/UserProfileManager.java deleted file mode 100644 index 4e70e005..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/UserProfileManager.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.infobip.mobile.messaging.chat.core; - -import android.content.Context; -import android.content.SharedPreferences; -import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; -import android.text.TextUtils; - -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.MobileMessaging; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.repository.Participant; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepository; -import org.infobip.mobile.messaging.chat.repository.ParticipantRepositoryImpl; -import org.infobip.mobile.messaging.chat.repository.RepositoryMapper; -import org.infobip.mobile.messaging.util.PreferenceHelper; - -import static android.support.annotation.VisibleForTesting.PACKAGE_PRIVATE; - -/** - * @author sslavin - * @since 10/10/2017. - */ - -@VisibleForTesting(otherwise = PACKAGE_PRIVATE) -public class UserProfileManager { - - private final String PARTICIPANT_ID_TAG = "org.infobip.mobile.messaging.chat.PARTICIPANT_ID_TAG"; - - private final ParticipantRepository participantRepository; - private final RepositoryMapper repositoryMapper; - private final SharedPreferences sharedPreferences; - private final String pushRegistrationId; - - UserProfileManager(Context context) { - this.participantRepository = new ParticipantRepositoryImpl(context); - this.repositoryMapper = new RepositoryMapper(); - this.sharedPreferences = PreferenceHelper.getDefaultMMSharedPreferences(context); - this.pushRegistrationId = MobileMessaging.getInstance(context).getInstallation().getPushRegistrationId(); - } - - @VisibleForTesting - UserProfileManager(ParticipantRepository participantRepository, RepositoryMapper repositoryMapper, SharedPreferences sharedPreferences, @NonNull String pushRegistrationId) { - this.participantRepository = participantRepository; - this.repositoryMapper = repositoryMapper; - this.sharedPreferences = sharedPreferences; - this.pushRegistrationId = pushRegistrationId; - } - - @VisibleForTesting(otherwise = PACKAGE_PRIVATE) - public void save(ChatParticipant profile) { - if (profile == null || profile.getId() == null) { - return; - } - participantRepository.upsert(repositoryMapper.dbParticipantFromChatParticipant(profile)); - sharedPreferences - .edit() - .putString(PARTICIPANT_ID_TAG, profile.getId()) - .apply(); - } - - ChatParticipant get() { - String id = sharedPreferences.getString(PARTICIPANT_ID_TAG, null); - if (id == null) { - return new ChatParticipant(pushRegistrationId); - } - - Participant participant = participantRepository.findOne(id); - return repositoryMapper.chatParticipantFromDbParticipant(participant); - } - - boolean isUsersMessage(Message message) { - if (message == null || message.getCustomPayload() == null) { - return false; - } - - String authorId = message.getCustomPayload().optString("sender", null); - String userId = sharedPreferences.getString(PARTICIPANT_ID_TAG, ""); - return userId.equalsIgnoreCase(authorId) || (TextUtils.isEmpty(userId) && pushRegistrationId.equalsIgnoreCase(authorId)); - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/properties/MobileChatProperty.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/properties/MobileChatProperty.java deleted file mode 100644 index 130eaa9c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/properties/MobileChatProperty.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.infobip.mobile.messaging.chat.properties; - -/** - * @author sslavin - * @since 01/11/2017. - */ - -public enum MobileChatProperty { - USER_NAME_DIALOG_SHOWN("org.infobip.mobile.messaging.infobip.chat.USER_NAME_DIALOG_SHOWN", false), - ON_MESSAGE_TAP_ACTIVITY_CLASSES("org.infobip.mobile.messaging.infobip.chat.ON_MESSAGE_TAP_ACTIVITY_CLASSES", new Class[0]); - - private final String key; - private final Object defaultValue; - - MobileChatProperty(String key, Object defaultValue) { - this.key = key; - this.defaultValue = defaultValue; - } - - public Object getDefaultValue() { - return defaultValue; - } - - public String getKey() { - return key; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MJSONObject.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MJSONObject.java deleted file mode 100644 index 39f8e665..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MJSONObject.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.infobip.mobile.messaging.logging.MobileMessagingLogger; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class MJSONObject extends JSONObject { - - private MJSONObject() { - super(); - } - - private MJSONObject(String json) throws JSONException { - super(json); - } - - private MJSONObject(JSONObject o, String... names) throws JSONException { - super(o, names); - } - - public static MJSONObject copy(JSONObject object, String... keysToExclude) { - if (object == null) { - return null; - } - - try { - return new MJSONObject(object, iteratorToArray(object.keys(), keysToExclude)); - } catch (Exception e) { - MobileMessagingLogger.e("Cannot clone json object", e); - return new MJSONObject(); - } - } - - public static @Nullable MJSONObject create(String json) { - if (json == null) { - return null; - } - - try { - return new MJSONObject(json); - } catch (Exception e) { - MobileMessagingLogger.e("Cannot create json object from " + json, e); - return null; - } - } - - public static @NonNull MJSONObject create() { - return new MJSONObject(); - } - - public MJSONObject add(String key, Object value) { - try { - super.putOpt(key, value); - } catch (JSONException e) { - MobileMessagingLogger.e("Cannot put data to json object (" + key + ":" + value.toString() + ")", e); - } - return this; - } - - // region private methods - - private static String[] iteratorToArray(Iterator iterator, String... toExclude) { - Set exclude = arrayToSet(toExclude); - List values = new ArrayList<>(); - while (iterator.hasNext()) { - String value = iterator.next(); - if (!exclude.contains(value)) { - values.add(value); - } - } - return values.toArray(new String[0]); - } - - private static Set arrayToSet(String... values) { - return new HashSet<>(Arrays.asList(values)); - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Message.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Message.java deleted file mode 100644 index 6536adef..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Message.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.content.ContentValues; -import android.database.Cursor; - -import org.infobip.mobile.messaging.chat.repository.db.ChatDatabaseContract; -import org.infobip.mobile.messaging.dal.sqlite.DatabaseContract; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class Message implements DatabaseContract.DatabaseObject { - - protected String id; - String chatId; - String body; - Long receivedAt; - Long createdAt; - Long readAt; - String category; - String contentUrl; - String authorId; - String status; - String customData; - boolean isYours; - - @Override - public String getTableName() { - return ChatDatabaseContract.Tables.MESSAGES; - } - - @Override - public String getPrimaryKeyColumnName() { - return ChatDatabaseContract.MessageColumns.ID; - } - - @Override - public void fillFromCursor(Cursor cursor) throws Exception { - id = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.ID)); - chatId = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.CHAT_ID)); - body = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.BODY)); - receivedAt = cursor.getLong(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.RECEIVED_TIMESTAMP)); - createdAt = cursor.getLong(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.CREATED_TIMESTAMP)); - readAt = cursor.getLong(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.READ_TIMESTAMP)); - category = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.CATEGORY)); - contentUrl = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.CONTENT_URL)); - authorId = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.AUTHOR_ID)); - status = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.STATUS)); - customData = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.CUSTOM_DATA)); - isYours = cursor.getShort(cursor.getColumnIndexOrThrow(ChatDatabaseContract.MessageColumns.YOURS)) == 1; - } - - @Override - public ContentValues getContentValues() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ChatDatabaseContract.MessageColumns.ID, id); - contentValues.put(ChatDatabaseContract.MessageColumns.CHAT_ID, chatId); - contentValues.put(ChatDatabaseContract.MessageColumns.BODY, body); - contentValues.put(ChatDatabaseContract.MessageColumns.RECEIVED_TIMESTAMP, receivedAt); - contentValues.put(ChatDatabaseContract.MessageColumns.CREATED_TIMESTAMP, createdAt); - contentValues.put(ChatDatabaseContract.MessageColumns.READ_TIMESTAMP, readAt); - contentValues.put(ChatDatabaseContract.MessageColumns.CATEGORY, category); - contentValues.put(ChatDatabaseContract.MessageColumns.CONTENT_URL, contentUrl); - contentValues.put(ChatDatabaseContract.MessageColumns.AUTHOR_ID, authorId); - contentValues.put(ChatDatabaseContract.MessageColumns.STATUS, status); - contentValues.put(ChatDatabaseContract.MessageColumns.CUSTOM_DATA, customData); - contentValues.put(ChatDatabaseContract.MessageColumns.YOURS, isYours ? 1 : 0); - return contentValues; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepository.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepository.java deleted file mode 100644 index 43a0155c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepository.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.infobip.mobile.messaging.dal.sqlite.PrimaryKeyViolationException; - -import java.util.List; -import java.util.Set; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public interface MessageRepository { - - /** - * Returns all messages - * @return list of all messages - */ - @NonNull - List findAll(); - - /** - * Returns count of all stored messages - * @return number of stored messages - */ - long countAll(); - - /** - * Returns count of all unread messages - * @return number of unread messages - */ - long countAllUnread(); - - /** - * Finds one message by id - * @param id message id - * @return message or null - */ - @Nullable - Message findOne(@NonNull String id); - - /** - * Saves provided messages to database - * @param message message to save to repository - */ - void upsert(Message message); - - /** - * Inserts new message or throws exception - * @param message message to insert - * @throws PrimaryKeyViolationException exception when same message already exists in database - */ - void insert(Message message) throws PrimaryKeyViolationException; - - /** - * Finds message and marks it read with the provided time if message is present - * @param id message id - * @param time timestamp ms - * @return updated message - */ - @Nullable - Message markRead(String id, long time); - - /** - * Finds all messages and marks them read with the provided time. - * Will keep existing read timestamps untouched. - * @param time timestamp ms - * @return returns set of ids of messages that were marked read - */ - Set markAllMessagesRead(long time); - - /** - * Removes messages from database using provided ids - * @param ids set of ids to remove messages for - */ - void remove(String... ids); - - /** - * Clears repository and removes all messages - */ - void clear(); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepositoryImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepositoryImpl.java deleted file mode 100644 index 0b813ad5..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/MessageRepositoryImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.chat.repository.db.ChatDatabaseContract; -import org.infobip.mobile.messaging.chat.repository.db.DatabaseHelperImpl; -import org.infobip.mobile.messaging.dal.sqlite.DatabaseHelper; -import org.infobip.mobile.messaging.dal.sqlite.PrimaryKeyViolationException; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class MessageRepositoryImpl implements MessageRepository { - - private final Context context; - private DatabaseHelper databaseHelper; - - public MessageRepositoryImpl(@NonNull Context context) { - this.context = context; - } - - @VisibleForTesting - public MessageRepositoryImpl(@NonNull Context context, @NonNull DatabaseHelper databaseHelper) { - this.context = context; - this.databaseHelper = databaseHelper; - } - - @NonNull - @Override - public List findAll() { - return databaseHelper().findAll(Message.class); - } - - @Override - public long countAll() { - return databaseHelper().countAll(Message.class); - } - - @Override - public long countAllUnread() { - return databaseHelper().countAll(Message.class, - ChatDatabaseContract.MessageColumns.READ_TIMESTAMP + "IS NOT NULL AND " + ChatDatabaseContract.MessageColumns.READ_TIMESTAMP + "IS NOT 0"); - } - - @Nullable - @Override - public Message findOne(@NonNull String id) { - return databaseHelper().find(Message.class, id); - } - - @Override - public void upsert(Message message) { - databaseHelper().save(message); - } - - @Override - public void insert(Message message) throws PrimaryKeyViolationException { - databaseHelper().insert(message); - } - - @Override - public Message markRead(String id, long time) { - Message message = databaseHelper().find(Message.class, id); - if (message == null) { - return null; - } - - message.readAt = time; - databaseHelper().save(message); - return message; - } - - @Override - public Set markAllMessagesRead(long time) { - Set ids = new HashSet<>(); - for (Message message : databaseHelper().findAll(Message.class)) { - if (message.readAt != null && message.readAt > 0) { - continue; - } - - message.readAt = time; - databaseHelper().save(message); - ids.add(message.id); - } - return ids; - } - - @Override - public void remove(String... ids) { - databaseHelper().delete(Message.class, ids); - } - - @Override - public void clear() { - databaseHelper().deleteAll(Message.class); - } - - // region private methods - - private DatabaseHelper databaseHelper() { - if (databaseHelper == null) { - databaseHelper = new DatabaseHelperImpl(context); - } - return databaseHelper; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Participant.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Participant.java deleted file mode 100644 index cff68f4d..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/Participant.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.content.ContentValues; -import android.database.Cursor; - -import org.infobip.mobile.messaging.chat.repository.db.ChatDatabaseContract; -import org.infobip.mobile.messaging.dal.sqlite.DatabaseContract; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class Participant implements DatabaseContract.DatabaseObject { - - protected String id; - String firstName; - String lastName; - String middleName; - String email; - String phone; - String customData; - - @Override - public String getTableName() { - return ChatDatabaseContract.Tables.PARTICIPANTS; - } - - @Override - public String getPrimaryKeyColumnName() { - return ChatDatabaseContract.ParticipantColumns.ID; - } - - @Override - public void fillFromCursor(Cursor cursor) throws Exception { - id = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.ID)); - firstName = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.FIRST_NAME)); - lastName = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.LAST_NAME)); - middleName = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.MIDDLE_NAME)); - email = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.EMAIL)); - phone = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.GSM)); - customData = cursor.getString(cursor.getColumnIndexOrThrow(ChatDatabaseContract.ParticipantColumns.CUSTOM_DATA)); - } - - @Override - public ContentValues getContentValues() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ChatDatabaseContract.ParticipantColumns.ID, id); - contentValues.put(ChatDatabaseContract.ParticipantColumns.FIRST_NAME, firstName); - contentValues.put(ChatDatabaseContract.ParticipantColumns.LAST_NAME, lastName); - contentValues.put(ChatDatabaseContract.ParticipantColumns.MIDDLE_NAME, middleName); - contentValues.put(ChatDatabaseContract.ParticipantColumns.EMAIL, email); - contentValues.put(ChatDatabaseContract.ParticipantColumns.GSM, phone); - contentValues.put(ChatDatabaseContract.ParticipantColumns.CUSTOM_DATA, customData); - return contentValues; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepository.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepository.java deleted file mode 100644 index e9ed65fb..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepository.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.support.annotation.NonNull; - -import java.util.List; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public interface ParticipantRepository { - - /** - * Returns all known participants - * - * @return list of participants - */ - List findAll(); - - /** - * Returns participant based on provided id - * - * @param id id of participant - * @return participant - */ - Participant findOne(@NonNull String id); - - /** - * Find author of message - * - * @param message message to look author for - * @return participant - */ - Participant findAuthor(@NonNull Message message); - - /** - * Saves participant to database - * - * @param participant data to save - */ - void upsert(@NonNull Participant participant); - - /** - * Clears repository and removes all participants - */ - void clear(); -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepositoryImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepositoryImpl.java deleted file mode 100644 index 9c2c9761..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/ParticipantRepositoryImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.content.Context; -import android.support.annotation.NonNull; - -import org.infobip.mobile.messaging.chat.repository.db.DatabaseHelperImpl; -import org.infobip.mobile.messaging.dal.sqlite.DatabaseHelper; - -import java.util.List; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class ParticipantRepositoryImpl implements ParticipantRepository { - - private final Context context; - private DatabaseHelper databaseHelper; - - public ParticipantRepositoryImpl(Context context) { - this.context = context; - } - - @Override - public List findAll() { - return databaseHelper().findAll(Participant.class); - } - - @Override - public Participant findOne(@NonNull String id) { - return databaseHelper().find(Participant.class, id); - } - - @Override - public Participant findAuthor(@NonNull Message message) { - if (message.authorId == null) { - return null; - } - return databaseHelper().find(Participant.class, message.authorId); - } - - @Override - public void upsert(@NonNull Participant participant) { - databaseHelper().save(participant); - } - - @Override - public void clear() { - databaseHelper().deleteAll(Participant.class); - } - - // region private methods - - private DatabaseHelper databaseHelper() { - if (databaseHelper == null) { - databaseHelper = new DatabaseHelperImpl(context); - } - return databaseHelper; - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/RepositoryMapper.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/RepositoryMapper.java deleted file mode 100644 index f936b67c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/RepositoryMapper.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatParticipant; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class RepositoryMapper { - - @NonNull - public ChatMessage chatMessageFromDbMessageAndParticipant(@NonNull Message message, @Nullable Participant participant) { - return new ChatMessage( - message.id, - message.body, - message.chatId, - message.createdAt, - message.receivedAt, - message.readAt, - message.category, - message.contentUrl, - chatParticipantFromDbParticipant(participant), - org.infobip.mobile.messaging.Message.Status.valueOf(message.status), - MJSONObject.create(message.customData), - message.isYours); - } - - @Nullable - public ChatParticipant chatParticipantFromDbParticipant(@Nullable Participant participant) { - return participant == null ? null : new ChatParticipant( - participant.id, - participant.firstName, - participant.lastName, - participant.middleName, - participant.email, - participant.phone, - MJSONObject.create(participant.customData)); - } - - @NonNull - public Message dbMessageFromChatMessage(@NonNull ChatMessage chatMessage) { - Message message = new Message(); - message.id = chatMessage.getId(); - message.body = chatMessage.getBody(); - message.chatId = chatMessage.getChatId(); - message.createdAt = chatMessage.getCreatedAt(); - message.receivedAt = chatMessage.getReceivedAt(); - message.readAt = chatMessage.getReadAt(); - message.category = chatMessage.getCategory(); - message.contentUrl = chatMessage.getContentUrl(); - message.authorId = chatMessage.getAuthor() == null ? null : chatMessage.getAuthor().getId(); - message.status = chatMessage.getStatus() == null ? null : chatMessage.getStatus().name(); - message.customData = chatMessage.getCustomData() == null ? null : chatMessage.getCustomData().toString(); - message.isYours = chatMessage.isYours(); - return message; - } - - @NonNull - public Participant dbParticipantFromChatParticipant(@NonNull ChatParticipant chatParticipant) { - Participant participant = new Participant(); - participant.id = chatParticipant.getId(); - participant.firstName = chatParticipant.getFirstName(); - participant.lastName = chatParticipant.getLastName(); - participant.middleName = chatParticipant.getMiddleName(); - participant.email = chatParticipant.getEmail(); - participant.phone = chatParticipant.getGsm(); - participant.customData = chatParticipant.getCustomData() == null ? null : chatParticipant.getCustomData().toString(); - return participant; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/ChatDatabaseContract.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/ChatDatabaseContract.java deleted file mode 100644 index e71c7c41..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/ChatDatabaseContract.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository.db; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public interface ChatDatabaseContract { - - interface Tables { - /** - * Table for messages - */ - String MESSAGES = "messages"; - - /** - * Table for participants - */ - String PARTICIPANTS = "participants"; - } - - interface MessageColumns { - /** - * Unique string identifier, typically UUID, primary key - * [TEXT] - */ - String ID = "id"; - - /** - * Unique string identifier of chat - * [TEXT] - */ - String CHAT_ID = "chat_id"; - - /** - * Message body text - * [TEXT] - */ - String BODY = "body"; - - /** - * Timestamp when message was received - * [INTEGER] - */ - String RECEIVED_TIMESTAMP = "received_timestamp"; - - /** - * Timestamp when message was created - * [INTEGER] - */ - String CREATED_TIMESTAMP = "created_timestamp"; - - /** - * Timestamp when message was seen - * [INTEGER] - */ - String READ_TIMESTAMP = "read_timestamp"; - - /** - * Actionable category - * [TEXT] - */ - String CATEGORY = "category"; - - /** - * Actionable category - * [TEXT] - */ - String CONTENT_URL = "content_url"; - - - /** - * ID of author of message (Participant) - * [TEXT] - */ - String AUTHOR_ID = "author_id"; - - /** - * Message status name - * [TEXT] - */ - String STATUS = "status"; - - /** - * Custom data json - * [TEXT] - */ - String CUSTOM_DATA = "custom_data"; - - /** - * 1 if message belongs to current user, 0 otherwise - * [INTEGER] - */ - String YOURS = "yours"; - } - - interface ParticipantColumns { - /** - * Unique string identifier, typically UUID, primary key - * [TEXT] - */ - String ID = "id"; - - /** - * First name of participant - * [TEXT] - */ - String FIRST_NAME = "first_name"; - - /** - * Last name of participant - * [TEXT] - */ - String LAST_NAME = "last_name"; - - /** - * Middle name of participant - * [TEXT] - */ - String MIDDLE_NAME = "middle_name"; - - /** - * Email of participant - * [TEXT] - */ - String EMAIL = "email"; - - /** - * GSM number of participant - * [TEXT] - */ - String GSM = "gsm"; - - /** - * Custom data json - * [TEXT] - */ - String CUSTOM_DATA = "custom_data"; - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/DatabaseHelperImpl.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/DatabaseHelperImpl.java deleted file mode 100644 index 44e4026c..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/repository/db/DatabaseHelperImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.infobip.mobile.messaging.chat.repository.db; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.support.annotation.VisibleForTesting; - -import org.infobip.mobile.messaging.dal.sqlite.BaseDatabaseHelper; - -/** - * @author sslavin - * @since 09/10/2017. - */ - -public class DatabaseHelperImpl extends BaseDatabaseHelper { - - @VisibleForTesting - static final int VER_2018_APR_24 = 1; // Initial version - private static final int VER_CURRENT = VER_2018_APR_24; - - @SuppressWarnings("WeakerAccess") - static final String DATABASE_NAME = "mm_infobip_database_chat.db"; - - private static final String SQL_CREATE_CHAT_MESSAGES_TABLE = "CREATE TABLE " + ChatDatabaseContract.Tables.MESSAGES + " (" + - ChatDatabaseContract.MessageColumns.ID + " TEXT PRIMARY KEY NOT NULL ON CONFLICT FAIL, " + - ChatDatabaseContract.MessageColumns.CHAT_ID + " TEXT, " + - ChatDatabaseContract.MessageColumns.BODY + " TEXT, " + - ChatDatabaseContract.MessageColumns.RECEIVED_TIMESTAMP + " INTEGER, " + - ChatDatabaseContract.MessageColumns.CREATED_TIMESTAMP + " INTEGER, " + - ChatDatabaseContract.MessageColumns.READ_TIMESTAMP + " INTEGER, " + - ChatDatabaseContract.MessageColumns.CATEGORY + " TEXT, " + - ChatDatabaseContract.MessageColumns.CONTENT_URL + " TEXT, " + - ChatDatabaseContract.MessageColumns.AUTHOR_ID + " TEXT, " + - ChatDatabaseContract.MessageColumns.STATUS + " TEXT, " + - ChatDatabaseContract.MessageColumns.CUSTOM_DATA + " TEXT," + - ChatDatabaseContract.MessageColumns.YOURS + " INTEGER)"; - - private static final String SQL_CREATE_CHAT_PARTICIPANTS_TABLE = "CREATE TABLE " + ChatDatabaseContract.Tables.PARTICIPANTS + " (" + - ChatDatabaseContract.ParticipantColumns.ID + " TEXT PRIMARY KEY NOT NULL ON CONFLICT FAIL, " + - ChatDatabaseContract.ParticipantColumns.FIRST_NAME + " TEXT, " + - ChatDatabaseContract.ParticipantColumns.LAST_NAME + " TEXT, " + - ChatDatabaseContract.ParticipantColumns.MIDDLE_NAME + " TEXT, " + - ChatDatabaseContract.ParticipantColumns.EMAIL + " TEXT, " + - ChatDatabaseContract.ParticipantColumns.GSM + " TEXT, " + - ChatDatabaseContract.MessageColumns.CUSTOM_DATA + " TEXT)"; - - public DatabaseHelperImpl(Context context) { - super(context, DATABASE_NAME, VER_CURRENT); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.beginTransaction(); - db.execSQL(SQL_CREATE_CHAT_MESSAGES_TABLE); - db.execSQL(SQL_CREATE_CHAT_PARTICIPANTS_TABLE); - db.setTransactionSuccessful(); - db.endTransaction(); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // has single version now, do nothing - } -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatActivity.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatActivity.java deleted file mode 100644 index 200c4e0e..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatActivity.java +++ /dev/null @@ -1,658 +0,0 @@ -package org.infobip.mobile.messaging.chat.view; - -import android.animation.Animator; -import android.animation.AnimatorInflater; -import android.annotation.SuppressLint; -import android.app.NotificationManager; -import android.app.ProgressDialog; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.graphics.PorterDuff; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.net.ConnectivityManager; -import android.os.Bundle; -import android.os.Handler; -import android.support.design.widget.Snackbar; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.text.Html; -import android.text.TextUtils; -import android.text.method.LinkMovementMethod; -import android.util.TypedValue; -import android.view.ActionMode; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; - -import org.infobip.mobile.messaging.Message; -import org.infobip.mobile.messaging.MobileMessaging; -import org.infobip.mobile.messaging.MobileMessagingCore; -import org.infobip.mobile.messaging.User; -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatMessageStorage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.R; -import org.infobip.mobile.messaging.chat.core.MobileChatImpl; -import org.infobip.mobile.messaging.chat.properties.MobileChatProperty; -import org.infobip.mobile.messaging.chat.properties.PropertyHelper; -import org.infobip.mobile.messaging.interactive.NotificationAction; -import org.infobip.mobile.messaging.mobile.MobileMessagingError; -import org.infobip.mobile.messaging.mobile.Result; -import org.infobip.mobile.messaging.mobile.common.MAsyncTask; -import org.infobip.mobile.messaging.util.StringUtils; -import org.json.JSONObject; - -import static org.infobip.mobile.messaging.BroadcastParameter.EXTRA_EXCEPTION; -import static org.infobip.mobile.messaging.Event.API_COMMUNICATION_ERROR; -import static org.infobip.mobile.messaging.chat.ChatEvent.CHAT_MESSAGE_RECEIVED; - -public class ChatActivity extends AppCompatActivity implements ChatAdapter.ActionTappedReceiver { - - public static final String MESSAGE_TEXT_EXTRA = "messageText"; - - public static final String MO_ROUTE_NOT_ENABLED_ERROR_CODE = "14"; - public static final int CONNECTIVITY_ANIMATION_DELAY_MILLIS = 4000; - public static final int CLEAR_NOTIFICATIONS_DELAY_MILLIS = 3000; - - private EditText etReply; - private ListView messagesListView; - private TextView connectionIndicatorView; - private ChatAdapter listAdapter = null; - private ChatViewSettingsResolver chatViewSettingsResolver; - private ChatMessageStorage messageStore; - private MobileChatImpl mobileChat; - private boolean receiversRegistered = false; - private boolean inForeground = false; - private ActionMode actionMode; - private Boolean internetConnected = null; - - private Handler handler; - private Runnable clearNotificationsRunnable; - private Runnable connectivityRunnable; - - private PropertyHelper propertyHelper; - private ProgressDialog progressDialog; - - private final BroadcastReceiver messageReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - ChatMessage message = ChatMessage.createFrom(intent); - - onMessageReceived(message); - listAdapter.notifyDataSetChanged(); - - if (inForeground) { - clearNotificationsWithDelay(); - } - } - }; - private final BroadcastReceiver connectivityReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)) { - handleNotConnectedState(context); - } else { - handleConnectedState(); - } - } - }; - - private void handleNotConnectedState(Context context) { - if (messagesListView != null) { - Snackbar noConnectivitySnackbar = Snackbar.make(messagesListView, R.string.no_internet_connection, Snackbar.LENGTH_SHORT); - noConnectivitySnackbar.show(); - } - - if (connectionIndicatorView != null) { - connectionIndicatorView.setBackgroundColor(ContextCompat.getColor(context, R.color.connectivityStateColor)); - connectionIndicatorView.setText(R.string.no_connection); - connectionIndicatorView.setVisibility(View.VISIBLE); - } - internetConnected = false; - } - - private void handleConnectedState() { - if (connectionIndicatorView != null && internetConnected != null && !internetConnected) { - Animator animator = AnimatorInflater.loadAnimator(ChatActivity.this, R.animator.connectivity_state); - animator.setTarget(connectionIndicatorView); - animator.start(); - connectionIndicatorView.setText(R.string.connected); - } - - connectivityRunnable = new Runnable() { - @Override - public void run() { - if (connectionIndicatorView != null) { - connectionIndicatorView.setVisibility(View.GONE); - } - } - }; - handler.postDelayed(connectivityRunnable, CONNECTIVITY_ANIMATION_DELAY_MILLIS); - internetConnected = true; - } - - private void clearNotificationsWithDelay() { - if (actionMode == null) { - // fix for reported bug that chat notification isn't canceled when user is on the chat screen - // we need notification displayed event in lib for this delayed behaviour to be changed - if (clearNotificationsRunnable == null) { - clearNotificationsRunnable = new Runnable() { - @Override - public void run() { - clearNotifications(); - } - }; - } - handler.postDelayed(clearNotificationsRunnable, CLEAR_NOTIFICATIONS_DELAY_MILLIS); - } - } - - private final BroadcastReceiver errorReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - MobileMessagingError mobileMessagingError = null; - if (intent.hasExtra(EXTRA_EXCEPTION)) { - mobileMessagingError = (MobileMessagingError) intent.getSerializableExtra(EXTRA_EXCEPTION); - } - - if (mobileMessagingError == null) { - return; - } - - if (MO_ROUTE_NOT_ENABLED_ERROR_CODE.equals(mobileMessagingError.getCode())) { - showMoRouteNotEnabledDialog(); - } - } - }; - - protected void onMessageReceived(ChatMessage message) { - String body = message.getBody(); - if (StringUtils.isBlank(message.getCategory())) { - Toast.makeText(this, String.format(getString(R.string.toast_message_received), body), Toast.LENGTH_LONG).show(); - } - - configureEmptyState(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - scrollToBottom(); - } - } - - private void showMoRouteNotEnabledDialog() { - AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(ChatActivity.this); - alertDialogBuilderUserInput - .setCancelable(true) - .setMessage(getString(R.string.dialog_text_mo_route_not_enabled)) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dialogInterface.cancel(); - } - }); - AlertDialog alertDialog = alertDialogBuilderUserInput.create(); - alertDialog.show(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - chatViewSettingsResolver = new ChatViewSettingsResolver(this); - setTheme(chatViewSettingsResolver.getChatViewTheme()); - - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_chat); - Toolbar toolbar = findViewById(R.id.toolbar); - setUpToolbar(toolbar, chatViewSettingsResolver.getChatViewTitle(), true); - - mobileChat = (MobileChatImpl) MobileChatImpl.getInstance(this); - messageStore = mobileChat.getChatMessageStorage(); - configureEmptyState(); - - propertyHelper = new PropertyHelper(this); - - etReply = findViewById(R.id.et_reply); - ImageView ivReply = findViewById(R.id.iv_reply); - messagesListView = findViewById(R.id.messagesListView); - connectionIndicatorView = findViewById(R.id.connection_indicator); - - LinearLayout llEmptyState = findViewById(R.id.ll_empty_state); - messagesListView.setEmptyView(llEmptyState); - - messagesListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { - messagesListView.setItemChecked(position, !messagesListView.isItemChecked(position)); - return true; - } - }); - - messagesListView.setMultiChoiceModeListener(new ChatMultiChoiceModeListener()); - messagesListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); - - listAdapter = new ChatAdapter(this, mobileChat.chatView().getNotificationCategories(), messageStore.findAllMessages(), this); - messagesListView.setAdapter(listAdapter); - messageStore.registerListener(listAdapter); - - if (ivReply != null) { - ivReply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (TextUtils.isEmpty(getUserNameFromAuthor()) || - !propertyHelper.findBoolean(MobileChatProperty.USER_NAME_DIALOG_SHOWN)) { - showUserNameInputDialog(); - } else { - sendMessage(); - } - } - }); - } - - handler = new Handler(); - - registerReceivers(); - scrollToBottom(); - - processSendRequestIfAny(getIntent()); - } - - @Override - protected void onDestroy() { - unregisterReceivers(); - messageStore.unregisterListener(listAdapter); - if (handler != null) { - if (clearNotificationsRunnable != null) { - handler.removeCallbacks(clearNotificationsRunnable); - } - if (connectivityRunnable != null) { - handler.removeCallbacks(connectivityRunnable); - } - } - super.onDestroy(); - } - - @Override - protected void onResume() { - super.onResume(); - inForeground = true; - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - if (actionMode == null) { - clearNotifications(); - } - } - - @Override - protected void onPause() { - super.onPause(); - inForeground = false; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - - if (id == android.R.id.home) { - onBackPressed(); - return true; - } - - if (id == R.id.action_mark_all_seen) { - markAllSeen(); - return true; - } - - if (id == R.id.action_clear_chat) { - clearChatHistory(); - return true; - } - - return super.onOptionsItemSelected(item); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_chat, menu); - return true; - } - - @Override - public void actionTapped(ChatMessage message, NotificationAction action) { - mobileChat.processTappedAction(message, action); - } - - private void processSendRequestIfAny(Intent intent) { - final String text = intent.getStringExtra(MESSAGE_TEXT_EXTRA); - if (TextUtils.isEmpty(text)) { - return; - } - - etReply.setText(text); - etReply.setSelection(text.length()); - etReply.requestFocus(); - - if (TextUtils.isEmpty(getUserNameFromAuthor()) || - !propertyHelper.findBoolean(MobileChatProperty.USER_NAME_DIALOG_SHOWN)) { - showUserNameInputDialog(); - } else { - sendMessage(); - } - } - - protected void markAllSeen() { - - new MAsyncTask() { - - ProgressDialog progressDialog; - - @Override - public void before() { - progressDialog = ProgressDialog.show(ChatActivity.this, getString(R.string.progress_title_wait), getString(R.string.progress_processing_messages), true); - } - - @Override - public Void run(Void... params) { - mobileChat.markAllMessagesRead(); - return null; - } - - @Override - public void after(Void aVoid) { - progressDialog.dismiss(); - } - }.execute(); - } - - protected void clearChatHistory() { - if (messageStore != null) { - messageStore.deleteAll(); - } - configureEmptyState(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - clearNotifications(); - } - - private void onMessageSent(ChatMessage message) { - if (message.getStatus() == Message.Status.SUCCESS) { - Toast.makeText(ChatActivity.this, R.string.message_sent, Toast.LENGTH_SHORT).show(); - } - - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - } - - private void sendMessage() { - String text = etReply.getText().toString(); - if (text.trim().length() == 0) { - return; - } - - mobileChat.sendMessage(text, new JSONObject(), new MobileMessaging.ResultListener() { - @Override - public void onResult(Result result) { - if (result.isSuccess()) { - if (internetConnected != null && !internetConnected) { - showToast(R.string.sending_message_failed_no_connection); - } - - onMessageSent(result.getData()); - scrollToBottom(); - } - } - }); - - configureEmptyState(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - scrollToBottom(); - } - - etReply.setText(""); - } - - private void scrollToBottom() { - if (messagesListView == null) { - return; - } - - messagesListView.post(new Runnable() { - @Override - public void run() { - if (listAdapter != null && !listAdapter.isEmpty()) { - messagesListView.setSelection(listAdapter.getCount() - 1); - } - } - }); - } - - protected void registerReceivers() { - if (!receiversRegistered) { - LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this); - localBroadcastManager.registerReceiver(errorReceiver, new IntentFilter(API_COMMUNICATION_ERROR.getKey())); - localBroadcastManager.registerReceiver(messageReceiver, new IntentFilter(CHAT_MESSAGE_RECEIVED.getKey())); - registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); - receiversRegistered = true; - } - } - - protected void unregisterReceivers() { - if (receiversRegistered) { - LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this); - localBroadcastManager.unregisterReceiver(errorReceiver); - localBroadcastManager.unregisterReceiver(messageReceiver); - unregisterReceiver(connectivityReceiver); - receiversRegistered = false; - } - } - - protected void clearNotifications() { - NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null) notificationManager.cancelAll(); - } - - private void showUserNameInputDialog() { - User user = MobileMessagingCore.getInstance(this).getUser(); - if (user != null) { - String firstName = user.getFirstName(); - String lastName = user.getLastName(); - - if (StringUtils.isNotBlank(firstName) || StringUtils.isNotBlank(lastName)) { - createChatParticipantAndSendMessage(firstName, lastName); - return; - } - } - - LayoutInflater inflater = LayoutInflater.from(this); - @SuppressLint("InflateParams") - View mView = inflater.inflate(R.layout.username_dialog, null); - AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); - alertDialogBuilderUserInput.setView(mView); - - final EditText etUserName = mView.findViewById(R.id.etUserName); - etUserName.setText(getUserNameFromAuthor()); - alertDialogBuilderUserInput - .setCancelable(false) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogBox, int id) { - dialogBox.dismiss(); - showProgressDialog(getString(R.string.progress_title_wait)); - - String userName = etUserName.getText().toString(); - - createChatParticipantAndSendMessage(userName, null); - } - }); - - AlertDialog alertDialogAndroid = alertDialogBuilderUserInput.create(); - alertDialogAndroid.show(); - } - - void createChatParticipantAndSendMessage(String firstName, String lastName) { - ChatParticipant chatParticipant = mobileChat.getUserInfo(); - chatParticipant.setFirstName(firstName); - if (StringUtils.isNotBlank(lastName)) { - chatParticipant.setLastName(lastName); - } - chatParticipant.setCustomData(new JSONObject()); - - mobileChat.setUserInfo(chatParticipant, new MobileMessaging.ResultListener() { - @Override - public void onResult(Result result) { - if (!result.isSuccess()) { - hideProgressDialog(); - Toast.makeText(ChatActivity.this, result.getError().getMessage(), Toast.LENGTH_SHORT).show(); - return; - } - - propertyHelper.saveBoolean(MobileChatProperty.USER_NAME_DIALOG_SHOWN, true); - sendMessage(); - hideProgressDialog(); - } - }); - } - - String getUserNameFromAuthor() { - ChatParticipant author = mobileChat.getUserInfo(); - return author.getUserName(); - } - - private class ChatMultiChoiceModeListener implements AbsListView.MultiChoiceModeListener { - @Override - public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - final int checkedCount = messagesListView.getCheckedItemCount(); - - mode.setTitle(String.format(getString(R.string.chat_selected), checkedCount)); - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - actionMode = mode; - ChatActivity.this.getMenuInflater().inflate(R.menu.menu_chat_item, menu); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) { - if (menuItem.getItemId() == R.id.action_delete) { - for (int i = 0; i < messagesListView.getCount(); i++) { - if (messagesListView.isItemChecked(i)) { - messageStore.delete(listAdapter.getItem(i).getId()); - } - } - } - actionMode.finish(); - configureEmptyState(); - return true; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - actionMode = null; - listAdapter.notifyDataSetChanged(); - clearNotifications(); - } - } - - protected void showProgressDialog(String message) { - if (progressDialog == null) { - progressDialog = new ProgressDialog(this); - } - progressDialog.setMessage(message); - progressDialog.show(); - } - - protected void hideProgressDialog() { - if (progressDialog != null) { - progressDialog.dismiss(); - } - } - - protected void showToast(int resId) { - showToast(getString(resId)); - } - - protected void showToast(String text) { - Toast.makeText(this, text, Toast.LENGTH_LONG).show(); - } - - protected void setUpToolbar(Toolbar toolbar, String title, boolean displayHomeAsUpEnabled) { - if (toolbar == null) return; - - setSupportActionBar(toolbar); - ActionBar supportActionBar = getSupportActionBar(); - if (supportActionBar != null) { - supportActionBar.setTitle(""); - - TypedValue colorValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.colorPrimary, colorValue, true); - supportActionBar.setBackgroundDrawable(new ColorDrawable(colorValue.data)); - - if (title != null) { - setToolbarTitle(title); - } - - if (displayHomeAsUpEnabled) { - supportActionBar.setDisplayHomeAsUpEnabled(true); - - // set back arrow color to white - Drawable drawable = toolbar.getNavigationIcon(); - if (drawable != null) { - drawable.setColorFilter(ContextCompat.getColor(this, android.R.color.white), PorterDuff.Mode.SRC_ATOP); - } - } else { - toolbar.setNavigationIcon(R.drawable.ic_menu_white); - } - } - } - - protected void setToolbarTitle(String title) { - TextView tvTitle = findViewById(R.id.tv_toolbar_title); - if (tvTitle == null) { - return; - } - tvTitle.setText(title); - } - - private void configureEmptyState() { - TextView tv = findViewById(R.id.tv_empty_state); - RelativeLayout rl = findViewById(R.id.rl_chat_messages); - if (messageStore.countAllMessages() == 0) { - tv.setVisibility(View.VISIBLE); - tv.setText(Html.fromHtml(chatViewSettingsResolver.getChatViewEmptyStateText())); - tv.setClickable(true); - tv.setMovementMethod(LinkMovementMethod.getInstance()); - rl.setVisibility(View.GONE); - } else { - tv.setVisibility(View.GONE); - rl.setVisibility(View.VISIBLE); - } - } -} \ No newline at end of file diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatAdapter.java b/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatAdapter.java deleted file mode 100644 index fa03df58..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/ChatAdapter.java +++ /dev/null @@ -1,237 +0,0 @@ -package org.infobip.mobile.messaging.chat.view; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.text.TextUtils; -import android.text.format.DateUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; - -import org.infobip.mobile.messaging.Message.Status; -import org.infobip.mobile.messaging.chat.ChatMessage; -import org.infobip.mobile.messaging.chat.ChatMessageStorage; -import org.infobip.mobile.messaging.chat.ChatParticipant; -import org.infobip.mobile.messaging.chat.R; -import org.infobip.mobile.messaging.interactive.NotificationAction; -import org.infobip.mobile.messaging.interactive.NotificationCategory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static android.support.annotation.VisibleForTesting.PACKAGE_PRIVATE; - -public class ChatAdapter extends BaseAdapter implements ChatMessageStorage.Listener { - - private static final int MAX_ACTION_BUTTONS_IN_MESSAGE = 3; - - private final Context context; - private final List messages = new ArrayList<>(); - private final Map> notificationActions = new HashMap<>(); - private final ActionTappedReceiver actionTappedReceiver; - - public interface ActionTappedReceiver { - void actionTapped(ChatMessage message, NotificationAction action); - } - - @VisibleForTesting(otherwise = PACKAGE_PRIVATE) - public ChatAdapter(Context context, Set notificationCategories, List existingMessages, ActionTappedReceiver actionTappedReceiver) { - this.context = context; - this.messages.addAll(existingMessages); - this.actionTappedReceiver = actionTappedReceiver; - - for (NotificationCategory category : notificationCategories) { - List actions = new ArrayList<>(category.getNotificationActions().length); - for (NotificationAction action : category.getNotificationActions()) { - if (!action.hasInput()) { - actions.add(action); - } - } - actions = actions.subList(0, Math.min(actions.size(), MAX_ACTION_BUTTONS_IN_MESSAGE)); - notificationActions.put(category.getCategoryId(), actions); - } - } - - @Override - public int getCount() { - return messages.size(); - } - - @Override - public ChatMessage getItem(int position) { - return messages.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ChatMessage message = messages.get(position); - View view = initViewHolder(convertView, message.isYours()); - fillView(view, message); - return view; - } - - @Override - public int getViewTypeCount() { - return 2; - } - - @Override - public int getItemViewType(int position) { - ChatMessage message = messages.get(position); - return message.isYours() ? 1 : 0; - } - - @Override - public void onNew(ChatMessage message) { - messages.add(message); - Collections.sort(messages); - notifyDataSetChanged(); - } - - @Override - public void onUpdated(ChatMessage message) { - int position = getPosition(message.getId()); - if (position >= 0) { - messages.set(position, message); - } else { - messages.add(message); - } - Collections.sort(messages); - notifyDataSetChanged(); - } - - @Override - public void onDeleted(String messageId) { - int position = getPosition(messageId); - if (position >= 0) { - messages.remove(position); - notifyDataSetChanged(); - } - } - - @Override - public void onAllDeleted() { - messages.clear(); - notifyDataSetChanged(); - } - - // region private methods - - private static class ViewHolder { - private ImageView messageStatus; - private TextView messageTextView; - private TextView timeTextView; - private TextView senderTextView; - private Button[] buttons; - } - - private String getUserName(ChatMessage message) { - if (message == null || message.getAuthor() == null) { - return ""; - } - - ChatParticipant author = message.getAuthor(); - return author.getUserName(); - } - - private int getPosition(String messageId) { - for (int position = 0; position < messages.size(); position++) { - if (messages.get(position).getId().equalsIgnoreCase(messageId)) { - return position; - } - } - return -1; - } - - @SuppressLint("InflateParams") - @NonNull - private View initViewHolder(@Nullable View convertView, boolean isYours) { - if (convertView != null) { - return convertView; - } - - View view; - if (isYours) { - view = LayoutInflater.from(context).inflate(R.layout.list_item_chat_message_outgoing, null, false); - ViewHolder holder = new ViewHolder(); - holder.messageTextView = view.findViewById(R.id.message_text); - holder.timeTextView = view.findViewById(R.id.time_text); - holder.messageStatus = view.findViewById(R.id.user_reply_status); - view.setTag(holder); - } else { - view = LayoutInflater.from(context).inflate(R.layout.list_item_chat_message_incoming, null, false); - ViewHolder holder = new ViewHolder(); - holder.messageTextView = view.findViewById(R.id.message_text); - holder.timeTextView = view.findViewById(R.id.time_text); - holder.senderTextView = view.findViewById(R.id.chat_company_reply_author); - holder.buttons = new Button[]{view.findViewById(R.id.btn_action_1), view.findViewById(R.id.btn_action_2), view.findViewById(R.id.btn_action_3)}; - view.setTag(holder); - } - return view; - } - - private void fillView(@NonNull View view, final ChatMessage message) { - ViewHolder holder = (ViewHolder) view.getTag(); - if (message.isYours()) { - holder.messageTextView.setText(message.getBody()); - holder.timeTextView.setText(DateUtils.getRelativeTimeSpanString(context, message.getCreatedAt())); - - if (message.getStatus() == Status.UNKNOWN) { - holder.messageStatus.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_clock)); - } else if (message.getStatus() == Status.SUCCESS) { - holder.messageStatus.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_single_tick)); - } else { - holder.messageStatus.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_error)); - } - } else { - holder.messageTextView.setText(message.getBody()); - holder.timeTextView.setText(DateUtils.getRelativeTimeSpanString(context, message.getCreatedAt())); - - String userName = getUserName(message); - if (!TextUtils.isEmpty(userName)) { - holder.senderTextView.setText(userName); - holder.senderTextView.setVisibility(View.VISIBLE); - } else { - holder.senderTextView.setVisibility(View.GONE); - } - - List actions = notificationActions.get(message.getCategory()); - if (actions == null) actions = Collections.emptyList(); - for (int index = 0; index < holder.buttons.length; index++) { - final NotificationAction action = index < actions.size() ? actions.get(index) : null; - if (action != null) { - holder.buttons[index].setVisibility(View.VISIBLE); - holder.buttons[index].setText(action.getTitleResourceId()); - holder.buttons[index].setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (actionTappedReceiver != null) { - actionTappedReceiver.actionTapped(message, action); - } - } - }); - } else { - holder.buttons[index].setVisibility(View.GONE); - } - } - } - } - - // endregion -} diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/animator/connectivity_state.xml b/infobip-mobile-messaging-android-chat-sdk/src/main/res/animator/connectivity_state.xml deleted file mode 100644 index 56fa9e2e..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/res/animator/connectivity_state.xml +++ /dev/null @@ -1,6 +0,0 @@ - - \ No newline at end of file diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_incoming_normal.9.png b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_incoming_normal.9.png deleted file mode 100644 index c9a3f766..00000000 Binary files a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_incoming_normal.9.png and /dev/null differ diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_outgoing_normal.9.png b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_outgoing_normal.9.png deleted file mode 100644 index 31b56706..00000000 Binary files a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/balloon_outgoing_normal.9.png and /dev/null differ diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_chat_send.png b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_chat_send.png deleted file mode 100644 index fb8fa3c7..00000000 Binary files a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_chat_send.png and /dev/null differ diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_error.png b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_error.png deleted file mode 100644 index fccac99a..00000000 Binary files a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_error.png and /dev/null differ diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_single_tick.png b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_single_tick.png deleted file mode 100644 index c5611e1e..00000000 Binary files a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable-xxhdpi/ic_single_tick.png and /dev/null differ diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable/ic_clock.xml b/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable/ic_clock.xml deleted file mode 100644 index 9c506de3..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/res/drawable/ic_clock.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/activity_chat.xml b/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/activity_chat.xml deleted file mode 100644 index 2d3e0caf..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/activity_chat.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/list_item_chat_message_incoming.xml b/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/list_item_chat_message_incoming.xml deleted file mode 100644 index 7e208bb5..00000000 --- a/infobip-mobile-messaging-android-chat-sdk/src/main/res/layout/list_item_chat_message_incoming.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - -