Pārlūkot izejas kodu

增加直播连麦头像显示

Pq 2 gadi atpakaļ
vecāks
revīzija
a02d08bea9

+ 1 - 0
BaseLibrary/src/main/res/values/colors.xml

@@ -141,6 +141,7 @@
     <color name="color_b4fff3">#B4FFF3</color>
     <color name="color_fff4ec">#fff4ec</color>
     <color name="color_fffdfb">#FFFDFB</color>
+    <color name="color_f37c17">#F37C17</color>
 
     <color name="color_25292e">#25292E</color>
     <color name="color_F8F8F8">#F8F8F8</color>

+ 5 - 1
rong_im/live/src/main/java/com/rong/io/live/bean/User.java

@@ -66,7 +66,11 @@ public class User implements Serializable {
     }
 
     public Uri getPortraitUri() {
-        return Uri.parse(getPortraitUrl());
+        if (!TextUtils.isEmpty(getPortraitUrl())) {
+            return Uri.parse(getPortraitUrl());
+        } else {
+            return null;
+        }
     }
 
     public void setPortrait(String portrait) {

+ 18 - 4
rong_im/live/src/main/java/com/rong/io/live/widget/LiveRoomMicIconView.java

@@ -1,8 +1,10 @@
 package com.rong.io.live.widget;
 
 import android.content.Context;
+import android.net.Uri;
 import android.text.TextUtils;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -10,6 +12,7 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.cooleshow.base.utils.GlideUtils;
 import com.cooleshow.usercenter.helper.UserHelper;
 import com.rong.io.live.R;
 import com.rong.io.live.bean.User;
@@ -17,6 +20,7 @@ import com.rong.io.live.bean.User;
 import java.util.ArrayList;
 
 import androidx.annotation.Nullable;
+import de.hdodenhof.circleimageview.CircleImageView;
 import io.rong.imlib.model.UserInfo;
 
 /**
@@ -28,6 +32,7 @@ public class LiveRoomMicIconView extends LinearLayout {
     public static final String DEFAULT_NICK = "连麦用户";
     public OnEventListener mEventListener;
     private String mCurrentUserName;
+    private String mCurrentUserAvatar;
 
     public LiveRoomMicIconView(Context context) {
         this(context, null);
@@ -48,6 +53,7 @@ public class LiveRoomMicIconView extends LinearLayout {
         mMicUserInfos = new ArrayList<>();
         mCurrentUserId = UserHelper.getUserId();
         mCurrentUserName = UserHelper.getUserName();
+        mCurrentUserAvatar = UserHelper.getUserAvatar();
     }
 
     public void delAll() {
@@ -80,7 +86,7 @@ public class LiveRoomMicIconView extends LinearLayout {
         for (int i = 0; i < mMicUserInfos.size(); i++) {
             UserInfo userInfo = mMicUserInfos.get(i);
             View view = LayoutInflater.from(getContext()).inflate(R.layout.item_live_room_mic_user_layout, this, false);
-            ImageView iv_icon = view.findViewById(R.id.iv_icon);
+            CircleImageView iv_icon = view.findViewById(R.id.iv_icon);
             TextView tv_name = view.findViewById(R.id.tv_name);
             String nickName = DEFAULT_NICK;
             if (!TextUtils.isEmpty(userInfo.getName())) {
@@ -88,12 +94,19 @@ public class LiveRoomMicIconView extends LinearLayout {
             }
             userInfo.setName(nickName);
             tv_name.setText(nickName);
+            //头像
+            String avatarPath = "";
+            if(userInfo.getPortraitUri()!=null){
+                Log.i("pq","userInfo.getPortraitUri().getPath():"+userInfo.getPortraitUri().toString());
+                avatarPath = userInfo.getPortraitUri().toString();
+            }
+            GlideUtils.INSTANCE.loadImage(getContext(), avatarPath, iv_icon, R.drawable.icon_live_room_mic_other);
             if (userInfo != null && TextUtils.equals(userInfo.getUserId(), mCurrentUserId)) {
                 //自己
-                iv_icon.setImageResource(R.drawable.icon_live_room_mic_own);
+                iv_icon.setBorderColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_f37c17));
                 tv_name.setBackgroundResource(R.drawable.shape_live_room_mic_nickname_bg);
             } else {
-                iv_icon.setImageResource(R.drawable.icon_live_room_mic_other);
+                iv_icon.setBorderColor(getContext().getResources().getColor(com.cooleshow.base.R.color.transparent));
                 tv_name.setBackgroundResource(R.drawable.shape_live_room_mic_nickname_bg_normal);
             }
             this.addView(view);
@@ -133,7 +146,7 @@ public class LiveRoomMicIconView extends LinearLayout {
         mMicUserInfos.clear();
         for (int i = 0; i < users.size(); i++) {
             User user = users.get(i);
-            UserInfo userInfo = new UserInfo(user.getUserId(), user.getUserName(), null);
+            UserInfo userInfo = new UserInfo(user.getUserId(), user.getUserName(), user.getPortraitUri());
             mMicUserInfos.add(userInfo);
         }
         refreshAllUser();
@@ -167,6 +180,7 @@ public class LiveRoomMicIconView extends LinearLayout {
                         if (TextUtils.equals(targetUser.getUserId(), mCurrentUserId)) {
                             //如果是自身则不需要查询,直接取缓存名称
                             targetUser.setName(mCurrentUserName);
+                            targetUser.setPortraitUri(Uri.parse(mCurrentUserAvatar));
                         }
                         String lastName = targetUser.getName();
                         if (TextUtils.isEmpty(lastName) || TextUtils.equals(lastName, DEFAULT_NICK)) {

+ 5 - 3
rong_im/live/src/main/res/layout/item_live_room_mic_user_layout.xml

@@ -14,10 +14,12 @@
         android:background="@drawable/shape_live_mic_bg_round"
         android:layout_width="0dp"
         android:layout_height="0dp"/>
-    <ImageView
+
+    <de.hdodenhof.circleimageview.CircleImageView
         android:id="@+id/iv_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:layout_width="54dp"
+        android:layout_height="54dp"
+        app:civ_border_width="1dp"
         android:src="@drawable/icon_live_room_mic_own"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"

+ 3 - 3
student/src/main/java/com/cooleshow/student/ui/live/LiveRoomActivity.java

@@ -1108,7 +1108,7 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
     public void showEmptyStatusView() {
         //显示老师不在线view
         showRestView();
-        refreshAudio(null,null);
+        refreshAudio(null, null);
     }
 
     @Override
@@ -1221,7 +1221,7 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
             if (type == LiveRoomMsgConstants.MIC_RESPONSE_AGREE) {
                 //主播同意
                 if (presenter != null) {
-                    if(isOnApplyMic()){
+                    if (isOnApplyMic()) {
                         presenter.joinMic();
                     }
                 }
@@ -1570,7 +1570,7 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
             return;
         }
         if (mLlMicContainer != null && friendInfoBean != null) {
-            mLlMicContainer.updateTargetUserInfo(new UserInfo(friendInfoBean.friendId, friendInfoBean.friendNickname, null));
+            mLlMicContainer.updateTargetUserInfo(new UserInfo(friendInfoBean.friendId, friendInfoBean.friendNickname, Uri.parse(friendInfoBean.friendAvatar)));
         }
     }
 

+ 0 - 43
student/src/main/res/layout/item_live_room_mic_user_layout.xml

@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
-    android:layout_height="wrap_content"
-    android:layout_marginStart="5dp"
-    android:layout_marginEnd="5dp">
-    <View
-        app:layout_constraintRight_toRightOf="@+id/iv_icon"
-        app:layout_constraintLeft_toLeftOf="@+id/iv_icon"
-        app:layout_constraintBottom_toBottomOf="@+id/iv_icon"
-        app:layout_constraintTop_toTopOf="@+id/iv_icon"
-        android:background="@drawable/shape_live_mic_bg_round"
-        android:layout_width="0dp"
-        android:layout_height="0dp"/>
-    <ImageView
-        android:id="@+id/iv_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:src="@drawable/icon_live_room_mic_own"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-
-    <TextView
-        android:id="@+id/tv_name"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="3dp"
-        android:background="@drawable/shape_live_room_mic_nickname_bg"
-        android:includeFontPadding="false"
-        android:paddingStart="5dp"
-        android:paddingTop="1dp"
-        android:paddingEnd="5dp"
-        android:paddingBottom="1dp"
-        android:textColor="@color/white"
-        android:textSize="@dimen/sp_10"
-        app:layout_constraintLeft_toLeftOf="@+id/iv_icon"
-        app:layout_constraintRight_toRightOf="@+id/iv_icon"
-        app:layout_constraintTop_toBottomOf="@+id/iv_icon"
-        tools:text="张嘉佳" />
-</androidx.constraintlayout.widget.ConstraintLayout>