Parcourir la source

#增加呼叫倒计时,默认30s

weizhengliang il y a 3 ans
Parent
commit
bd8327bc39

+ 30 - 2
home/src/main/code/com/wdkl/ncs/android/component/home/activity/HomeActivity.kt

@@ -9,6 +9,7 @@ import android.content.pm.PackageManager
 import android.graphics.Color
 import android.net.ConnectivityManager
 import android.os.Bundle
+import android.os.CountDownTimer
 import android.provider.Settings
 import android.support.v4.app.ActivityCompat
 import android.support.v4.app.Fragment
@@ -92,6 +93,9 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
 
     private lateinit var receiver: TimeReceiver
 
+    //呼叫倒计时
+    lateinit var countDownTimer: CountDownTimer
+
     override fun getLayId(): Int {
         return R.layout.activity_home
     }
@@ -181,6 +185,8 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
 
         //注册广播
         regReceiver()
+
+        initCountDownTimer()
     }
 
     private fun regReceiver() {
@@ -194,6 +200,22 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
         unregisterReceiver(receiver)
     }
 
+    fun initCountDownTimer() {
+        countDownTimer = object: CountDownTimer(30000, 1000) {
+            override fun onTick(millisUntilFinished: Long) {
+                //
+            }
+
+            override fun onFinish() {
+                //呼叫超时,返回到主界面
+                showMessage("无人应答...")
+                DeviceChannel.calling = false
+                VideoUtil.cancelVideoCall(Constants.deviceId, Constants.interactionId)
+                CallDialogHelper.dismissCallDialog()
+            }
+        }
+    }
+
     /**
      * 返回的tcp信息
      */
@@ -348,6 +370,7 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
         SocketManager.getInstance().unConnect()
 
         releaseReceiver()
+        countDownTimer.cancel()
     }
 
     override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
@@ -373,26 +396,29 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
                 TcpAction.VideoAction.CALLING->{
                     DeviceChannel.calling = false
                     CallDialogHelper.dismissCallDialog()
+                    countDownTimer.cancel()
                     showMessage("对方忙线中")
                 }
 
                 TcpAction.VideoAction.FAILED->{
                     DeviceChannel.calling = false
                     showMessage("呼叫失败,请稍候重试")
+                    countDownTimer.cancel()
                 }
 
                 TcpAction.VideoAction.SUCCESS->{
                     DeviceChannel.calling = true
-                    Constants.fromId = tcpModel.fromId
                     Constants.interactionId = interactionVO.id
                     Util.wakeUpAndUnlock(this)
+                    countDownTimer.start()
 
                     CallDialogHelper.dismissCallDialog()
                     CallDialogHelper.showCallDialog(this@HomeActivity, 0, "探视请求已发送,请等待...", View.OnClickListener {
                         //呼出取消
                         DeviceChannel.calling = false
-                        VideoUtil.cancelVideoCall(Constants.deviceId, Constants.fromId, Constants.interactionId)
+                        VideoUtil.cancelVideoCall(Constants.deviceId, Constants.interactionId)
                         CallDialogHelper.dismissCallDialog()
+                        countDownTimer.cancel()
                     }, View.OnClickListener {
                         //来电接听
                     }, View.OnClickListener {
@@ -416,6 +442,7 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
                     DeviceChannel.calling = true
                     Constants.interactionId = interactionVO.id
                     CallDialogHelper.dismissCallDialog()
+                    countDownTimer.cancel()
 
                     //先和主机视频请求探视,得到允许后方可和分机视频
                     /*currentFragment = VisitFragment()
@@ -453,6 +480,7 @@ class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(),
                     showMessage("对方拒绝")
                     DeviceChannel.calling = false
                     CallDialogHelper.dismissCallDialog()
+                    countDownTimer.cancel()
                 }
 
                 TcpAction.VideoAction.HANDOFF -> {

+ 3 - 4
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/channel/VideoUtil.java

@@ -28,12 +28,11 @@ public class VideoUtil {
         return tcpModel;
     }
 
-    public static TcpModel videoCancelCall(Integer fromId, Integer toId, Integer interactionId){
+    public static TcpModel videoCancelCall(Integer fromId, Integer interactionId){
         TcpModel tcpModel = new TcpModel();
         tcpModel.setType(TcpType.VIDEO);
         tcpModel.setAction(TcpAction.VideoAction.CANCEL);
         tcpModel.setFromId(fromId);
-        tcpModel.setToId(toId);
         tcpModel.setData(interactionId);
         return tcpModel;
     }
@@ -96,8 +95,8 @@ public class VideoUtil {
     }
 
     //取消视频
-    public static void cancelVideoCall(Integer fromId, Integer toId, Integer interactionId) {
-        TcpModel tcpModel = videoCancelCall(fromId, toId, interactionId);
+    public static void cancelVideoCall(Integer fromId, Integer interactionId) {
+        TcpModel tcpModel = videoCancelCall(fromId, interactionId);
         TcpClient.getInstance().sendMsg(tcpModel.toJson());
     }