|
@@ -0,0 +1,238 @@
|
|
|
+package com.cooleshow.chatmodule.ui;
|
|
|
+
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemChildClickListener;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemClickListener;
|
|
|
+import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.constanst.LoginStatusConstants;
|
|
|
+import com.cooleshow.base.event.LoginStatusEvent;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.base.widgets.CustomSuspensionDecoration;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonDialog;
|
|
|
+import com.cooleshow.chatmodule.R;
|
|
|
+import com.cooleshow.chatmodule.adapter.BlackListAdapter;
|
|
|
+import com.cooleshow.chatmodule.adapter.ContactListAdapter;
|
|
|
+import com.cooleshow.chatmodule.bean.ContactListBean;
|
|
|
+import com.cooleshow.chatmodule.constants.IMConstants;
|
|
|
+import com.cooleshow.chatmodule.contract.BlackListFragmentContract;
|
|
|
+import com.cooleshow.chatmodule.contract.ContactListFragmentContract;
|
|
|
+import com.cooleshow.chatmodule.databinding.TcFragmentBlackListLayoutBinding;
|
|
|
+import com.cooleshow.chatmodule.databinding.TcFragmentContactListLayoutBinding;
|
|
|
+import com.cooleshow.chatmodule.presenter.BlackListPresenter;
|
|
|
+import com.cooleshow.chatmodule.presenter.ContactListPresenter;
|
|
|
+import com.cooleshow.chatmodule.utils.helper.ChatAvatarClickHelper;
|
|
|
+import com.cooleshow.chatmodule.utils.helper.ChatHelper;
|
|
|
+import com.cooleshow.chatmodule.utils.helper.IMThemManager;
|
|
|
+import com.cooleshow.chatmodule.widget.CommonConfirmDialog2;
|
|
|
+import com.cooleshow.chatmodule.widget.CustomIndexBarDataHelperImpl;
|
|
|
+import com.mcxtzhang.indexlib.suspension.SuspensionDecoration;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
+import com.tencent.imsdk.v2.V2TIMFriendInfo;
|
|
|
+import com.tencent.qcloud.tuikit.timcommon.component.MessageProperties;
|
|
|
+
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+import org.greenrobot.eventbus.ThreadMode;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 联系人列表
|
|
|
+ */
|
|
|
+public class BlackListFragment extends BaseMVPFragment<TcFragmentBlackListLayoutBinding, BlackListPresenter> implements BlackListFragmentContract.View, View.OnClickListener {
|
|
|
+
|
|
|
+ private BlackListAdapter mListAdapter;
|
|
|
+ private String searchCondition;
|
|
|
+ private EmptyViewLayout mEmptyViewLayout;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected TcFragmentBlackListLayoutBinding getLayoutView() {
|
|
|
+ return TcFragmentBlackListLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected BlackListPresenter createPresenter() {
|
|
|
+ return new BlackListPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+ IMThemManager.getInstance().setSearchIconStyles(mViewBinding.ivSearchIcon);
|
|
|
+ IMThemManager.getInstance().setSearchButtonStyles(mViewBinding.tvSearch);
|
|
|
+ IMThemManager.getInstance().setEditStyle(mViewBinding.etTargetName);
|
|
|
+
|
|
|
+ mViewBinding.etTargetName.setHint("请输入用户名称");
|
|
|
+ mViewBinding.tvSearch.setOnClickListener(this);
|
|
|
+ mViewBinding.tvFilter.setOnClickListener(this);
|
|
|
+ mListAdapter = new BlackListAdapter();
|
|
|
+ setEmptyView();
|
|
|
+ LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
|
|
+ mViewBinding.recyclerView.setLayoutManager(layoutManager);
|
|
|
+ mViewBinding.recyclerView.setAdapter(mListAdapter);
|
|
|
+
|
|
|
+ mListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ if (position < mListAdapter.getData().size()) {
|
|
|
+ V2TIMFriendInfo v2TIMFriendInfo = mListAdapter.getData().get(position);
|
|
|
+ if (view.getId() == R.id.iv_remove_black) {
|
|
|
+ String id = v2TIMFriendInfo.getUserID();
|
|
|
+ String name = "用户" + id;
|
|
|
+ if (v2TIMFriendInfo.getUserProfile() != null) {
|
|
|
+ name = v2TIMFriendInfo.getUserProfile().getNickName();
|
|
|
+ }
|
|
|
+ showConfirmDialog(id, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showConfirmDialog(String id, String nickName) {
|
|
|
+ CommonDialog commonDialog = new CommonDialog(getContext());
|
|
|
+ commonDialog.show();
|
|
|
+ commonDialog.setTitle("移除黑名单");
|
|
|
+ commonDialog.setContent(String.format("将%s移除黑名单后,您可向对方发送和接收消息。", nickName));
|
|
|
+ commonDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.removeBlackList(id);
|
|
|
+ commonDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ commonDialog.setOnCancelClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (commonDialog != null) {
|
|
|
+ commonDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void setEmptyView() {
|
|
|
+ if (mEmptyViewLayout == null) {
|
|
|
+ mEmptyViewLayout = new EmptyViewLayout(getContext());
|
|
|
+ }
|
|
|
+ Drawable conversationListEmptyDrawable = MessageProperties.getInstance().getConversationListEmptyDrawable();
|
|
|
+ if (conversationListEmptyDrawable != null) {
|
|
|
+ mEmptyViewLayout.setContent(conversationListEmptyDrawable, "暂无联系人");
|
|
|
+ } else {
|
|
|
+ mEmptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_content, "暂无联系人");
|
|
|
+ }
|
|
|
+ mListAdapter.setEmptyView(mEmptyViewLayout);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.tv_search) {
|
|
|
+ String targetSearchStr = mViewBinding.etTargetName.getText().toString().trim();
|
|
|
+ searchCondition = targetSearchStr;
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+ if (v.getId() == R.id.tv_filter) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getData() {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.queryBlackList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getBlackListSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ if (mListAdapter != null) {
|
|
|
+ if (v2TIMFriendInfos != null && v2TIMFriendInfos.size() > 0) {
|
|
|
+ mListAdapter.setNewInstance(v2TIMFriendInfos);
|
|
|
+ } else {
|
|
|
+ mListAdapter.getData().clear();
|
|
|
+ mListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getBlackListError() {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mListAdapter != null) {
|
|
|
+ mListAdapter.getData().clear();
|
|
|
+ mListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void operateSuccess() {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+ public void loadEventBus(LoginStatusEvent event) {
|
|
|
+ if (event != null && event.eventCode == LoginStatusConstants.LOGIN_OUT) {
|
|
|
+ searchCondition = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
+ }
|
|
|
+}
|