use of com.cometchat.pro.models.Group 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.Group 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.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupDetailActivity method updateGroupDialog.
private void updateGroupDialog() {
dialog = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.cometchat_update_group_dialog, null);
CometChatAvatar avatar = view.findViewById(R.id.group_icon);
TextInputEditText avatar_url = view.findViewById(R.id.icon_url_edt);
if (groupIcon.getAvatarUrl() != null) {
avatar.setVisibility(View.VISIBLE);
avatar.setAvatar(groupIcon.getAvatarUrl());
avatar_url.setText(groupIcon.getAvatarUrl());
} else {
avatar.setVisibility(View.GONE);
}
TextInputEditText groupName = view.findViewById(R.id.groupname_edt);
TextInputEditText groupDesc = view.findViewById(R.id.groupdesc_edt);
TextInputEditText groupOldPwd = view.findViewById(R.id.group_old_pwd);
TextInputEditText groupNewPwd = view.findViewById(R.id.group_new_pwd);
TextInputLayout groupOldPwdLayout = view.findViewById(R.id.input_group_old_pwd);
TextInputLayout groupNewPwdLayout = view.findViewById(R.id.input_group_new_pwd);
Spinner groupTypeSp = view.findViewById(R.id.groupTypes);
MaterialButton updateGroupBtn = view.findViewById(R.id.updateGroupBtn);
MaterialButton cancelBtn = view.findViewById(R.id.cancelBtn);
groupName.setText(gName);
groupDesc.setText(gDesc);
if (groupType != null && groupType.equals(CometChatConstants.GROUP_TYPE_PUBLIC)) {
groupTypeSp.setSelection(0);
groupOldPwdLayout.setVisibility(View.GONE);
groupNewPwdLayout.setVisibility(View.GONE);
} else if (groupType != null && groupType.equals(CometChatConstants.GROUP_TYPE_PRIVATE)) {
groupTypeSp.setSelection(1);
groupOldPwdLayout.setVisibility(View.GONE);
groupNewPwdLayout.setVisibility(View.GONE);
} else {
groupTypeSp.setSelection(2);
groupOldPwdLayout.setVisibility(View.VISIBLE);
groupNewPwdLayout.setVisibility(View.VISIBLE);
}
groupTypeSp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (parent.getSelectedItemPosition() == 2) {
if (gPassword == null) {
groupOldPwdLayout.setVisibility(View.GONE);
} else
groupOldPwdLayout.setVisibility(View.VISIBLE);
groupNewPwdLayout.setVisibility(View.VISIBLE);
} else {
groupOldPwdLayout.setVisibility(View.GONE);
groupNewPwdLayout.setVisibility(View.GONE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
avatar_url.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!s.toString().isEmpty()) {
avatar.setVisibility(View.VISIBLE);
avatar.setAvatar(s.toString());
} else
avatar.setVisibility(View.GONE);
}
});
AlertDialog alertDialog = dialog.create();
alertDialog.setView(view);
updateGroupBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Group group = new Group();
group.setDescription(groupDesc.getText().toString().trim());
if (groupName.getText().toString().isEmpty()) {
groupName.setError(getString(R.string.fill_this_field));
} else if (groupTypeSp.getSelectedItemPosition() == 2) {
if (gPassword != null && groupOldPwd.getText().toString().trim().isEmpty()) {
groupOldPwd.setError(getResources().getString(R.string.fill_this_field));
} else if (gPassword != null && !groupOldPwd.getText().toString().trim().equals(gPassword.trim())) {
groupOldPwd.setError(getResources().getString(R.string.password_not_matched));
} else if (groupNewPwd.getText().toString().trim().isEmpty()) {
groupNewPwd.setError(getResources().getString(R.string.fill_this_field));
} else {
group.setName(groupName.getText().toString());
group.setGuid(guid);
group.setGroupType(CometChatConstants.GROUP_TYPE_PASSWORD);
group.setPassword(groupNewPwd.getText().toString());
group.setIcon(avatar_url.getText().toString());
updateGroup(group, alertDialog);
}
} else if (groupTypeSp.getSelectedItemPosition() == 1) {
group.setName(groupName.getText().toString());
group.setGuid(guid);
group.setGroupType(CometChatConstants.GROUP_TYPE_PRIVATE);
group.setIcon(avatar_url.getText().toString());
} else {
group.setName(groupName.getText().toString());
group.setGroupType(CometChatConstants.GROUP_TYPE_PUBLIC);
group.setIcon(avatar_url.getText().toString());
}
group.setGuid(guid);
updateGroup(group, alertDialog);
}
});
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupList method searchGroup.
/**
* This method is used to search groups present in your App_ID.
* For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-groups-retrieve-groups" }
*
* @param s is a string used to get groups matches with this string.
* @see GroupsRequest
*/
private void searchGroup(String s) {
GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder().setSearchKeyWord(s).setLimit(100).build();
groupsRequest.fetchNext(new CometChat.CallbackListener<List<Group>>() {
@Override
public void onSuccess(List<Group> groups) {
// sets the groups in rvGroupList i.e CometChatGroupList Component.
rvGroupList.searchGroupList(groups);
}
@Override
public void onError(CometChatException e) {
Toast.makeText(getContext(), CometChatError.localized(e), Toast.LENGTH_SHORT).show();
}
});
}
use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupList 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_grouplist, container, false);
title = view.findViewById(R.id.tv_title);
title.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
rvGroupList = view.findViewById(R.id.rv_group_list);
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
noGroupLayout = view.findViewById(R.id.no_group_layout);
etSearch = view.findViewById(R.id.search_bar);
clearSearch = view.findViewById(R.id.clear_search);
CometChatError.init(getContext());
ivCreateGroup = view.findViewById(R.id.create_group);
ivCreateGroup.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
isTitleVisible();
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
groupsRequest = null;
rvGroupList.clear();
fetchGroup();
}
});
FeatureRestriction.isGroupSearchEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
etSearch.setVisibility(View.VISIBLE);
else
etSearch.setVisibility(View.GONE);
}
});
FeatureRestriction.isGroupCreationEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal && isGroupCreateVisible)
ivCreateGroup.setVisibility(View.VISIBLE);
else
ivCreateGroup.setVisibility(View.GONE);
}
});
if (Utils.isDarkMode(getContext())) {
title.setTextColor(getResources().getColor(R.color.textColorWhite));
} else {
title.setTextColor(getResources().getColor(R.color.primaryTextColor));
}
FeatureRestriction.isPublicGroupEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
isPublicGroupEnabled = booleanVal;
checkGroups();
}
});
FeatureRestriction.isPrivateGroupEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
isPrivateGroupEnabled = booleanVal;
checkGroups();
}
});
FeatureRestriction.isPasswordGroupEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
isPasswordGroupEnabled = booleanVal;
checkGroups();
}
});
ivCreateGroup.setOnClickListener(view1 -> {
Intent intent = new Intent(getContext(), CometChatCreateGroupActivity.class);
startActivity(intent);
});
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 groups.
groupsRequest = null;
rvGroupList.clear();
fetchGroup();
} else {
// Search group based on text in etSearch field.
searchGroup(editable.toString());
}
}
});
etSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH) {
searchGroup(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);
searchGroup(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 group if rvGroupList (RecyclerView) is scrolled in upward direction.
rvGroupList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!recyclerView.canScrollVertically(1)) {
fetchGroup();
}
}
});
// Used to trigger event on click of group item in rvGroupList (RecyclerView)
rvGroupList.setItemClickListener(new OnItemClickListener<Group>() {
@Override
public void OnItemClick(Group group, int position) {
if (event != null)
event.OnItemClick(group, position);
}
});
isGroupCreateVisible();
return view;
}
Aggregations