Skip to content

Commit

Permalink
Merge pull request #3 from cometchat-pro/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
vivekCometChat authored Feb 7, 2023
2 parents 6c1ff2d + ae244d5 commit 7237484
Show file tree
Hide file tree
Showing 24 changed files with 829 additions and 175 deletions.
3 changes: 3 additions & 0 deletions ConnectionService + Firebase/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ConnectionService + Firebase/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ConnectionService + Firebase/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ConnectionService + Firebase/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions ConnectionService + Firebase/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions ConnectionService + Firebase/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ConnectionService + Firebase/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions ConnectionService + Firebase/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
versionCode 1
renderscriptSupportModeEnabled true
multiDexEnabled true
versionName "2.4"
versionName "3.0.4-1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

manifestPlaceholders = [file_provider: "com.cometchat.pro.android.pushnotification"]
Expand Down Expand Up @@ -47,7 +47,9 @@ android {
}
}
}

packagingOptions {
pickFirst '**'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
Expand Down Expand Up @@ -83,3 +85,9 @@ dependencies {
implementation 'com.cometchat:pro-android-chat-sdk:3.0.4'
implementation 'com.cometchat:pro-android-calls-sdk:2.1.2-beta6'
}
configurations.all {
resolutionStrategy {
force 'androidx.appcompat:appcompat:1.3.0'
force 'androidx.core:core-ktx:1.6.0'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.appcompat.widget.AppCompatImageView;

import com.cometchat.pro.android.pushnotification.utils.MyFirebaseMessagingService;
import com.cometchat.pro.core.AppSettings;
import com.cometchat.pro.core.CometChat;
import com.cometchat.pro.exceptions.CometChatException;
import com.cometchat.pro.models.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseService";
private JSONObject json;
private Intent intent;
private int count=0;
private int count = 0;
private Call call;
public static String token;
private static final int REQUEST_CODE = 12;
Expand All @@ -54,57 +54,53 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {


public static void subscribeUserNotification(String UID) {
FirebaseMessaging.getInstance().subscribeToTopic(AppConfig.AppDetails.APP_ID + "_"+ CometChatConstants.RECEIVER_TYPE_USER +"_" +
UID).addOnSuccessListener(new OnSuccessListener<Void>() {
FirebaseMessaging.getInstance().subscribeToTopic(AppConfig.AppDetails.APP_ID + "_" + CometChatConstants.RECEIVER_TYPE_USER + "_" + UID).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e(TAG, UID+ " Subscribed Success");
Log.e(TAG, UID + " Subscribed Success");
}
});
}

public static void unsubscribeUserNotification(String UID) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(AppConfig.AppDetails.APP_ID + "_"+ CometChatConstants.RECEIVER_TYPE_USER +"_" +
UID).addOnSuccessListener(new OnSuccessListener<Void>() {
FirebaseMessaging.getInstance().unsubscribeFromTopic(AppConfig.AppDetails.APP_ID + "_" + CometChatConstants.RECEIVER_TYPE_USER + "_" + UID).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e(TAG, UID+ " Unsubscribed Success");
Log.e(TAG, UID + " Unsubscribed Success");
}
});
}

public static void subscribeGroupNotification(String GUID) {
FirebaseMessaging.getInstance().subscribeToTopic(AppConfig.AppDetails.APP_ID + "_"+ CometChatConstants.RECEIVER_TYPE_GROUP +"_" +
GUID).addOnSuccessListener(new OnSuccessListener<Void>() {
FirebaseMessaging.getInstance().subscribeToTopic(AppConfig.AppDetails.APP_ID + "_" + CometChatConstants.RECEIVER_TYPE_GROUP + "_" + GUID).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e(TAG, GUID+ " Subscribed Success");
Log.e(TAG, GUID + " Subscribed Success");
}
});
}

public static void unsubscribeGroupNotification(String GUID) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(AppConfig.AppDetails.APP_ID + "_"+ CometChatConstants.RECEIVER_TYPE_GROUP +"_" +
GUID);
FirebaseMessaging.getInstance().unsubscribeFromTopic(AppConfig.AppDetails.APP_ID + "_" + CometChatConstants.RECEIVER_TYPE_GROUP + "_" + GUID);
}

@Override
public void onNewToken(String s) {
token = s;
Log.d(TAG, "onNewToken: "+s);
token = s;
Log.d(TAG, "onNewToken: " + s);
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
count++;
json = new JSONObject(remoteMessage.getData());
Log.d(TAG, "JSONObject: "+json.toString());
Log.d(TAG, "JSONObject: " + json.toString());
JSONObject messageData = new JSONObject(json.getString("message"));
BaseMessage baseMessage = CometChatHelper.processMessage(new JSONObject(remoteMessage.getData().get("message")));
if (baseMessage instanceof Call){
call = (Call)baseMessage;
isCall=true;
if (baseMessage instanceof Call) {
call = (Call) baseMessage;
isCall = true;
}

showNotifcation(baseMessage);
Expand All @@ -114,7 +110,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
}

public Bitmap getBitmapFromURL(String strURL) {
if (strURL!=null) {
if (strURL != null) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
Expand All @@ -138,69 +134,50 @@ private void showNotifcation(BaseMessage baseMessage) {
int m = (int) ((new Date().getTime()));
String GROUP_ID = "group_id";
Intent messageIntent = new Intent(getApplicationContext(), CometChatMessageListActivity.class);
messageIntent.putExtra(UIKitConstants.IntentStrings.TYPE,baseMessage.getReceiverType());
messageIntent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME,baseMessage.getSender().getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.UID,baseMessage.getSender().getUid());
messageIntent.putExtra(UIKitConstants.IntentStrings.AVATAR,baseMessage.getSender().getAvatar());
messageIntent.putExtra(UIKitConstants.IntentStrings.STATUS,baseMessage.getSender().getStatus());
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
messageIntent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
messageIntent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage.getSender().getStatus());
} else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
messageIntent.putExtra(UIKitConstants.IntentStrings.GUID,((Group)baseMessage.getReceiver()).getGuid());
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME,((Group)baseMessage.getReceiver()).getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC,((Group) baseMessage.getReceiver()).getDescription());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE,((Group) baseMessage.getReceiver()).getGroupType());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER,((Group) baseMessage.getReceiver()).getOwner());
messageIntent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT,((Group) baseMessage.getReceiver()).getMembersCount());
messageIntent.putExtra(UIKitConstants.IntentStrings.GUID, ((Group) baseMessage.getReceiver()).getGuid());
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, ((Group) baseMessage.getReceiver()).getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, ((Group) baseMessage.getReceiver()).getDescription());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, ((Group) baseMessage.getReceiver()).getGroupType());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, ((Group) baseMessage.getReceiver()).getOwner());
messageIntent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, ((Group) baseMessage.getReceiver()).getMembersCount());
}
PendingIntent messagePendingIntent = PendingIntent.getActivity(getApplicationContext(),
0123,messageIntent,PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"2")
.setSmallIcon(R.drawable.cc)
.setContentTitle(json.getString("title"))
.setContentText(json.getString("alert"))
.setColor(getResources().getColor(R.color.colorPrimary))
.setLargeIcon(getBitmapFromURL(baseMessage.getSender().getAvatar()))
.setGroup(GROUP_ID)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
PendingIntent messagePendingIntent = PendingIntent.getActivity(getApplicationContext(), 0123, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "2").setSmallIcon(R.drawable.cc).setContentTitle(json.getString("title")).setContentText(json.getString("alert")).setColor(getResources().getColor(R.color.colorPrimary)).setLargeIcon(getBitmapFromURL(baseMessage.getSender().getAvatar())).setGroup(GROUP_ID).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(getBitmapFromURL(((MediaMessage)baseMessage).getAttachment().getFileUrl())));
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(getBitmapFromURL(((MediaMessage) baseMessage).getAttachment().getFileUrl())));
}
NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(this,"2")
.setContentTitle("CometChat")
.setContentText(count+" messages")
.setSmallIcon(R.drawable.cc)
.setGroup(GROUP_ID)
.setGroupSummary(true);
NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(this, "2").setContentTitle("CometChat").setContentText(count + " messages").setSmallIcon(R.drawable.cc).setGroup(GROUP_ID).setGroupSummary(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

if (isCall && json.getString("alert").contains("Incoming")) {
if (!UIKitApplication.isForeground)
initiateCallService(call);
} else if(isCall && json.getString("alert").contains("Missed")) {
if (!UIKitApplication.isForeground)
endCallService();
if (!UIKitApplication.isForeground) {
if (((System.currentTimeMillis() / 1000) - call.getInitiatedAt()) < 45)
initiateCallService(call);
}
} else if (isCall && json.getString("alert").contains("Missed")) {
if (!UIKitApplication.isForeground) endCallService();
else {
if (CometChatCallActivity.callActivity != null) {
CometChatCallActivity.callActivity.finish();
}
}
}
else {
showNotification(builder, summaryBuilder, messagePendingIntent, notificationManager, baseMessage);
} else {
// Person person = createPerson(baseMessage);
// builder.setStyle(new NotificationCompat.MessagingStyle(person)
// .setGroupConversation(true)
// .setConversationTitle(json.getString("title"))
// .addMessage(json.getString("alert"),
// currentTimeMillis(), person));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setContentIntent(messagePendingIntent);
builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
// Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_message);
builder.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(baseMessage.getId(), builder.build());
notificationManager.notify(0, summaryBuilder.build());
showNotification(builder, summaryBuilder, messagePendingIntent, notificationManager, baseMessage);
}

} catch (Exception e) {
Expand All @@ -209,22 +186,31 @@ private void showNotifcation(BaseMessage baseMessage) {

}

private void showNotification(NotificationCompat.Builder builder, NotificationCompat.Builder summaryBuilder, PendingIntent messagePendingIntent, NotificationManagerCompat notificationManager, BaseMessage baseMessage) {
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setContentIntent(messagePendingIntent);
builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
// Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_message);
builder.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(baseMessage.getId(), builder.build());
notificationManager.notify(0, summaryBuilder.build());
}

private void endCallService() {
if(callManager==null)
callManager = new CallManager(getApplicationContext());
if (callManager == null) callManager = new CallManager(getApplicationContext());
callManager.endCall();
}

private void initiateCallService(Call call) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Log.e("initiateCallService: ",call.toString());
Log.e("initiateCallService: ", call.toString());
callManager = new CallManager(getApplicationContext());
callManager.startIncomingCall(call);
}
} catch (Exception e) {
Log.e("initiateCallError:","${e.message}" );
Toast.makeText(getApplicationContext(), "Unable to receive call due to " +
e.getMessage(), Toast.LENGTH_LONG);
Log.e("initiateCallError:", "${e.message}");
Toast.makeText(getApplicationContext(), "Unable to receive call due to " + e.getMessage(), Toast.LENGTH_LONG);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ private Intent getCallIntent(String title,Call call){
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);
// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion Firebase/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Loading

0 comments on commit 7237484

Please sign in to comment.