| | |
| | | package safeluck.drive.evaluation.DB.rtktb |
| | | |
| | | import android.content.Context |
| | | import android.os.Looper |
| | | import android.text.TextUtils |
| | | import android.util.Log |
| | | import android.widget.Toast |
| | | import androidx.work.Worker |
| | | import androidx.work.WorkerParameters |
| | | import com.anyun.exam.lib.AYSdk |
| | | import com.anyun.exam.lib.MyLog |
| | | import com.google.gson.Gson |
| | | import okhttp3.ResponseBody |
| | | import org.json.JSONException |
| | | import org.json.JSONObject |
| | | import retrofit2.Call |
| | | import retrofit2.Callback |
| | | import retrofit2.Response |
| | | import safeluck.drive.evaluation.DB.Constant |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase |
| | | import safeluck.drive.evaluation.bean.ExamPlatformData |
| | | import safeluck.drive.evaluation.httpmodule.HttpCarRespBean |
| | | import safeluck.drive.evaluation.httpmodule.HttpRequetBean |
| | | import safeluck.drive.evaluation.httpmodule.RetrofitCreator.Companion.getRestService |
| | | import safeluck.drive.evaluation.im.IMSClientBootstrap |
| | | import safeluck.drive.evaluation.platformMessage.PlatFormConstant |
| | | import safeluck.drive.evaluation.util.FileUtil |
| | | import java.io.IOException |
| | | |
| | | class RTKConfigUpdateWorker(context:Context, workerParams: WorkerParameters) :Worker(context, workerParams){ |
| | | |
| | |
| | | */ |
| | | phone = sn |
| | | Log.i(TAG,"phone="+phone) |
| | | |
| | | if (!FileUtil.isMapExist(applicationContext,"map.json")){ |
| | | MyLog.i("地图文件不存在,去平台取") |
| | | getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, "place")).enqueue(object : Callback<ResponseBody> { |
| | | override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { |
| | | var str: String? = null |
| | | try { |
| | | str = response.body()!!.string() |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | } |
| | | Log.i(TAG, "服务器返回的body=$str") |
| | | if (Looper.myLooper() == Looper.getMainLooper()) { |
| | | Toast.makeText(applicationContext, "主线程", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | |
| | | override fun onFailure(call: Call<ResponseBody>, t: Throwable) { |
| | | Log.i(TAG, t.localizedMessage) |
| | | } |
| | | }) |
| | | } |
| | | if (!FileUtil.isMapExist(applicationContext,"car.json")){ |
| | | MyLog.i("车辆模型文件不存在,去平台取") |
| | | getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, "car")).enqueue(object : Callback<ResponseBody> { |
| | | override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { |
| | | var str: String? = null |
| | | try { |
| | | str = response.body()!!.string() |
| | | Log.i(TAG, "服务器返回的body=$str") |
| | | val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java) |
| | | if (car.isResult){ |
| | | if (car.data !=null){ |
| | | str = gson.toJson(car.data.map_json) |
| | | Log.i(TAG, "解析之后的车模型=$str") |
| | | FileUtil.writeTxtFileToSD(applicationContext,"car.json",str,"") |
| | | } |
| | | } |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | } |
| | | |
| | | if (Looper.myLooper() == Looper.getMainLooper()) { |
| | | Toast.makeText(applicationContext, "主线程", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | |
| | | override fun onFailure(call: Call<ResponseBody>, t: Throwable) { |
| | | Log.i(TAG, t.localizedMessage) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | MyLog.i(PlatFormConstant.TAG,"重置TCP连接") |
| | | IMSClientBootstrap.getInstance().resetConnect(); |
| | | } |