use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.
the class MissedCall method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cometchat_missed_call, container, false);
rvCallList = view.findViewById(R.id.callList_rv);
CometChatError.init(getContext());
linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
rvCallList.setLayoutManager(linearLayoutManager);
noCallView = view.findViewById(R.id.no_call_vw);
rvCallList.setItemClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
User user;
if (((User) var.getCallInitiator()).getUid().equals(CometChat.getLoggedInUser().getUid())) {
user = ((User) var.getCallReceiver());
} else {
user = (User) var.getCallInitiator();
}
Intent intent = new Intent(getContext(), CometChatUserDetailScreenActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.IS_BLOCKED_BY_ME, user.isBlockedByMe());
intent.putExtra(UIKitConstants.IntentStrings.FROM_CALL_LIST, true);
startActivity(intent);
} else {
Group group;
group = ((Group) var.getCallReceiver());
Intent intent = new Intent(getContext(), CometChatGroupDetailActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.GUID, group.getGuid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_SCOPE, group.getScope());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, group.getOwner());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
startActivity(intent);
}
}
});
rvCallList.setItemCallClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
checkOnGoingCall(var);
}
});
rvCallList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!rvCallList.canScrollVertically(1)) {
getCallList();
}
}
});
return view;
}
use of com.cometchat.pro.models.User 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();
}
});
}
use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.
the class BlockedListAdapter method onBindViewHolder.
/**
* This method is used to bind the BlockedViewHolder contents with user at given position.
* It sets name and avatar field of a user with respective BlockedViewHolder content.
*
* @param blockedViewHolder is a object of BlockedViewHolder
* @param i is a position of item in recyclerView
* @see User
*/
@Override
public void onBindViewHolder(@NonNull BlockedViewHolder blockedViewHolder, int i) {
// Take User which is at ith position in userArrayList
final User user = userArrayList.get(i);
User user1 = i + 1 < userArrayList.size() ? userArrayList.get(i + 1) : null;
if (user1 != null && user.getName().substring(0, 1).toCharArray()[0] == user1.getName().substring(0, 1).toCharArray()[0]) {
blockedViewHolder.userListRowBinding.tvSeprator.setVisibility(View.GONE);
} else {
blockedViewHolder.userListRowBinding.tvSeprator.setVisibility(View.VISIBLE);
}
blockedViewHolder.userListRowBinding.txtUserName.setText(user.getName());
blockedViewHolder.userListRowBinding.getRoot().setTag(R.string.user, user);
blockedViewHolder.userListRowBinding.txtUserScope.setVisibility(View.GONE);
blockedViewHolder.userListRowBinding.unblockUser.setVisibility(View.VISIBLE);
blockedViewHolder.userListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
if (user.getAvatar() == null || user.getAvatar().isEmpty()) {
blockedViewHolder.userListRowBinding.avUser.setInitials(user.getName());
} else {
blockedViewHolder.userListRowBinding.avUser.setAvatar(user.getAvatar());
}
if (Utils.isDarkMode(context))
blockedViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
else
blockedViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
}
use of com.cometchat.pro.models.User 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.models.User 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);
}
});
}
Aggregations