diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt index a8d1e7a..bc0002b 100644 --- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt @@ -24,14 +24,18 @@ import com.casic.br.ktd.extensions.toChineseAddress import com.casic.br.ktd.listener.OnGeocodeSearchListener import com.casic.br.ktd.model.DeviceListModel +import com.casic.br.ktd.model.TaskListModel import com.casic.br.ktd.model.VehicleListModel import com.casic.br.ktd.utils.LocaleConstant import com.casic.br.ktd.vm.DeviceViewModel +import com.casic.br.ktd.vm.TaskViewModel import com.casic.br.ktd.vm.VehicleViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton +import org.json.JSONObject class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt index a8d1e7a..bc0002b 100644 --- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt @@ -24,14 +24,18 @@ import com.casic.br.ktd.extensions.toChineseAddress import com.casic.br.ktd.listener.OnGeocodeSearchListener import com.casic.br.ktd.model.DeviceListModel +import com.casic.br.ktd.model.TaskListModel import com.casic.br.ktd.model.VehicleListModel import com.casic.br.ktd.utils.LocaleConstant import com.casic.br.ktd.vm.DeviceViewModel +import com.casic.br.ktd.vm.TaskViewModel import com.casic.br.ktd.vm.VehicleViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton +import org.json.JSONObject class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt index a8d1e7a..bc0002b 100644 --- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt @@ -24,14 +24,18 @@ import com.casic.br.ktd.extensions.toChineseAddress import com.casic.br.ktd.listener.OnGeocodeSearchListener import com.casic.br.ktd.model.DeviceListModel +import com.casic.br.ktd.model.TaskListModel import com.casic.br.ktd.model.VehicleListModel import com.casic.br.ktd.utils.LocaleConstant import com.casic.br.ktd.vm.DeviceViewModel +import com.casic.br.ktd.vm.TaskViewModel import com.casic.br.ktd.vm.VehicleViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton +import org.json.JSONObject class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - + (), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - + (), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - + (), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - + (), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - + (), AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, Handler.Callback { @@ -39,11 +43,14 @@ private val kTag = "HomePageFragment" private lateinit var vehicleViewModel: VehicleViewModel private lateinit var deviceViewModel: DeviceViewModel + private lateinit var taskViewModel: TaskViewModel private lateinit var aMap: AMap private lateinit var weakReferenceHandler: WeakReferenceHandler private var isInfoWindowShow = false + private var taskModels: MutableList = ArrayList() private val handlerVehicleCode = 2023082501 private val handlerDeviceCode = 2023082502 + private val handlerTaskCode = 2023082503 override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -89,6 +96,32 @@ weakReferenceHandler.sendMessage(message) } } + + taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java] + taskViewModel.getTasksByPage("", "", "", "", 1) + taskViewModel.taskList.observe(this) { + if (it.code == 200) { + taskModels = it.data.rows!! + taskModels.forEach { row -> + if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) { + val latLng = LatLng( + row.latitude.toDouble(), row.longitude.toDouble() + ) + + val hashMap = HashMap() + hashMap["type"] = "Task" + hashMap["id"] = row.id + + addMarker(latLng, hashMap.toJson(), R.mipmap.task_on) + } + } + } + } + + // val message = weakReferenceHandler.obtainMessage() +// message.what = handlerTaskCode +// message.obj = it +// weakReferenceHandler.sendMessage(message) } override fun handleMessage(msg: Message): Boolean { @@ -110,7 +143,11 @@ val latLng = LatLng( vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble() ) - addMarker(latLng, "Car", marker) + val hashMap = HashMap() + hashMap["type"] = "Car" + hashMap["id"] = vehicleModel.id + + addMarker(latLng, hashMap.toJson(), marker) /** * 地图PopupWindow数据绑定 @@ -140,6 +177,14 @@ deviceModelView.text = "云台型号:${deviceModel.deviceModel}" } } + + handlerTaskCode -> { + if (isInfoWindowShow) { + routeView.setOnClickListener { + + } + } + } } return true } @@ -161,6 +206,7 @@ private lateinit var deviceModelView: TextView private lateinit var timeView: TextView private lateinit var locationView: TextView + private lateinit var routeView: QMUIRoundButton override fun getInfoWindow(marker: Marker?): View { isInfoWindowShow = true @@ -174,21 +220,34 @@ deviceModelView = v.findViewById(R.id.deviceModelView) timeView = v.findViewById(R.id.timeView) locationView = v.findViewById(R.id.locationView) - val routeView = v.findViewById(R.id.routeView) + routeView = v.findViewById(R.id.routeView) - if (marker?.title == "Car") { - taskStateView.visibility = View.GONE - routeView.visibility = View.GONE + if (!marker?.snippet.isNullOrEmpty()) { + val hashMapJson = marker?.snippet!! + val jsonObject = JSONObject(hashMapJson) + val type = jsonObject.getString("type") + val id = jsonObject.getString("id") - vehicleViewModel.getVehicles() + if (type == "Car") { + taskStateView.visibility = View.GONE + routeView.visibility = View.GONE - deviceViewModel.getDevices() - } else { - taskStateView.visibility = View.VISIBLE - routeView.visibility = View.VISIBLE + vehicleViewModel.getVehicles() - routeView.setOnClickListener { + deviceViewModel.getDevices() + } else { + taskStateView.visibility = View.VISIBLE + routeView.visibility = View.VISIBLE + taskModels.forEach { task -> + if (task.id == id) { + windowTitleView.text = "${task.taskName}(${id})" + carStateView.text = "巡检车牌号:${task.carPlate}" + deviceModelView.text = "云台型号:${task.modelName}" + timeView.text = "开始时间:${task.beginDate}" + locationView.text = "结束时间:${task.endDate}" + } + } } } @@ -242,7 +301,7 @@ private fun addMarker(point: LatLng, type: String, res: Int) { val markerOption = MarkerOptions() markerOption.position(point) - markerOption.title(type) + markerOption.snippet(type) markerOption.icon(BitmapDescriptorFactory.fromResource(res)) aMap.addMarker(markerOption) } diff --git a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java index f6737bd..91e6cbb 100644 --- a/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java +++ b/app/src/main/java/com/casic/br/ktd/model/TaskListModel.java @@ -3,15 +3,16 @@ import java.util.List; public class TaskListModel { - private int code; + + private Integer code; private DataModel data; private String message; - public int getCode() { + public Integer getCode() { return code; } - public void setCode(int code) { + public void setCode(Integer code) { this.code = code; } @@ -33,7 +34,7 @@ public static class DataModel { private List rows; - private int total; + private Integer total; public List getRows() { return rows; @@ -43,24 +44,29 @@ this.rows = rows; } - public int getTotal() { + public Integer getTotal() { return total; } - public void setTotal(int total) { + public void setTotal(Integer total) { this.total = total; } public static class RowsModel { private String beginDate; private String carId; + private String carPlate; private String description; private String description1; private String description2; private String endDate; private String id; private String km; + private String latitude; + private String longitude; + private String modelName; private String status; + private String statusName; private String taskCode; private String taskName; private String ts; @@ -83,6 +89,14 @@ this.carId = carId; } + public String getCarPlate() { + return carPlate; + } + + public void setCarPlate(String carPlate) { + this.carPlate = carPlate; + } + public String getDescription() { return description; } @@ -131,6 +145,30 @@ this.km = km; } + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + public String getStatus() { return status; } @@ -139,6 +177,14 @@ this.status = status; } + public String getStatusName() { + return statusName; + } + + public void setStatusName(String statusName) { + this.statusName = statusName; + } + public String getTaskCode() { return taskCode; } diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml index b04d908..e0dbcae 100644 --- a/app/src/main/res/layout/popu_map_car_window.xml +++ b/app/src/main/res/layout/popu_map_car_window.xml @@ -7,24 +7,26 @@ android:orientation="vertical" android:padding="@dimen/dp_10"> - + + android:layout_width="0dp" + android:layout_weight="1" + android:text="@string/app_name" /> @@ -33,9 +35,8 @@ android:id="@+id/closeView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" android:src="@drawable/error" /> - +