From 2119d75e5b2543a96f2268944493026f90b39c6d Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Sat, 12 Nov 2022 15:48:45 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=B8=AA=E4=BA=BA=E5=90=8D?=
=?UTF-8?q?=E7=89=87=E4=B8=BB=E6=92=AD=E7=AB=AF=E8=B8=A2=E4=BA=BA=E9=80=89?=
=?UTF-8?q?=E9=A1=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../live/dialog/LiveUserDialogFragment.java | 204 ++++++++++++++++++
.../main/res/layout/dialog_new_live_user.xml | 11 +
2 files changed, 215 insertions(+)
diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java
index f39936720..8e03f5bd0 100644
--- a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java
+++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java
@@ -98,6 +98,8 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
private String mToUid;
private String mStream;
private int mType;
+ private int mAction;
+ private String mToName;//对方的名字
private TextView mFollowText;
private TextView mName;
private TextView mID;
@@ -123,6 +125,7 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
private ImageView shawl;
private ImageView honorIcon;
private ImageView mTitleBg;
+ private ImageView mSetting;
private UserBean mUserBean;
private LinearLayout mGuardLayout;
private LinearLayout mUnionLayout;
@@ -242,7 +245,9 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
mNobleTitleVal = mRootView.findViewById(R.id.noble_title_val);
mHonorLayout = mRootView.findViewById(R.id.honor_layout);
mTitleBg = mRootView.findViewById(R.id.title_bg);
+ mSetting = mRootView.findViewById(R.id.btn_setting);
mNobleIconLayout.setOnClickListener(this);
+ mSetting.setOnClickListener(this);
mHonorLayout.setOnClickListener(v -> forwardHomePage());
}
@@ -299,11 +304,17 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
Log.i(TAG, "showData: " + data);
JSONObject obj = JSON.parseObject(data);
mUserBean = JSON.toJavaObject(obj, UserBean.class);
+
+ mToName = obj.getString("user_nicename");
+ mAction = obj.getIntValue("action");
if (mUserBean.getIslive().equals("1")) {
btn_live.setVisibility(View.VISIBLE);
} else {
btn_live.setVisibility(View.GONE);
}
+ if(mType==TYPE_ANC_AUD){
+ mSetting.setVisibility(View.VISIBLE);
+ }
if (isAnchor) {
mGuardLayout.setVisibility(View.VISIBLE);
if (obj.containsKey("user_president_name") && !StringUtil.isEmpty(obj.getString("user_president_name"))) {
@@ -623,6 +634,199 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
dismiss();
((LiveActivity) mContext).openFansWindow();
}
+ } else if (i == R.id.btn_setting) {
+ setting();
}
}
+
+
+ /**
+ * 设置
+ *
+ * 某个大神说,角色是权限的集合。。
+ *
+ * 理论上,角色的权限应该有服务端以数组或集合的形式返回,这样可以在后台动态配置某种角色的权限,而不是这样口头约定写死。。。
+ * 然而,是服务端这样做的,我也很无奈。。。也许他们不知道如何做成动态配置的吧。。
+ *
+ * 我一直想通过不断重构把代码写的像艺术品,然而,最近发现,这完全是多此一举,自讨苦吃。。是我太天真了。。
+ * 下面是我发现的一篇文章,说的非常好,也点醒了我。。如果你们发现当前代码写的太烂,不堪入目的话,请阅读下面的文章。
+ *
+ * https://www.jianshu.com/p/71521541cd25?utm_campaign=haruki&utm_content=note&utm_medium=reader_share&utm_source=weixin_timeline&from=timeline
+ */
+ private void setting() {
+ List list = new ArrayList<>();
+ switch (mAction) {
+ case SETTING_ACTION_ADM://设置 房间管理员点普通观众
+ list.add(R.string.live_setting_kick);
+// list.add(R.string.live_setting_gap);
+ list.add(R.string.live_setting_gap_2);
+ break;
+ case SETTING_ACTION_SUP://设置 超管点主播
+ list.add(R.string.live_setting_close_live);
+ list.add(R.string.live_setting_close_live_2);
+ list.add(R.string.live_setting_forbid_account);
+ break;
+ case SETTING_ACTION_ANC_AUD://设置 主播点普通观众
+ list.add(R.string.live_setting_kick);
+// list.add(R.string.live_setting_gap);
+ list.add(R.string.live_setting_gap_2);
+ list.add(R.string.live_setting_admin);
+ list.add(R.string.live_setting_admin_list);
+ break;
+ case SETTING_ACTION_ANC_ADM://设置 主播点房间管理员
+ list.add(R.string.live_setting_kick);
+// list.add(R.string.live_setting_gap);
+ list.add(R.string.live_setting_gap_2);
+ list.add(R.string.live_setting_admin_cancel);
+ list.add(R.string.live_setting_admin_list);
+ break;
+ }
+
+ DialogUitl.showStringArrayDialog(mContext, list.toArray(new Integer[list.size()]), mArrayDialogCallback);
+ }
+
+ private DialogUitl.StringArrayDialogCallback mArrayDialogCallback = new DialogUitl.StringArrayDialogCallback() {
+ @Override
+ public void onItemClick(String text, int tag) {
+ if (tag == R.string.live_setting_kick) {
+ kick();
+
+ } else if (tag == R.string.live_setting_gap) {//永久禁言->改成三天禁言
+ setShutUp();
+
+ } else if (tag == R.string.live_setting_gap_2) {//本场禁言
+ setShutUp2();
+
+ } else if (tag == R.string.live_setting_admin || tag == R.string.live_setting_admin_cancel) {
+ setAdmin();
+
+ } else if (tag == R.string.live_setting_admin_list) {
+ adminList();
+
+ } else if (tag == R.string.live_setting_close_live) {
+ closeLive();
+
+ } else if (tag == R.string.live_setting_forbid_account) {
+ forbidAccount();
+
+ } else if (tag == R.string.live_setting_close_live_2) {//禁用直播
+ closeLive2();
+ }
+ }
+ };
+
+ /**
+ * 查看管理员列表
+ */
+ private void adminList() {
+ dismiss();
+ ((LiveActivity) mContext).openAdminListWindow();
+ }
+
+ /**
+ * 踢人
+ */
+ private void kick() {
+ LiveHttpUtil.kicking(mLiveUid, mToUid, new HttpCallback() {
+ @Override
+ public void onSuccess(int code, String msg, String[] info) {
+ if (code == 0) {
+ ((LiveActivity) mContext).kickUser(mToUid, mToName);
+ } else {
+ ToastUtil.show(msg);
+ }
+ }
+ });
+ }
+
+ /**
+ * 永久禁言->改成三天禁言
+ */
+ private void setShutUp() {
+ LiveHttpUtil.setShutUp(mLiveUid, "0", 0, mToUid, new HttpCallback() {
+ @Override
+ public void onSuccess(int code, String msg, String[] info) {
+ if (code == 0) {
+ ((LiveActivity) mContext).setShutUp(mToUid, mToName, 0);
+ } else {
+ ToastUtil.show(msg);
+ }
+ }
+ });
+ }
+
+ /**
+ * 本场禁言
+ */
+ private void setShutUp2() {
+ LiveHttpUtil.setShutUp(mLiveUid, mStream, 1, mToUid, new HttpCallback() {
+ @Override
+ public void onSuccess(int code, String msg, String[] info) {
+ if (code == 0) {
+ ((LiveActivity) mContext).setShutUp(mToUid, mToName, 1);
+ } else {
+ ToastUtil.show(msg);
+ }
+ }
+ });
+ }
+
+
+ /**
+ * 设置或取消管理员
+ */
+ private void setAdmin() {
+ LiveHttpUtil.setAdmin(mLiveUid, mToUid, new HttpCallback() {
+ @Override
+ public void onSuccess(int code, String msg, String[] info) {
+ if (code == 0 && info.length > 0) {
+ int res = JSON.parseObject(info[0]).getIntValue("isadmin");
+ if (res == 1) {//被设为管理员
+ mAction = SETTING_ACTION_ANC_ADM;
+ } else {//被取消管理员
+ mAction = SETTING_ACTION_ANC_AUD;
+ }
+ ((LiveActivity) mContext).sendSetAdminMessage(res, mToUid, mToName);
+ }
+ }
+ });
+ }
+
+
+ /**
+ * 超管关闭直播间
+ */
+ private void closeLive() {
+ dismiss();
+ LiveHttpUtil.superCloseRoom(mLiveUid, 0, mSuperCloseRoomCallback);
+ }
+
+ /**
+ * 超管关闭直播间并禁止主播直播
+ */
+ private void closeLive2() {
+ dismiss();
+ LiveHttpUtil.superCloseRoom(mLiveUid, 1, mSuperCloseRoomCallback);
+ }
+
+ /**
+ * 超管关闭直播间并禁用主播账户
+ */
+ private void forbidAccount() {
+ dismiss();
+ LiveHttpUtil.superCloseRoom(mLiveUid, 2, mSuperCloseRoomCallback);
+ }
+
+ private HttpCallback mSuperCloseRoomCallback = new HttpCallback() {
+ @Override
+ public void onSuccess(int code, String msg, String[] info) {
+ if (code == 0) {
+ ToastUtil.show(JSON.parseObject(info[0]).getString("msg"));
+ ((LiveActivity) mContext).superCloseRoom();
+ } else {
+ ToastUtil.show(msg);
+ }
+ }
+ };
+
}
diff --git a/live/src/main/res/layout/dialog_new_live_user.xml b/live/src/main/res/layout/dialog_new_live_user.xml
index cc1e4eff5..9fad3bd75 100644
--- a/live/src/main/res/layout/dialog_new_live_user.xml
+++ b/live/src/main/res/layout/dialog_new_live_user.xml
@@ -63,6 +63,17 @@
+