diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt index 28665a5b2c..c996b22223 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt @@ -5,7 +5,6 @@ import android.graphics.Bitmap import android.graphics.Point import android.graphics.drawable.Drawable import android.util.Log -import com.amap.api.maps.model.LatLng import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners import com.bumptech.glide.request.RequestOptions @@ -32,6 +31,7 @@ import com.mogo.eagle.core.utilcode.util.LocationUtils import com.mogo.eagle.core.utilcode.util.Md5Util import me.jessyan.autosize.utils.AutoSizeUtils import java.util.Locale +import java.util.concurrent.ConcurrentHashMap class TravelRealityModel private constructor() { @@ -47,6 +47,10 @@ class TravelRealityModel private constructor() { @Volatile private var liveKey = "" + private val targetMap by lazy { + ConcurrentHashMap() + } + companion object { val travelNetWorkModel by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { TravelRealityModel() @@ -80,9 +84,17 @@ class TravelRealityModel private constructor() { } } onSuccess { + if (eventKey.isEmpty()) { + Log.w("TravelRealityModel", "getEventsWithTrajRequest不处理onSuccess") + return@onSuccess + } onSuccess.invoke(it.data ?: ArrayList()) } onError { + if (eventKey.isEmpty()) { + Log.w("TravelRealityModel", "getEventsWithTrajRequest不处理onError") + return@onError + } onError.invoke(it.message ?: "") } } @@ -111,9 +123,17 @@ class TravelRealityModel private constructor() { } } onSuccess { + if (deviceKey.isEmpty()) { + Log.w("TravelRealityModel", "getCrossDevice不处理onSuccess") + return@onSuccess + } onSuccess.invoke(it.result ?: ArrayList()) } onError { + if (deviceKey.isEmpty()) { + Log.w("TravelRealityModel", "getCrossDevice不处理onError") + return@onError + } onError.invoke(it.message ?: "") } } @@ -121,18 +141,22 @@ class TravelRealityModel private constructor() { fun cancelAllRequest() { if (eventKey.isNotEmpty()) { + eventKey = "" cancel(eventKey) } if (deviceKey.isNotEmpty()) { + deviceKey = "" cancel(deviceKey) } if (trackKey.isNotEmpty()) { + trackKey = "" cancel(trackKey) } if (liveKey.isNotEmpty()) { + liveKey = "" cancel(liveKey) } - cancelDownload() + clearDownload() } /** @@ -191,9 +215,17 @@ class TravelRealityModel private constructor() { } } onSuccess { + if (trackKey.isEmpty()) { + Log.w("TravelRealityModel", "getCityRoadTrack不处理onSuccess") + return@onSuccess + } onSuccess.invoke(it.result) } onError { + if (trackKey.isEmpty()) { + Log.w("TravelRealityModel", "getCityRoadTrack不处理onError") + return@onError + } onError.invoke(it.message ?: "") } } @@ -226,9 +258,17 @@ class TravelRealityModel private constructor() { } } onSuccess { + if (liveKey.isEmpty()) { + Log.w("TravelRealityModel", "batchRequestCrossLive不处理onSuccess") + return@onSuccess + } onSuccess.invoke(it.result) } onError { + if (liveKey.isEmpty()) { + Log.w("TravelRealityModel", "batchRequestCrossLive不处理onError") + return@onError + } onError.invoke(it.message.toString()) } } @@ -237,34 +277,45 @@ class TravelRealityModel private constructor() { fun downloadImage( context: Context, url: String?, videoMarkerList: MutableList, - lineId: Long, - onSuccess: ((Bitmap, MutableList, Long) -> Unit), - onFailed: ((MutableList, Long) -> Unit) + onSuccess: ((Bitmap, MutableList) -> Unit), + onFailed: ((MutableList) -> Unit) ) { if (url.isNullOrEmpty()) return + Log.d("TravelRealityModel", "下载缩略图!") val radiusPx = AutoSizeUtils.dp2px(context, 24f).toFloat() val options = RequestOptions().transform( GranularRoundedCorners(radiusPx, radiusPx, 0f, 0f) ) + val target = object : CustomTarget() { + override fun onResourceReady(resource: Bitmap, transition: Transition?) { + if (!targetMap.containsKey("CustomTarget_${this.hashCode()}")) { + Log.w("TravelRealityModel", "downloadImage不处理onResourceReady") + return + } + onSuccess(resource, videoMarkerList) + } + + override fun onLoadCleared(placeholder: Drawable?) {} + + override fun onLoadFailed(errorDrawable: Drawable?) { + super.onLoadFailed(errorDrawable) + if (!targetMap.containsKey("CustomTarget_${this.hashCode()}")) { + Log.w("TravelRealityModel", "downloadImage不处理onLoadFailed") + return + } + onFailed(videoMarkerList) + } + } + targetMap["CustomTarget_${target.hashCode()}"] = 1 Glide.with(context).asBitmap() .apply(options) .load(url) - .into(object : CustomTarget() { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - onSuccess(resource, videoMarkerList, lineId) - } - - override fun onLoadCleared(placeholder: Drawable?) {} - - override fun onLoadFailed(errorDrawable: Drawable?) { - super.onLoadFailed(errorDrawable) - onFailed(videoMarkerList, lineId) - } - }) + .into(target) } - private fun cancelDownload() { - + private fun clearDownload() { + Log.w("TravelRealityModel", "clearDownload") + targetMap.clear() } /** diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt index 6a19f0286e..ae49cbf778 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt @@ -753,9 +753,7 @@ class TravelRealityView @JvmOverloads constructor( context, url, videoList, - CallerAutoPilotStatusListenerManager.getLineId(), - onSuccess = { bitmap, videoMarkerList, lineId -> -// if (CallerAutoPilotStatusListenerManager.getLineId() != 0L) { + onSuccess = { bitmap, videoMarkerList -> val optionList = ArrayList() var view: EventVideoView videoMarkerList.forEach { videoEntity -> @@ -772,12 +770,8 @@ class TravelRealityView @JvmOverloads constructor( }) } updateVideoMarker(optionList) -// } else { -// Log.w(TAG, "downloadImage:onSuccess:lineId为0!") -// } }, - onFailed = { videoMarkerList, lineId -> -// if (CallerAutoPilotStatusListenerManager.getLineId() != 0L) { + onFailed = { videoMarkerList -> val optionList = ArrayList() var view: EventVideoView videoMarkerList.forEach { videoEntity -> @@ -795,9 +789,6 @@ class TravelRealityView @JvmOverloads constructor( } updateVideoMarker(optionList) -// } else { -// Log.w(TAG, "downloadImage:onFailed:lineId为0!") -// } }) } @@ -1543,6 +1534,9 @@ class TravelRealityView @JvmOverloads constructor( deviceMarkerList.clear() } + /** + * 绘制在智慧道路范围内的轨迹 + */ private fun realDrawGlobalTrajectory(polylineOptionsList: ArrayList) { Log.d(TAG, "realDrawGlobalTrajectory") if (globalPolylineList.isNotEmpty() && globalPolylineList.size != polylineOptionsList.size) { @@ -1570,6 +1564,9 @@ class TravelRealityView @JvmOverloads constructor( } } + /** + * 绘制智慧道路范围(和全局轨迹匹配过的) + */ private fun realDrawRoadTrajectory(polylineOptionsList: ArrayList) { Log.d(TAG, "realDrawRoadTrajectory") if (trajectoryPolylineList.isNotEmpty() && trajectoryPolylineList.size != polylineOptionsList.size) {