Skip to content

Commit

Permalink
Merge pull request #16 from cometchat-pro/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
vivekCometChat authored Dec 26, 2022
2 parents dbf473f + d8cedb5 commit ece277f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
10 changes: 5 additions & 5 deletions uikit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
compileSdkVersion 32

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 32
versionCode 1
versionName "3.0.9-2"
versionName "3.0.9-3"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
renderscriptSupportModeEnabled true
Expand Down Expand Up @@ -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:3.0.9'
compileOnly 'com.cometchat:pro-android-calls-sdk:2.2.0'
implementation 'com.cometchat:pro-android-chat-sdk:3.0.9'
implementation 'com.cometchat:pro-android-calls-sdk:2.2.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0'
}
1 change: 1 addition & 0 deletions uikit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (type!=null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
callSettings = new CallSettings.CallSettingsBuilder(this,mainView)
.setSessionId(sessionID)
.setMode(CallSettings.MODE_SINGLE)
.setMode(CallSettings.MODE_DEFAULT)
.build();
else
callSettings = new CallSettings.CallSettingsBuilder(this,mainView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
Expand All @@ -15,6 +16,7 @@

import com.cometchat.pro.core.CometChat;
import com.cometchat.pro.uikit.R;
import com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity;
import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI;
import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants;

Expand All @@ -27,13 +29,14 @@ public class OngoingCallService extends Service {
private int counter = 0;

NotificationManager notificationManager;

@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O)
startMyOwnForeground();
else
this.startForeground(1,new Notification());
this.startForeground(1, new Notification());
}

@Nullable
Expand All @@ -46,12 +49,35 @@ private void startMyOwnForeground() {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(2);
PendingIntent pendingIntent = null;
if (CometChat.getActiveCall()!=null) {
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),REQUEST_CODE,
getCallIntent("Ongoing"),
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
if (CometChat.getActiveCall() != null) {
if (Build.VERSION.SDK_INT >= 31) {
Intent joinOngoingIntent =
new Intent(getApplicationContext(), CometChatStartCallActivity.class);
joinOngoingIntent.putExtra(
UIKitConstants.IntentStrings.SESSION_ID,
CometChat.getActiveCall().getSessionId()
);
joinOngoingIntent.putExtra(
UIKitConstants.IntentStrings.TYPE,
CometChat.getActiveCall().getType()
);
joinOngoingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(joinOngoingIntent);
pendingIntent= stackBuilder.getPendingIntent(
REQUEST_CODE,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
);

} else {
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE,
getCallIntent("Ongoing"),
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
}
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"2");
Log.e("", "startMyOwnForeground: "+pendingIntent);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "2");
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.cc)
.setColor(getResources().getColor(R.color.colorPrimary))
Expand All @@ -60,13 +86,13 @@ private void startMyOwnForeground() {
.setContentIntent(pendingIntent)
.setCategory(Notification.CATEGORY_CALL)
.build();
startForeground(1,notification);
startForeground(1, notification);
}

private Intent getCallIntent(String title) {
Intent callIntent;
if (CometChat.getActiveCall()!=null) {
callIntent = new Intent(getApplicationContext(),OngoingCallBroadcast.class);
if (CometChat.getActiveCall() != null) {
callIntent = new Intent(getApplicationContext(), OngoingCallBroadcast.class);
callIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, CometChat.getActiveCall().getSessionId());
callIntent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChat.getActiveCall().getType());
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down Expand Up @@ -101,21 +127,22 @@ public boolean stopService(Intent name) {

private Timer timer;
private TimerTask timerTask;

public void startTimer() {
timer = new Timer();
timerTask = new TimerTask() {
@Override
public void run() {
Log.d("AppInBackground: ",""+ counter++ );
Log.d("AppInBackground: ", "" + counter++);
}
};
timer.schedule(timerTask, 1000, 1000);
}

public void stopTimer() {
if (timer!=null) {
if (timer != null) {
timer.cancel();
timer = null;
}
}
}
}

0 comments on commit ece277f

Please sign in to comment.