use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatUserDetailScreenActivity method unblockUser.
private void unblockUser() {
ProgressDialog progressDialog = ProgressDialog.show(CometChatUserDetailScreenActivity.this, null, userName.getText().toString() + " " + getString(R.string.unblocked_successfully));
ArrayList<String> uids = new ArrayList<>();
uids.add(uid);
CometChat.unblockUsers(uids, new CometChat.CallbackListener<HashMap<String, String>>() {
@Override
public void onSuccess(HashMap<String, String> stringStringHashMap) {
// if (tvBlockUser!=null)
// CometChatSnackBar.show(CometChatUserDetailScreenActivity.this,
// tvBlockUser,
// userName.getText().toString()+" "+getResources().getString(R.string.unblocked_successfully),CometChatSnackBar.SUCCESS);
progressDialog.dismiss();
isBlocked = false;
setBlockUnblock();
}
@Override
public void onError(CometChatException e) {
Log.d(TAG, "onError: " + e.getMessage());
if (tvBlockUser != null)
CometChatSnackBar.show(CometChatUserDetailScreenActivity.this, tvBlockUser, getString(R.string.unblock_user_error), CometChatSnackBar.ERROR);
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatConversationList method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_cometchat_conversationlist, container, false);
rvConversationList = view.findViewById(R.id.rv_conversation_list);
noConversationView = view.findViewById(R.id.no_conversation_view);
searchEdit = view.findViewById(R.id.search_bar);
tvTitle = view.findViewById(R.id.tv_title);
tvTitle.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
rlSearchBox = view.findViewById(R.id.rl_search_box);
conversationShimmer = view.findViewById(R.id.shimmer_layout);
checkDarkMode();
CometChatError.init(getContext());
startConversation = view.findViewById(R.id.start_conversation);
FeatureRestriction.isStartConversationEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
startConversation.setVisibility(View.VISIBLE);
else
startConversation.setVisibility(View.GONE);
}
});
startConversation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CometChatStartConversation.launch(getContext());
}
});
searchEdit.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_SEARCH) {
if (!textView.getText().toString().isEmpty()) {
progressDialog = ProgressDialog.show(getContext(), "", getString(R.string.search));
refreshConversation(new CometChat.CallbackListener<List<Conversation>>() {
@Override
public void onSuccess(List<Conversation> conversationList) {
if (progressDialog != null)
progressDialog.dismiss();
rvConversationList.searchConversation(textView.getText().toString());
}
@Override
public void onError(CometChatException e) {
if (progressDialog != null)
progressDialog.dismiss();
CometChatSnackBar.show(getContext(), rvConversationList, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
});
}
return true;
}
return false;
});
// clearSearch.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// searchEdit.setText("");
// clearSearch.setVisibility(View.GONE);
// refreshConversation();
// InputMethodManager inputMethodManager = (InputMethodManager)
// getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// // Hide the soft keyboard
// inputMethodManager.hideSoftInputFromWindow(searchEdit.getWindowToken(),0);
// }
// });
// Uses to fetch next list of conversations if rvConversationList (RecyclerView) is scrolled in upward direction.
rvConversationList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!recyclerView.canScrollVertically(1)) {
makeConversationList();
}
}
});
// Used to trigger event on click of conversation item in rvConversationList (RecyclerView)
rvConversationList.setItemClickListener(new OnItemClickListener<Conversation>() {
@Override
public void OnItemClick(Conversation conversation, int position) {
if (events != null)
events.OnItemClick(conversation, position);
}
});
RecyclerViewSwipeListener swipeHelper = new RecyclerViewSwipeListener(getContext()) {
@Override
public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
Bitmap deleteBitmap = Utils.drawableToBitmap(getResources().getDrawable(R.drawable.ic_delete_conversation));
FeatureRestriction.isDeleteConversationEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal) {
underlayButtons.add(new RecyclerViewSwipeListener.UnderlayButton("Delete", deleteBitmap, getResources().getColor(R.color.red), new RecyclerViewSwipeListener.UnderlayButtonClickListener() {
@Override
public void onClick(final int pos) {
Conversation conversation = rvConversationList.getConversation(pos);
if (conversation != null) {
String conversationUid = "";
String type = "";
if (conversation.getConversationType().equalsIgnoreCase(CometChatConstants.CONVERSATION_TYPE_GROUP)) {
conversationUid = ((Group) conversation.getConversationWith()).getGuid();
type = CometChatConstants.CONVERSATION_TYPE_GROUP;
} else {
conversationUid = ((User) conversation.getConversationWith()).getUid();
type = CometChatConstants.CONVERSATION_TYPE_USER;
}
String finalConversationUid = conversationUid;
String finalType = type;
new CustomAlertDialogHelper(getContext(), getString(R.string.delete_conversation_message), null, getString(R.string.yes), "", getString(R.string.no), new OnAlertDialogButtonClickListener() {
@Override
public void onButtonClick(AlertDialog alertDialog, View v, int which, int popupId) {
if (which == DialogInterface.BUTTON_POSITIVE) {
ProgressDialog progressDialog = ProgressDialog.show(getContext(), null, getString(R.string.deleting_conversation));
CometChat.deleteConversation(finalConversationUid, finalType, new CometChat.CallbackListener<String>() {
@Override
public void onSuccess(String s) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
alertDialog.dismiss();
progressDialog.dismiss();
}
}, 1500);
rvConversationList.remove(conversation);
}
@Override
public void onError(CometChatException e) {
progressDialog.dismiss();
e.printStackTrace();
}
});
} else if (which == DialogInterface.BUTTON_NEGATIVE) {
alertDialog.dismiss();
}
}
}, 1, true);
}
}
}));
}
}
});
}
};
swipeHelper.attachToRecyclerView(rvConversationList);
return view;
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatAddMembers method searchUser.
private void searchUser(String s) {
UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setSearchKeyword(s).setLimit(100).build();
usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
@Override
public void onSuccess(List<User> users) {
if (userListAdapter != null)
userListAdapter.searchUser(users);
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(getContext(), rvUserList, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
});
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CallBroadcast method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String ourCode = "*007#";
String dialNumber = intent.getData().toString();
if (dialNumber.contains(ourCode)) {
setResultData(null);
String phoneNumber = dialNumber.replace(ourCode, "");
UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setTags(Arrays.asList(phoneNumber)).setLimit(10).build();
usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
@Override
public void onSuccess(List<User> users) {
if (!users.isEmpty()) {
User user = users.get(0);
Intent userDetail = new Intent(context, CometChatUserDetailScreenActivity.class);
userDetail.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
userDetail.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
userDetail.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
context.startActivity(userDetail);
}
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Unable to find user", Toast.LENGTH_LONG).show();
context.startActivity(new Intent(context, CometChatUI.class));
}
});
}
}
use of com.cometchat.pro.exceptions.CometChatException in project android-java-chat-push-notification-app by cometchat-pro.
the class CallNotificationAction method onReceive.
@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("Answer_")) {
CometChat.acceptCall(sessionID, new CometChat.CallbackListener<Call>() {
@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(UIKitConstants.Notification.ID);
} else if (intent.getAction().equals("Decline_")) {
CometChat.rejectCall(sessionID, CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(UIKitConstants.Notification.ID);
if (CometChatCallActivity.callActivity != null)
CometChatCallActivity.callActivity.finish();
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
} else if (intent.getAction().equals("StartCall")) {
Log.e(TAG, "onReceive: StartCall");
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);
}
}
Aggregations