From 71a056d02f9084af82bd6fe3962e5b46d5628e4f Mon Sep 17 00:00:00 2001
From: liugl <liugl@sinata.cn>
Date: 星期二, 11 八月 2020 21:56:10 +0800
Subject: [PATCH] 8.11

---
 app/src/main/java/com/okgoincar/base/MyApplication.kt |   44 +++++++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/app/src/main/java/com/okgoincar/base/MyApplication.kt b/app/src/main/java/com/okgoincar/base/MyApplication.kt
index b5f64c1..2506495 100644
--- a/app/src/main/java/com/okgoincar/base/MyApplication.kt
+++ b/app/src/main/java/com/okgoincar/base/MyApplication.kt
@@ -3,12 +3,12 @@
 import android.app.Activity
 import android.app.Application
 import android.content.Context
-import android.content.Intent
 import android.os.Bundle
 import android.os.Handler
 import android.os.Looper
 import android.util.Log
 import androidx.multidex.MultiDex
+import cn.sinata.rxnetty.Cache.CacheUtil
 import cn.sinata.rxnetty.NettyClient
 import cn.sinata.xldutils.BaseApplication
 import cn.sinata.xldutils.utils.sysErr
@@ -71,10 +71,12 @@
 //        LogUtils.OpenLog(true)
         initUpPoint()
         initSocket()
-
     }
 
     private fun initSocket() {
+        Handler(Looper.getMainLooper()).post {
+            toast("websocket初始化")
+        }
         NettyClient.getInstance().init(this, Api.SOCKET_SERVER, Api.SOCKET_PORT, true)
         NettyClient.getInstance()
             .addOnMessageListener { message: String? ->
@@ -84,9 +86,9 @@
                     currentTime = System.currentTimeMillis()
                     val json = JSONObject(message)
                     val method = json.optString("method")
-//                    Handler(Looper.getMainLooper()).post {
-//                        toast("收到websocket=$method")
-//                    }
+                    Handler(Looper.getMainLooper()).post {
+                        toast("收到websocket=$method")
+                    }
                     val data = json.optString("data")
                     val code = json.optInt("code", -1)
                     if (code == 200) {
@@ -158,6 +160,7 @@
             .setOnConnectListener {
                 sendHeart()
             }
+        sendHeart()
     }
 
     override fun attachBaseContext(base: Context?) {
@@ -258,14 +261,14 @@
             bean.data = dataBean
             NettyClient.getInstance()
                 .sendMessage(Gson().toJson(bean))
-            Handler(Looper.getMainLooper()).post {
-                toast("发送location --> $dataBean")
-            }
+//            Handler(Looper.getMainLooper()).post {
+//                toast("发送location --> $dataBean")
+//            }
             sysErr(dataBean.toString())
         }
     }
 
-    private fun sendHeart() {
+    open fun sendHeart() {
         if (getUserId() != -1) {
             Log.i(TAG, "sendHeart: userId === " + getUserId())
             val bean = HeartBean()
@@ -281,7 +284,13 @@
             if ((System.currentTimeMillis() - currentTime) / 1000 > 30) {
                 sysErr("sendHeart_websocket 重新连接")
                 currentTime = System.currentTimeMillis()
-                NettyClient.getInstance().checkNettyState()
+//                var s = CacheUtil.get().getAsString("reConnect")
+//                s = "$s###初始化重连"
+//                CacheUtil.get().put("reConnect", s)
+//                NettyClient.getInstance().checkNettyState()
+                NettyClient.getInstance().checkNettyStateNull() //reconnect
+
+//                initSocket()
                 heartHandler!!.postDelayed({ sendHeart() }, 5000)
             } else {
                 sysErr("sendHeart_websocket 发送心跳")
@@ -321,8 +330,8 @@
                     return Gson().fromJson(locationStr, AMapLocation::class.java)
                 } else {
                     val amap = AMapLocation("")
-                    amap.latitude = -1.0
-                    amap.longitude = -1.0
+                    amap.latitude = 0.0
+                    amap.longitude = 0.0
                     return amap
                 }
             } else {
@@ -400,8 +409,7 @@
         showNum--
         Handler(Looper.getMainLooper()).postDelayed({
             if (showNum == 0) {
-                setVideoText("OK出行司机已置于后台,可能会导致听单异常,里程计费差异,请勿切换。")
-//                getTTsManager().setVideoText("OK出行司机已置于后台,可能会导致听单异常,里程计费差异,请勿切换。")
+                getTTsManager().setVideoText("OK出行司机已置于后台,可能会导致听单异常,里程计费差异,请勿切换。")
             }
         }, 600)
 
@@ -411,11 +419,5 @@
         activities.add(activity)
     }
 
-    fun setVideoText(s: String?) {
-        val intent = Intent()
-        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
-        intent.action = "com.wisdom.gps.action.tts"
-        intent.putExtra("msg", s)
-        sendBroadcast(intent)
-    }
+
 }
\ No newline at end of file

--
Gitblit v1.7.1