diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 690c5f4..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,8 +1,6 @@ - - - + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 690c5f4..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,8 +1,6 @@ - - - + \ No newline at end of file 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 9640889..40ba172 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -1,6 +1,5 @@ package com.casic.detector.view -import android.annotation.SuppressLint import android.app.DatePickerDialog import android.app.Dialog import android.content.Context @@ -38,7 +37,6 @@ 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 @@ -120,7 +118,6 @@ import java.util.Timer import java.util.TimerTask -@SuppressLint("all") class MainActivity : SerialPortActivity(), SensorEventListener, Handler.Callback { @@ -134,6 +131,7 @@ private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private val detailDialog by lazy { MarkerDetailDialog(this) } + private val lineViewModel by lazy { ViewModelProvider(this)[PipelineViewModel::class.java] } private val sensorMessageCode = 2024022301 private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 private val valueArray = FloatArray(3)//方位角数值 @@ -155,7 +153,6 @@ private lateinit var sensorManager: SensorManager private lateinit var weakReferenceHandler: WeakReferenceHandler - /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } @@ -239,7 +236,7 @@ .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - saveTaskInformation(it) + saveTask(it) } }).build().show() } @@ -258,6 +255,53 @@ aMap.clear() showLabelsOnMap() } + + //缓存管线数据 +// 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) { +// DataBaseManager.get.insertMapPipeCache(dot) +// } +// } +// } +// } +// } +// } + + //渲染管线 +// lifecycleScope.launch(Dispatchers.IO) { +// //取Pipe缓存 +// DataBaseManager.get.loadMapPipeCache().forEach { dot -> +// //瞄点画线 +// 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)) +// } +// } } override fun initEvent() { @@ -339,18 +383,16 @@ val latitudeList = ArrayList() val longitudeList = ArrayList() - labelBeans.forEach { - val latitude = it.lat - val longitude = it.lng - if (latitude.isNotBlank() && longitude.isNotBlank()) { - if (CoordinateConverter.isAMapDataAvailable( - latitude.toDouble(), longitude.toDouble() - ) - ) { - //分别缓存经、纬度 - latitudeList.add(latitude.toDouble()) - longitudeList.add(longitude.toDouble()) - } + val latitude = labelBeans.first().lat + val longitude = labelBeans.first().lng + if (latitude.isNotBlank() && longitude.isNotBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + latitude.toDouble(), longitude.toDouble() + ) + ) { + //分别缓存经、纬度 + latitudeList.add(latitude.toDouble()) + longitudeList.add(longitude.toDouble()) } } @@ -481,6 +523,15 @@ } } + private fun uploadTask(taskId: String?, state: String) { + if (isNetworkConnected()) { + val userId = SaveKeyValues.getValue(LocaleConstant.USER_ID, "") as String + taskViewModel.uploadTask(this, userId, taskId, state) + } else { + "网络连接已断开,请检查".show(this) + } + } + private fun startFreeTask() { AlertInputDialog.Builder().setContext(this).setTitle("新建自由巡检任务") .setHintMessage("请输入自由巡检任务简要描述").setNegativeButton("取消") @@ -614,9 +665,35 @@ } } } - } - private lateinit var lineViewModel: PipelineViewModel +// lineViewModel.loadState.observe(this) { +// when (it) { +// is LoadState.Loading -> LoadingDialogHub.show(this, "数据更新中,请稍后") +// +// is LoadState.Fail -> { +// LoadingDialogHub.dismiss() +// "数据更新超时".show(this) +// } +// +// else -> { +// LoadingDialogHub.dismiss() +// AlertControlDialog.Builder().setContext(this).setTitle("温馨提示") +// .setMessage("数据更新成功,请重启应用").setNegativeButton("取消") +// .setPositiveButton("确定").setOnDialogButtonClickListener(object : +// AlertControlDialog.OnDialogButtonClickListener { +// override fun onConfirmClick() { +// finish() +// } +// +// override fun onCancelClick() { +// +// } +// }).build().show() +// +// } +// } +// } + } private fun initMapConfig(savedInstanceState: Bundle?) { binding.mapView.onCreate(savedInstanceState) @@ -648,48 +725,6 @@ //首次移动到定位点 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) { @@ -720,29 +755,27 @@ }) } - private fun saveTaskInformation(it: TaskModel) { + private fun saveTask(task: TaskModel) { val userName = SaveKeyValues.getValue(LocaleConstant.USER_NAME, "") as String - if (it.message.size > 0) { - it.message.forEach { messageModel -> - val count = DataBaseManager.get.countTaskById(messageModel.id.toString()) - if (count == 0) { - messageModel.taskDetailInfos.forEach { info -> - DataBaseManager.get.insertTaskInformation( - userName, - messageModel.description, - info.taskId.toString(), - info.id.toString(), - info.markerId.toString(), - info.markerIdReal.toString(), - info.longitude.toString(), - info.latitude.toString(), - messageModel.status - ) - } + task.message.forEach { model -> + model.taskDetailInfos.forEach { info -> + //只保存有b标识器ID得数据 + if (!info.markerIdReal.isNullOrBlank()) { + DataBaseManager.get.insertTask( + userName, + model.description, + info.taskId.toString(), + info.id.toString(), + info.markerId.toString(), + info.markerIdReal.toString(), + info.longitude.toString(), + info.latitude.toString(), + model.status + ) } } - "工单下载成功!".show(this) } + "工单下载成功!".show(this) } private fun showLabelsOnMap() { @@ -874,16 +907,27 @@ showLabelsOnMap() } - private fun uploadTask(taskId: String?, state: String) { - if (isNetworkConnected()) { - val userId = SaveKeyValues.getValue(LocaleConstant.USER_ID, "") as String - taskViewModel.uploadTask(this, userId, taskId, state) - } else { - "网络连接已断开,请检查".show(this) - } - } + //更新管线数据 +// private fun updatePipeline() { +// AlertControlDialog.Builder().setContext(this).setTitle("提示").setMessage("是否更新数据?") +// .setNegativeButton("取消").setPositiveButton("确定") +// .setOnDialogButtonClickListener(object : +// AlertControlDialog.OnDialogButtonClickListener { +// override fun onConfirmClick() { +// if (isNetworkConnected()) { +// lineViewModel.getPipeline() +// } else { +// "网络连接已断开,请检查".show(context) +// } +// } +// +// override fun onCancelClick() { +// +// } +// }).build().show() +// } - //更新数据 + //更新标识器数据 private fun updateLabels() { AlertControlDialog.Builder().setContext(this).setTitle("提示").setMessage("是否更新数据?") .setNegativeButton("取消").setPositiveButton("确定") @@ -1862,8 +1906,7 @@ } withContext(Dispatchers.Main) { binding.radarScanView.renderPointData( - dataPoints, - object : RadarScanView.OnGetNearestPointCallback { + dataPoints, object : RadarScanView.OnGetNearestPointCallback { override fun getNearestPoint(point: RadarScanView.DataPoint?) { if (point == null) { binding.distanceValueView.text = "大于550cm"