From c73a6318cb54e1bd16f6f1f2e432c2ed0ab4f594 Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期一, 24 八月 2020 18:01:53 +0800
Subject: [PATCH] SharedPrefernce增加保存hashmap ;设置界面增加车辆模型、地图信息展示(名字、版本)和版本更新功能,点击之后进行http请求,请求完成后发送地图、车辆给移动站服务;设置界面信息展示增加TypeCount,展示地图简要信息

---
 app/src/main/java/safeluck/drive/evaluation/util/DataInit.kt |  166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 163 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/util/DataInit.kt b/app/src/main/java/safeluck/drive/evaluation/util/DataInit.kt
index 36b87e7..ca4620d 100644
--- a/app/src/main/java/safeluck/drive/evaluation/util/DataInit.kt
+++ b/app/src/main/java/safeluck/drive/evaluation/util/DataInit.kt
@@ -1,6 +1,10 @@
 package safeluck.drive.evaluation.util
 
 import android.content.Context
+import android.os.Environment
+import android.text.TextUtils
+import android.util.Log
+import android.widget.Toast
 import androidx.work.Data
 import androidx.work.ListenableWorker
 import com.anyun.exam.lib.AYSdk
@@ -8,15 +12,24 @@
 import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import com.google.gson.stream.JsonReader
+import okhttp3.ResponseBody
 import org.json.JSONException
 import org.json.JSONObject
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
 import safeluck.drive.evaluation.Constant
 import safeluck.drive.evaluation.DB.WorkRoomDataBase
 import safeluck.drive.evaluation.DB.rtktb.RTKConfig
 import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig
-import safeluck.drive.evaluation.bean.ExamPlatformData
-import safeluck.drive.evaluation.bean.SignalConfigRemote
-import safeluck.drive.evaluation.bean.SimulateNightBean
+import safeluck.drive.evaluation.app
+import safeluck.drive.evaluation.bean.*
+import safeluck.drive.evaluation.httpmodule.HttpCarRespBean
+import safeluck.drive.evaluation.httpmodule.HttpRequetBean
+import safeluck.drive.evaluation.httpmodule.HttpRoadMapRsp
+import safeluck.drive.evaluation.httpmodule.HttpYardRsp
+import safeluck.drive.evaluation.httpmodule.RetrofitCreator.Companion.getRestService
+import safeluck.drive.evaluation.platformMessage.PlatFormConstant
 import safeluck.drive.evaluation.worker.MCUUpgradeWorker
 import java.io.IOException
 import java.io.InputStreamReader
@@ -205,3 +218,150 @@
     }
     return false
 }
+
+
+
+
+ fun getMap(sn: String, type: String){
+    lateinit var jsonObject1 :JSONObject
+    lateinit var fileName :String
+    when(type){
+        "road" -> fileName =  safeluck.drive.evaluation.Constant.ROAD_MAP
+        "yard" -> fileName =  safeluck.drive.evaluation.Constant.MAP
+        else -> fileName = safeluck.drive.evaluation.Constant.VEHICLE
+    }
+        getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, type)).enqueue(object : Callback<ResponseBody> {
+            override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
+                MyLog.i(PlatFormConstant.HTTPTAG,t.localizedMessage)
+            }
+
+            override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
+                var str: String = response.body()!!.string()
+                MyLog.i(PlatFormConstant.HTTPTAG,str)
+                jsonObject1 = JSONObject(str)
+                val result = jsonObject1!!.getBoolean("result")
+                if (result) {
+                    var mapInfoHead: MapInfoHead = MapInfoHead("","", BaseDataUIBean.TYPE_.car)
+
+                    when(type){
+                        "road" ->{
+                            mapInfoHead.type = BaseDataUIBean.TYPE_.road
+                            val map = gson.fromJson<HttpRoadMapRsp>(str, HttpRoadMapRsp::class.java)
+                            if (map.isResult) {
+                                if (map.data != null) {
+                                    mapInfoHead.version = map.data.version
+
+                                    if (map.data.map_json.type.equals("road")) {
+                                        mapInfoHead.str = map.data.map_json.name
+                                        ExamPlatformData.getInstance().setNewRoadMapPath(Environment.getExternalStorageDirectory().absolutePath + "/"
+                                                + app.getAppContext().getPackageName() + "/" + fileName)
+                                        CThreadPoolExecutor.runInBackground(Runnable {
+                                            str = gson.toJson(map.data.map_json)
+                                            MyLog.i(PlatFormConstant.HTTPTAG,"绉戜笁閬撹矾鍦板浘淇濆瓨鎴愬姛")
+                                            FileUtil.writeTxtFileToSD(app.getAppContext(), fileName, str, "")
+//                                            sendRoadMapInfo()
+                                        })
+                                    }
+
+
+                                }
+
+
+                            }}
+                        "yard" ->{
+                            mapInfoHead.type = BaseDataUIBean.TYPE_.yard
+                            val yard = gson.fromJson<HttpYardRsp>(str,HttpYardRsp::class.java)
+                            if (yard.isResult){
+                                if (yard.data !=null){
+                                    mapInfoHead.version = yard.data.version
+                                    mapInfoHead.str = yard.data.map_json.name
+                                    ExamPlatformData.getInstance().setNewMapPath(Environment.getExternalStorageDirectory().absolutePath + "/"
+                                            + app.getAppContext().getPackageName() + "/"+fileName)
+                                    CThreadPoolExecutor.runInBackground(Runnable{
+                                        MyLog.i(PlatFormConstant.HTTPTAG,"绉戜笁鍦哄湴鍦板浘淇濆瓨鎴愬姛")
+                                        str = gson.toJson(yard.data.map_json)
+                                        FileUtil.writeTxtFileToSD(app.getAppContext(),fileName,str,"")
+                                        sendMapInfo()
+                                    })
+                                }
+                            }
+                        }
+                        else ->{
+                            mapInfoHead.type = BaseDataUIBean.TYPE_.car
+                            val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java)
+
+                            if (car.isResult){
+                                if (car.data !=null){
+                                    mapInfoHead.version = car.data.version
+                                    mapInfoHead.str = car.data.map_json.name
+                                    ExamPlatformData.getInstance().carModelPath = Environment.getExternalStorageDirectory().absolutePath + "/" +
+                                            app.getAppContext().getPackageName() + "/"+fileName
+
+//                                    Log.i(TAG, "瑙f瀽涔嬪悗鐨勮溅妯″瀷=$str")
+                                    CThreadPoolExecutor.runInBackground(Runnable{
+                                        str = gson.toJson(car.data.map_json)
+                                        MyLog.i(PlatFormConstant.HTTPTAG,"杞﹁締妯″瀷淇濆瓨鎴愬姛")
+                                        FileUtil.writeTxtFileToSD(app.getAppContext(),fileName,str,"")
+                                        sendVehicleInfo()
+                                    })
+
+                                }
+                            }
+                        }
+                    }
+                    ExamPlatformData.getInstance().setMapHeadInfo(mapInfoHead)
+                } else {
+//                        Toast.makeText(applicationContext, jsonObject1!!.getString("data"), Toast.LENGTH_SHORT).show()
+                }
+            }
+        })
+
+}
+
+private fun sendMapInfo(){
+    val mapPath = ExamPlatformData.getInstance().mapPath
+
+
+    if (!TextUtils.isEmpty(mapPath)) {
+        MyLog.i("鏇存柊Map鐨勫湴鍥�$mapPath")
+        val fileContent = FileUtil.readFile(mapPath)
+        if (fileContent != null) {
+            val str = String(fileContent)
+            AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_MAP_INFO, str)
+        } else {
+            MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", mapPath))
+            CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "鏂囦欢锛�" + mapPath + "涓嶅瓨鍦�", Toast.LENGTH_SHORT).show() }
+        }
+    }
+}
+
+private fun sendVehicleInfo(){
+    val carPath = ExamPlatformData.getInstance().carModelPath
+    if (!TextUtils.isEmpty(carPath)) {
+        MyLog.i("鏇存柊鍚庣殑Car妯″瀷$carPath")
+        val bytes = FileUtil.readFile(carPath)
+        if (bytes != null) {
+            val str = String(bytes)
+            AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_VECHILE_PROFILE, str)
+        } else {
+            MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", carPath))
+        }
+    }
+}
+private fun sendRoadMapInfo(){
+    val roadmapPath = ExamPlatformData.getInstance().roadMapPath
+
+    if (!TextUtils.isEmpty(roadmapPath)) {
+        MyLog.i("鏇存柊RoadMap鍦板浘$roadmapPath")
+        val fileContent = FileUtil.readFile(roadmapPath)
+        if (fileContent != null) {
+            val str = String(fileContent)
+            AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_ROAD_MAP_INFO, str)
+        } else {
+            MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", roadmapPath))
+            CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "鏂囦欢锛�" + roadmapPath + "涓嶅瓨鍦�", Toast.LENGTH_SHORT).show() }
+        }
+    } else {
+
+    }
+}

--
Gitblit v1.8.0