Skip to content

Commit

Permalink
Merge pull request #12 from cometchat-pro/dev
Browse files Browse the repository at this point in the history
Android Kotlin UI Kit v3.0.14-1
  • Loading branch information
vivekCometChat authored Apr 13, 2023
2 parents 133bf35 + b907f6e commit 2d18876
Show file tree
Hide file tree
Showing 40 changed files with 689 additions and 444 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ android {
```
## Configure CometChat inside your app
### i. Initialize CometChat
The `init()` method initializes the settings required for CometChat. We suggest calling the init() method on app startup, preferably in the onCreate() method of the Application class.
The `init()` method initializes the settings required for CometChat. Please make sure to call this method before calling any other methods from CometChat SDK.

```kotlin
private val appID = "APP_ID"
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ buildscript {
ext.kotlin_version = '1.5.20'
repositories {
google()
jcenter()
mavenCentral()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:7.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,7 +18,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()

maven {
url "https://dl.cloudsmith.io/public/cometchat/cometchat-pro-android/maven/"
Expand Down
Binary file added uikit-kotlin/.DS_Store
Binary file not shown.
10 changes: 4 additions & 6 deletions uikit-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 30
compileSdkVersion 33

defaultConfig {
minSdkVersion 24
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand Down Expand Up @@ -51,10 +51,8 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
testImplementation 'junit:junit:4.12'

implementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down Expand Up @@ -85,8 +83,8 @@ dependencies {
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0'

//cometchat
compileOnly 'com.cometchat:pro-android-chat-sdk:2.4.1'
compileOnly 'com.cometchat:pro-android-calls-sdk:2.1.0'
compileOnly 'com.cometchat:pro-android-chat-sdk:3.0.14'
compileOnly 'com.cometchat:pro-android-calls-sdk:2.3.0'

def activityKtxVersion = "1.3.1"
implementation "androidx.activity:activity-ktx:$activityKtxVersion"
Expand Down
Binary file added uikit-kotlin/src/.DS_Store
Binary file not shown.
Binary file added uikit-kotlin/src/main/.DS_Store
Binary file not shown.
19 changes: 17 additions & 2 deletions uikit-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
tools:targetApi="R">

<activity android:name=".ui_components.chats.CometChatStartConversation" />
<activity android:name=".ui_components.calls.call_manager.CometChatStartCallActivity" />
<activity android:name=".ui_components.calls.call_manager.CometChatStartCallActivity"
android:launchMode="singleInstance"/>
<activity android:name=".ui_components.messages.extensions.collaborative.CometChatCollaborativeActivity" />
<activity android:name=".ui_components.messages.extensions.message_reaction.CometChatReactionInfoActivity" />
<activity android:name=".ui_components.messages.message_information.CometChatMessageInfoScreenActivity" />
Expand Down Expand Up @@ -61,7 +62,8 @@
android:screenOrientation="portrait" />
<activity
android:name=".ui_components.messages.forward_message.CometChatForwardMessageActivity"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />

Expand Down Expand Up @@ -99,6 +101,19 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_path" />
</provider>

<receiver
android:name=".ui_components.calls.call_manager.ongoing_call.OngoingCallBroadcast"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="restartService" />
</intent-filter>
</receiver>

<service
android:name=".ui_components.calls.call_manager.ongoing_call.OngoingCallService"
android:enabled="true" />
</application>

</manifest>
Binary file added uikit-kotlin/src/main/java/.DS_Store
Binary file not shown.
Binary file added uikit-kotlin/src/main/java/com/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AllCall : Fragment() {
private fun initiateCall(`var`: Call) {
CometChat.initiateCall(`var`, object : CallbackListener<Call>() {
override fun onSuccess(call: Call) {
Log.e("onSuccess: ", call.toString())
Log.v("onSuccess: ", call.toString())
if (call.receiverType == CometChatConstants.RECEIVER_TYPE_USER) {
val user: User
user = if ((call.callInitiator as User).uid == CometChat.getLoggedInUser().uid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ class CometChatNewCallList constructor() : AppCompatActivity() {
*/
private fun fetchUsers() {
if (usersRequest == null) {
Log.e(TAG, "newfetchUsers: ")
Log.v(TAG, "newfetchUsers: ")
usersRequest = UsersRequestBuilder().setLimit(30).build()
}
usersRequest!!.fetchNext(object : CallbackListener<List<User?>>() {
public override fun onSuccess(users: List<User?>) {
Log.e(TAG, "onfetchSuccess: " + users.size)
Log.v(TAG, "onfetchSuccess: " + users.size)
stopHideShimmer()
rvUserList!!.setUserList(users)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class MissedCall : Fragment() {
private fun initiateCall(`var`: Call) {
CometChat.initiateCall(`var`, object : CallbackListener<Call>() {
override fun onSuccess(call: Call) {
Log.e("onSuccess: ", call.toString())
Log.v("onSuccess: ", call.toString())
if (call.receiverType == CometChatConstants.RECEIVER_TYPE_USER) {
val user: User
user = if ((call.callInitiator as User).uid == CometChat.getLoggedInUser().uid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.cometchat.pro.uikit.ui_components.calls.call_manager

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Bundle
Expand Down Expand Up @@ -146,7 +147,7 @@ class CometChatCallActivity : AppCompatActivity(), View.OnClickListener {
private fun setValues() {
if (isOngoing) {
cometChatAudioHelper!!.stop(false)
if (CometChat.getActiveCall() != null) Utils.startCall(this, CometChat.getActiveCall(), mainView) else onBackPressed()
if (CometChat.getActiveCall() != null) Utils.startCall(this, CometChat.getActiveCall()) else onBackPressed()
}
userTv!!.text = name
callerName!!.text = name
Expand Down Expand Up @@ -200,13 +201,13 @@ class CometChatCallActivity : AppCompatActivity(), View.OnClickListener {
override fun onClick(v: View) {
val id = v.id
if (id == R.id.call_hang_btn) {
cometChatAudioHelper!!.stop(false)
cometChatAudioHelper?.stop(false)
AnimUtil.stopBlinkAnimation(tvDots!!)
rejectCall(sessionId, CometChatConstants.CALL_STATUS_CANCELLED)
} else if (id == R.id.accept_incoming) {
cometChatAudioHelper!!.stop(false)
cometChatAudioHelper?.stop(false)
incomingCallView!!.visibility = View.GONE
answerCall(mainView, sessionId)
answerCall(sessionId)
} else if (id == R.id.decline_incoming) {
cometChatAudioHelper!!.stop(true)
rejectCall(sessionId, CometChatConstants.CALL_STATUS_REJECTED)
Expand Down Expand Up @@ -240,18 +241,16 @@ class CometChatCallActivity : AppCompatActivity(), View.OnClickListener {
/**
* This method is used to accept the incoming call receievd.
*
* @param mainView is a object of Relativelayout, It is used to load the CallingComponent after
* the call is accepted.
* @param sessionId is a String, It is sessionId of call.
*
* @see CometChat.acceptCall
* @see Call
*/
private fun answerCall(mainView: RelativeLayout?, sessionId: String?) {
private fun answerCall(sessionId: String?) {
CometChat.acceptCall(sessionId!!, object : CallbackListener<Call>() {
override fun onSuccess(call: Call) {
Log.e("CallMeta", call.toString())
startCall(mainView, call)
startCall(call)
}

override fun onError(e: CometChatException) {
Expand All @@ -272,9 +271,9 @@ class CometChatCallActivity : AppCompatActivity(), View.OnClickListener {
*
* @see CometChat.startCall
*/
private fun startCall(mainView: RelativeLayout?, call: Call) {
private fun startCall(call: Call) {
hangUp!!.visibility = View.GONE
Utils.startCall(this@CometChatCallActivity, call, mainView)
Utils.startCall(this@CometChatCallActivity,call)
}

fun startOnGoingCall(call: Call?) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cometchat.pro.uikit.ui_components.calls.call_manager

import android.app.ActivityManager
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.Gravity
Expand All @@ -14,12 +16,13 @@ import com.cometchat.pro.core.CallSettings
import com.cometchat.pro.core.CallSettings.CallSettingsBuilder
import com.cometchat.pro.core.CometChat
import com.cometchat.pro.exceptions.CometChatException
import com.cometchat.pro.models.User
import com.cometchat.pro.models.AudioMode
import com.cometchat.pro.models.User
import com.cometchat.pro.uikit.R
import com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService
import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI
import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants
import com.cometchat.pro.uikit.ui_resources.utils.ErrorMessagesUtils
import com.cometchat.pro.uikit.ui_resources.utils.Utils

class CometChatStartCallActivity : AppCompatActivity() {

Expand All @@ -32,62 +35,101 @@ class CometChatStartCallActivity : AppCompatActivity() {

private lateinit var callSettings: CallSettings

private var ongoingCallService: OngoingCallService? = null

private var mServiceIntent: Intent? = null

private var isDefaultCall = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cometchat_start_call)
activity = this
mainView = findViewById(R.id.call_view)
if (intent != null)
sessionID = intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID)


callSettings = CallSettingsBuilder(this, mainView)
.setSessionId(sessionID)
.startWithAudioMuted(true)
.startWithVideoMuted(true)
.build()
if (intent != null) sessionID =
intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID)
ongoingCallService = OngoingCallService()
mServiceIntent = Intent(this, ongoingCallService?.javaClass)
isDefaultCall = intent.getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false)
if (isDefaultCall && !isMyServiceRunning(ongoingCallService?.javaClass!!)) {
startService(mServiceIntent)
}

callSettings =
CallSettingsBuilder(this, mainView).setSessionId(sessionID).startWithAudioMuted(true)
.startWithVideoMuted(true).build()

CometChat.startCall(callSettings, object : CometChat.OngoingCallListener {
override fun onUserJoined(p0: User?) {
p0?.uid?.let { Log.e("onUserJoined: ", it) }
p0?.uid?.let { Log.i("onUserJoined: ", it) }
}

override fun onUserLeft(p0: User?) {
p0?.uid?.let { Log.e("onUserLeft: ", it) }
p0?.uid?.let { Log.i("onUserLeft: ", it) }
}

override fun onError(p0: CometChatException) {
p0.message?.let { Log.e("onstartcallError: ", it) }
ErrorMessagesUtils.cometChatErrorMessage(this@CometChatStartCallActivity, p0.code)
override fun onError(p0: CometChatException?) {
p0?.message?.let { Log.i("onstartcallError: ", it) }
ErrorMessagesUtils.cometChatErrorMessage(this@CometChatStartCallActivity, p0?.code)
}

override fun onCallEnded(p0: Call?) {
Log.e("TAG", "onCallEnded: ")
Log.i("TAG", "onCallEnded: ")
showToast()
finish()
stopService(mServiceIntent)
}

override fun onUserListUpdated(p0: MutableList<User>?) {
Log.e("TAG", "onUserListUpdated: " + p0.toString())
Log.i("TAG", "onUserListUpdated: " + p0.toString())
}

override fun onAudioModesUpdated(p0: MutableList<AudioMode>?) {
Log.e("TAG", "onAudioModesUpdated: "+p0.toString() )
Log.i("TAG", "onAudioModesUpdated: " + p0.toString())
}

override fun onRecordingStarted(p0: User?) {
Log.i("TAG", "onRecordingStarted: " + p0.toString())
}

override fun onRecordingStopped(p0: User?) {
Log.i("TAG", "onRecordingStopped: " + p0.toString())
}

override fun onUserMuted(p0: User?, p1: User?) {
Log.i("TAG", "onUserMuted: " + p0.toString())
}

override fun onCallSwitchedToVideo(p0: String?, p1: User?, p2: User?) {
Log.i("TAG", "onCallSwitchedToVideo: " + p0.toString())
}

})
}

private fun showToast() {
val layoutInflater = layoutInflater
val layout :View = layoutInflater.inflate(R.layout.custom_toast, findViewById<ViewGroup>(R.id.group_layout))
val layout: View = layoutInflater.inflate(
R.layout.custom_toast, findViewById<ViewGroup>(R.id.group_layout)
)
val tvMessage = layout.findViewById<TextView>(R.id.message)
tvMessage.text = "Call Ended"
val toast = Toast(applicationContext)
toast.duration = Toast.LENGTH_SHORT
toast.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM,0,0)
toast.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM, 0, 0)
toast.view = layout

toast.show()
}
}

override fun onBackPressed() {
startActivity(Intent(this@CometChatStartCallActivity, CometChatUI::class.java))
}

private fun isMyServiceRunning(serviceClass: Class<out OngoingCallService?>): Boolean {
val manager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
return manager.getRunningServices(Integer.MAX_VALUE)
.any { it.service.className == serviceClass.canonicalName }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object CometChatCallListener {
override fun onOutgoingCallAccepted(call: Call) {
if (CometChatCallActivity.mainView != null) {
CometChatCallActivity.cometChatAudioHelper!!.stop(false)
Utils.startCall(CometChatCallActivity.callActivity!!, call, CometChatCallActivity.mainView)
Utils.startCall(CometChatCallActivity.callActivity!!, call)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity
import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants

class OngoingCallBroadcast : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val sessionID = intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID)
val type = intent.getStringExtra(UIKitConstants.IntentStrings.TYPE)
Log.e("onReceive: ", sessionID!!)
if (intent.action == "Ongoing") {
val joinOngoingIntent = Intent(context, CometChatStartCallActivity::class.java)
joinOngoingIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, sessionID)
joinOngoingIntent.putExtra(UIKitConstants.IntentStrings.TYPE, type)
joinOngoingIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(joinOngoingIntent)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, OngoingCallService::class.java))
} else {
context.startService(Intent(context, OngoingCallService::class.java))
}
}
}
Loading

0 comments on commit 2d18876

Please sign in to comment.