diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt index ec896d3..956a034 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt @@ -43,17 +43,32 @@ class DevicesApi : BaseObserve(Api::class.java) { suspend fun uploadGasData( gasList: List = emptyList() - ): BaseResponse { - val gasReq = GasRequest(detections = gasList) - return api.uploadGasData(gasReq) + ): BaseResponse? { + try { + val gasReq = GasRequest(detections = gasList) + return api.uploadGasData(gasReq) + } catch (e: Exception) { + e.printStackTrace() + } + return null } - suspend fun getDetectionLastTime() : LastTimeResponse{ - return api.getDetectionLastTime(LztekUtil.getSn()) + suspend fun getDetectionLastTime(): LastTimeResponse? { + try { + return api.getDetectionLastTime(LztekUtil.getSn()) + } catch (e: Exception) { + e.printStackTrace() + } + return null } - suspend fun getVideoLastTime(): LastTimeResponse { - return api.getVideoLastTime(LztekUtil.getSn()) + suspend fun getVideoLastTime(): LastTimeResponse? { + try { + return api.getVideoLastTime(LztekUtil.getSn()) + } catch (e: Exception) { + e.printStackTrace() + } + return null } interface Api { diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt index 74da8e3..b5cf38a 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt @@ -93,13 +93,13 @@ class CloudActivity : NoOptionsActivity() { uploadingVideo.set(true) // 1.拿到云端最新数据时间 val timeResponse = devicesApi.getVideoLastTime() - if (timeResponse.isOk()) { + if (timeResponse?.isOk() == true) { val cloudTime = timeResponse.data // 2. 拿到待上传文件列表 上传 getFileListAndUpload(cloudTime) LogUtils.v("uploadVideo ok") } else { - LogUtils.e("getVideoLastTime error code = ${timeResponse.code}") + LogUtils.e("getVideoLastTime error code = ${timeResponse?.code}") } uploadingVideo.set(false) } @@ -110,14 +110,14 @@ class CloudActivity : NoOptionsActivity() { uploadingGas.set(true) // 1.拿到云端最新数据时间 val lastTimeResponse = devicesApi.getDetectionLastTime() - if (lastTimeResponse.isOk()) { + if (lastTimeResponse?.isOk() == true) { val cloudTime = lastTimeResponse.data // 2. 查询本地数据库中该时间之后的数据 // 3. 上传数据给服务器 getSensorDataUpload(cloudTime) LogUtils.v("uploadSensorData ok") } else { - LogUtils.e("getVideoLastTime error code = ${lastTimeResponse.code}") + LogUtils.e("getVideoLastTime error code = ${lastTimeResponse?.code}") } uploadingGas.set(false) } @@ -132,7 +132,7 @@ class CloudActivity : NoOptionsActivity() { tempReqList.add(GasReqBean(it)) if (tempList.size == GAS_CLOUD_UPLOAD_SIZE_ONCE) { val response = devicesApi.uploadGasData(tempReqList) - if (response.isOk()) { + if (response?.isOk() == true) { val gasDao = DBUtils.gasDao() tempList.forEach { gas -> gas.syncFlag = true @@ -145,7 +145,7 @@ class CloudActivity : NoOptionsActivity() { } if (tempList.isNotEmpty()) { val response = devicesApi.uploadGasData(tempReqList) - if (response.isOk()) { + if (response?.isOk() == true) { val gasDao = DBUtils.gasDao() tempList.forEach { it.syncFlag = true