|
|
@@ -7,6 +7,7 @@ import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
|
import android.text.TextUtils
|
|
|
+import android.util.Log
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import android.view.ViewTreeObserver
|
|
|
@@ -20,8 +21,13 @@ import androidx.constraintlayout.widget.ConstraintSet
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.bumptech.glide.Glide
|
|
|
+import com.tencent.imsdk.v2.V2TIMAdvancedMsgListener
|
|
|
+import com.tencent.imsdk.v2.V2TIMCallback
|
|
|
+import com.tencent.imsdk.v2.V2TIMManager
|
|
|
+import com.tencent.imsdk.v2.V2TIMMessage
|
|
|
import com.yingyangfly.baselib.bean.GameDataBean
|
|
|
import com.yingyangfly.baselib.bean.GetSaveGameRecordBean
|
|
|
+import com.yingyangfly.baselib.bean.MessageBean
|
|
|
import com.yingyangfly.baselib.db.VoicePlayerBean
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
@@ -158,6 +164,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
Glide.with(mContext).asGif().load(R.drawable.fish).into(binding.loadingImage)
|
|
|
initLiveData()
|
|
|
setScreenData()
|
|
|
+ addSimpleMsgListener()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,6 +391,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
destoryWebView()
|
|
|
+ removeAdvancedMsgListener()
|
|
|
super.onDestroy()
|
|
|
}
|
|
|
|
|
|
@@ -743,4 +751,138 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
sendLog(log)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义消息监听
|
|
|
+ */
|
|
|
+ private var simpleMsgListener: V2TIMAdvancedMsgListener = object : V2TIMAdvancedMsgListener() {
|
|
|
+ override fun onRecvNewMessage(msg: V2TIMMessage) {
|
|
|
+ super.onRecvNewMessage(msg)
|
|
|
+ runOnUiThread {
|
|
|
+ makeMessageAsRead(msg)
|
|
|
+ analyticMessage(msg)
|
|
|
+ oneLog("原始版本IM消息内容: " + GsonUtil.GsonString(msg))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息改成已读
|
|
|
+ */
|
|
|
+ private fun makeMessageAsRead(msg: V2TIMMessage) {
|
|
|
+ runOnUiThread {
|
|
|
+ V2TIMManager.getConversationManager()
|
|
|
+ .cleanConversationUnreadMessageCount(String.format("c2c_%s", msg.sender),
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ object : V2TIMCallback {
|
|
|
+ override fun onSuccess() {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(p0: Int, p1: String?) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析IM消息
|
|
|
+ */
|
|
|
+ private fun analyticMessage(msg: V2TIMMessage) {
|
|
|
+ runOnUiThread {
|
|
|
+ if (msg.elemType == V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM) {
|
|
|
+ val customElem = msg.customElem
|
|
|
+ if (customElem != null && customElem.data != null) {
|
|
|
+ val data = String(customElem.data)
|
|
|
+ val description = customElem.description
|
|
|
+ val messageBean = GsonUtil.GsonToBean(data, MessageBean::class.java)
|
|
|
+ if (messageBean != null) {
|
|
|
+ messageBean.timestamp = msg.timestamp
|
|
|
+ if (TextUtils.isEmpty(description).not()) {
|
|
|
+ messageBean.description = description
|
|
|
+ }
|
|
|
+ when (messageBean.businessID) {
|
|
|
+ "end" -> {
|
|
|
+ //结束问诊清空IM聊天历史
|
|
|
+ clearC2CHistoryMessage(msg.sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ "start", "live", "gameDetails", "endLive" -> {
|
|
|
+ Log.e("wpp", "直播消息,此处不做处理")
|
|
|
+ }
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ showTaskDialog(messageBean)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val messageInfo = GsonUtil.GsonString(messageBean)
|
|
|
+ if (TextUtils.isEmpty(messageInfo).not()) {
|
|
|
+ oneLog(messageInfo)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ oneLog("IM消息解析失败" + GsonUtil.GsonString(msg))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清空消息列表
|
|
|
+ */
|
|
|
+ private fun clearC2CHistoryMessage(userId: String) {
|
|
|
+ runOnUiThread {
|
|
|
+ V2TIMManager.getMessageManager().clearC2CHistoryMessage(userId, object : V2TIMCallback {
|
|
|
+ override fun onSuccess() {
|
|
|
+ // 清空单聊消息成功
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(code: Int, desc: String) {
|
|
|
+ // 清空单聊消息失败
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 展示IM消息弹窗
|
|
|
+ */
|
|
|
+ private fun showTaskDialog(msg: MessageBean) {
|
|
|
+ runOnUiThread {
|
|
|
+ LiveEventBusUtil.send(RxBusCodes.SHOWTASKDIALOG, msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 阿里云日志上报
|
|
|
+ */
|
|
|
+ private fun oneLog(messageInfo: String) {
|
|
|
+ runOnUiThread {
|
|
|
+ val log = com.aliyun.sls.android.producer.Log()
|
|
|
+ log.putContent(
|
|
|
+ "游戏页面IM消息内容", messageInfo
|
|
|
+ )
|
|
|
+ log.putContent("患者id", User.getUserId())
|
|
|
+ log.putContent("患者姓名", User.getName())
|
|
|
+ sendLog(log)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * IM消息监听
|
|
|
+ */
|
|
|
+ private fun addSimpleMsgListener() {
|
|
|
+ //消息接受监听
|
|
|
+ V2TIMManager.getMessageManager().addAdvancedMsgListener(simpleMsgListener)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 移除消息监听
|
|
|
+ */
|
|
|
+ private fun removeAdvancedMsgListener() {
|
|
|
+ runOnUiThread {
|
|
|
+ //消息接受监听
|
|
|
+ V2TIMManager.getMessageManager().removeAdvancedMsgListener(simpleMsgListener)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|