diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index f654364..ced95b2 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -38,6 +38,7 @@ import com.amap.api.maps.model.LatLngBounds import com.amap.api.maps.model.MarkerOptions import com.amap.api.maps.model.MyLocationStyle +import com.amap.api.maps.model.PolylineOptions import com.casic.detector.R import com.casic.detector.adapter.EditableImageAdapter import com.casic.detector.base.SerialPortActivity @@ -73,6 +74,7 @@ import com.casic.detector.utils.LocaleConstant import com.casic.detector.utils.LocationHub import com.casic.detector.utils.RouteOnMap +import com.casic.detector.vm.PipelineViewModel import com.casic.detector.vm.TaskViewModel import com.casic.detector.widgets.MarkerDetailDialog import com.casic.detector.widgets.QueryMarkerDialog @@ -123,7 +125,7 @@ Handler.Callback { private val kTag = "MainActivity" - private val context = this@MainActivity + private val context = this private val samplePopupWindow by lazy { SamplePopupWindow(this) } private val gson by lazy { Gson() } private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(this) } @@ -318,7 +320,7 @@ //查看 binding.viewButton.setOnClickListener { - QueryMarkerDialog.Builder().setContext(context).setTitle("查看标识器") + QueryMarkerDialog.Builder().setContext(this).setTitle("查看标识器") .setSpinnerArray(LocaleConstant.SPINNER_ARRAY).setNegativeButton("取消") .setPositiveButton("确定").setOnDialogButtonClickListener(object : QueryMarkerDialog.OnDialogButtonClickListener { @@ -448,7 +450,7 @@ //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { @@ -456,6 +458,11 @@ isFreeTask = false soundPool.autoPause() + //停止信号和ID搜索定时器 + signalTask?.cancel() + energyTask?.cancel() + searchMarkerTimer?.cancel() + //降低串口电位 gpioManager.setGpioLow("18") @@ -589,7 +596,7 @@ if (installDialog.isInstallMarker) { installDialog.clearDefaultData() installDialog.dismiss() - "${installDialog.markerId}安装成功".show(context) + "${installDialog.markerId}安装成功".show(this) } if (searchDialog.isDetectMarker) { @@ -604,6 +611,8 @@ } } + private lateinit var lineViewModel: PipelineViewModel + private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) aMap = binding.mapView.map @@ -634,6 +643,48 @@ //首次移动到定位点 moveToCurrentLocation() + //TODO 加载管线数据 + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] +// lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + it.data.forEach { dot -> + val startLat = dot.startLatitudeGd + val startLng = dot.startLongitudeGd + val endLat = dot.endLatitudeGd + val endLng = dot.endLongitudeGd + if (!startLat.isNullOrBlank() && !startLng.isNullOrBlank() && !endLat.isNullOrBlank() && !endLng.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + startLat.toDouble(), startLng.toDouble() + ) && + CoordinateConverter.isAMapDataAvailable( + endLat.toDouble(), endLng.toDouble() + ) + ) { + //渲染管线 + lifecycleScope.launch(Dispatchers.IO) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + } + aMap.setOnMapLongClickListener { //协程异步显示默认数据 lifecycleScope.launch(Dispatchers.Main) { @@ -685,7 +736,7 @@ } } } - "工单下载成功!".show(context) + "工单下载成功!".show(this) } } @@ -704,9 +755,9 @@ } } - clusterOverlay = ClusterOverlay(context, aMap, clusterItems, regionRadius) + clusterOverlay = ClusterOverlay(this, aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> - val radius = 80.dp2px(context) + val radius = 80.dp2px(this) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { @@ -762,7 +813,7 @@ } if (item == null) { - "标识器经纬度异常".show(context) + "标识器经纬度异常".show(this) return@setOnClusterClickListener } @@ -1004,9 +1055,6 @@ override fun onDestroy() { super.onDestroy() binding.mapView.onDestroy() - signalTask?.cancel() - energyTask?.cancel() - searchMarkerTimer?.cancel() soundPool.release() locationHub.stopLocation() //降低串口电位 @@ -1014,7 +1062,7 @@ } /**安装标识器对话框******************************************************************************/ - inner class InstallMarkerDialog(context: Context) : Dialog(context) { + inner class InstallMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogInstallMarkerBinding by binding() private val calendar by lazy { Calendar.getInstance() } @@ -1479,7 +1527,7 @@ } /**探测标识器对话框******************************************************************************/ - inner class SearchMarkerDialog(context: Context) : Dialog(context) { + inner class SearchMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerBinding by binding() private val decimal by lazy { DecimalFormat("0.0") } @@ -1712,7 +1760,7 @@ } /**探测标识器新对话框****************************************************************************/ - inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + inner class SearchMarkerNewDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerNewBinding by binding() private var markerId = "" diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index f654364..ced95b2 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -38,6 +38,7 @@ import com.amap.api.maps.model.LatLngBounds import com.amap.api.maps.model.MarkerOptions import com.amap.api.maps.model.MyLocationStyle +import com.amap.api.maps.model.PolylineOptions import com.casic.detector.R import com.casic.detector.adapter.EditableImageAdapter import com.casic.detector.base.SerialPortActivity @@ -73,6 +74,7 @@ import com.casic.detector.utils.LocaleConstant import com.casic.detector.utils.LocationHub import com.casic.detector.utils.RouteOnMap +import com.casic.detector.vm.PipelineViewModel import com.casic.detector.vm.TaskViewModel import com.casic.detector.widgets.MarkerDetailDialog import com.casic.detector.widgets.QueryMarkerDialog @@ -123,7 +125,7 @@ Handler.Callback { private val kTag = "MainActivity" - private val context = this@MainActivity + private val context = this private val samplePopupWindow by lazy { SamplePopupWindow(this) } private val gson by lazy { Gson() } private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(this) } @@ -318,7 +320,7 @@ //查看 binding.viewButton.setOnClickListener { - QueryMarkerDialog.Builder().setContext(context).setTitle("查看标识器") + QueryMarkerDialog.Builder().setContext(this).setTitle("查看标识器") .setSpinnerArray(LocaleConstant.SPINNER_ARRAY).setNegativeButton("取消") .setPositiveButton("确定").setOnDialogButtonClickListener(object : QueryMarkerDialog.OnDialogButtonClickListener { @@ -448,7 +450,7 @@ //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { @@ -456,6 +458,11 @@ isFreeTask = false soundPool.autoPause() + //停止信号和ID搜索定时器 + signalTask?.cancel() + energyTask?.cancel() + searchMarkerTimer?.cancel() + //降低串口电位 gpioManager.setGpioLow("18") @@ -589,7 +596,7 @@ if (installDialog.isInstallMarker) { installDialog.clearDefaultData() installDialog.dismiss() - "${installDialog.markerId}安装成功".show(context) + "${installDialog.markerId}安装成功".show(this) } if (searchDialog.isDetectMarker) { @@ -604,6 +611,8 @@ } } + private lateinit var lineViewModel: PipelineViewModel + private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) aMap = binding.mapView.map @@ -634,6 +643,48 @@ //首次移动到定位点 moveToCurrentLocation() + //TODO 加载管线数据 + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] +// lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + it.data.forEach { dot -> + val startLat = dot.startLatitudeGd + val startLng = dot.startLongitudeGd + val endLat = dot.endLatitudeGd + val endLng = dot.endLongitudeGd + if (!startLat.isNullOrBlank() && !startLng.isNullOrBlank() && !endLat.isNullOrBlank() && !endLng.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + startLat.toDouble(), startLng.toDouble() + ) && + CoordinateConverter.isAMapDataAvailable( + endLat.toDouble(), endLng.toDouble() + ) + ) { + //渲染管线 + lifecycleScope.launch(Dispatchers.IO) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + } + aMap.setOnMapLongClickListener { //协程异步显示默认数据 lifecycleScope.launch(Dispatchers.Main) { @@ -685,7 +736,7 @@ } } } - "工单下载成功!".show(context) + "工单下载成功!".show(this) } } @@ -704,9 +755,9 @@ } } - clusterOverlay = ClusterOverlay(context, aMap, clusterItems, regionRadius) + clusterOverlay = ClusterOverlay(this, aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> - val radius = 80.dp2px(context) + val radius = 80.dp2px(this) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { @@ -762,7 +813,7 @@ } if (item == null) { - "标识器经纬度异常".show(context) + "标识器经纬度异常".show(this) return@setOnClusterClickListener } @@ -1004,9 +1055,6 @@ override fun onDestroy() { super.onDestroy() binding.mapView.onDestroy() - signalTask?.cancel() - energyTask?.cancel() - searchMarkerTimer?.cancel() soundPool.release() locationHub.stopLocation() //降低串口电位 @@ -1014,7 +1062,7 @@ } /**安装标识器对话框******************************************************************************/ - inner class InstallMarkerDialog(context: Context) : Dialog(context) { + inner class InstallMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogInstallMarkerBinding by binding() private val calendar by lazy { Calendar.getInstance() } @@ -1479,7 +1527,7 @@ } /**探测标识器对话框******************************************************************************/ - inner class SearchMarkerDialog(context: Context) : Dialog(context) { + inner class SearchMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerBinding by binding() private val decimal by lazy { DecimalFormat("0.0") } @@ -1712,7 +1760,7 @@ } /**探测标识器新对话框****************************************************************************/ - inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + inner class SearchMarkerNewDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerNewBinding by binding() private var markerId = "" diff --git a/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt new file mode 100644 index 0000000..9b9e839 --- /dev/null +++ b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt @@ -0,0 +1,35 @@ +package com.casic.detector.vm + +import android.content.Context +import androidx.lifecycle.MutableLiveData +import com.casic.detector.extensions.getResponseCode +import com.casic.detector.model.PipelineModel +import com.casic.detector.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.LoadState + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + loadState.value = LoadState.Success + } else { + loadState.value = LoadState.Fail + } + }, { + it.printStackTrace() + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index f654364..ced95b2 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -38,6 +38,7 @@ import com.amap.api.maps.model.LatLngBounds import com.amap.api.maps.model.MarkerOptions import com.amap.api.maps.model.MyLocationStyle +import com.amap.api.maps.model.PolylineOptions import com.casic.detector.R import com.casic.detector.adapter.EditableImageAdapter import com.casic.detector.base.SerialPortActivity @@ -73,6 +74,7 @@ import com.casic.detector.utils.LocaleConstant import com.casic.detector.utils.LocationHub import com.casic.detector.utils.RouteOnMap +import com.casic.detector.vm.PipelineViewModel import com.casic.detector.vm.TaskViewModel import com.casic.detector.widgets.MarkerDetailDialog import com.casic.detector.widgets.QueryMarkerDialog @@ -123,7 +125,7 @@ Handler.Callback { private val kTag = "MainActivity" - private val context = this@MainActivity + private val context = this private val samplePopupWindow by lazy { SamplePopupWindow(this) } private val gson by lazy { Gson() } private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(this) } @@ -318,7 +320,7 @@ //查看 binding.viewButton.setOnClickListener { - QueryMarkerDialog.Builder().setContext(context).setTitle("查看标识器") + QueryMarkerDialog.Builder().setContext(this).setTitle("查看标识器") .setSpinnerArray(LocaleConstant.SPINNER_ARRAY).setNegativeButton("取消") .setPositiveButton("确定").setOnDialogButtonClickListener(object : QueryMarkerDialog.OnDialogButtonClickListener { @@ -448,7 +450,7 @@ //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { @@ -456,6 +458,11 @@ isFreeTask = false soundPool.autoPause() + //停止信号和ID搜索定时器 + signalTask?.cancel() + energyTask?.cancel() + searchMarkerTimer?.cancel() + //降低串口电位 gpioManager.setGpioLow("18") @@ -589,7 +596,7 @@ if (installDialog.isInstallMarker) { installDialog.clearDefaultData() installDialog.dismiss() - "${installDialog.markerId}安装成功".show(context) + "${installDialog.markerId}安装成功".show(this) } if (searchDialog.isDetectMarker) { @@ -604,6 +611,8 @@ } } + private lateinit var lineViewModel: PipelineViewModel + private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) aMap = binding.mapView.map @@ -634,6 +643,48 @@ //首次移动到定位点 moveToCurrentLocation() + //TODO 加载管线数据 + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] +// lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + it.data.forEach { dot -> + val startLat = dot.startLatitudeGd + val startLng = dot.startLongitudeGd + val endLat = dot.endLatitudeGd + val endLng = dot.endLongitudeGd + if (!startLat.isNullOrBlank() && !startLng.isNullOrBlank() && !endLat.isNullOrBlank() && !endLng.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + startLat.toDouble(), startLng.toDouble() + ) && + CoordinateConverter.isAMapDataAvailable( + endLat.toDouble(), endLng.toDouble() + ) + ) { + //渲染管线 + lifecycleScope.launch(Dispatchers.IO) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + } + aMap.setOnMapLongClickListener { //协程异步显示默认数据 lifecycleScope.launch(Dispatchers.Main) { @@ -685,7 +736,7 @@ } } } - "工单下载成功!".show(context) + "工单下载成功!".show(this) } } @@ -704,9 +755,9 @@ } } - clusterOverlay = ClusterOverlay(context, aMap, clusterItems, regionRadius) + clusterOverlay = ClusterOverlay(this, aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> - val radius = 80.dp2px(context) + val radius = 80.dp2px(this) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { @@ -762,7 +813,7 @@ } if (item == null) { - "标识器经纬度异常".show(context) + "标识器经纬度异常".show(this) return@setOnClusterClickListener } @@ -1004,9 +1055,6 @@ override fun onDestroy() { super.onDestroy() binding.mapView.onDestroy() - signalTask?.cancel() - energyTask?.cancel() - searchMarkerTimer?.cancel() soundPool.release() locationHub.stopLocation() //降低串口电位 @@ -1014,7 +1062,7 @@ } /**安装标识器对话框******************************************************************************/ - inner class InstallMarkerDialog(context: Context) : Dialog(context) { + inner class InstallMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogInstallMarkerBinding by binding() private val calendar by lazy { Calendar.getInstance() } @@ -1479,7 +1527,7 @@ } /**探测标识器对话框******************************************************************************/ - inner class SearchMarkerDialog(context: Context) : Dialog(context) { + inner class SearchMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerBinding by binding() private val decimal by lazy { DecimalFormat("0.0") } @@ -1712,7 +1760,7 @@ } /**探测标识器新对话框****************************************************************************/ - inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + inner class SearchMarkerNewDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerNewBinding by binding() private var markerId = "" diff --git a/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt new file mode 100644 index 0000000..9b9e839 --- /dev/null +++ b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt @@ -0,0 +1,35 @@ +package com.casic.detector.vm + +import android.content.Context +import androidx.lifecycle.MutableLiveData +import com.casic.detector.extensions.getResponseCode +import com.casic.detector.model.PipelineModel +import com.casic.detector.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.LoadState + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + loadState.value = LoadState.Success + } else { + loadState.value = LoadState.Fail + } + }, { + it.printStackTrace() + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_more_white.xml b/app/src/main/res/drawable/ic_more_white.xml deleted file mode 100644 index da5378e..0000000 --- a/app/src/main/res/drawable/ic_more_white.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index f654364..ced95b2 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -38,6 +38,7 @@ import com.amap.api.maps.model.LatLngBounds import com.amap.api.maps.model.MarkerOptions import com.amap.api.maps.model.MyLocationStyle +import com.amap.api.maps.model.PolylineOptions import com.casic.detector.R import com.casic.detector.adapter.EditableImageAdapter import com.casic.detector.base.SerialPortActivity @@ -73,6 +74,7 @@ import com.casic.detector.utils.LocaleConstant import com.casic.detector.utils.LocationHub import com.casic.detector.utils.RouteOnMap +import com.casic.detector.vm.PipelineViewModel import com.casic.detector.vm.TaskViewModel import com.casic.detector.widgets.MarkerDetailDialog import com.casic.detector.widgets.QueryMarkerDialog @@ -123,7 +125,7 @@ Handler.Callback { private val kTag = "MainActivity" - private val context = this@MainActivity + private val context = this private val samplePopupWindow by lazy { SamplePopupWindow(this) } private val gson by lazy { Gson() } private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(this) } @@ -318,7 +320,7 @@ //查看 binding.viewButton.setOnClickListener { - QueryMarkerDialog.Builder().setContext(context).setTitle("查看标识器") + QueryMarkerDialog.Builder().setContext(this).setTitle("查看标识器") .setSpinnerArray(LocaleConstant.SPINNER_ARRAY).setNegativeButton("取消") .setPositiveButton("确定").setOnDialogButtonClickListener(object : QueryMarkerDialog.OnDialogButtonClickListener { @@ -448,7 +450,7 @@ //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { @@ -456,6 +458,11 @@ isFreeTask = false soundPool.autoPause() + //停止信号和ID搜索定时器 + signalTask?.cancel() + energyTask?.cancel() + searchMarkerTimer?.cancel() + //降低串口电位 gpioManager.setGpioLow("18") @@ -589,7 +596,7 @@ if (installDialog.isInstallMarker) { installDialog.clearDefaultData() installDialog.dismiss() - "${installDialog.markerId}安装成功".show(context) + "${installDialog.markerId}安装成功".show(this) } if (searchDialog.isDetectMarker) { @@ -604,6 +611,8 @@ } } + private lateinit var lineViewModel: PipelineViewModel + private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) aMap = binding.mapView.map @@ -634,6 +643,48 @@ //首次移动到定位点 moveToCurrentLocation() + //TODO 加载管线数据 + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] +// lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + it.data.forEach { dot -> + val startLat = dot.startLatitudeGd + val startLng = dot.startLongitudeGd + val endLat = dot.endLatitudeGd + val endLng = dot.endLongitudeGd + if (!startLat.isNullOrBlank() && !startLng.isNullOrBlank() && !endLat.isNullOrBlank() && !endLng.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + startLat.toDouble(), startLng.toDouble() + ) && + CoordinateConverter.isAMapDataAvailable( + endLat.toDouble(), endLng.toDouble() + ) + ) { + //渲染管线 + lifecycleScope.launch(Dispatchers.IO) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + } + aMap.setOnMapLongClickListener { //协程异步显示默认数据 lifecycleScope.launch(Dispatchers.Main) { @@ -685,7 +736,7 @@ } } } - "工单下载成功!".show(context) + "工单下载成功!".show(this) } } @@ -704,9 +755,9 @@ } } - clusterOverlay = ClusterOverlay(context, aMap, clusterItems, regionRadius) + clusterOverlay = ClusterOverlay(this, aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> - val radius = 80.dp2px(context) + val radius = 80.dp2px(this) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { @@ -762,7 +813,7 @@ } if (item == null) { - "标识器经纬度异常".show(context) + "标识器经纬度异常".show(this) return@setOnClusterClickListener } @@ -1004,9 +1055,6 @@ override fun onDestroy() { super.onDestroy() binding.mapView.onDestroy() - signalTask?.cancel() - energyTask?.cancel() - searchMarkerTimer?.cancel() soundPool.release() locationHub.stopLocation() //降低串口电位 @@ -1014,7 +1062,7 @@ } /**安装标识器对话框******************************************************************************/ - inner class InstallMarkerDialog(context: Context) : Dialog(context) { + inner class InstallMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogInstallMarkerBinding by binding() private val calendar by lazy { Calendar.getInstance() } @@ -1479,7 +1527,7 @@ } /**探测标识器对话框******************************************************************************/ - inner class SearchMarkerDialog(context: Context) : Dialog(context) { + inner class SearchMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerBinding by binding() private val decimal by lazy { DecimalFormat("0.0") } @@ -1712,7 +1760,7 @@ } /**探测标识器新对话框****************************************************************************/ - inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + inner class SearchMarkerNewDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerNewBinding by binding() private var markerId = "" diff --git a/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt new file mode 100644 index 0000000..9b9e839 --- /dev/null +++ b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt @@ -0,0 +1,35 @@ +package com.casic.detector.vm + +import android.content.Context +import androidx.lifecycle.MutableLiveData +import com.casic.detector.extensions.getResponseCode +import com.casic.detector.model.PipelineModel +import com.casic.detector.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.LoadState + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + loadState.value = LoadState.Success + } else { + loadState.value = LoadState.Fail + } + }, { + it.printStackTrace() + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_more_white.xml b/app/src/main/res/drawable/ic_more_white.xml deleted file mode 100644 index da5378e..0000000 --- a/app/src/main/res/drawable/ic_more_white.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_title_right.xml b/app/src/main/res/drawable/ic_title_right.xml new file mode 100644 index 0000000..5f18286 --- /dev/null +++ b/app/src/main/res/drawable/ic_title_right.xml @@ -0,0 +1,12 @@ + + + + diff --git a/.gitignore b/.gitignore index 7430070..e895293 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cmake-build-debug local.properties -/app/build \ No newline at end of file +/app/build +/app/release \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 419b327..975e3c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ applicationId "com.casic.detector" minSdkVersion 22 targetSdkVersion 33 - versionCode 5040 - versionName "5.0.4" + versionCode 5060 + versionName "5.0.6" ndk { moduleName "serial_port" diff --git a/app/src/main/java/com/casic/detector/extensions/String.kt b/app/src/main/java/com/casic/detector/extensions/String.kt index 785b89f..1493e1c 100644 --- a/app/src/main/java/com/casic/detector/extensions/String.kt +++ b/app/src/main/java/com/casic/detector/extensions/String.kt @@ -32,6 +32,15 @@ return jsonObject.get("message").asString } +fun String.getResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt +} + /** * 下载路径为 http://xx.com/static/ 拼接downloadUrl * */ diff --git a/app/src/main/java/com/casic/detector/model/PipelineModel.java b/app/src/main/java/com/casic/detector/model/PipelineModel.java new file mode 100644 index 0000000..774efa6 --- /dev/null +++ b/app/src/main/java/com/casic/detector/model/PipelineModel.java @@ -0,0 +1,91 @@ +package com.casic.detector.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private List data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; + + public String getEndLatitudeGd() { + return endLatitudeGd; + } + + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; + } + + public String getEndLongitudeGd() { + return endLongitudeGd; + } + + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; + } + + public String getPipeCode() { + return pipeCode; + } + + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } + + public String getStartLatitudeGd() { + return startLatitudeGd; + } + + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } + + public String getStartLongitudeGd() { + return startLongitudeGd; + } + + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; + } + } +} diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt index cae51d5..2be5e7b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitService.kt @@ -99,4 +99,10 @@ * */ @POST("ems/event/uploadAppMarker.do") suspend fun uploadTaskMarker(@Body requestBody: RequestBody): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/appList") + suspend fun getPipeline(): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt index ac06760..143fb8b 100644 --- a/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/detector/retrofit/RetrofitServiceManager.kt @@ -24,6 +24,13 @@ return RetrofitFactory.createRetrofit(httpConfig) } + private val api by lazy { + val defaultValue = SaveKeyValues.getValue( + LocaleConstant.PIPELINE_SERVER_CONFIG, LocaleConstant.PIPELINE_SERVER + ) as String + RetrofitFactory.createRetrofit(defaultValue) + } + /** * 登录 */ @@ -241,4 +248,11 @@ ) return createApi().uploadTaskMarker(requestBody) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline() + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt index 0f81928..f80138e 100644 --- a/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/detector/utils/LocaleConstant.kt @@ -27,6 +27,8 @@ const val SERVER_IP = "SERVER_IP" const val SERVER_PORT = "SERVER_PORT" const val APP_AUTHORITY = "com.casic.detector.fileprovider" + const val PIPELINE_SERVER_CONFIG = "PIPELINE_SERVER_CONFIG" + const val PIPELINE_SERVER = "http://60.208.121.150:5001" val POPUP_TITLES = arrayOf("更新数据", "下载工单", "关于软件", "事件上报", "标识器补全") var POINT_TYPE_ARRAY = arrayOf("管线", "管线附属物", "管线特征管点", "交叉穿越点") diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index f654364..ced95b2 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -38,6 +38,7 @@ import com.amap.api.maps.model.LatLngBounds import com.amap.api.maps.model.MarkerOptions import com.amap.api.maps.model.MyLocationStyle +import com.amap.api.maps.model.PolylineOptions import com.casic.detector.R import com.casic.detector.adapter.EditableImageAdapter import com.casic.detector.base.SerialPortActivity @@ -73,6 +74,7 @@ import com.casic.detector.utils.LocaleConstant import com.casic.detector.utils.LocationHub import com.casic.detector.utils.RouteOnMap +import com.casic.detector.vm.PipelineViewModel import com.casic.detector.vm.TaskViewModel import com.casic.detector.widgets.MarkerDetailDialog import com.casic.detector.widgets.QueryMarkerDialog @@ -123,7 +125,7 @@ Handler.Callback { private val kTag = "MainActivity" - private val context = this@MainActivity + private val context = this private val samplePopupWindow by lazy { SamplePopupWindow(this) } private val gson by lazy { Gson() } private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(this) } @@ -318,7 +320,7 @@ //查看 binding.viewButton.setOnClickListener { - QueryMarkerDialog.Builder().setContext(context).setTitle("查看标识器") + QueryMarkerDialog.Builder().setContext(this).setTitle("查看标识器") .setSpinnerArray(LocaleConstant.SPINNER_ARRAY).setNegativeButton("取消") .setPositiveButton("确定").setOnDialogButtonClickListener(object : QueryMarkerDialog.OnDialogButtonClickListener { @@ -448,7 +450,7 @@ //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { @@ -456,6 +458,11 @@ isFreeTask = false soundPool.autoPause() + //停止信号和ID搜索定时器 + signalTask?.cancel() + energyTask?.cancel() + searchMarkerTimer?.cancel() + //降低串口电位 gpioManager.setGpioLow("18") @@ -589,7 +596,7 @@ if (installDialog.isInstallMarker) { installDialog.clearDefaultData() installDialog.dismiss() - "${installDialog.markerId}安装成功".show(context) + "${installDialog.markerId}安装成功".show(this) } if (searchDialog.isDetectMarker) { @@ -604,6 +611,8 @@ } } + private lateinit var lineViewModel: PipelineViewModel + private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) aMap = binding.mapView.map @@ -634,6 +643,48 @@ //首次移动到定位点 moveToCurrentLocation() + //TODO 加载管线数据 + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] +// lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + it.data.forEach { dot -> + val startLat = dot.startLatitudeGd + val startLng = dot.startLongitudeGd + val endLat = dot.endLatitudeGd + val endLng = dot.endLongitudeGd + if (!startLat.isNullOrBlank() && !startLng.isNullOrBlank() && !endLat.isNullOrBlank() && !endLng.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + startLat.toDouble(), startLng.toDouble() + ) && + CoordinateConverter.isAMapDataAvailable( + endLat.toDouble(), endLng.toDouble() + ) + ) { + //渲染管线 + lifecycleScope.launch(Dispatchers.IO) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + } + aMap.setOnMapLongClickListener { //协程异步显示默认数据 lifecycleScope.launch(Dispatchers.Main) { @@ -685,7 +736,7 @@ } } } - "工单下载成功!".show(context) + "工单下载成功!".show(this) } } @@ -704,9 +755,9 @@ } } - clusterOverlay = ClusterOverlay(context, aMap, clusterItems, regionRadius) + clusterOverlay = ClusterOverlay(this, aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> - val radius = 80.dp2px(context) + val radius = 80.dp2px(this) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { @@ -762,7 +813,7 @@ } if (item == null) { - "标识器经纬度异常".show(context) + "标识器经纬度异常".show(this) return@setOnClusterClickListener } @@ -1004,9 +1055,6 @@ override fun onDestroy() { super.onDestroy() binding.mapView.onDestroy() - signalTask?.cancel() - energyTask?.cancel() - searchMarkerTimer?.cancel() soundPool.release() locationHub.stopLocation() //降低串口电位 @@ -1014,7 +1062,7 @@ } /**安装标识器对话框******************************************************************************/ - inner class InstallMarkerDialog(context: Context) : Dialog(context) { + inner class InstallMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogInstallMarkerBinding by binding() private val calendar by lazy { Calendar.getInstance() } @@ -1479,7 +1527,7 @@ } /**探测标识器对话框******************************************************************************/ - inner class SearchMarkerDialog(context: Context) : Dialog(context) { + inner class SearchMarkerDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerBinding by binding() private val decimal by lazy { DecimalFormat("0.0") } @@ -1712,7 +1760,7 @@ } /**探测标识器新对话框****************************************************************************/ - inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + inner class SearchMarkerNewDialog(private val context: Context) : Dialog(context) { private val binding: DialogSearchMarkerNewBinding by binding() private var markerId = "" diff --git a/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt new file mode 100644 index 0000000..9b9e839 --- /dev/null +++ b/app/src/main/java/com/casic/detector/vm/PipelineViewModel.kt @@ -0,0 +1,35 @@ +package com.casic.detector.vm + +import android.content.Context +import androidx.lifecycle.MutableLiveData +import com.casic.detector.extensions.getResponseCode +import com.casic.detector.model.PipelineModel +import com.casic.detector.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.LoadState + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + loadState.value = LoadState.Success + } else { + loadState.value = LoadState.Fail + } + }, { + it.printStackTrace() + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_more_white.xml b/app/src/main/res/drawable/ic_more_white.xml deleted file mode 100644 index da5378e..0000000 --- a/app/src/main/res/drawable/ic_more_white.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_title_right.xml b/app/src/main/res/drawable/ic_title_right.xml new file mode 100644 index 0000000..5f18286 --- /dev/null +++ b/app/src/main/res/drawable/ic_title_right.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ceb1e46..7cfbca5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -29,7 +29,7 @@ android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:paddingHorizontal="@dimen/dp_10" - android:src="@drawable/ic_more_white" /> + android:src="@drawable/ic_title_right" /> @@ -49,6 +50,7 @@ android:id="@+id/viewButton" style="@style/MainButtonStyle" android:layout_width="0dp" + android:layout_height="@dimen/dp_35" android:layout_marginHorizontal="@dimen/dp_5" android:layout_weight="1" android:text="查看" /> @@ -57,6 +59,7 @@ android:id="@+id/inspectionButton" style="@style/MainButtonStyle" android:layout_width="0dp" + android:layout_height="@dimen/dp_35" android:layout_weight="1" android:text="巡检" /> @@ -64,6 +67,7 @@ android:id="@+id/detectionButton" style="@style/MainButtonStyle" android:layout_width="0dp" + android:layout_height="@dimen/dp_35" android:layout_marginStart="@dimen/dp_5" android:layout_weight="1" android:text="探测" />