use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerViewSwipeListener 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;
}
Aggregations