瀏覽代碼

优化直播人数显示

Pq 2 年之前
父節點
當前提交
1f8aa511db

+ 25 - 0
rong_im/live/src/main/java/com/rong/io/live/helper/LiveMemberHelper.java

@@ -33,4 +33,29 @@ public class LiveMemberHelper {
         }
         return name;
     }
+
+    public static String getMemberCountText(int memberCount) {
+        try {
+            if (memberCount >= 10000) {
+                return "1万+";
+            }
+            return String.valueOf(memberCount);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return String.valueOf(memberCount);
+    }
+
+    public static String getMemberCountText(String memberCount) {
+        try {
+            int count = Integer.parseInt(memberCount);
+            if (count >= 10000) {
+                return "1万+";
+            }
+            return memberCount;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return memberCount;
+    }
 }

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

@@ -891,7 +891,7 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
         updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
         if (mTvNumPeople != null) {
             int peopleCount = roomInfoBean.lookNum + 1;//加上自己
-            mTvNumPeople.setText(peopleCount + "人");
+            mTvNumPeople.setText(String.format("%s人", LiveMemberHelper.getMemberCountText(peopleCount)));
         }
 
         if (mIvAvatar != null) {
@@ -1335,7 +1335,7 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
             return;
         }
         if (mTvNumPeople != null) {
-            mTvNumPeople.setText(count + "人");
+            mTvNumPeople.setText(String.format("%s人", LiveMemberHelper.getMemberCountText(count)));
         }
     }
 

+ 2 - 2
teacher/src/main/java/com/cooleshow/teacher/ui/live/TeacherLiveRoomActivity.java

@@ -534,7 +534,7 @@ public class TeacherLiveRoomActivity extends BaseMVPActivity<ActivityTeacherLive
             mMessageAdapter.setRoomAuthorId(roomInfoBean.speakerId);
         }
         int peopleCount = roomInfoBean.lookNum;
-        mTvNumPeople.setText(peopleCount + "人");
+        mTvNumPeople.setText(String.format("%s人", LiveMemberHelper.getMemberCountText(peopleCount)));
         //同步点赞数
         currentAddLikeCount = roomInfoBean.likeNum;
         updateAddLikeCountView();
@@ -755,7 +755,7 @@ public class TeacherLiveRoomActivity extends BaseMVPActivity<ActivityTeacherLive
             return;
         }
         if (mTvNumPeople != null) {
-            mTvNumPeople.setText(count + "人");
+            mTvNumPeople.setText(String.format("%s人", LiveMemberHelper.getMemberCountText(count)));
         }
     }