diff --git a/ConnectionService + Firebase/app/build.gradle b/ConnectionService + Firebase/app/build.gradle index 821f835..d271d83 100644 --- a/ConnectionService + Firebase/app/build.gradle +++ b/ConnectionService + Firebase/app/build.gradle @@ -78,6 +78,6 @@ dependencies { implementation 'com.google.android.material:material:1.2.0-alpha01' implementation 'com.facebook.shimmer:shimmer:0.4.0' // - implementation 'com.cometchat:pro-android-chat-sdk:2.4.1' + implementation 'com.cometchat:pro-android-chat-sdk:3.0.0' implementation 'com.cometchat:pro-android-calls-sdk:2.1.0' } diff --git a/ConnectionService + Firebase/uikit/build.gradle b/ConnectionService + Firebase/uikit/build.gradle index 93a466f..a9d7f43 100644 --- a/ConnectionService + Firebase/uikit/build.gradle +++ b/ConnectionService + Firebase/uikit/build.gradle @@ -90,7 +90,7 @@ dependencies { implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' //cometchat - compileOnly 'com.cometchat:pro-android-chat-sdk:2.4.1' + compileOnly 'com.cometchat:pro-android-chat-sdk:3.0.0' compileOnly 'com.cometchat:pro-android-calls-sdk:2.1.0' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0' diff --git a/ConnectionService + Firebase/uikit/src/main/AndroidManifest.xml b/ConnectionService + Firebase/uikit/src/main/AndroidManifest.xml index 75babb6..9d0be74 100644 --- a/ConnectionService + Firebase/uikit/src/main/AndroidManifest.xml +++ b/ConnectionService + Firebase/uikit/src/main/AndroidManifest.xml @@ -26,13 +26,15 @@ android:usesCleartextTraffic="true" tools:node="merge" tools:targetApi="m"> - - + + + - + @@ -55,7 +57,7 @@ - + Search Users Search Groups Allow Background Location Permisssion - Please enable VoIP for this app + Please enable VoIP from Call Accounts Settings diff --git a/Firebase/app/build.gradle b/Firebase/app/build.gradle index 8b74dda..67f023c 100644 --- a/Firebase/app/build.gradle +++ b/Firebase/app/build.gradle @@ -60,6 +60,6 @@ dependencies { implementation 'com.google.android.material:material:1.2.0-alpha05' implementation 'com.facebook.shimmer:shimmer:0.4.0' // - implementation 'com.cometchat:pro-android-chat-sdk:2.4.1' + implementation 'com.cometchat:pro-android-chat-sdk:3.0.0' implementation 'com.cometchat:pro-android-calls-sdk:2.1.0' } diff --git a/Firebase/uikit/build.gradle b/Firebase/uikit/build.gradle index 93a466f..a9d7f43 100644 --- a/Firebase/uikit/build.gradle +++ b/Firebase/uikit/build.gradle @@ -90,7 +90,7 @@ dependencies { implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' //cometchat - compileOnly 'com.cometchat:pro-android-chat-sdk:2.4.1' + compileOnly 'com.cometchat:pro-android-chat-sdk:3.0.0' compileOnly 'com.cometchat:pro-android-calls-sdk:2.1.0' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0' diff --git a/Firebase/uikit/src/main/AndroidManifest.xml b/Firebase/uikit/src/main/AndroidManifest.xml index d4477cb..9d0be74 100644 --- a/Firebase/uikit/src/main/AndroidManifest.xml +++ b/Firebase/uikit/src/main/AndroidManifest.xml @@ -26,13 +26,15 @@ android:usesCleartextTraffic="true" tools:node="merge" tools:targetApi="m"> - - + + + - + @@ -55,7 +57,7 @@ - + + + + + + + \ No newline at end of file diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallConnection.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallConnection.java new file mode 100644 index 0000000..3a6360a --- /dev/null +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallConnection.java @@ -0,0 +1,182 @@ +package com.cometchat.pro.uikit.ui_components.calls.callconnection; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.telecom.CallAudioState; +import android.telecom.Connection; +import android.telecom.DisconnectCause; +import android.util.Log; +import android.widget.Toast; + +import androidx.annotation.RequiresApi; +import androidx.core.app.NotificationCompat; + +import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.Call; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatCallActivity; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; + +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; + +@RequiresApi(api = Build.VERSION_CODES.M) +public class CallConnection extends Connection { + + MyConnectionService service; + Call call; + String TAG = "CallConnection"; + + public CallConnection(MyConnectionService service,Call call) { + this.service = service; + this.call = call; + Log.e(TAG, "CallConnection: "+call.toString()); + } + + + @Override + public void onCallAudioStateChanged(CallAudioState state) { + Log.i(TAG, "onCallAudioStateChanged"+state); + } + + + @Override + public void onDisconnect() { + Log.i(TAG, "onDisconnect"); + super.onDisconnect(); + destroyConnection(); + Log.e(TAG,"onDisconnect"); + setDisconnected(new DisconnectCause(DisconnectCause.LOCAL, "Missed")); + if (CometChat.getActiveCall()!=null) + onDisconnect(CometChat.getActiveCall()); + } + + void onDisconnect(Call call) { + Log.e(TAG,"onDisconnect Call: $call"); + CometChat.rejectCall(call.getSessionId(), CometChatConstants.CALL_STATUS_CANCELLED, + new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + Log.e(TAG, "onSuccess: reject"); + } + + @Override + public void onError(CometChatException e) { + Toast.makeText(service,"Unable to end call due to ${p0?.code}", + Toast.LENGTH_LONG).show(); + } + }); + } + + public void destroyConnection() { + setDisconnected(new DisconnectCause(DisconnectCause.REMOTE, "Rejected")); + Log.e(TAG, "destroyConnection" ); + super.destroy(); + } + + @Override + public void onAnswer(int videoState) { + Log.e(TAG, "onAnswerVideo: " ); + if (call.getSessionId()!=null) { + CometChat.acceptCall(call.getSessionId(), new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + Log.e(TAG, "onSuccess: accept"); + service.sendBroadcast(getCallIntent("Answers")); +// Intent acceptIntent = new Intent(service, CometChatStartCallActivity.class); +// acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, call.getSessionId()); +// acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// service.startActivity(acceptIntent); + destroyConnection(); + } + + @Override + public void onError(CometChatException e) { + destroyConnection(); + Toast.makeText(service, "Error " + e.getMessage(), Toast.LENGTH_LONG).show(); + } + }); + } + } + + @Override + public void onShowIncomingCallUi() { + Log.e(TAG, "onShowIncomingCallUi: " ); + } + + @Override + public void onAnswer() { + Log.i(TAG, "onAnswer"+call.getSessionId()); + if (call.getSessionId()!=null) { + CometChat.acceptCall(call.getSessionId(), new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + Log.e(TAG, "onSuccess: accept"); + service.sendBroadcast(getCallIntent("Answers")); +// Intent acceptIntent = new Intent(service, CometChatStartCallActivity.class); +// acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, call.getSessionId()); +// acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// service.startActivity(acceptIntent); + destroyConnection(); + } + + @Override + public void onError(CometChatException e) { + destroyConnection(); + e.printStackTrace(); + } + }); + } + } + + + @Override + public void onHold() { + Log.i(TAG, "onHold"); + } + + @Override + public void onUnhold() { + Log.i(TAG, "onUnhold"); + } + + @Override + public void onReject() { + Log.i(TAG, "onReject"+call.getSessionId()); + if (call.getSessionId()!=null) { + CometChat.rejectCall(call.getSessionId(), CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + Log.e(TAG, "onSuccess: reject" ); + destroyConnection(); + setDisconnected(new DisconnectCause(DisconnectCause.REJECTED,"Rejected")); + } + + @Override + public void onError(CometChatException e) { + destroyConnection(); + Log.e(TAG, "onErrorReject: "+e.getMessage()); + } + }); + } + } + + public void onOutgoingReject() { + Log.e(TAG,"onDisconnect"); + destroyConnection(); + setDisconnected(new DisconnectCause(DisconnectCause.REMOTE, "REJECTED")); + } + + private Intent getCallIntent(String title){ + Intent callIntent = new Intent(service, CallNotificationAction.class); + callIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID,call.getSessionId()); + callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + callIntent.setAction(title); + return callIntent; + } +} diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallManager.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallManager.java new file mode 100644 index 0000000..5f95fca --- /dev/null +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallManager.java @@ -0,0 +1,172 @@ +package com.cometchat.pro.uikit.ui_components.calls.callconnection; + +import android.Manifest; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Parcelable; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telecom.VideoProfile; +import android.telephony.TelephonyManager; +import android.util.Log; +import android.widget.Toast; + +import androidx.annotation.RequiresApi; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.Call; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.models.Group; +import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.BuildConfig; +import com.cometchat.pro.uikit.R; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.cometchat.pro.uikit.ui_settings.UIKitSettings; + +import java.util.Arrays; +import java.util.List; + +import static android.content.Context.TELECOM_SERVICE; +import static android.content.Context.TELEPHONY_SERVICE; + +public class CallManager { + + Context context; + TelecomManager telecomManager; + PhoneAccountHandle phoneAccountHandle; + + public CallManager(Context context) { + this.context = context; + telecomManager = (TelecomManager) context.getSystemService(TELECOM_SERVICE); + ComponentName componentName = new ComponentName(context, MyConnectionService.class); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + phoneAccountHandle = new PhoneAccountHandle(componentName, context.getPackageName()); + PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, context.getPackageName()) + .setCapabilities(UIKitSettings.getConnectionCapability()).build(); + Log.e("CallManager: ", phoneAccount.toString()); + telecomManager.registerPhoneAccount(phoneAccount); + } + } + + @RequiresApi(api = Build.VERSION_CODES.M) + public void startOutgoingCall() { + Bundle extras = new Bundle(); + extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true); + + TelecomManager manager = (TelecomManager) context.getSystemService(TELECOM_SERVICE); + PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new ComponentName(context.getPackageName(), MyConnectionService.class.getName()), "estosConnectionServiceId"); + Bundle test = new Bundle(); + test.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + test.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL); + test.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); + try { + if (context.checkSelfPermission(Manifest.permission.MANAGE_OWN_CALLS) == PackageManager.PERMISSION_GRANTED) { + manager.placeCall(Uri.parse("tel:$number"), test); + } + } catch (SecurityException e) { + e.printStackTrace(); + } + } + + @RequiresApi(api = Build.VERSION_CODES.M) + public void startIncomingCall(Call call) { + if (context.checkSelfPermission(Manifest.permission.MANAGE_OWN_CALLS) == PackageManager.PERMISSION_GRANTED) { + Bundle extras = new Bundle(); + Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getSessionId().substring(0, 11), null); + extras.putString(UIKitConstants.IntentStrings.SESSION_ID, call.getSessionId()); + extras.putString(UIKitConstants.IntentStrings.TYPE, call.getReceiverType()); + extras.putString(UIKitConstants.IntentStrings.CALL_TYPE, call.getType()); + extras.putString(UIKitConstants.IntentStrings.ID, call.getReceiverUid()); + if (call.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP)) + extras.putString(UIKitConstants.IntentStrings.NAME, ((Group) call.getReceiver()).getName()); + else + extras.putString(UIKitConstants.IntentStrings.NAME, ((User) call.getCallInitiator()).getName()); + + if (call.getType().equalsIgnoreCase(CometChatConstants.CALL_TYPE_VIDEO)) + extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL); + else + extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_AUDIO_ONLY); + + extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri); + extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true); + boolean isCallPermitted = false; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + isCallPermitted = telecomManager.isIncomingCallPermitted(phoneAccountHandle); + } else { + isCallPermitted = true; + } + Log.e("CallManager", "is incoming call permited = " + isCallPermitted + "\n" + phoneAccountHandle.toString()); + try { + telecomManager.addNewIncomingCall(phoneAccountHandle, extras); + } catch (SecurityException e) { + e.printStackTrace(); + CometChat.rejectCall(call.getSessionId(), CometChatConstants.CALL_STATUS_BUSY, new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + Toast.makeText(context, context.getString(R.string.allow_connection_service), Toast.LENGTH_LONG).show(); + launchVoIPSetting(context); + } + + @Override + public void onError(CometChatException e) { + + } + }); + + } catch (Exception e) { + Log.e("CallManagerError: ", e.getMessage()); + } + } + } + + public void launchVoIPSetting(Context context) { + Intent intent = new Intent(); + intent.setAction(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS); +// ComponentName telecomComponent = new ComponentName("com.android.server.telecom", "com.android.server.telecom.settings.EnableAccountPreferenceActivity"); +// intent.setComponent(telecomComponent); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + context.startActivity(intent); + } + + public boolean checkAccountConnection(Context context) { + boolean isConnected = false; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) + == PackageManager.PERMISSION_GRANTED && telecomManager!=null) { + final List enabledAccounts = telecomManager.getCallCapablePhoneAccounts(); + for (PhoneAccountHandle account : enabledAccounts) { + if (account.getComponentName().getClassName().equals(MyConnectionService.class.getCanonicalName())) { + isConnected = true; + break; + } + } + } + + } + return isConnected; + } + + public void endCall() { + if (telecomManager != null) + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ANSWER_PHONE_CALLS) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + }telecomManager.endCall(); + } +} diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallNotificationAction.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallNotificationAction.java new file mode 100644 index 0000000..13c0bd9 --- /dev/null +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/CallNotificationAction.java @@ -0,0 +1,69 @@ +package com.cometchat.pro.uikit.ui_components.calls.callconnection; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.widget.Toast; + +import androidx.core.app.NotificationManagerCompat; + +import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.Call; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatCallActivity; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; + +public class CallNotificationAction extends BroadcastReceiver { + + String TAG = "CallNotificationAction"; + @Override + public void onReceive(Context context, Intent intent) { + String sessionID = intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID); + Log.e(TAG, "onReceive: " + intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID)); + if (intent.getAction().equals("Answers")) { + Log.e(TAG, "onReceive: Answers" ); +// CometChat.acceptCall(sessionID, new CometChat.CallbackListener() { +// @Override +// public void onSuccess(Call call) { + Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class); + acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID,sessionID); + acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + acceptIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + context.startActivity(acceptIntent); +// } +// +// @Override +// public void onError(CometChatException e) { +// Toast.makeText(context,"Error "+e.getMessage(),Toast.LENGTH_LONG).show(); +// } +// }); +// NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); +// notificationManager.cancel(05); + } else if (intent.getAction().equals("StartCall")){ + Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class); + acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID,sessionID); + acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(acceptIntent); + } + else { + Log.e(TAG, "onReceive: Reject" ); + CometChat.rejectCall(sessionID, CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener() { + @Override + public void onSuccess(Call call) { + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + notificationManager.cancel(05); + if (CometChatCallActivity.callActivity!=null) + CometChatCallActivity.callActivity.finish(); + } + + @Override + public void onError(CometChatException e) { + Toast.makeText(context,"Error: "+e.getMessage(),Toast.LENGTH_LONG).show(); + } + }); + } + } +} diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/MyConnectionService.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/MyConnectionService.java new file mode 100644 index 0000000..03e47b4 --- /dev/null +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/callconnection/MyConnectionService.java @@ -0,0 +1,185 @@ +package com.cometchat.pro.uikit.ui_components.calls.callconnection; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.telecom.Connection; +import android.telecom.ConnectionRequest; +import android.telecom.ConnectionService; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telecom.VideoProfile; +import android.util.Log; +import android.view.Surface; +import android.widget.Toast; + +import androidx.annotation.RequiresApi; + +import com.cometchat.pro.core.Call; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; + +import static android.telecom.TelecomManager.PRESENTATION_ALLOWED; + +@RequiresApi(api = Build.VERSION_CODES.M) +public class MyConnectionService extends ConnectionService { + + public static CallConnection conn; + public MyConnectionService() { + super(); + } + + + @Override + public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { + Bundle bundle = request.getExtras(); + String sessionID = bundle.getString(UIKitConstants.IntentStrings.SESSION_ID); + String name = bundle.getString(UIKitConstants.IntentStrings.NAME); + String type = bundle.getString(UIKitConstants.IntentStrings.TYPE); + String callType = bundle.getString(UIKitConstants.IntentStrings.CALL_TYPE); + String receiverUID = bundle.getString(UIKitConstants.IntentStrings.ID); + Call call = new Call(receiverUID,type,callType); + call.setSessionId(sessionID); + Log.i("CallConnectionService", "onCreateIncomingConnectionCall:"+call.toString()); + conn = new CallConnection(this,call); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { + conn.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); + } + conn.setCallerDisplayName(name, TelecomManager.PRESENTATION_ALLOWED); + conn.setAddress(request.getAddress(), PRESENTATION_ALLOWED); + conn.setInitializing(); + conn.setVideoProvider(new Connection.VideoProvider() { + @Override + public void onSetCamera(String cameraId) { + + } + + @Override + public void onSetPreviewSurface(Surface surface) { + + } + + @Override + public void onSetDisplaySurface(Surface surface) { + + } + + @Override + public void onSetDeviceOrientation(int rotation) { + + } + + @Override + public void onSetZoom(float value) { + + } + + @Override + public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { + + } + + @Override + public void onSendSessionModifyResponse(VideoProfile responseProfile) { + + } + + @Override + public void onRequestCameraCapabilities() { + + } + + @Override + public void onRequestConnectionDataUsage() { + + } + + @Override + public void onSetPauseImage(Uri uri) { + + } + }); + conn.setActive(); + return conn; +// return super.onCreateIncomingConnection(connectionManagerPhoneAccount, request); + } + + @Override + public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { + super.onCreateIncomingConnectionFailed(connectionManagerPhoneAccount, request); + Log.e("onIncomingFailed:",connectionManagerPhoneAccount.toString() ); + } + + @Override + public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { + super.onCreateOutgoingConnectionFailed(connectionManagerPhoneAccount, request); + } + + @Override + public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { +// Log.i("CallConnectionService", "onCreateOutgoingConnection"); +// CallConnection conn = new CallConnection(getApplicationContext()); +// conn.setAddress(request.getAddress(), PRESENTATION_ALLOWED); +// conn.setInitializing(); +// conn.setVideoProvider(new Connection.VideoProvider() { +// @Override +// public void onSetCamera(String cameraId) { +// +// } +// +// @Override +// public void onSetPreviewSurface(Surface surface) { +// +// } +// +// @Override +// public void onSetDisplaySurface(Surface surface) { +// +// } +// +// @Override +// public void onSetDeviceOrientation(int rotation) { +// +// } +// +// @Override +// public void onSetZoom(float value) { +// +// } +// +// @Override +// public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { +// +// } +// +// @Override +// public void onSendSessionModifyResponse(VideoProfile responseProfile) { +// +// } +// +// @Override +// public void onRequestCameraCapabilities() { +// +// } +// +// @Override +// public void onRequestConnectionDataUsage() { +// +// } +// +// @Override +// public void onSetPauseImage(Uri uri) { +// +// } +// }); +// conn.setActive(); +// return conn; + return super.onCreateOutgoingConnection(connectionManagerPhoneAccount, request); + } +} diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java index 58be0ac..faba9bc 100644 --- a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java @@ -407,6 +407,8 @@ private void addConversationListener() { CometChat.addMessageListener(TAG, new CometChat.MessageListener() { @Override public void onTextMessageReceived(TextMessage message) { + if (!message.getSender().getUid().equalsIgnoreCase(CometChat.getLoggedInUser().getUid())) + CometChat.markAsDelivered(message); if (rvConversationList!=null) { rvConversationList.refreshConversation(message); checkNoConverstaion(); @@ -415,6 +417,8 @@ public void onTextMessageReceived(TextMessage message) { @Override public void onMediaMessageReceived(MediaMessage message) { + if (!message.getSender().getUid().equalsIgnoreCase(CometChat.getLoggedInUser().getUid())) + CometChat.markAsDelivered(message); if (rvConversationList != null) { rvConversationList.refreshConversation(message); checkNoConverstaion(); @@ -423,6 +427,8 @@ public void onMediaMessageReceived(MediaMessage message) { @Override public void onCustomMessageReceived(CustomMessage message) { + if (!message.getSender().getUid().equalsIgnoreCase(CometChat.getLoggedInUser().getUid())) + CometChat.markAsDelivered(message); if (rvConversationList != null) { rvConversationList.refreshConversation(message); checkNoConverstaion(); diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java index f561329..6b27c94 100644 --- a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java @@ -76,6 +76,7 @@ import com.cometchat.pro.models.MediaMessage; import com.cometchat.pro.models.MessageReceipt; import com.cometchat.pro.models.TextMessage; +import com.cometchat.pro.models.TransientMessage; import com.cometchat.pro.models.TypingIndicator; import com.cometchat.pro.models.User; import com.cometchat.pro.uikit.R; @@ -327,6 +328,7 @@ public class CometChatMessageList extends Fragment implements View.OnClickListen private ImageView backIcon; private BaseMessage repliedMessage; + private boolean isLiveReactionEnded = true; public CometChatMessageList() { // Required empty public constructor } @@ -430,50 +432,13 @@ public void onSuccess(Boolean booleanVal) { } container = view.findViewById(R.id.reactions_container); - composeBox.liveReactionBtn.setOnTouchListener(new LiveReactionListener(700, 1000, new ReactionClickListener() { + composeBox.liveReactionBtn.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View var1) { - container.setAlpha(1.0f); - sendLiveReaction(); - } - - @Override - public void onCancel(View var1) { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (imageView != null && animation != null && animation.isRunning()) { - ObjectAnimator animator = ObjectAnimator.ofFloat(container, "alpha", 0.2f); - animator.setDuration(700); - animator.start(); - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if (imageView != null) - imageView.clearAnimation(); - container.removeAllViews(); - if (typingTimer != null) - typingTimer.schedule(new TimerTask() { - @Override - public void run() { - JSONObject metaData = new JSONObject(); - try { - metaData.put("reaction", "heart"); - } catch (JSONException e) { - e.printStackTrace(); - } - TypingIndicator typingIndicator = new TypingIndicator(Id, type, metaData); - CometChat.endTyping(typingIndicator); - } - }, 2000); - } - }); - } - } - }, 1400); + public void onClick(View v) { + if (isLiveReactionEnded) + sendLiveReaction(); } - })); + }); newMessageLayout = view.findViewById(R.id.new_message_layout); @@ -635,8 +600,7 @@ public void OnItemClick(String var, int position) { } private void checkOnGoingCall(String callType) { - if (CometChat.getActiveCall() != null && - CometChat.getActiveCall().getCallStatus().equals(CometChatConstants.CALL_STATUS_ONGOING) && CometChat.getActiveCall().getSessionId() != null) { + if (CometChat.getActiveCall() != null && CometChat.getActiveCall().getCallStatus().equals(CometChatConstants.CALL_STATUS_ONGOING) && CometChat.getActiveCall().getSessionId() != null) { AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle(getResources().getString(R.string.ongoing_call)) .setMessage(getResources().getString(R.string.ongoing_call_message)) @@ -2056,13 +2020,8 @@ public void onUserOffline(User user) { * @param baseMessage is object of BaseMessage.class. It is message which is been marked as read. */ private void markMessageAsRead(BaseMessage baseMessage) { -// CometChat.markAsRead(baseMessage); //Used for v3 - if (type.equals(CometChatConstants.RECEIVER_TYPE_USER)) - CometChat.markAsRead(baseMessage.getId(), baseMessage.getSender().getUid(), - baseMessage.getReceiverType()); - else - CometChat.markAsRead(baseMessage.getId(), baseMessage.getReceiverUid(), - baseMessage.getReceiverType()); + CometChat.markAsDelivered(baseMessage); + CometChat.markAsRead(baseMessage); } @@ -2134,6 +2093,12 @@ public void onMessageDeleted(BaseMessage message) { updateMessage(message); } } + @Override + public void onTransientMessageReceived(TransientMessage transientMessage) { + if (transientMessage.getData()!=null) { + setLiveReaction(); + } + } }); } @@ -2260,8 +2225,7 @@ public void onSuccess(Boolean booleanVal) { } }); } - else - setLiveReaction(); + } else { if (typingIndicator.getMetadata() == null) { FeatureRestriction.isTypingIndicatorsEnabled(new FeatureRestriction.OnSuccessListener() { @@ -2272,44 +2236,14 @@ public void onSuccess(Boolean booleanVal) { } }); } - else - setLiveReaction(); } } else { if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { if (typingIndicator.getMetadata() == null) tvStatus.setText(status); - else { - ObjectAnimator animator = ObjectAnimator.ofFloat(container,"alpha",0.2f); - animator.setDuration(700); - animator.start(); - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if (imageView!=null) - imageView.clearAnimation(); - container.removeAllViews(); - } - }); - } } else{ if (typingIndicator.getMetadata() == null) tvStatus.setText(memberNames); - else { - ObjectAnimator animator = ObjectAnimator.ofFloat(container,"alpha",0.2f); - animator.setDuration(700); - animator.start(); - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if (imageView!=null) - imageView.clearAnimation(); - container.removeAllViews(); - } - }); - } } } @@ -3400,20 +3334,43 @@ private void sendLiveReaction() { try { JSONObject metaData = new JSONObject(); metaData.put("reaction", "heart"); - TypingIndicator typingIndicator = new TypingIndicator(Id, type, metaData); - CometChat.startTyping(typingIndicator); + metaData.put("type","live_reaction"); + TransientMessage transientMessage = new TransientMessage(Id, type, metaData); + CometChat.sendTransientMessage(transientMessage); setLiveReaction(); } catch (Exception e) { Log.e(TAG, "sendLiveReaction: "+e.getMessage()); } } + private void stopLiveReaction() { + ObjectAnimator animator = ObjectAnimator.ofFloat(container,"alpha",0.2f); + animator.setDuration(700); + animator.start(); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + if (imageView!=null) + imageView.clearAnimation(); + container.removeAllViews(); + isLiveReactionEnded = true; + } + }); + } private void setLiveReaction() { container.setAlpha(1.0f); - flyEmoji(R.drawable.heart_reaction); + isLiveReactionEnded = false; + animateLiveReaction(R.drawable.heart_reaction); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + stopLiveReaction(); + } + },1500); } - private void flyEmoji(final int resId) { + private void animateLiveReaction(final int resId) { imageView = new ImageView(getContext()); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/thread_message_list/CometChatThreadMessageList.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/thread_message_list/CometChatThreadMessageList.java index 8fdb819..bdf6c4e 100644 --- a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/thread_message_list/CometChatThreadMessageList.java +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/thread_message_list/CometChatThreadMessageList.java @@ -1725,11 +1725,7 @@ private void scrollToBottom() { * @param baseMessage is object of BaseMessage.class. It is message which is been marked as read. */ private void markMessageAsRead(BaseMessage baseMessage) { -// CometChat.markAsRead(baseMessage); - if (type.equals(CometChatConstants.RECEIVER_TYPE_USER)) - CometChat.markAsRead(baseMessage.getId(), baseMessage.getSender().getUid(), baseMessage.getReceiverType()); - else - CometChat.markAsRead(baseMessage.getId(), baseMessage.getReceiverUid(), baseMessage.getReceiverType()); + CometChat.markAsRead(baseMessage); } diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/constants/UIKitConstants.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/constants/UIKitConstants.java index 94ecf32..4d5afcb 100644 --- a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/constants/UIKitConstants.java +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/constants/UIKitConstants.java @@ -134,9 +134,11 @@ public static class IntentStrings { public static final String INTENT_MEDIA_AUDIO_MESSAGE = "intent_media_audio_message"; public static final String INTENT_MEDIA_FILE_MESSAGE = "intent_media_file_message"; + public static final String LINK = "link"; public static final String IS_TITLE_VISIBLE = "IS_TITLE_VISIBLE"; + public static final String CREATE_GROUP_VISIBLE = "IS_CREATE_GROUP_VISIBLE"; public static final String CALL_TYPE = "CALL_TYPE"; diff --git a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_settings/UIKitSettings.java b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_settings/UIKitSettings.java index 1055da7..fe85303 100644 --- a/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_settings/UIKitSettings.java +++ b/Firebase/uikit/src/main/java/com/cometchat/pro/uikit/ui_settings/UIKitSettings.java @@ -467,7 +467,7 @@ public static void richMedia(boolean isEnable) { public static void sendStickers(boolean isEnable) { - sendStickers = isEnable; + sendStickers = isEnable; } public static void unreadCount(boolean isEnable) { unreadCount = isEnable; } diff --git a/Firebase/uikit/src/main/res/values/strings.xml b/Firebase/uikit/src/main/res/values/strings.xml index aa895a8..d68c0f2 100644 --- a/Firebase/uikit/src/main/res/values/strings.xml +++ b/Firebase/uikit/src/main/res/values/strings.xml @@ -342,5 +342,5 @@ Search Users Search Groups Allow Background Location Permisssion - Please enable VoIP for this app + Please enable VoIP from Call Accounts Settings