use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatUserList method searchUser.
/**
* This method is used to search users present in your App_ID.
* For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-users-retrieve-users#section-retrieve-list-of-users" }
*
* @param s is a string used to get users matches with this string.
* @see UsersRequest
*/
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) {
// set the users to rvUserList i.e CometChatUserList Component.
rvUserList.searchUserList(users);
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rlSearchBox, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
});
}
use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatUserList 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_cometchat_userlist, container, false);
title = view.findViewById(R.id.tv_title);
title.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
rvUserList = view.findViewById(R.id.rv_user_list);
noUserLayout = view.findViewById(R.id.no_user_layout);
etSearch = view.findViewById(R.id.search_bar);
clearSearch = view.findViewById(R.id.clear_search);
rlSearchBox = view.findViewById(R.id.rl_search_box);
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
usersRequest = null;
rvUserList.clear();
fetchUsers();
}
});
CometChatError.init(getContext());
shimmerFrameLayout = view.findViewById(R.id.shimmer_layout);
if (Utils.isDarkMode(getContext())) {
title.setTextColor(getResources().getColor(R.color.textColorWhite));
} else {
title.setTextColor(getResources().getColor(R.color.primaryTextColor));
}
FeatureRestriction.isUserSearchEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
etSearch.setVisibility(View.VISIBLE);
else
etSearch.setVisibility(View.GONE);
}
});
isTitleVisible();
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (editable.length() == 0) {
// if etSearch is empty then fetch all users.
usersRequest = null;
rvUserList.clear();
fetchUsers();
} else {
// Search users based on text in etSearch field.
searchUser(editable.toString());
}
}
});
etSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH) {
searchUser(textView.getText().toString());
clearSearch.setVisibility(View.VISIBLE);
return true;
}
return false;
}
});
clearSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
etSearch.setText("");
clearSearch.setVisibility(View.GONE);
searchUser(etSearch.getText().toString());
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// Hide the soft keyboard
inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
}
});
// Uses to fetch next list of user if rvUserList (RecyclerView) is scrolled in upward direction.
rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!recyclerView.canScrollVertically(1)) {
fetchUsers();
}
}
});
// Used to trigger event on click of user item in rvUserList (RecyclerView)
rvUserList.setItemClickListener(new OnItemClickListener<User>() {
@Override
public void OnItemClick(User user, int position) {
if (events != null)
events.OnItemClick(user, position);
}
});
return view;
}
use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.
the class CallUtils method initiateCall.
/**
* This method is used to initiate a call for user or a group.
* @param context is a object of Context
* @param recieverID is String - It can be either uid or guid
* @param receiverType is String - It can be either user or group
* [<code>CometChatConstants.RECEIVER_TYPE_USER</code> or
* <code>CometChatConstants.RECEIVER_TYPE_GROUP</code>]
* @param callType is String - It can be either audio or video
* [<code>CometChatConstants.CALL_TYPE_AUDIO</code> or
* <code>CometChatConstants.CALL_TYPE_VIDEO</code>]
*
* @see CometChat#initiateCall(Call, CometChat.CallbackListener)
*/
public static void initiateCall(Context context, String recieverID, String receiverType, String callType) {
Call call = new Call(recieverID, receiverType, callType);
CometChat.initiateCall(call, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER))
startCallIntent(context, ((User) call.getCallReceiver()), call.getType(), true, call.getSessionId());
else if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP))
startGroupCallIntent(context, ((Group) call.getCallReceiver()), call.getType(), true, call.getSessionId());
}
@Override
public void onError(CometChatException e) {
Log.e(TAG, "onError: " + e.getMessage());
Snackbar.make(((Activity) context).getWindow().getDecorView().getRootView(), context.getResources().getString(R.string.call_initiate_error) + ":" + e.getMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
Aggregations