浏览代码

增加聊天页面黑名单列表模块搜索筛选过滤逻辑

Pq 3 月之前
父节点
当前提交
57be7a0326

+ 65 - 4
chatModule/src/main/java/com/cooleshow/chatmodule/presenter/BlackListPresenter.java

@@ -1,6 +1,7 @@
 package com.cooleshow.chatmodule.presenter;
 
 import android.text.TextUtils;
+import android.widget.Filterable;
 
 import com.cooleshow.base.common.BaseConstant;
 import com.cooleshow.base.presenter.BasePresenter;
@@ -14,6 +15,7 @@ import com.cooleshow.chatmodule.contract.ContactListFragmentContract;
 import com.tencent.imsdk.v2.V2TIMFriendInfo;
 import com.tencent.imsdk.v2.V2TIMFriendOperationResult;
 import com.tencent.imsdk.v2.V2TIMManager;
+import com.tencent.imsdk.v2.V2TIMUserFullInfo;
 import com.tencent.imsdk.v2.V2TIMValueCallback;
 
 import org.json.JSONException;
@@ -22,21 +24,34 @@ import org.json.JSONObject;
 import java.util.ArrayList;
 import java.util.List;
 
+import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
+import io.reactivex.rxjava3.annotations.NonNull;
+import io.reactivex.rxjava3.core.Observable;
+import io.reactivex.rxjava3.core.Observer;
+import io.reactivex.rxjava3.core.SingleObserver;
+import io.reactivex.rxjava3.disposables.Disposable;
+import io.reactivex.rxjava3.functions.Predicate;
+import io.reactivex.rxjava3.schedulers.Schedulers;
+
 /**
  * Author by pq, Date on 2022/5/6.
  */
 public class BlackListPresenter extends BasePresenter<BlackListFragmentContract.View> implements BlackListFragmentContract.Presenter {
 
-    public void queryBlackList() {
+    public void queryBlackList(String search) {
         V2TIMManager.getFriendshipManager().getBlackList(new V2TIMValueCallback<List<V2TIMFriendInfo>>() {
             @Override
             public void onSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {
                 // 获取黑名单列表成功
-                if (getView() != null) {
-                    getView().getBlackListSuccess(v2TIMFriendInfos);
+                if (!TextUtils.isEmpty(search)) {
+                    filter(search, v2TIMFriendInfos);
+                } else {
+                    if (getView() != null) {
+                        getView().getBlackListSuccess(v2TIMFriendInfos);
+                    }
                 }
-
             }
+
             @Override
             public void onError(int code, String desc) {
                 // 获取黑名单列表失败
@@ -74,4 +89,50 @@ public class BlackListPresenter extends BasePresenter<BlackListFragmentContract.
             }
         });
     }
+
+    private void filter(String search, List<V2TIMFriendInfo> v2TIMFriendInfos) {
+        Observable<V2TIMFriendInfo> observable = Observable.fromIterable(v2TIMFriendInfos)
+                .filter(new Predicate<V2TIMFriendInfo>() {
+                    @Override
+                    public boolean test(V2TIMFriendInfo v2TIMFriendInfo) throws Throwable {
+                        if (v2TIMFriendInfo != null) {
+                            String userID = v2TIMFriendInfo.getUserID();
+                            if (userID.contains(search)) {
+                                return true;
+                            }
+                            V2TIMUserFullInfo userProfile = v2TIMFriendInfo.getUserProfile();
+                            if (userProfile != null) {
+                                if (userProfile.getNickName().contains(search)) {
+                                    return true;
+                                }
+                            }
+                        }
+                        return false;
+                    }
+                });
+
+        observable.toList().subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SingleObserver<List<V2TIMFriendInfo>>() {
+                    @Override
+                    public void onSubscribe(@NonNull Disposable d) {
+
+                    }
+
+                    @Override
+                    public void onSuccess(@NonNull List<V2TIMFriendInfo> v2TIMFriendInfos) {
+                        if (getView() != null) {
+                            getView().getBlackListSuccess(v2TIMFriendInfos);
+                        }
+                    }
+
+                    @Override
+                    public void onError(@NonNull Throwable e) {
+                        // 获取黑名单列表失败
+                        if (getView() != null) {
+                            getView().getBlackListError();
+                        }
+                    }
+                });
+    }
 }

+ 3 - 3
chatModule/src/main/java/com/cooleshow/chatmodule/ui/BlackListFragment.java

@@ -155,9 +155,9 @@ public class BlackListFragment extends BaseMVPFragment<TcFragmentBlackListLayout
         }
         Drawable conversationListEmptyDrawable = MessageProperties.getInstance().getConversationListEmptyDrawable();
         if (conversationListEmptyDrawable != null) {
-            mEmptyViewLayout.setContent(conversationListEmptyDrawable, "暂无联系人");
+            mEmptyViewLayout.setContent(conversationListEmptyDrawable, "暂无用户");
         } else {
-            mEmptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_content, "暂无联系人");
+            mEmptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_content, "暂无用户");
         }
         mListAdapter.setEmptyView(mEmptyViewLayout);
     }
@@ -177,7 +177,7 @@ public class BlackListFragment extends BaseMVPFragment<TcFragmentBlackListLayout
 
     private void getData() {
         if (presenter != null) {
-            presenter.queryBlackList();
+            presenter.queryBlackList(searchCondition);
         }
     }
 

+ 2 - 1
chatModule/src/main/res/layout/tc_fragment_black_list_layout.xml

@@ -63,7 +63,8 @@
         android:includeFontPadding="false"
         android:theme="@style/MyEditText"
         android:textCursorDrawable="@drawable/shape_2dc7aa_1dp"
-        android:textColor="@color/color_aaaaaa"
+        android:textColorHint="@color/color_999999"
+        android:textColor="@color/color_333333"
         android:textSize="@dimen/sp_14"
         app:layout_constraintBottom_toBottomOf="@+id/view_search_bg"
         app:layout_constraintLeft_toRightOf="@+id/iv_search_icon"

+ 2 - 1
chatModule/src/main/res/layout/tc_fragment_contact_list_layout.xml

@@ -63,7 +63,8 @@
         android:includeFontPadding="false"
         android:theme="@style/MyEditText"
         android:textCursorDrawable="@drawable/shape_2dc7aa_1dp"
-        android:textColor="@color/color_aaaaaa"
+        android:textColorHint="@color/color_999999"
+        android:textColor="@color/color_333333"
         android:textSize="@dimen/sp_14"
         app:layout_constraintBottom_toBottomOf="@+id/view_search_bg"
         app:layout_constraintLeft_toRightOf="@+id/iv_search_icon"

+ 2 - 1
chatModule/src/main/res/layout/tc_fragment_contact_room_list.xml

@@ -39,7 +39,8 @@
         android:hint="请输入群聊/学员名称"
         android:maxLines="1"
         android:paddingStart="8dp"
-        android:textColor="@color/color_aaaaaa"
+        android:textColorHint="@color/color_999999"
+        android:textColor="@color/color_333333"
         android:textSize="@dimen/sp_14"
         android:theme="@style/MyEditText"
         app:layout_constraintBottom_toBottomOf="@+id/view_search_bg"