Pārlūkot izejas kodu

增加单聊设置页面,增加加入黑名单功能

Pq 2 mēneši atpakaļ
vecāks
revīzija
24c7ac6c12

+ 7 - 0
chatModule/src/main/AndroidManifest.xml

@@ -98,6 +98,13 @@
             android:configChanges="orientation|screenSize|keyboardHidden|fontScale|smallestScreenSize|screenLayout|uiMode"
             android:screenOrientation="portrait" />
 
+        <activity
+            android:name=".ui.SingleChatSettingActivity"
+            android:windowSoftInputMode="adjustPan"
+            android:configChanges="orientation|screenSize|keyboardHidden|fontScale|smallestScreenSize|screenLayout|uiMode"
+            android:screenOrientation="portrait" />
+
+
         <provider
             android:name=".widget.CustomChatGroupTopRightIconExtension"
             android:authorities="${applicationId}.TUIGroup.ClassicUI.Init"

+ 1 - 0
chatModule/src/main/java/com/cooleshow/chatmodule/constants/TCChatRouterPath.java

@@ -18,4 +18,5 @@ public class TCChatRouterPath {
     public final static String CHAT_SELECT_CONTACT = "/tc/activity/SelectContactActivity";
     public final static String CHAT_GROUP_NOTICE_DETAIL = "/tc/activity/NoticeDetailActivity";
     public final static String CHAT_GROUP_INTRODUCE = "/tc/activity/GroupIntroduceActivity";
+    public final static String CHAT_SINGLE_SETTING = "/tc/activity/SingleChatSettingActivity";
 }

+ 31 - 0
chatModule/src/main/java/com/cooleshow/chatmodule/contract/ChatSingleSettingContract.java

@@ -0,0 +1,31 @@
+package com.cooleshow.chatmodule.contract;
+
+import com.cooleshow.base.presenter.view.BaseView;
+import com.cooleshow.chatmodule.bean.GroupApplyBean;
+import com.cooleshow.chatmodule.bean.GroupMemberBean;
+import com.cooleshow.chatmodule.bean.IMGroupInfo;
+import com.tencent.imsdk.v2.V2TIMFriendInfo;
+import com.tencent.qcloud.tuikit.tuigroup.bean.GroupInfo;
+
+import java.util.List;
+
+/**
+ * 创建日期:2022/6/11 14:43
+ *
+ * @author Ryan
+ * 类说明:
+ */
+public interface ChatSingleSettingContract {
+    interface ChatSingleSettingView extends BaseView {
+
+        void getBlackListError(int code, String desc);
+
+        void getBlackListSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos);
+
+        void operateSuccess();
+
+    }
+
+    interface Presenter {
+    }
+}

+ 108 - 0
chatModule/src/main/java/com/cooleshow/chatmodule/presenter/ChatSingleSettingPresenter.java

@@ -0,0 +1,108 @@
+package com.cooleshow.chatmodule.presenter;
+
+import com.cooleshow.base.presenter.BasePresenter;
+import com.cooleshow.base.utils.LOG;
+import com.cooleshow.chatmodule.contract.ChatSingleSettingContract;
+import com.tencent.imsdk.v2.V2TIMFriendInfo;
+import com.tencent.imsdk.v2.V2TIMFriendOperationResult;
+import com.tencent.imsdk.v2.V2TIMFriendshipListener;
+import com.tencent.imsdk.v2.V2TIMManager;
+import com.tencent.imsdk.v2.V2TIMValueCallback;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Author by pq, Date on 2025/4/7.
+ */
+public class ChatSingleSettingPresenter extends BasePresenter<ChatSingleSettingContract.ChatSingleSettingView> {
+
+    public void getBlackList() {
+        if (getView() != null) {
+            getView().showLoading();
+        }
+        V2TIMManager.getFriendshipManager().getBlackList(new V2TIMValueCallback<List<V2TIMFriendInfo>>() {
+            @Override
+            public void onSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {
+                // 获取黑名单列表成功
+                if (getView() != null) {
+                    getView().hideLoading();
+                    getView().getBlackListSuccess(v2TIMFriendInfos);
+                }
+            }
+
+            @Override
+            public void onError(int code, String desc) {
+                // 获取黑名单列表失败
+                if (getView() != null) {
+                    getView().hideLoading();
+                    getView().getBlackListError(code, desc);
+                }
+            }
+        });
+    }
+
+    public void changeBlackListMode(String targetId, boolean isAdd) {
+        if (isAdd) {
+            addBlackList(targetId);
+        } else {
+            removeBlackList(targetId);
+        }
+    }
+
+    private void addBlackList(String targetId) {
+        if (getView() != null) {
+            getView().showLoading();
+        }
+        List<String> userIDList = new ArrayList<>();
+        userIDList.add(targetId);
+        V2TIMManager.getFriendshipManager().addToBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {
+            @Override
+            public void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {
+                // 拉黑成功
+                if (getView() != null) {
+                    getView().hideLoading();
+                    LOG.i("addBlackList onSuccess");
+                    getView().operateSuccess();
+                }
+            }
+
+            @Override
+            public void onError(int code, String desc) {
+                // 拉黑失败
+                if (getView() != null) {
+                    LOG.i("addBlackList onError:" + code + " " + desc);
+                    getView().hideLoading();
+                }
+            }
+        });
+    }
+
+    private void removeBlackList(String targetId) {
+        if (getView() != null) {
+            getView().showLoading();
+        }
+        List<String> userIDList = new ArrayList<>();
+        userIDList.add(targetId);
+        V2TIMManager.getFriendshipManager().deleteFromBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {
+            @Override
+            public void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {
+                // 解除拉黑成功
+                if (getView() != null) {
+                    LOG.i("removeBlackList onSuccess");
+                    getView().hideLoading();
+                    getView().operateSuccess();
+                }
+            }
+
+            @Override
+            public void onError(int code, String desc) {
+                // 解除拉黑失败
+                if (getView() != null) {
+                    LOG.i("removeBlackList onError:" + code + " " + desc);
+                    getView().hideLoading();
+                }
+            }
+        });
+    }
+}

+ 190 - 0
chatModule/src/main/java/com/cooleshow/chatmodule/ui/SingleChatSettingActivity.java

@@ -0,0 +1,190 @@
+package com.cooleshow.chatmodule.ui;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.alibaba.android.arouter.launcher.ARouter;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.listener.OnItemClickListener;
+import com.cooleshow.base.bean.StudentPageListBean;
+import com.cooleshow.base.common.BaseApplication;
+import com.cooleshow.base.common.BaseConstant;
+import com.cooleshow.base.router.RouterPath;
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
+import com.cooleshow.base.utils.GlideUtils;
+import com.cooleshow.base.utils.JumpUtils;
+import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.LogUtils;
+import com.cooleshow.base.utils.ToastUtil;
+import com.cooleshow.base.utils.ToastUtils;
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
+import com.cooleshow.base.widgets.dialog.CommonDialog;
+import com.cooleshow.chatmodule.R;
+import com.cooleshow.chatmodule.adapter.GroupSettingMemberAdapter;
+import com.cooleshow.chatmodule.bean.GroupApplyBean;
+import com.cooleshow.chatmodule.bean.GroupMemberBean;
+import com.cooleshow.chatmodule.bean.IMGroupInfo;
+import com.cooleshow.chatmodule.constants.Constants;
+import com.cooleshow.chatmodule.constants.GroupRoleType;
+import com.cooleshow.chatmodule.constants.TCChatRouterPath;
+import com.cooleshow.chatmodule.contract.ChatGroupSettingContract;
+import com.cooleshow.chatmodule.contract.ChatSingleSettingContract;
+import com.cooleshow.chatmodule.databinding.TcActivityChatGroupSettingBinding;
+import com.cooleshow.chatmodule.databinding.TcActivityChatSingleSettingBinding;
+import com.cooleshow.chatmodule.presenter.ChatGroupSettingPresenter;
+import com.cooleshow.chatmodule.presenter.ChatSingleSettingPresenter;
+import com.cooleshow.chatmodule.utils.helper.ChatGroupHelper;
+import com.cooleshow.chatmodule.utils.helper.IMThemManager;
+import com.cooleshow.chatmodule.widget.CommonConfirmDialog2;
+import com.cooleshow.usercenter.helper.UserHelper;
+import com.tencent.imsdk.v2.V2TIMFriendInfo;
+import com.tencent.qcloud.tuicore.TUICore;
+import com.tencent.qcloud.tuikit.tuigroup.bean.GroupInfo;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+/**
+ * 创建日期:2022/6/11 14:29
+ *
+ * @author Ryan
+ * 类说明:
+ */
+@Route(path = TCChatRouterPath.CHAT_SINGLE_SETTING)
+public class SingleChatSettingActivity extends BaseMVPActivity<TcActivityChatSingleSettingBinding, ChatSingleSettingPresenter> implements ChatSingleSettingContract.ChatSingleSettingView, View.OnClickListener {
+    private String targetId;
+
+    @Override
+    public void onClick(View view) {
+        int id = view.getId();
+        if (id == R.id.ll_report) {
+            goAppeal();
+            return;
+        }
+    }
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        QMUIStatusBarHelper.setStatusBarLightMode(this);
+    }
+
+    @Override
+    protected void initView() {
+        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "设置");
+    }
+
+    @Override
+    public void initData() {
+        super.initData();
+        targetId = getIntent().getStringExtra(Constants.TARGET_ID_KEY);
+        if (TextUtils.isEmpty(targetId)) {
+            ToastUtils.showShort("参数异常");
+            finish();
+            return;
+        }
+
+        initListener();
+    }
+
+    private void initListener() {
+        viewBinding.llReport.setOnClickListener(this);
+        viewBinding.cbBlack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                if (buttonView.isPressed()) {
+                    presenter.changeBlackListMode(targetId, isChecked);
+                }
+            }
+        });
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        refresh();
+    }
+
+    private void refresh() {
+        presenter.getBlackList();
+    }
+
+    /**
+     * 举报
+     */
+    private void goAppeal() {
+        if (TextUtils.isEmpty(targetId)) {
+            return;
+        }
+        ARouter.getInstance().build(TCChatRouterPath.CHAT_IM_APPEAL)
+                .withString("targetId", targetId)
+                .withString("name", "")
+                .withString("type", "PERSON")
+                .navigation();
+    }
+
+    @Override
+    public void getBlackListError(int code, String desc) {
+        if (!checkActivityExist()) {
+            return;
+        }
+        ToastUtils.showShort("获取黑名单信息失败");
+    }
+
+    @Override
+    public void getBlackListSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {
+        if (!checkActivityExist()) {
+            return;
+        }
+        if (v2TIMFriendInfos != null) {
+            boolean isOnBlack = find(v2TIMFriendInfos);
+            viewBinding.cbBlack.setChecked(isOnBlack);
+        }
+    }
+
+    @Override
+    public void operateSuccess() {
+        if (!checkActivityExist()) {
+            return;
+        }
+    }
+
+    private boolean find(List<V2TIMFriendInfo> v2TIMFriendInfos) {
+        for (int i = 0; i < v2TIMFriendInfos.size(); i++) {
+            V2TIMFriendInfo v2TIMFriendInfo = v2TIMFriendInfos.get(i);
+            if (TextUtils.equals(v2TIMFriendInfo.getUserID(), targetId)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    @Override
+    protected TcActivityChatSingleSettingBinding getLayoutView() {
+        return TcActivityChatSingleSettingBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected ChatSingleSettingPresenter createPresenter() {
+        return new ChatSingleSettingPresenter();
+    }
+
+}

+ 7 - 6
chatModule/src/main/java/com/cooleshow/chatmodule/widget/CustomChatGroupTopRightIconExtension.java

@@ -6,6 +6,7 @@ import android.text.TextUtils;
 
 import com.alibaba.android.arouter.launcher.ARouter;
 import com.cooleshow.base.router.RouterPath;
+import com.cooleshow.chatmodule.constants.Constants;
 import com.cooleshow.chatmodule.constants.TCChatRouterPath;
 import com.tencent.qcloud.tuicore.ServiceInitializer;
 import com.tencent.qcloud.tuicore.TUIConstants;
@@ -52,7 +53,7 @@ public class CustomChatGroupTopRightIconExtension extends ServiceInitializer imp
 //                        getAppContext().startActivity(intent);
 //                          ToastUtil.getInstance().showShort("点击群组右上角");
                         ARouter.getInstance().build(TCChatRouterPath.CHAT_GROUP_SETTING)
-                                .withString("targetId",(String) groupID)
+                                .withString("targetId", (String) groupID)
                                 .navigation();
                     }
                 });
@@ -63,15 +64,15 @@ public class CustomChatGroupTopRightIconExtension extends ServiceInitializer imp
             if (uId instanceof String) {
                 String userId = (String) uId;
                 TUIExtensionInfo extensionInfo = new TUIExtensionInfo();
-                extensionInfo.setText("举报");
                 extensionInfo.setIcon(TUIThemeManager.getAttrResId(getContext(), com.tencent.qcloud.tuikit.tuigroup.R.attr.group_chat_extension_title_bar_more_menu));
+//                TUIExtensionInfo extensionInfo = new TUIExtensionInfo();
+//                extensionInfo.setText("举报");
+//                extensionInfo.setIcon(TUIThemeManager.getAttrResId(getContext(), com.tencent.qcloud.tuikit.tuigroup.R.attr.group_chat_extension_title_bar_more_menu));
                 extensionInfo.setExtensionListener(new TUIExtensionEventListener() {
                     @Override
                     public void onClicked(Map<String, Object> param) {
-                        ARouter.getInstance().build(TCChatRouterPath.CHAT_IM_APPEAL)
-                                .withString("targetId", userId)
-                                .withString("name", "")
-                                .withString("type", "PERSON")
+                        ARouter.getInstance().build(TCChatRouterPath.CHAT_SINGLE_SETTING)
+                                .withString(Constants.TARGET_ID_KEY, userId)
                                 .navigation();
                     }
                 });

+ 75 - 0
chatModule/src/main/res/layout/tc_activity_chat_single_setting.xml

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include
+        android:id="@+id/toolbar_include"
+        layout="@layout/common_toolbar_layout" />
+
+
+    <androidx.core.widget.NestedScrollView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:orientation="vertical">
+
+            <CheckBox
+                android:id="@+id/cb_black"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/dp_50"
+                android:layout_marginTop="@dimen/dp_15"
+                android:background="@color/white"
+                android:button="@null"
+                android:checked="false"
+                android:drawableEnd="@drawable/tc_switch_selector"
+                android:paddingStart="@dimen/dp_13"
+                android:paddingEnd="@dimen/dp_15"
+                android:text="加入黑名单"
+                android:textColor="@color/color_333333"
+                android:textSize="@dimen/sp_16" />
+
+            <LinearLayout
+                android:id="@+id/ll_report"
+                android:layout_width="match_parent"
+                android:layout_height="50dp"
+                android:layout_marginTop="@dimen/dp_15"
+                android:background="@color/white"
+                android:orientation="horizontal">
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:gravity="center_vertical"
+                    android:paddingLeft="@dimen/dp_13"
+                    android:text="投诉"
+                    android:textColor="@color/color_333333"
+                    android:textSize="@dimen/sp_16" />
+
+                <TextView
+                    android:id="@+id/tv_feedback"
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:layout_weight="1"
+                    android:background="@color/transparent"
+                    android:drawableEnd="@drawable/icon_arrow_right"
+                    android:drawablePadding="@dimen/dp_12"
+                    android:gravity="center_vertical|right"
+                    android:paddingLeft="@dimen/dp_15"
+                    android:paddingRight="@dimen/dp_15"
+                    android:singleLine="true"
+                    android:text=""
+                    android:textColor="@color/color_666666"
+                    android:textSize="@dimen/dp_16" />
+            </LinearLayout>
+
+        </LinearLayout>
+    </androidx.core.widget.NestedScrollView>
+</LinearLayout>