|
|
@@ -1,7 +1,9 @@
|
|
|
package com.yingyangfly.home.activity
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
-import android.os.CountDownTimer
|
|
|
+import android.app.Activity
|
|
|
+import android.app.ActivityManager
|
|
|
+import android.content.Context
|
|
|
import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
import android.view.MotionEvent
|
|
|
@@ -69,8 +71,6 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
|
|
|
//推荐游戏分页数据
|
|
|
private var pageList = mutableListOf<Record>()
|
|
|
private val gameAdapter by lazy { GameAdapter() }
|
|
|
- private var aCountDownTimer: CountDownTimer? = null
|
|
|
- private var aMessageList = mutableMapOf<Long, MessageBean>()
|
|
|
|
|
|
override fun initViews() {
|
|
|
voicePlayer = VoicePlayer.getInstance(mContext)
|
|
|
@@ -160,6 +160,11 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
|
|
|
}
|
|
|
LiveEventBusUtil.send(RxBusCodes.FINISHGAME, "")
|
|
|
reportLog("跳转home页")
|
|
|
+ if (TextUtils.isEmpty(User.getMessageBean()).not()) {
|
|
|
+ val messageBean =
|
|
|
+ GsonUtil.GsonToBean(User.getMessageBean(), MessageBean::class.java)
|
|
|
+ showTaskDialog(messageBean)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -682,70 +687,12 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 移除消息监听
|
|
|
- */
|
|
|
- private fun removeAdvancedMsgListener() {
|
|
|
- runOnUiThread {
|
|
|
- //消息接受监听
|
|
|
- V2TIMManager.getMessageManager().removeAdvancedMsgListener(simpleMsgListener)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 记录消息
|
|
|
*/
|
|
|
- private fun addAMessageData(msg: MessageBean) {
|
|
|
+ private fun addAMessageData(bean: MessageBean) {
|
|
|
runOnUiThread {
|
|
|
- if (aMessageList.isNotEmpty() && aMessageList.containsKey(msg.timestamp).not()) {
|
|
|
- aMessageList[msg.timestamp] = msg
|
|
|
- } else {
|
|
|
- aMessageList[msg.timestamp] = msg
|
|
|
- }
|
|
|
- if (aCountDownTimer != null) {
|
|
|
- aCountDownTimer?.cancel()
|
|
|
- aCountDownTimer?.start()
|
|
|
- } else {
|
|
|
- aCountDownTimer = object : CountDownTimer(1500, 500) {
|
|
|
- override fun onTick(millisUntilFinished: Long) {
|
|
|
- }
|
|
|
-
|
|
|
- override fun onFinish() {
|
|
|
- sortMessageDataByTimestamp(ArrayList(aMessageList.values))
|
|
|
- }
|
|
|
- }
|
|
|
- aCountDownTimer?.start()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 消息分类
|
|
|
- */
|
|
|
- private fun sortMessageDataByTimestamp(conversationList: List<MessageBean>) {
|
|
|
- runOnUiThread {
|
|
|
- if (conversationList.isNullOrEmpty().not()) {
|
|
|
- if (conversationList.isNotEmpty()) {
|
|
|
- binding.headLayout.postDelayed({
|
|
|
- showMessageDialog(conversationList)
|
|
|
- }, 3000)
|
|
|
- }
|
|
|
- }
|
|
|
- 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]
|
|
|
- )
|
|
|
+ User.saveMessageBean(GsonUtil.GsonString(bean))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -831,7 +778,11 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
|
|
|
}
|
|
|
|
|
|
"C" -> {
|
|
|
- addAMessageData(messageBean)
|
|
|
+ if (isTopActivity(this)) {
|
|
|
+ showTaskDialog(messageBean)
|
|
|
+ } else {
|
|
|
+ addAMessageData(messageBean)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
"end" -> {
|
|
|
@@ -982,4 +933,14 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前activity是否位于栈顶
|
|
|
+ */
|
|
|
+ private fun isTopActivity(activity: Activity): Boolean {
|
|
|
+ val am = activity.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val cn = am.getRunningTasks(1)[0].topActivity
|
|
|
+ return cn!!.className == activity.javaClass.name
|
|
|
+ }
|
|
|
+
|
|
|
}
|