公屏获取历史记录
This commit is contained in:
@@ -2,7 +2,9 @@ package com.yizhuan.erban.avroom.presenter;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -12,9 +14,16 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.netease.nimlib.sdk.NIMClient;
|
||||||
|
import com.netease.nimlib.sdk.RequestCallbackWrapper;
|
||||||
|
import com.netease.nimlib.sdk.ResponseCode;
|
||||||
|
import com.netease.nimlib.sdk.chatroom.ChatRoomService;
|
||||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomInfo;
|
import com.netease.nimlib.sdk.chatroom.model.ChatRoomInfo;
|
||||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMember;
|
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMember;
|
||||||
|
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
|
||||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData;
|
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData;
|
||||||
|
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
||||||
|
import com.netease.nimlib.sdk.msg.model.QueryDirectionEnum;
|
||||||
import com.netease.nimlib.sdk.util.Entry;
|
import com.netease.nimlib.sdk.util.Entry;
|
||||||
import com.orhanobut.logger.Logger;
|
import com.orhanobut.logger.Logger;
|
||||||
import com.yizhuan.erban.avroom.view.IAvRoomView;
|
import com.yizhuan.erban.avroom.view.IAvRoomView;
|
||||||
@@ -28,6 +37,7 @@ import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
|||||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||||
import com.yizhuan.xchat_android_core.manager.RtcEngineManager;
|
import com.yizhuan.xchat_android_core.manager.RtcEngineManager;
|
||||||
|
import com.yizhuan.xchat_android_core.manager.event.HistoryMessageEvent;
|
||||||
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterInfo;
|
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterInfo;
|
||||||
import com.yizhuan.xchat_android_core.monsterhunting.model.MonsterHuntingModel;
|
import com.yizhuan.xchat_android_core.monsterhunting.model.MonsterHuntingModel;
|
||||||
import com.yizhuan.xchat_android_core.patriarch.exception.PmRoomLimitException;
|
import com.yizhuan.xchat_android_core.patriarch.exception.PmRoomLimitException;
|
||||||
@@ -52,12 +62,14 @@ import com.yizhuan.xchat_android_core.super_admin.SuperAdminDataMrg;
|
|||||||
|
|
||||||
import com.yizhuan.xchat_android_library.base.PresenterEvent;
|
import com.yizhuan.xchat_android_library.base.PresenterEvent;
|
||||||
import com.yizhuan.xchat_android_library.net.rxnet.callback.CallBack;
|
import com.yizhuan.xchat_android_library.net.rxnet.callback.CallBack;
|
||||||
|
import com.yizhuan.xchat_android_library.rxbus.RxBus;
|
||||||
import com.yizhuan.xchat_android_library.threadmgr.ThreadPoolManager;
|
import com.yizhuan.xchat_android_library.threadmgr.ThreadPoolManager;
|
||||||
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -140,6 +152,20 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
|||||||
.subscribe(roomQueueInfoSparseArray -> {
|
.subscribe(roomQueueInfoSparseArray -> {
|
||||||
long uid = AuthModel.get().getCurrentUid();
|
long uid = AuthModel.get().getCurrentUid();
|
||||||
RtcEngineManager.get().startRtcEngine(uid);
|
RtcEngineManager.get().startRtcEngine(uid);
|
||||||
|
if (!roomInfo.isCloseScreen()) {
|
||||||
|
NIMClient.getService(ChatRoomService.class)
|
||||||
|
.pullMessageHistoryExType(String.valueOf(roomInfo.getRoomId()), 0,
|
||||||
|
10, QueryDirectionEnum.QUERY_OLD, new MsgTypeEnum[]{MsgTypeEnum.text})
|
||||||
|
.setCallback(new RequestCallbackWrapper<List<ChatRoomMessage>>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(int code, List<ChatRoomMessage> result, Throwable exception) {
|
||||||
|
if (code == ResponseCode.RES_SUCCESS && result != null && result.size() > 0) {
|
||||||
|
Collections.reverse(result);
|
||||||
|
RxBus.get().post(new HistoryMessageEvent(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//成功进入房间发送log 到阿里
|
//成功进入房间发送log 到阿里
|
||||||
StatisticManager.Instance().sendAliyunLog(LogFactory.create(
|
StatisticManager.Instance().sendAliyunLog(LogFactory.create(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
@@ -11,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.OrientationHelper;
|
import androidx.recyclerview.widget.OrientationHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||||
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
@@ -101,6 +103,7 @@ import com.yizhuan.xchat_android_core.magic.bean.MultiMagicReceivedInfo;
|
|||||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||||
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
|
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
|
||||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||||
|
import com.yizhuan.xchat_android_core.manager.event.HistoryMessageEvent;
|
||||||
import com.yizhuan.xchat_android_core.miniworld.bean.MiniWorldInWorldInfo;
|
import com.yizhuan.xchat_android_core.miniworld.bean.MiniWorldInWorldInfo;
|
||||||
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterHuntingResult;
|
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterHuntingResult;
|
||||||
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterProtocol;
|
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterProtocol;
|
||||||
@@ -201,6 +204,7 @@ public class MessageView extends FrameLayout {
|
|||||||
|
|
||||||
private DialogManager mDialogManager;
|
private DialogManager mDialogManager;
|
||||||
private Disposable subscribe;
|
private Disposable subscribe;
|
||||||
|
private Disposable historyDisposable;
|
||||||
|
|
||||||
private static final int LOAD_MESSAGE_COUNT = 10;
|
private static final int LOAD_MESSAGE_COUNT = 10;
|
||||||
|
|
||||||
@@ -240,21 +244,25 @@ public class MessageView extends FrameLayout {
|
|||||||
updateGameItemStatus(gameRespondEvent.fromAcount);
|
updateGameItemStatus(gameRespondEvent.fromAcount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
historyDisposable = RxBus.get().toFlowable(HistoryMessageEvent.class)
|
||||||
|
.subscribe(historyMessageEvent -> addHistoryMessages(historyMessageEvent.getMessages()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
subscribe.dispose();
|
subscribe.dispose();
|
||||||
|
historyDisposable.dispose();
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int imageHeight;
|
private int imageHeight;
|
||||||
private int imageWidth;
|
private int imageWidth;
|
||||||
|
|
||||||
private void init(Context context) {
|
private void init(Context context) {
|
||||||
imageHeight= Utils.dip2px(context, 15);
|
imageHeight = Utils.dip2px(context, 15);
|
||||||
imageWidth= Utils.dip2px(context, 59);
|
imageWidth = Utils.dip2px(context, 59);
|
||||||
|
|
||||||
whiteColor = ContextCompat.getColor(context, R.color.white);
|
whiteColor = ContextCompat.getColor(context, R.color.white);
|
||||||
greyColor = ContextCompat.getColor(context, R.color.white_transparent_50);
|
greyColor = ContextCompat.getColor(context, R.color.white_transparent_50);
|
||||||
@@ -272,7 +280,7 @@ public class MessageView extends FrameLayout {
|
|||||||
expLevelWidth = expLevelHeight * 22 / 17;//expLevelHeight * 114 / 45
|
expLevelWidth = expLevelHeight * 22 / 17;//expLevelHeight * 114 / 45
|
||||||
giftLength = Utils.dip2px(context, 35);
|
giftLength = Utils.dip2px(context, 35);
|
||||||
// 内容区域
|
// 内容区域
|
||||||
layoutManger = new LinearLayoutManager(context, OrientationHelper.VERTICAL, false);
|
layoutManger = new LinearLayoutManager(context, RecyclerView.VERTICAL, false);
|
||||||
FrameLayout.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
FrameLayout.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
messageListView = new RecyclerView(context);
|
messageListView = new RecyclerView(context);
|
||||||
messageListView.setLayoutParams(params);
|
messageListView.setLayoutParams(params);
|
||||||
@@ -368,6 +376,12 @@ public class MessageView extends FrameLayout {
|
|||||||
return chatRoomMessages.size() - 1;
|
return chatRoomMessages.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addHistoryMessages(List<ChatRoomMessage> messages) {
|
||||||
|
chatRoomMessages.addAll(chatRoomMessages.size() > 0 ? 1 : 0, messages);
|
||||||
|
mMessageAdapter.notifyDataSetChanged();
|
||||||
|
messageListView.scrollToPosition(mMessageAdapter.getItemCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
private void keepSizeUnderLimit() {
|
private void keepSizeUnderLimit() {
|
||||||
while (chatRoomMessages.size() > MAX_MESSAGE_SIZE) {
|
while (chatRoomMessages.size() > MAX_MESSAGE_SIZE) {
|
||||||
Log.i("keepSizeUnderLimit", "size" + chatRoomMessages.size());
|
Log.i("keepSizeUnderLimit", "size" + chatRoomMessages.size());
|
||||||
@@ -393,7 +407,6 @@ public class MessageView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改关注状态
|
* 修改关注状态
|
||||||
*
|
*
|
||||||
@@ -1349,7 +1362,7 @@ public class MessageView extends FrameLayout {
|
|||||||
SpannableBuilder text = new SpannableBuilder(tvContent)
|
SpannableBuilder text = new SpannableBuilder(tvContent)
|
||||||
.append("厉害了 ", new ForegroundColorSpan(greyColor))
|
.append("厉害了 ", new ForegroundColorSpan(greyColor))
|
||||||
.append(attachment.getNick() + " ", new ForegroundColorSpan(roomTipColor))
|
.append(attachment.getNick() + " ", new ForegroundColorSpan(roomTipColor))
|
||||||
.append(attachment.getBoxTypeStr()+" ", new ForegroundColorSpan(greyColor))
|
.append(attachment.getBoxTypeStr() + " ", new ForegroundColorSpan(greyColor))
|
||||||
.append(attachment.getPrizeName(), new ForegroundColorSpan(Color.WHITE));
|
.append(attachment.getPrizeName(), new ForegroundColorSpan(Color.WHITE));
|
||||||
if (attachment.getPrizeNum() > 1) {
|
if (attachment.getPrizeNum() > 1) {
|
||||||
text.append(" x" + attachment.getPrizeNum() + " ", new ForegroundColorSpan(roomTipColor));
|
text.append(" x" + attachment.getPrizeNum() + " ", new ForegroundColorSpan(roomTipColor));
|
||||||
@@ -1519,8 +1532,8 @@ public class MessageView extends FrameLayout {
|
|||||||
|
|
||||||
SpannableBuilder text = new SpannableBuilder(tvContent);
|
SpannableBuilder text = new SpannableBuilder(tvContent);
|
||||||
text.append(isOfficial ? ResourcesCompat.getDrawable(getResources(),
|
text.append(isOfficial ? ResourcesCompat.getDrawable(getResources(),
|
||||||
R.mipmap.ic_user_official_13dp, null) : null,
|
R.mipmap.ic_user_official_13dp, null) : null,
|
||||||
badgeWidth, badgeHeight)
|
badgeWidth, badgeHeight)
|
||||||
.append(newUser ? Constants.NEW_USER_ICON : "", badgeWidth, badgeHeight)
|
.append(newUser ? Constants.NEW_USER_ICON : "", badgeWidth, badgeHeight)
|
||||||
.append(NobleUtil.getLocalResourcePath(userBadge), badgeWidth, badgeHeight);
|
.append(NobleUtil.getLocalResourcePath(userBadge), badgeWidth, badgeHeight);
|
||||||
|
|
||||||
@@ -2185,7 +2198,7 @@ public class MessageView extends FrameLayout {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (welcomeInfo.isShowAttentedBtn()){
|
} else if (welcomeInfo.isShowAttentedBtn()) {
|
||||||
text.append(" ").append(
|
text.append(" ").append(
|
||||||
ResourcesCompat.getDrawable(getResources(),
|
ResourcesCompat.getDrawable(getResources(),
|
||||||
R.drawable.icon_room_attent_gray, null),
|
R.drawable.icon_room_attent_gray, null),
|
||||||
@@ -2203,9 +2216,9 @@ public class MessageView extends FrameLayout {
|
|||||||
* 进入公聊大厅页面,加载历史记录
|
* 进入公聊大厅页面,加载历史记录
|
||||||
*/
|
*/
|
||||||
public void fetchHistory() {
|
public void fetchHistory() {
|
||||||
IMMessage anchor = MessageBuilder.createEmptyMessage(AvRoomDataManager.get().getRoomId()+"", SessionTypeEnum.P2P, System.currentTimeMillis());
|
IMMessage anchor = MessageBuilder.createEmptyMessage(AvRoomDataManager.get().getRoomId() + "", SessionTypeEnum.P2P, System.currentTimeMillis());
|
||||||
InvocationFuture<List<IMMessage>> listInvocationFuture = IMMessageManager.get().pullMessageHistory(anchor, 50, false);
|
InvocationFuture<List<IMMessage>> listInvocationFuture = IMMessageManager.get().pullMessageHistory(anchor, 50, false);
|
||||||
Log.e(TAG, "fetchHistory: "+listInvocationFuture );
|
Log.e(TAG, "fetchHistory: " + listInvocationFuture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package com.yizhuan.xchat_android_core.manager;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.netease.nimlib.sdk.NIMChatRoomSDK;
|
import com.netease.nimlib.sdk.NIMChatRoomSDK;
|
||||||
import com.netease.nimlib.sdk.RequestCallback;
|
import com.netease.nimlib.sdk.RequestCallback;
|
||||||
import com.netease.nimlib.sdk.chatroom.constant.MemberType;
|
import com.netease.nimlib.sdk.chatroom.constant.MemberType;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.yizhuan.xchat_android_core.manager.event;
|
||||||
|
|
||||||
|
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HistoryMessageEvent {
|
||||||
|
|
||||||
|
private List<ChatRoomMessage> messages;
|
||||||
|
|
||||||
|
public HistoryMessageEvent(List<ChatRoomMessage> messages) {
|
||||||
|
this.messages = messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ChatRoomMessage> getMessages() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessages(List<ChatRoomMessage> messages) {
|
||||||
|
this.messages = messages;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user