feat:新增聚会房、狂欢房;
This commit is contained in:
@@ -39,7 +39,7 @@ class RoomTypeSwitchActivity : BaseViewBindingActivity<RoomTypeSwitchActivityBin
|
||||
binding.tvSubmit.singleClick {
|
||||
selectType?.let {
|
||||
if (currentType != it) {
|
||||
switchRoomType(it)
|
||||
trySwitchRoomType(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,23 @@ class RoomTypeSwitchActivity : BaseViewBindingActivity<RoomTypeSwitchActivityBin
|
||||
}
|
||||
}
|
||||
|
||||
private fun trySwitchRoomType(type: Int) {
|
||||
val currentType = this.currentType
|
||||
if (currentType != null && currentType > type) {
|
||||
dialogManager.showOkCancelDialog(
|
||||
ResUtil.getString(R.string.switch_room_type_tips),
|
||||
ResUtil.getString(R.string.login_fragment_adduserinfofragment_04)
|
||||
) {
|
||||
requestSwitchRoomType(type)
|
||||
}
|
||||
} else {
|
||||
requestSwitchRoomType(type)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private fun switchRoomType(type: Int) {
|
||||
private fun requestSwitchRoomType(type: Int) {
|
||||
dialogManager.showProgressDialog(context)
|
||||
OpenRoomHelper.updateRoomInfoRx(
|
||||
AvRoomDataManager.get().mCurrentRoomInfo,
|
||||
type,
|
||||
|
@@ -277,7 +277,7 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
|
||||
protected void setDefalutText(int index) {
|
||||
tvNick.setTextColor(Color.WHITE);
|
||||
tvNick.setText("NO."+ (index + 1));
|
||||
tvNick.setText("NO."+ (index + 2));
|
||||
}
|
||||
|
||||
protected void setSelectText(int index, String nick, int gender) {
|
||||
@@ -481,10 +481,10 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
//控制最高最低头饰
|
||||
Observer<Integer> headWearObserver = headWearValue -> {
|
||||
if (ivCharmLevelTag == null) return;
|
||||
ivCharmLevelTag.setVisibility(View.GONE);
|
||||
if (headWearValue == 1) {
|
||||
ivCharmLevelTag.setVisibility(View.VISIBLE);
|
||||
ivCharmLevelTag.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_charm_level_min));
|
||||
ivCharmLevelTag.setVisibility(View.GONE);
|
||||
// ivCharmLevelTag.setVisibility(View.VISIBLE);
|
||||
// ivCharmLevelTag.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_charm_level_min));
|
||||
} else if (headWearValue == 2) {
|
||||
ivCharmLevelTag.setVisibility(View.VISIBLE);
|
||||
ivCharmLevelTag.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_charm_level_max));
|
||||
|
@@ -95,7 +95,10 @@ public class PKSelectPeopleDialog extends BaseDialog implements View.OnClickList
|
||||
keys[i] = micQueue.keyAt(i);
|
||||
}
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
for (int i = 0; i < micEntityList.size(); i++) {
|
||||
if (i >= micQueue.size()) {
|
||||
continue;
|
||||
}
|
||||
RoomQueueInfo roomQueueInfo = micQueue.get(keys[i]);
|
||||
MicMemberInfo chatRoomMember = roomQueueInfo.mChatRoomMember;
|
||||
if (chatRoomMember != null) {
|
||||
|
@@ -25,6 +25,7 @@ import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.room.anotherroompk.SingleRoomPKModel
|
||||
import com.chwl.core.room.bean.RoomIcon
|
||||
import com.chwl.core.room.bean.RoomInfo
|
||||
import com.chwl.core.room.core.RoomDataService
|
||||
import com.chwl.core.room.game.bean.BaiShunGameConfig
|
||||
import com.chwl.core.room.model.AvRoomModel
|
||||
@@ -261,10 +262,7 @@ class RoomGameplayDialog :
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isSingleRoom) {
|
||||
if (AvRoomDataManager.get().roomType != RoomInfo.ROOMTYPE_HOME_PARTY) {
|
||||
return null
|
||||
}
|
||||
val roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
@@ -299,10 +297,7 @@ class RoomGameplayDialog :
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame) {
|
||||
return null
|
||||
}
|
||||
if (AvRoomDataManager.get().isSingleRoom) {
|
||||
if (AvRoomDataManager.get().roomType != RoomInfo.ROOMTYPE_HOME_PARTY) {
|
||||
return null
|
||||
}
|
||||
val roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
|
||||
|
@@ -288,10 +288,7 @@ public class RoomOperationDialog extends BottomSheetDialog {
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isOpenGame()) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isSingleRoom()) {
|
||||
if (AvRoomDataManager.get().getRoomType() != RoomInfo.ROOMTYPE_HOME_PARTY) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isManager() && !AvRoomDataManager.get().isCpRoom()) {
|
||||
@@ -567,6 +564,18 @@ public class RoomOperationDialog extends BottomSheetDialog {
|
||||
if (SuperAdminUtil.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().getRoomType() != RoomInfo.ROOMTYPE_HOME_PARTY
|
||||
&& AvRoomDataManager.get().getRoomType() != RoomInfo.ROOMTYPE_PARTY
|
||||
&& AvRoomDataManager.get().getRoomType() != RoomInfo.ROOMTYPE_REVELRY) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isDatingMode()) {
|
||||
return;
|
||||
}
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null || roomInfo.getIsPermitRoom() == 1) {
|
||||
return;
|
||||
}
|
||||
if (AvRoomDataManager.get().isManager()) {
|
||||
optAdapter.addData(new OptAction(R.drawable.icon_room_type_switch,
|
||||
getContext().getResources().getString(R.string.room_type), () -> RoomTypeSwitchActivity.Companion.start(getContext())));
|
||||
|
@@ -370,7 +370,7 @@ public class HomePartyFragment extends BaseFragment implements View.OnClickListe
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!(tempFragment instanceof HomePartyRoomFragment)) {
|
||||
if (tempFragment == null || !(tempFragment.getClass().getSimpleName().equals(HomePartyRoomFragment.class.getSimpleName()))) {
|
||||
tempFragment = HomePartyRoomFragment.newInstance();
|
||||
}
|
||||
break;
|
||||
|
@@ -9,6 +9,7 @@ import android.util.SparseArray;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chwl.core.manager.RoomMicQueueModel;
|
||||
import com.chwl.core.support.room.AudioRoomContext;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -121,11 +122,11 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
AvRoomDataManager.get().updateServiceRoomInfo(roomInfo);
|
||||
mAvRoomModel.enterRoom(roomInfo.getRoomId(), 3, fromType, fromNick, fromUid)
|
||||
.flatMap(this::dealServerMicInfo)
|
||||
.map(this::dealMicMemberFromIMNet)
|
||||
.flatMap(this::dealMicChatRoomMemberFromIMNet)
|
||||
.flatMap((Function<SparseArray<RoomQueueInfo>, ObservableSource<SparseArray<RoomQueueInfo>>>) roomQueue -> RoomMicQueueModel.INSTANCE.queueMicQueue(roomInfo.getRoomId(),roomQueue))
|
||||
.compose(bindUntilEvent(PresenterEvent.DESTROY))
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(roomQueueInfoSparseArray -> {
|
||||
AvRoomDataManager.get().replaceMicQueue(roomQueueInfoSparseArray);
|
||||
long uid = AuthModel.get().getCurrentUid();
|
||||
AudioEngineManager.get().startRtcEngine(uid, roomInfo.getAudioSdkType());
|
||||
// TODO 临时方案:后续逐步完善整个房间的RoomContext替换计划
|
||||
@@ -220,52 +221,12 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
IMNetEaseManager.get().getChatRoomEventObservable().onNext(new RoomEvent().setEvent(RoomEvent.ROOM_EXIT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理网易云信队列上人员的信息
|
||||
*/
|
||||
private Observable<SparseArray<RoomQueueInfo>> dealMicChatRoomMemberFromIMNet(List<String> accounts) {
|
||||
if (ListUtils.isListEmpty(accounts))
|
||||
return Observable.just(AvRoomDataManager.get().mMicQueueMemberMap);
|
||||
return IMNetEaseManager.get().fetchRoomMembersByIds(accounts).observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(chatRoomMembers -> {
|
||||
for (ChatRoomMember chatRoomMember : chatRoomMembers) {
|
||||
AvRoomDataManager.get().updateQueueChatRoomMemberExtension(chatRoomMember);
|
||||
}
|
||||
return Single.just(AvRoomDataManager.get().mMicQueueMemberMap);
|
||||
}).toObservable();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理网易云信坑位信息
|
||||
*/
|
||||
private List<String> dealMicMemberFromIMNet(List<Entry<String, String>> entries) {
|
||||
List<String> accounts = new ArrayList<>();
|
||||
if (!ListUtils.isListEmpty(entries)) {
|
||||
JsonParser jsonParser = new JsonParser();
|
||||
MicMemberInfo chatRoomMember;
|
||||
for (Entry<String, String> entry : entries) {
|
||||
RoomQueueInfo roomQueueInfo = AvRoomDataManager.get().mMicQueueMemberMap.get(Integer.parseInt(entry.key));
|
||||
if (roomQueueInfo != null) {
|
||||
JsonObject valueJsonObj = jsonParser.parse(entry.value).getAsJsonObject();
|
||||
if (valueJsonObj != null) {
|
||||
chatRoomMember = mGson.fromJson(valueJsonObj, MicMemberInfo.class);
|
||||
accounts.add(chatRoomMember.getAccount());
|
||||
roomQueueInfo.mChatRoomMember = chatRoomMember;
|
||||
}
|
||||
AvRoomDataManager.get().mMicQueueMemberMap.put(Integer.valueOf(entry.key), roomQueueInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return accounts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理服务端坑位信息
|
||||
*/
|
||||
@Nullable
|
||||
private ObservableSource<List<Entry<String, String>>> dealServerMicInfo(EnterChatRoomResultData enterChatRoomResultData) {
|
||||
private ObservableSource<SparseArray<RoomQueueInfo>> dealServerMicInfo(EnterChatRoomResultData enterChatRoomResultData) {
|
||||
AvRoomDataManager.get().mEnterChatRoomResultData = enterChatRoomResultData;
|
||||
if (enterChatRoomResultData == null)
|
||||
return Observable.error(new Throwable(GET_ROOM_FROM_IMNET_ERROR));
|
||||
@@ -295,11 +256,12 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
//初始化所有坑位
|
||||
Map<String, String> micMapStr = mGson.fromJson(roomMicStr, new TypeToken<Map<String, String>>() {
|
||||
}.getType());
|
||||
SparseArray<RoomQueueInfo> queue = new SparseArray<>();
|
||||
for (Map.Entry<String, String> entry : micMapStr.entrySet()) {
|
||||
AvRoomDataManager.get().mMicQueueMemberMap.put(Integer.valueOf(entry.getKey()),
|
||||
queue.put(Integer.valueOf(entry.getKey()),
|
||||
new RoomQueueInfo(mGson.fromJson(entry.getValue(), RoomMicInfo.class), null));
|
||||
}
|
||||
return mAvRoomModel.queryRoomMicInfo(roomInfo.getRoomId());
|
||||
return Observable.just(queue);
|
||||
}
|
||||
}
|
||||
return Observable.error(new Throwable(GET_ROOM_FROM_IMNET_ERROR));
|
||||
|
@@ -57,7 +57,7 @@ public class BottomView extends LinearLayout implements View.OnClickListener {
|
||||
/**
|
||||
* 有新功能,加1
|
||||
*/
|
||||
private static final int NEW_OPTION = 1;
|
||||
private static final int NEW_OPTION = 2;
|
||||
private static final String SH_NEW_OPTION = "sh_new_option";
|
||||
|
||||
private BottomViewListenerWrapper wrapper;
|
||||
@@ -157,7 +157,7 @@ public class BottomView extends LinearLayout implements View.OnClickListener {
|
||||
if (newOption == NEW_OPTION) {
|
||||
sendMagic.setImageResource(R.drawable.room_menu_ic_more);
|
||||
} else {
|
||||
sendMagic.setImageResource(R.drawable.room_menu_ic_more);
|
||||
sendMagic.setImageResource(R.drawable.room_menu_ic_more_new);
|
||||
}
|
||||
sendMagic.setClickable(true);
|
||||
sendMagic.setOnClickListener(this);
|
||||
|
BIN
app/src/main/res/drawable-xxhdpi/room_ic_notice.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/room_ic_notice.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/drawable-xxhdpi/room_menu_ic_more_new.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/room_menu_ic_more_new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
@@ -5305,5 +5305,6 @@
|
||||
<string name="photo_album_empty_tips">لا توجد صور بعد</string>
|
||||
<string name="gift_empty_tips">لا توجد هدايا بعد</string>
|
||||
<string name="medal">ميدالية</string>
|
||||
<string name="room_type">房間類型</string>
|
||||
<string name="room_type">نوع الغرفة</string>
|
||||
<string name="switch_room_type_tips">بعد الإعداد، ستتم إزالة الأعضاء الذين يتجاوزون خارج الترتيب علي المايك ؛ هل تريد تأكيد الإعداد ؟</string>
|
||||
</resources>
|
@@ -5247,4 +5247,5 @@
|
||||
<string name="gift_empty_tips">塹無禮物</string>
|
||||
<string name="medal">勳章</string>
|
||||
<string name="room_type">房間類型</string>
|
||||
<string name="switch_room_type_tips">設置後將移除超出麥序的成員,確認設置?</string>
|
||||
</resources>
|
@@ -5286,7 +5286,8 @@ You cannot join again within 24 hours after leaving</string>
|
||||
<string name="photo_album_empty_tips">No photos yet</string>
|
||||
<string name="gift_empty_tips">No gifts yet</string>
|
||||
<string name="medal">Medal</string>
|
||||
<string name="room_type">房間類型</string>
|
||||
<string name="room_type">Room type</string>
|
||||
<string name="switch_room_type_tips">After the setting is completed, members who are out of the microphone order will be removed. Do you confirm the setting?</string>
|
||||
</resources>
|
||||
|
||||
|
||||
|
@@ -430,13 +430,13 @@ public final class AvRoomDataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateQueueChatRoomMemberExtension(ChatRoomMember chatRoomMember) {
|
||||
int size = mMicQueueMemberMap.size();
|
||||
public void updateQueueChatRoomMemberExtension(SparseArray<RoomQueueInfo> queue, ChatRoomMember chatRoomMember) {
|
||||
int size = queue.size();
|
||||
if (chatRoomMember == null || chatRoomMember.getExtension() == null ||
|
||||
TextUtils.isEmpty(chatRoomMember.getAccount())) return;
|
||||
for (int i = 0; i < size; i++) {
|
||||
int key = mMicQueueMemberMap.keyAt(i);
|
||||
RoomQueueInfo roomQueueInfo = mMicQueueMemberMap.get(key);
|
||||
int key = queue.keyAt(i);
|
||||
RoomQueueInfo roomQueueInfo = queue.get(key);
|
||||
if (roomQueueInfo == null || roomQueueInfo.mChatRoomMember == null) continue;
|
||||
if (!chatRoomMember.getAccount().equals(roomQueueInfo.mChatRoomMember.getAccount()))
|
||||
continue;
|
||||
@@ -594,6 +594,13 @@ public final class AvRoomDataManager {
|
||||
return mCurrentRoomInfo != null && mCurrentRoomInfo.getType() == RoomInfo.ROOM_TYPE_SINGLE;
|
||||
}
|
||||
|
||||
public int getRoomType() {
|
||||
if (mCurrentRoomInfo == null) {
|
||||
return -1;
|
||||
}
|
||||
return mCurrentRoomInfo.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是房间管理员
|
||||
*
|
||||
@@ -844,6 +851,16 @@ public final class AvRoomDataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceMicQueue(SparseArray<RoomQueueInfo> queue) {
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
mMicQueueMemberMap.clear();
|
||||
for (int i = 0; i < queue.size(); i++) {
|
||||
mMicQueueMemberMap.put(queue.keyAt(i), queue.valueAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是房主或管理员
|
||||
*
|
||||
|
@@ -126,7 +126,6 @@ import com.chwl.core.miniworld.bean.MiniWorldDetailInfo;
|
||||
import com.chwl.core.miniworld.bean.MiniWorldDetailInfoWithCurrentMember;
|
||||
import com.chwl.core.miniworld.event.MiniWorldJoinVerifiedEvent;
|
||||
import com.chwl.core.monsterhunting.bean.MonsterInfo;
|
||||
import com.chwl.core.monsterhunting.bean.MonsterProtocol;
|
||||
import com.chwl.core.msg.sys.bean.ErbanSysMsgInfo;
|
||||
import com.chwl.core.msg.sys.ErbanSysMsgParamKey;
|
||||
import com.chwl.core.msg.sysv2.bean.ErbanSysMsgV2Info;
|
||||
@@ -1840,15 +1839,39 @@ public final class IMNetEaseManager {
|
||||
private void roomInfoUpdate(Map<String, Object> extension) {
|
||||
String roomInfoStr = (String) extension.get("roomInfo");
|
||||
if (!TextUtils.isEmpty(roomInfoStr)) {
|
||||
LogUtils.d(roomInfoStr);
|
||||
com.example.lib_utils.log.LogUtil.d(TAG, "roomInfoUpdate roomInfoStr:" + roomInfoStr, false);
|
||||
RoomInfo roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class);
|
||||
if (roomInfo != null) {
|
||||
boolean isTypeChanged = false;
|
||||
if (AvRoomDataManager.get().mCurrentRoomInfo != null && AvRoomDataManager.get().mCurrentRoomInfo.getType() != roomInfo.getType()) {
|
||||
isTypeChanged = true;
|
||||
}
|
||||
AvRoomDataManager.get().mCurrentRoomInfo = roomInfo;
|
||||
noticeRoomInfoUpdate(roomInfo);
|
||||
com.example.lib_utils.log.LogUtil.d(TAG, "roomInfoUpdate isTypeChanged:" + isTypeChanged, false);
|
||||
if (isTypeChanged) {
|
||||
onRoomTypeChanged(roomInfo);
|
||||
}else{
|
||||
AvRoomDataManager.get().mCurrentRoomInfo = roomInfo;
|
||||
noticeRoomInfoUpdate(roomInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void onRoomTypeChanged(RoomInfo roomInfo) {
|
||||
RoomMicQueueModel.INSTANCE.queueMicQueue(roomInfo.getRoomId()).subscribe(new Consumer<SparseArray<RoomQueueInfo>>() {
|
||||
@Override
|
||||
public void accept(SparseArray<RoomQueueInfo> roomQueue) throws Exception {
|
||||
com.example.lib_utils.log.LogUtil.d(TAG, "onRoomTypeChanged accept", false);
|
||||
AvRoomDataManager.get().replaceMicQueue(roomQueue);
|
||||
GiftValueMrg.get().updateRoomGiftValue(false);
|
||||
noticeRoomInfoUpdate(roomInfo);
|
||||
tryAutoUpMic();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void chatRoomQueueChangeNotice(ChatRoomMessage msg) {
|
||||
ChatRoomQueueChangeAttachment roomQueueChangeAttachment = (ChatRoomQueueChangeAttachment) msg.getAttachment();
|
||||
//麥上成員信息(uid...) key:坑位 ,content:{"nick":"行走的老者","uid":90972,"gender":1,"avatar":"https://image.zhongjialx.com/Fmtbprx5cGc3KABKjDxs_udJZb3O?imageslim"}
|
||||
@@ -1903,7 +1926,13 @@ public final class IMNetEaseManager {
|
||||
if (curRoomInfo == null) return;
|
||||
noticeEnterMessages();
|
||||
//個播模式房主進房自動上麥
|
||||
if (AvRoomDataManager.get().isSingleRoom() && AvRoomDataManager.get().isRoomOwner()) {
|
||||
tryAutoUpMic();
|
||||
}
|
||||
|
||||
private void tryAutoUpMic() {
|
||||
RoomInfo curRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (curRoomInfo == null) return;
|
||||
if (AvRoomDataManager.get().isSingleRoom() && AvRoomDataManager.get().isRoomOwner() && !AvRoomDataManager.get().isOwnerOnMic()) {
|
||||
AvRoomModel.get().upMicroPhone(
|
||||
-1,
|
||||
String.valueOf(AuthModel.get().getCurrentUid()),
|
||||
@@ -1922,7 +1951,6 @@ public final class IMNetEaseManager {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ChatRoomMessage getFirstMessageContent() {
|
||||
|
130
core/src/main/java/com/chwl/core/manager/RoomMicQueueModel.kt
Normal file
130
core/src/main/java/com/chwl/core/manager/RoomMicQueueModel.kt
Normal file
@@ -0,0 +1,130 @@
|
||||
package com.chwl.core.manager
|
||||
|
||||
import android.util.Log
|
||||
import android.util.SparseArray
|
||||
import com.chwl.core.Constants
|
||||
import com.chwl.core.bean.RoomMicInfo
|
||||
import com.chwl.core.bean.RoomQueueInfo
|
||||
import com.chwl.core.room.model.AvRoomModel
|
||||
import com.chwl.core.room.queue.bean.MicMemberInfo
|
||||
import com.chwl.library.utils.ListUtils
|
||||
import com.chwl.library.utils.json.JsonUtils
|
||||
import com.example.lib_utils.log.ILog
|
||||
import com.google.gson.JsonParser
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomInfo
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMember
|
||||
import com.netease.nimlib.sdk.util.Entry
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
||||
object RoomMicQueueModel : ILog {
|
||||
|
||||
fun queueMicQueue(roomId: Long): Observable<SparseArray<RoomQueueInfo>> {
|
||||
return AvRoomModel.get().queryRoomInfo(roomId).map {
|
||||
parseMicQueue(it)
|
||||
}.flatMap {
|
||||
queueMicQueue(roomId, it)
|
||||
}
|
||||
}
|
||||
|
||||
fun queueMicQueue(
|
||||
roomId: Long,
|
||||
queue: SparseArray<RoomQueueInfo>
|
||||
): Observable<SparseArray<RoomQueueInfo>> {
|
||||
return AvRoomModel.get().queryRoomMicInfo(roomId.toString()).map {
|
||||
dealMicMemberFromIMNet(queue, it)
|
||||
}.flatMap {
|
||||
dealMicChatRoomMemberFromIMNet(queue, it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseMicQueue(
|
||||
chatRoomInfo: ChatRoomInfo
|
||||
): SparseArray<RoomQueueInfo> {
|
||||
val extension: Map<String, Any> = chatRoomInfo.extension
|
||||
val micQueueStr =
|
||||
extension[Constants.KEY_CHAT_ROOM_INFO_MIC] as? String
|
||||
return parseMicQueue(micQueueStr)
|
||||
}
|
||||
|
||||
private fun parseMicQueue(
|
||||
micQueueStr: String?
|
||||
): SparseArray<RoomQueueInfo> {
|
||||
val micQueue = SparseArray<RoomQueueInfo>()
|
||||
if (micQueueStr.isNullOrEmpty()) {
|
||||
return micQueue
|
||||
}
|
||||
val micQueueMap = JsonUtils.getGson().fromJson<Map<String, String?>>(
|
||||
micQueueStr, object : TypeToken<Map<String, String?>>() {}.type
|
||||
)
|
||||
logD("parseMicQueue micQueueStr:$micQueueStr")
|
||||
micQueueMap.forEach {
|
||||
val micPosition = it.key.toIntOrNull()
|
||||
val micInfo =
|
||||
JsonUtils.getGson().fromJson<RoomMicInfo>(it.value, RoomMicInfo::class.java)
|
||||
if (micPosition != null && micInfo != null) {
|
||||
micQueue.put(
|
||||
micPosition,
|
||||
RoomQueueInfo(
|
||||
micInfo,
|
||||
null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
return micQueue
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理网易云信坑位信息
|
||||
*/
|
||||
private fun dealMicMemberFromIMNet(
|
||||
micQueue: SparseArray<RoomQueueInfo>,
|
||||
entries: List<Entry<String, String>>
|
||||
): List<String> {
|
||||
logD("dealMicMemberFromIMNet entries:${entries.size}")
|
||||
val accounts: MutableList<String> = ArrayList()
|
||||
if (!ListUtils.isListEmpty(entries)) {
|
||||
val jsonParser = JsonParser()
|
||||
var chatRoomMember: MicMemberInfo
|
||||
for (entry in entries) {
|
||||
val roomQueueInfo = micQueue[entry.key.toInt()]
|
||||
if (roomQueueInfo != null) {
|
||||
val valueJsonObj = jsonParser.parse(entry.value).asJsonObject
|
||||
if (valueJsonObj != null) {
|
||||
chatRoomMember =
|
||||
JsonUtils.getGson()
|
||||
.fromJson<MicMemberInfo>(valueJsonObj, MicMemberInfo::class.java)
|
||||
accounts.add(chatRoomMember.account)
|
||||
roomQueueInfo.mChatRoomMember = chatRoomMember
|
||||
}
|
||||
micQueue.put(
|
||||
Integer.valueOf(entry.key),
|
||||
roomQueueInfo
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return accounts
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理网易云信队列上人员的信息
|
||||
*/
|
||||
private fun dealMicChatRoomMemberFromIMNet(
|
||||
micQueue: SparseArray<RoomQueueInfo>,
|
||||
accounts: List<String>
|
||||
): Observable<SparseArray<RoomQueueInfo>> {
|
||||
return if (ListUtils.isListEmpty(accounts)) Observable.just(micQueue) else IMNetEaseManager.get()
|
||||
.fetchRoomMembersByIds(accounts).observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap { chatRoomMembers: List<ChatRoomMember?> ->
|
||||
for (chatRoomMember in chatRoomMembers) {
|
||||
AvRoomDataManager.get()
|
||||
.updateQueueChatRoomMemberExtension(micQueue, chatRoomMember)
|
||||
}
|
||||
Single.just(micQueue)
|
||||
}.toObservable()
|
||||
}
|
||||
}
|
@@ -436,7 +436,7 @@ public class RoomBaseModel extends BaseModel implements IRoomBaseModel {
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(chatRoomMembers -> {
|
||||
for (ChatRoomMember chatRoomMember : chatRoomMembers) {
|
||||
AvRoomDataManager.get().updateQueueChatRoomMemberExtension(chatRoomMember);
|
||||
AvRoomDataManager.get().updateQueueChatRoomMemberExtension(AvRoomDataManager.get().mMicQueueMemberMap, chatRoomMember);
|
||||
}
|
||||
//accounts不为空则表示出现了本地队列信息和云信队列信息不一致的情况,更新队列信息后更新下相应的坑位信息
|
||||
|
||||
@@ -710,6 +710,16 @@ public class RoomBaseModel extends BaseModel implements IRoomBaseModel {
|
||||
*/
|
||||
@Override
|
||||
public Observable<ChatRoomInfo> startGetOnlineMemberNumberJob(final long roomId) {
|
||||
return queryRoomInfo(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天室信息
|
||||
*
|
||||
* @param roomId 聊天室id
|
||||
* @return ChatRoomInfo 房间信息
|
||||
*/
|
||||
public Observable<ChatRoomInfo> queryRoomInfo(final long roomId) {
|
||||
return Observable.create(new ObservableOnSubscribe<ChatRoomInfo>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<ChatRoomInfo> e) throws Exception {
|
||||
|
@@ -69,6 +69,14 @@ public class MicMemberInfo {
|
||||
|
||||
}
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
return nick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@@ -45,6 +45,7 @@ object LogUtil {
|
||||
e(tag, message + "\t\t" + cause, filePrinter)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun d(tag: String, message: String, filePrinter: Boolean = false) {
|
||||
log(Log.DEBUG, tag, message, filePrinter)
|
||||
}
|
||||
|
Reference in New Issue
Block a user