Search in sources :

Example 1 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.

the class LoginActivity method registerPushNotification.

private void registerPushNotification(String token) {
    CometChat.registerTokenForPushNotification(token, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            Toast.makeText(LoginActivity.this, s, Toast.LENGTH_LONG).show();
            Log.e("onSuccessPN: ", s);
        }

        @Override
        public void onError(CometChatException e) {
            Log.e("onErrorPN: ", e.getMessage());
            Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
    progressBar.setVisibility(View.GONE);
    finish();
    startActivity(new Intent(LoginActivity.this, PushNotificationActivity.class));
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent)

Example 2 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.

the class MainActivity method registerPushNotification.

private void registerPushNotification(String uid, String token) {
    Log.e(TAG, "onComplete: " + token);
    CometChat.registerTokenForPushNotification(token, new CometChat.CallbackListener<String>() {

        @Override
        public void onSuccess(String s) {
            Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
            Log.e("onSuccessPN: ", s);
        }

        @Override
        public void onError(CometChatException e) {
            Log.e("onErrorPN: ", e.getMessage());
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
    String str = uid + "_progressbar";
    int id = getResources().getIdentifier(str, "id", getPackageName());
    findViewById(id).setVisibility(View.GONE);
    startActivity(new Intent(MainActivity.this, PushNotificationActivity.class));
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent)

Example 3 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.

the class MoreActionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_more_actions, container, false);
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
            // androidx should use: com.google.android.material.R.id.design_bottom_sheet
            FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
            BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            behavior.setPeekHeight(0);
        }
    });
    loggedInUser = view.findViewById(R.id.loggedIn_user);
    loggedInUser.setText("Logged In As : " + CometChat.getLoggedInUser().getName());
    logout = view.findViewById(R.id.logout_tv);
    logout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // MyFirebaseMessagingService.unsubscribeUserNotification(CometChat.getLoggedInUser().getUid());
            CometChat.logout(new CometChat.CallbackListener<String>() {

                @Override
                public void onSuccess(String s) {
                    if (getActivity() != null) {
                        getActivity().finish();
                        Toast.makeText(getActivity(), getResources().getString(R.string.logout_success), Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onError(CometChatException e) {
                    Log.e(TAG, "onError: " + e.getMessage());
                }
            });
        }
    });
    launchUI = view.findViewById(R.id.launch_ui_kit);
    launchUI.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getContext(), CometChatUI.class));
        }
    });
    return view;
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver)

Example 4 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatStartCallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.activity_cometchat_start_call);
    ongoingCallService = new OngoingCallService();
    mServiceIntent = new Intent(this, ongoingCallService.getClass());
    isDefaultCall = getIntent().getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false);
    if (isDefaultCall && !isMyServiceRunning(ongoingCallService.getClass())) {
        startService(mServiceIntent);
    }
    mainView = findViewById(R.id.call_view);
    connectingLayout = findViewById(R.id.connecting_to_call);
    sessionID = getIntent().getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
    type = getIntent().getStringExtra(UIKitConstants.IntentStrings.TYPE);
    if (type != null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).setMode(CallSettings.MODE_SINGLE).build();
    else
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).build();
    CometChatError.init(this);
    Log.e("startCallActivity: ", sessionID + " " + type);
    CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {

        @Override
        public void onUserListUpdated(List<User> list) {
            Log.e("onUserListUpdated: ", list.toString());
        }

        @Override
        public void onAudioModesUpdated(List<AudioMode> list) {
            Log.e("onAudioModesUpdated: ", list.toString());
        }

        @Override
        public void onUserJoined(User user) {
            connectingLayout.setVisibility(View.GONE);
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_joined) + ":" + user.getName(), CometChatSnackBar.INFO);
            Log.e("onUserJoined: ", user.getUid());
        }

        @Override
        public void onUserLeft(User user) {
            if (user != null) {
                CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_left) + ":" + user.getName(), CometChatSnackBar.INFO);
                Log.e("onUserLeft: ", user.getUid());
                if (callSettings.getMode().equals(CallSettings.MODE_SINGLE)) {
                    endCall();
                }
            } else {
                Log.e("onUserLeft: ", "triggered");
            }
        }

        @Override
        public void onError(CometChatException e) {
            stopService(mServiceIntent);
            Log.e("onstartcallError: ", e.getMessage());
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }

        @Override
        public void onCallEnded(Call call) {
            stopService(mServiceIntent);
            Log.e("TAG", "onCallEnded: ");
            finish();
        }
    });
}
Also used : OngoingCallService(com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService) CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent) CallSettings(com.cometchat.pro.core.CallSettings) AudioMode(com.cometchat.pro.models.AudioMode)

Example 5 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatUserDetailScreenActivity method blockUser.

private void blockUser() {
    ProgressDialog progressDialog = ProgressDialog.show(CometChatUserDetailScreenActivity.this, null, String.format(getResources().getString(R.string.user_is_blocked), userName.getText().toString()));
    ArrayList<String> uids = new ArrayList<>();
    uids.add(uid);
    CometChat.blockUsers(uids, new CometChat.CallbackListener<HashMap<String, String>>() {

        @Override
        public void onSuccess(HashMap<String, String> stringStringHashMap) {
            // if (tvBlockUser!=null)
            // CometChatSnackBar.show(CometChatUserDetailScreenActivity.this,
            // tvBlockUser,
            // String.format(getResources().getString(R.string.user_is_blocked),userName.getText().toString()),
            // CometChatSnackBar.SUCCESS);
            isBlocked = true;
            progressDialog.dismiss();
            setBlockUnblock();
        }

        @Override
        public void onError(CometChatException e) {
            if (tvBlockUser != null)
                CometChatSnackBar.show(CometChatUserDetailScreenActivity.this, tvBlockUser, String.format(getResources().getString(R.string.block_user_error), userName.getText().toString()), CometChatSnackBar.ERROR);
            Log.d(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) HashMap(java.util.HashMap) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog)

Aggregations

CometChatException (com.cometchat.pro.exceptions.CometChatException)54 CometChat (com.cometchat.pro.core.CometChat)45 JSONObject (org.json.JSONObject)20 JSONException (org.json.JSONException)19 Intent (android.content.Intent)14 ArrayList (java.util.ArrayList)13 ProgressDialog (android.app.ProgressDialog)12 User (com.cometchat.pro.models.User)10 View (android.view.View)9 TextView (android.widget.TextView)9 TextMessage (com.cometchat.pro.models.TextMessage)9 List (java.util.List)8 ImageView (android.widget.ImageView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 BaseMessage (com.cometchat.pro.models.BaseMessage)6 Call (com.cometchat.pro.core.Call)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 UsersRequest (com.cometchat.pro.core.UsersRequest)4 CometChatReactionDialog (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog)4 MaterialCardView (com.google.android.material.card.MaterialCardView)4