From 6521ab0f203b66b589e9990f090f04c16ea36320 Mon Sep 17 00:00:00 2001
From: 唐浩 <15928265276@163.com>
Date: 星期一, 20 七月 2020 19:17:04 +0800
Subject: [PATCH] commit

---
 app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt |   83 ++++++++++++++++++++++++++++++++---------
 1 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt b/app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt
index 19f5c0d..9aab87f 100644
--- a/app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt
+++ b/app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt
@@ -5,33 +5,78 @@
 import android.content.Intent
 import android.os.Handler
 import android.os.Looper
+import cn.sinata.rxnetty.netStatus.NetUtils
 import cn.sinata.xldutils.utils.toast
+import com.google.gson.Gson
+import com.okgoincar.bean.LoginBean
+import com.okgoincar.netUtls.Api
+import com.okgoincar.netUtls.callNet
+import com.okgoincar.netUtls.getMapByAny
+import com.okgoincar.netUtls.getToken
 import com.okgoincar.slab.SlabLoginActivity
+import com.okgoincar.slab.SlabMainActivity
+import com.okgoincar.utils.Cache.CacheKey
 import com.okgoincar.utils.Cache.CacheUtil
 import org.greenrobot.eventbus.EventBus
 import org.jetbrains.anko.startActivity
+import java.lang.Exception
 
 class MainBroadCastReceiver : BroadcastReceiver() {
-    override fun onReceive(context: Context?, intent: Intent?) {
-        toast("收到广播1")
-        Handler(Looper.getMainLooper()).post {
-            val b = intent!!.getBooleanExtra("isLogin",false)
-            val driverName = intent!!.getStringExtra("driverName")
-            toast("司机名字=$driverName")
-            if (!b){
-                toast("LED退出登录")
-                CacheUtil.get().clear()
-                EventBus.getDefault().post(BaseEvent(BaseEvent.OUT_APP))
-//                context?.startActivity<SlabLoginActivity>()
-            }else{
-                toast("开始登录")
+    override fun onReceive(contexts: Context?, intent: Intent?) {
+        if (intent == null){
+            toast("内容获取为空,广播接收消息错误")
+            return
+        }
+        try {
+            Handler(Looper.getMainLooper()).post {
+                val b = intent.getBooleanExtra("isLogin",true)
+                toast("isLogin=$b")
+                if (!b){
+                    CacheUtil.get().clear()
+                    EventBus.getDefault().post(BaseEvent(BaseEvent.OUT_APP))
+                }else{
+                    if (getToken().isNullOrEmpty()){
+                        Handler(Looper.getMainLooper()).post {
+                            toast("开始登录")
+                        }
+                        var driverCertificate = intent.getStringExtra("driverCertificate")
+                        if (driverCertificate == null){
+                            toast("身份证获取失败")
+                        }else{
+                            if (contexts == null){
+                                toast("上下文为空,使用全局跳转")
+                                toLoginActivity(MyApplication.getInstance(),driverCertificate)
+                            }else{
+                                toLoginActivity(MyApplication.getInstance(),driverCertificate)
+                            }
+                        }
+
+                    }
+                }
             }
-            var heay = intent.getBooleanExtra("isHeavy",false)
-            toast("获取的网约=$heay") //顶灯
-            var price = intent.getDoubleExtra("price",0.0)
-            toast("收到的显示价格$price")
-            var mileage = intent.getDoubleExtra("mileage",0.0)
-            toast("收到的显示价格$mileage")
+        }catch (e:Exception){
+
+        }
+
+    }
+
+    private fun toLoginActivity(context: Context?,driverCertificate: String?) {
+        var map = getMapByAny()
+        map["identification"] = driverCertificate
+        callNet(context!!,Api.loginByIdentification,map){
+            toast("登录成功")
+            var bean = Gson().fromJson<LoginBean>(it, LoginBean::class.java)
+            CacheKey.putKeyStr("appid", bean.data.appid)
+            CacheKey.putKeyStr("token", bean.data.token)
+            CacheKey.putKeyStr("userId", bean.data.id.toString())
+            CacheKey.putKeyStr("serverId", bean.data.serverId.toString())
+            CacheKey.putKeyStr("terminalName", bean.data.terminalId.toString())
+            Handler(Looper.getMainLooper()).post {
+                var intent = Intent()
+                intent.setClass(context,SlabMainActivity::class.java)
+                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+                context.startActivity(intent)
+            }
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.7.1