Skip to content

Commit

Permalink
update to SDK version 1.8.2 (#48)
Browse files Browse the repository at this point in the history
* - add proguard rules;

* add active inactive state (#47)

* remove initForChat

* remove dialog.join() (#49)

* fix allMessageListener initialization

* update version to 1.2.1

Co-authored-by: TatankaConCube <48598737+TatankaConCube@users.noreply.github.com>
  • Loading branch information
CubeRomanMagellan and TatankaConCube committed Feb 28, 2020
1 parent 71f29ae commit 2bd96d3
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 33 deletions.
12 changes: 8 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.connectycube.messenger"
minSdkVersion 16
targetSdkVersion 28
versionCode 3
versionName "1.2.0"
versionCode 4
versionName "1.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
javaCompileOptions {
Expand All @@ -26,11 +26,14 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-connectycube-sdk.pro',
'proguard-gson.pro',
'proguard-rules.pro',
'proguard-matisse.pro',
'proguard-glide.pro'

}
}

// work-runtime-ktx 2.1.0 and above now requires Java 8
kotlinOptions {
jvmTarget = "1.8"
Expand All @@ -43,7 +46,7 @@ android {
}

ext {
sdkVersion = '1.8.1'
sdkVersion = '1.8.2'
roomVersion = '2.2.0-beta01'
lifecycleVersion = '2.2.0-alpha02'
workVersion = '2.1.0'
Expand Down Expand Up @@ -82,6 +85,7 @@ private static void androidJetPackComponents(configuration, roomVersion, lifecyc
configuration.implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
configuration.implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
configuration.implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
configuration.implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
configuration.implementation "androidx.paging:paging-runtime-ktx:$paging_version"
configuration.implementation "androidx.work:work-runtime-ktx:$workVersion"
}
Expand Down
28 changes: 28 additions & 0 deletions app/proguard-connectycube-sdk.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-keep class com.connectycube.auth.model.** { !transient <fields>; }

-keep class com.connectycube.chat.model.** { !transient <fields>; }

-keep class com.connectycube.core.model.** { !transient <fields>; }
-keep class com.connectycube.core.server.** { *; }
-keep class com.connectycube.core.rest.** { *; }
-keep class com.connectycube.core.error.** { *; }
-keep class com.connectycube.core.account.model.** { !transient <fields>; }

-keep class com.connectycube.customobjects.model.** { !transient <fields>; }

# uncomment if use Connectycube Extentions lib
#-keep class com.connectycube.extensions.** { *; }

-keep class com.connectycube.pushnotifications.model.** { !transient <fields>; }

-keep class com.connectycube.storage.model.** { !transient <fields>; }

-keep class com.connectycube.users.model.** { !transient <fields>; }

-keep class com.connectycube.videochat.** { *; }

-keep class org.jivesoftware.** { *; }

-dontwarn org.jivesoftware.smackx.**

-keep class org.webrtc.** { *; }
28 changes: 28 additions & 0 deletions app/proguard-gson.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}

##---------------End: proguard configuration for Gson ----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.connectycube.messenger

import androidx.lifecycle.*
import com.connectycube.chat.ConnectycubeChatService
import com.connectycube.messenger.events.EVENT_CHAT_LOGIN
import com.connectycube.messenger.events.EventChatConnection
import com.connectycube.messenger.events.LiveDataBus
import timber.log.Timber


class ChatAppLifecycleObserver : DefaultLifecycleObserver {

fun registeredObserver() {
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}

private fun registeredEventChat(lifecycle: LifecycleOwner) {
LiveDataBus.subscribe(EVENT_CHAT_LOGIN, lifecycle, Observer<EventChatConnection> {
if (it.connected) {
Timber.d("connected")
if (ProcessLifecycleOwner.get().lifecycle.currentState == Lifecycle.State.RESUMED) {
Timber.d("connected enterActiveState")
ConnectycubeChatService.getInstance().enterActiveState()
}
}
})
}

private fun unregisteredEventChat(lifecycle: LifecycleOwner) {
LiveDataBus.unsubscribe<EventChatConnection>(EVENT_CHAT_LOGIN, lifecycle)
}

fun unregisteredObserver() {
ProcessLifecycleOwner.get().lifecycle.removeObserver(this)
}

override fun onStart(owner: LifecycleOwner) {
registeredEventChat(owner)
if (ConnectycubeChatService.getInstance().isLoggedIn) {
Timber.d("onStart enterActiveState")
ConnectycubeChatService.getInstance().enterActiveState()
}
}

override fun onStop(owner: LifecycleOwner) {
unregisteredEventChat(owner)
if (ConnectycubeChatService.getInstance().isLoggedIn) {
Timber.d("onStop enterInactiveState")
ConnectycubeChatService.getInstance().enterInactiveState()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ChatConnectionManager {

private val isPending = AtomicBoolean(false)
private val isInitialized = AtomicBoolean(false)
private val chatAppObserver = ChatAppLifecycleObserver()

fun initWith(context: Context) {
Timber.d("initWith, isPending ${isPending.get()}")
Expand All @@ -47,6 +48,7 @@ class ChatConnectionManager {
override fun onSuccess(void: Void?, bundle: Bundle?) {
isPending.set(false)
isInitialized.set(true)
registerAppLifeCycleObserver()
initCallManager(context)
}

Expand Down Expand Up @@ -74,6 +76,14 @@ class ChatConnectionManager {
})
}

private fun registerAppLifeCycleObserver() {
chatAppObserver.registeredObserver()
}

private fun unregisterAppLifeCycleObserver() {
chatAppObserver.unregisteredObserver()
}

private fun notifyErrorLoginToChat(exception: Exception) {
LiveDataBus.publish(EVENT_CHAT_LOGIN, EventChatConnection.error(exception))
}
Expand All @@ -91,6 +101,7 @@ class ChatConnectionManager {

fun terminate() {
ConnectycubeChatService.getInstance().destroy()
unregisterAppLifeCycleObserver()
isPending.set(false)
isInitialized.set(false)
instance = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
private lateinit var chatDialogAdapter: ChatDialogAdapter
private var incomingMessagesManager: IncomingMessagesManager? = null
private val messageStatusListener: MessageStatusListener = ChatMessagesStatusListener()
private val allMessageListener: AllMessageListener = AllMessageListener()

private var currentDialogId: String? = null

Expand Down Expand Up @@ -106,6 +107,11 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
private fun subscribeUi() {
Timber.d("subscribeUi")
showProgress(progressbar)

if(ConnectycubeChatService.getInstance().isLoggedIn) {
initManagers()
}

LiveDataBus.subscribe(EVENT_CHAT_LOGIN, this, Observer<EventChatConnection> {
if (it.error != null) {
val errMsg =
Expand Down Expand Up @@ -144,14 +150,12 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
private fun initManagers() {
ConnectycubeChatService.getInstance().messageStatusesManager?.addMessageStatusListener(messageStatusListener)
incomingMessagesManager = ConnectycubeChatService.getInstance().incomingMessagesManager
incomingMessagesManager?.addDialogMessageListener(AllMessageListener())
incomingMessagesManager?.addDialogMessageListener(allMessageListener)
}

private fun unregisterChatManagers() {
ConnectycubeChatService.getInstance().messageStatusesManager?.removeMessageStatusListener(messageStatusListener)
incomingMessagesManager?.dialogMessageListeners?.forEach {
incomingMessagesManager?.removeDialogMessageListrener(it)
}
incomingMessagesManager?.removeDialogMessageListrener(allMessageListener)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
39 changes: 16 additions & 23 deletions app/src/main/java/com/connectycube/messenger/ChatMessageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,34 @@ class ChatMessageActivity : BaseChatActivity() {
Timber.d("onCreate")
setContentView(R.layout.activity_chatmessages)
setSupportActionBar(toolbar)
initWithData(intent)
initWithData()
}

private fun initWithData(intent: Intent) {
override fun onResume() {
super.onResume()
handleNotifications()
}

private fun initWithData() {
if (intent.hasExtra(EXTRA_CHAT)) {
val chatDialog = intent.getSerializableExtra(EXTRA_CHAT) as ConnectycubeChatDialog
modelChatMessageList = getChatMessageListViewModel(chatDialog.dialogId)
AppNotificationManager.getInstance().clearNotificationData(this, chatDialog.dialogId)
} else if (intent.hasExtra(EXTRA_CHAT_ID)) {
val dialogId = intent.getStringExtra(EXTRA_CHAT_ID)
modelChatMessageList = getChatMessageListViewModel(dialogId)
AppNotificationManager.getInstance().clearNotificationData(this, dialogId)
}

subscribeToDialog()
}

private fun handleNotifications() {
if (intent.hasExtra(EXTRA_CHAT)) AppNotificationManager.getInstance().clearNotificationData(
this, (intent.getSerializableExtra(EXTRA_CHAT) as ConnectycubeChatDialog).dialogId
)
if (intent.hasExtra(EXTRA_CHAT_ID)) AppNotificationManager.getInstance().clearNotificationData(
this, intent.getStringExtra(EXTRA_CHAT_ID)
)
}

private fun subscribeToDialog() {
modelChatMessageList.liveDialog.observe(this, Observer { resource ->
when (resource.status) {
Expand Down Expand Up @@ -250,9 +261,6 @@ class ChatMessageActivity : BaseChatActivity() {
}

private fun bindToChatConnection() {
chatDialog.initForChat(ConnectycubeChatService.getInstance())
initChat(chatDialog)

subscribeMessageSenderAttachment()
subscribeMessageSenderText()
chatDialog.addMessageListener(messageListener)
Expand Down Expand Up @@ -404,21 +412,6 @@ class ChatMessageActivity : BaseChatActivity() {
chatAdapter.setOccupants(occupants)
}

private fun initChat(chatDialog: ConnectycubeChatDialog) {
when (chatDialog.type) {
ConnectycubeDialogType.GROUP, ConnectycubeDialogType.BROADCAST -> {
chatDialog.join(null)
}

ConnectycubeDialogType.PRIVATE -> Timber.d("ConnectycubeDialogType.PRIVATE type")

else -> {
Timber.d("Unsupported type")
finish()
}
}
}

private fun initManagers() {
chatDialog.addIsTypingListener(messageTypingListener)
chatDialog.addMessageSentListener(messageSentListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface MessageDao {
@Query("SELECT * FROM messages WHERE dialogId = :dialogId ORDER BY dateSent DESC")
fun postsByDialogId(dialogId: String): DataSource.Factory<Int, Message>

@Query("DELETE FROM messages WHERE id = :dialogId")
@Query("DELETE FROM messages WHERE dialogId = :dialogId")
fun deleteByDialogId(dialogId: String)

@Query("DELETE FROM messages WHERE id = :messageId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class MessageSenderRepository private constructor(private val messageDao: Messag
): ConnectycubeChatMessage {
val chatMessage = ConnectycubeChatMessage()
chatMessage.id = messageToTempSave.id
chatMessage.dialogId = messageToTempSave.dialogId
chatMessage.setSaveToHistory(true)
chatMessage.dateSent = System.currentTimeMillis() / 1000
chatMessage.isMarkable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ object LiveDataBus {
events.remove(eventId)
}

/**
* Removes all observers that are tied to the given LifecycleOwner.
*/
fun <T>unsubscribe(@EventIdentifier eventId: Int, lifecycle: LifecycleOwner) {
getLiveData<T>(eventId).removeObservers(lifecycle)
}

/**
* Publish an object to the specified eventId for all subscribers of that eventId.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ object SettingsProvider {
val builder = TcpConfigurationBuilder()
.setAllowListenNetwork(true)
.setUseStreamManagement(true)
.setSocketTimeout(0)

ConnectycubeChatService.setConnectionFabric(TcpChatConnectionFabric(builder.apply { socketTimeout = 0 }))
ConnectycubeChatService.setConnectionFabric(TcpChatConnectionFabric(builder))

}
}

0 comments on commit 2bd96d3

Please sign in to comment.