|
@@ -1,6 +1,7 @@
|
|
|
package com.yingyangfly.home.activity
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.os.CountDownTimer
|
|
|
import android.text.TextUtils
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
@@ -8,7 +9,10 @@ import androidx.recyclerview.widget.GridLayoutManager
|
|
|
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.*
|
|
|
+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.yingyang.home.R
|
|
|
import com.yingyang.home.databinding.ActivityHomeBinding
|
|
|
import com.yingyangfly.baselib.bean.MessageBean
|
|
@@ -61,6 +65,8 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
|
|
|
//推荐游戏分页数据
|
|
|
private var pageList = mutableListOf<Record>()
|
|
|
private val gameAdapter by lazy { GameAdapter() }
|
|
|
+ private var aCountDownTimer: CountDownTimer? = null
|
|
|
+ private var aMessageList = mutableListOf<MessageBean>()
|
|
|
|
|
|
override fun initViews() {
|
|
|
voicePlayer = VoicePlayer.getInstance(mContext)
|
|
@@ -647,41 +653,34 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
|
|
|
super.onRecvNewMessage(msg)
|
|
|
runOnUiThread {
|
|
|
if (msg.isRead.not()) {
|
|
|
-// makeMessageAsRead(msg)
|
|
|
+ makeMessageAsRead(msg)
|
|
|
if (msg.elemType == V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM) {
|
|
|
val customElem = msg.customElem
|
|
|
if (customElem != null && customElem.data != null) {
|
|
|
val data = String(customElem.data)
|
|
|
val messageBean = GsonUtil.GsonToBean(data, MessageBean::class.java)
|
|
|
if (messageBean != null) {
|
|
|
- if (TextUtils.equals("A", messageBean.businessID)) {
|
|
|
- //缴费通知
|
|
|
- if (TextUtils.equals("购买成功,等待医生接诊。", messageBean.data)) {
|
|
|
- LiveEventBusUtil.send(
|
|
|
- RxBusCodes.SuccessfulPurchase,
|
|
|
- messageBean.data
|
|
|
- )
|
|
|
- binding.imageSetting.postDelayed({
|
|
|
+ messageBean.timestamp = msg.timestamp
|
|
|
+ when (messageBean.businessID) {
|
|
|
+ "A" -> {
|
|
|
+ if (TextUtils.equals("购买成功,等待医生接诊。", messageBean.data)) {
|
|
|
LiveEventBusUtil.send(
|
|
|
- RxBusCodes.SHOWTASKDIALOG,
|
|
|
- messageBean
|
|
|
+ RxBusCodes.SuccessfulPurchase,
|
|
|
+ messageBean.data
|
|
|
)
|
|
|
- }, 800)
|
|
|
- } else {
|
|
|
- LiveEventBusUtil.send(
|
|
|
- RxBusCodes.SHOWTASKDIALOG,
|
|
|
- messageBean
|
|
|
- )
|
|
|
+ binding.imageSetting.postDelayed({
|
|
|
+ LiveEventBusUtil.send(
|
|
|
+ RxBusCodes.SHOWTASKDIALOG,
|
|
|
+ messageBean
|
|
|
+ )
|
|
|
+ }, 800)
|
|
|
+ } else {
|
|
|
+ addAMessageData(messageBean)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ "B", "C", "D" -> {
|
|
|
+ addAMessageData(messageBean)
|
|
|
}
|
|
|
- } else if (TextUtils.equals("B", messageBean.businessID)) {
|
|
|
- //系统通知
|
|
|
- LiveEventBusUtil.send(RxBusCodes.SHOWTASKDIALOG, messageBean)
|
|
|
- } else if (TextUtils.equals("C", messageBean.businessID)) {
|
|
|
- //报告通知
|
|
|
- LiveEventBusUtil.send(RxBusCodes.SHOWTASKDIALOG, messageBean)
|
|
|
- } else if (TextUtils.equals("D", messageBean.businessID)) {
|
|
|
- //理疗通知
|
|
|
- LiveEventBusUtil.send(RxBusCodes.SHOWTASKDIALOG, messageBean)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -715,4 +714,73 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
|
|
|
//消息接受监听
|
|
|
V2TIMManager.getMessageManager().removeAdvancedMsgListener(simpleMsgListener)
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录消息
|
|
|
+ */
|
|
|
+ private fun addAMessageData(msg: MessageBean) {
|
|
|
+ runOnUiThread {
|
|
|
+ aMessageList.add(msg)
|
|
|
+ if (aCountDownTimer != null) {
|
|
|
+ aCountDownTimer?.cancel()
|
|
|
+ aCountDownTimer?.start()
|
|
|
+ } else {
|
|
|
+ aCountDownTimer = object : CountDownTimer(1500, 500) {
|
|
|
+ override fun onTick(millisUntilFinished: Long) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFinish() {
|
|
|
+ sortMessageDataByTimestamp(aMessageList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ aCountDownTimer?.start()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息分类
|
|
|
+ */
|
|
|
+ private fun sortMessageDataByTimestamp(conversationList: List<MessageBean>) {
|
|
|
+ val aMessages = mutableListOf<MessageBean>()
|
|
|
+ val bMessages = mutableListOf<MessageBean>()
|
|
|
+ val cMessages = mutableListOf<MessageBean>()
|
|
|
+ val dMessages = mutableListOf<MessageBean>()
|
|
|
+ conversationList.forEach {
|
|
|
+ when (it.businessID) {
|
|
|
+ "A" -> aMessages.add(it)
|
|
|
+ "B" -> bMessages.add(it)
|
|
|
+ "C" -> cMessages.add(it)
|
|
|
+ "D" -> dMessages.add(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (aMessages.isNullOrEmpty().not()) {
|
|
|
+ showMessageDialog(aMessages)
|
|
|
+ }
|
|
|
+ if (bMessages.isNullOrEmpty().not()) {
|
|
|
+ showMessageDialog(bMessages)
|
|
|
+ }
|
|
|
+ if (cMessages.isNullOrEmpty().not()) {
|
|
|
+ showMessageDialog(cMessages)
|
|
|
+ }
|
|
|
+ if (dMessages.isNullOrEmpty().not()) {
|
|
|
+ showMessageDialog(dMessages)
|
|
|
+ }
|
|
|
+ aMessageList.clear()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 展示消息弹框
|
|
|
+ */
|
|
|
+ private fun showMessageDialog(messageBeans: List<MessageBean>) {
|
|
|
+ val lengthComparator =
|
|
|
+ Comparator { o1: MessageBean, o2: MessageBean -> o2.timestamp.toInt() - o1.timestamp.toInt() }
|
|
|
+ val list = messageBeans.sortedWith(lengthComparator)
|
|
|
+ if (list.isNullOrEmpty().not()) {
|
|
|
+ LiveEventBusUtil.send(
|
|
|
+ RxBusCodes.SHOWTASKDIALOG,
|
|
|
+ list[0]
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|