|
@@ -0,0 +1,257 @@
|
|
|
|
+package com.wdkl.ncs.android.component.home.activity
|
|
|
|
+
|
|
|
|
+import android.content.Context
|
|
|
|
+import android.os.VibrationEffect
|
|
|
|
+import android.os.Vibrator
|
|
|
|
+import android.util.Log
|
|
|
|
+import android.view.View
|
|
|
|
+import com.alibaba.android.vlayout.DelegateAdapter
|
|
|
|
+import com.alibaba.android.vlayout.VirtualLayoutManager
|
|
|
|
+import com.enation.javashop.android.jrouter.external.annotation.Autowired
|
|
|
|
+import com.enation.javashop.android.jrouter.external.annotation.Router
|
|
|
|
+import com.enation.javashop.net.engine.model.NetState
|
|
|
|
+import com.google.common.base.Strings
|
|
|
|
+import com.google.gson.Gson
|
|
|
|
+import com.wdkl.ncs.android.component.home.R
|
|
|
|
+import com.wdkl.ncs.android.component.home.adapter.NewEventItemAdapter
|
|
|
|
+import com.wdkl.ncs.android.component.home.databinding.ActivityEventListBinding
|
|
|
|
+import com.wdkl.ncs.android.component.home.launch.HomeLaunch
|
|
|
|
+import com.wdkl.ncs.android.component.home.service.WdKeepAliveService
|
|
|
|
+import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
|
|
|
|
+import com.wdkl.ncs.android.component.home.util.SpeechUtil
|
|
|
|
+import com.wdkl.ncs.android.component.home.util.Util
|
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseActivity
|
|
|
|
+import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
|
+import com.wdkl.ncs.android.lib.utils.showMessage
|
|
|
|
+import com.wdkl.ncs.android.middleware.logic.contract.home.NewEventListContract
|
|
|
|
+import com.wdkl.ncs.android.middleware.logic.presenter.home.NewEventListPresenter
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
|
|
+import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
|
|
+import kotlinx.android.synthetic.main.activity_event_list.*
|
|
|
|
+import org.greenrobot.eventbus.Subscribe
|
|
|
|
+import org.greenrobot.eventbus.ThreadMode
|
|
|
|
+
|
|
|
|
+class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventListBinding>(),NewEventListContract.View {
|
|
|
|
+ var TAG = NewEventListActivity::class.java.getSimpleName()
|
|
|
|
+
|
|
|
|
+ lateinit var mVibrator: Vibrator
|
|
|
|
+
|
|
|
|
+ private val adapter = NewEventItemAdapter(ArrayList(),this)
|
|
|
|
+ private lateinit var virtualLayoutManager: VirtualLayoutManager
|
|
|
|
+ private lateinit var delegateAdapter: DelegateAdapter
|
|
|
|
+
|
|
|
|
+ //参数自动注入
|
|
|
|
+ @Autowired(name = "tcpModelStr", required = true)
|
|
|
|
+ @JvmField
|
|
|
|
+ var tcpModelStr:String = ""
|
|
|
|
+ @Autowired(name = "boolVibrator", required = false)
|
|
|
|
+ @JvmField
|
|
|
|
+ var boolVibrator = false
|
|
|
|
+
|
|
|
|
+ var listData = ArrayList<InteractionVO>()
|
|
|
|
+
|
|
|
|
+ override fun getLayId(): Int {
|
|
|
|
+ return R.layout.activity_event_list
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun bindDagger() {
|
|
|
|
+ HomeLaunch.component.inject(this)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun init() {
|
|
|
|
+ //震动
|
|
|
|
+ mVibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
|
|
+ if (boolVibrator) {
|
|
|
|
+ handleVibrator()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ val tcpModel = TcpModel.getModelByJson(tcpModelStr)
|
|
|
|
+ val interactionVO = Gson().fromJson<InteractionVO>(tcpModel.data.toString(),InteractionVO::class.java)
|
|
|
|
+ listData.add(interactionVO)
|
|
|
|
+
|
|
|
|
+ WdKeepAliveService.mNewEventListActive = true
|
|
|
|
+ /**初始化LayoutMannager*/
|
|
|
|
+ virtualLayoutManager = VirtualLayoutManager(this.activity)
|
|
|
|
+
|
|
|
|
+ /**初始化适配器*/
|
|
|
|
+ delegateAdapter = DelegateAdapter(virtualLayoutManager)
|
|
|
|
+ delegateAdapter.addAdapter(adapter)
|
|
|
|
+ /**配置到RecycleView*/
|
|
|
|
+ rv_event_list.layoutManager = virtualLayoutManager
|
|
|
|
+ rv_event_list.adapter = delegateAdapter
|
|
|
|
+
|
|
|
|
+ renderData(listData)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun bindEvent() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun destory() {
|
|
|
|
+ MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
+ mVibrator.cancel()
|
|
|
|
+ SpeechUtil.getInstance().stopSpeak()
|
|
|
|
+ WdKeepAliveService.mNewEventListActive = false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun renderData(data: ArrayList<InteractionVO>) {
|
|
|
|
+ Log.e(TAG,"返回的数据 "+data.size)
|
|
|
|
+ data.sortByDescending { it.id }
|
|
|
|
+ srl_event_list.finishRefresh()
|
|
|
|
+ if (data.size > 0) {
|
|
|
|
+ adapter.data.clear()
|
|
|
|
+ adapter.data.addAll(listData)
|
|
|
|
+ adapter.notifyDataSetChanged()
|
|
|
|
+ } else {
|
|
|
|
+ tv_empty_event.visibility = View.VISIBLE
|
|
|
|
+ AppTool.Time.delay(1200){
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onError(message: String, type: Int) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun complete(message: String, type: Int) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun start() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun networkMonitor(state: NetState) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun handleVibrator(){
|
|
|
|
+ mVibrator.cancel()
|
|
|
|
+ //开启振动后 等待0.1s振动 振动2s 等待1s 振动2s 等待1s
|
|
|
|
+ val pattern = longArrayOf(100, 2000, 1000, 2000)
|
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
|
|
+ mVibrator.vibrate(VibrationEffect.createWaveform(pattern, -1))
|
|
|
|
+ } else {
|
|
|
|
+ mVibrator.vibrate(pattern, -1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
+ fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
|
+ if (messageEvent.tag == 2) {
|
|
|
|
+ mVibrator.cancel()
|
|
|
|
+ val resTcpModel = messageEvent.getMessage() as TcpModel
|
|
|
|
+ if (resTcpModel.action == TcpAction.VoiceAction.FAILED) {
|
|
|
|
+ showMessage("呼叫失败,可能对方不在线")
|
|
|
|
+ } else if (resTcpModel.action == TcpAction.VoiceAction.CALLING) {
|
|
|
|
+ showMessage("对方通话中")
|
|
|
|
+ }
|
|
|
|
+ } else if (messageEvent.tag == 4) {
|
|
|
|
+ val resTcpModel = messageEvent.getMessage() as TcpModel
|
|
|
|
+ if (resTcpModel.type == TcpType.DATA && resTcpModel.action == TcpAction.DataAction.INTERACTION) {
|
|
|
|
+ if (resTcpModel.data != null) {
|
|
|
|
+ dismissDialog()
|
|
|
|
+ mVibrator.cancel()
|
|
|
|
+ val responseInteractionVO = Gson().fromJson<InteractionVO>(resTcpModel.data.toString(), InteractionVO::class.java)
|
|
|
|
+ showMessage("已响应"+responseInteractionVO.fromFrameFullName + " " + responseInteractionVO.data)
|
|
|
|
+
|
|
|
|
+ var doFinish = false
|
|
|
|
+ for (it in listData){
|
|
|
|
+ if (it.id == responseInteractionVO.id) {
|
|
|
|
+ listData.remove(it)
|
|
|
|
+
|
|
|
|
+ if (responseInteractionVO.actionType.equals(TcpType.IM.name)){
|
|
|
|
+ AppTool.Time.delay(1000){
|
|
|
|
+ while (MediaPlayHelper.getInstance().isMediaPlaying){
|
|
|
|
+ Thread.sleep(1000)
|
|
|
|
+ }
|
|
|
|
+ adapter.data.remove(it)
|
|
|
|
+ adapter.notifyDataSetChanged()
|
|
|
|
+ if (listData.isEmpty()||listData.size==0){
|
|
|
|
+ AppTool.Time.delay(1200) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ renderData(listData)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ adapter.data.remove(it)
|
|
|
|
+ adapter.notifyDataSetChanged()
|
|
|
|
+ doFinish = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if ((listData.isEmpty()||listData.size==0) && doFinish){
|
|
|
|
+ AppTool.Time.delay(1200) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ renderData(listData)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (messageEvent.tag == 3){ //新事件到来
|
|
|
|
+ val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
|
+ val responseInteractionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
|
+ SpeechUtil.getInstance().stopSpeak()
|
|
|
|
+ if (tcpModel.type == TcpType.EVENT) {
|
|
|
|
+ if (tcpModel.action == TcpAction.EventAction.KEY_CLICK) {
|
|
|
|
+ listData.add(responseInteractionVO)
|
|
|
|
+ renderData(listData)
|
|
|
|
+ val eventStr = Util.appendSpace(responseInteractionVO.fromFrameFullName.replace("-", ",")) + ", " + responseInteractionVO.data
|
|
|
|
+ SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
|
|
|
|
+ }
|
|
|
|
+ } else if (tcpModel.type == TcpType.IM){
|
|
|
|
+ if (tcpModel.action == TcpAction.IMAction.MSG) {
|
|
|
|
+ listData.add(responseInteractionVO)
|
|
|
|
+ renderData(listData)
|
|
|
|
+ SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (messageEvent.tag == 999){ //SOS
|
|
|
|
+ val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
|
+ if (tcpModel.type == TcpType.SOS) {
|
|
|
|
+ val responseInteractionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
|
+ if (tcpModel.action === TcpAction.SOSAction.CANCEL) {
|
|
|
|
+ MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
+ mVibrator.cancel()
|
|
|
|
+ if (!Strings.isNullOrEmpty(responseInteractionVO.toRoleName)) {
|
|
|
|
+ showMessage(responseInteractionVO.toRoleName + " " + responseInteractionVO.toMemberName + " 已响应")
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("已响应")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (it in listData){
|
|
|
|
+ if (it.id == responseInteractionVO.id) {
|
|
|
|
+ listData.remove(it)
|
|
|
|
+ adapter.data.remove(it)
|
|
|
|
+ adapter.notifyDataSetChanged()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (listData.isEmpty()||listData.size==0){
|
|
|
|
+ AppTool.Time.delay(1200) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ renderData(listData)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else if (tcpModel.action === TcpAction.SOSAction.CALL) {
|
|
|
|
+ listData.add(responseInteractionVO)
|
|
|
|
+ renderData(listData)
|
|
|
|
+
|
|
|
|
+ SpeechUtil.getInstance().stopSpeak()
|
|
|
|
+ handleVibrator()
|
|
|
|
+ MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
+ MediaPlayHelper.getInstance().playResMusic(R.raw.sos2, 1.0f, false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|