[6.5.0][Fix]优化偶现的事件、卡片不清除的逻辑

This commit is contained in:
chenfufeng
2024-07-25 12:09:59 +08:00
parent 2c86d8ef6b
commit a332f0f37a
2 changed files with 78 additions and 30 deletions

View File

@@ -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<String, Int>()
}
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<VideoMarkerEntity>,
lineId: Long,
onSuccess: ((Bitmap, MutableList<VideoMarkerEntity>, Long) -> Unit),
onFailed: ((MutableList<VideoMarkerEntity>, Long) -> Unit)
onSuccess: ((Bitmap, MutableList<VideoMarkerEntity>) -> Unit),
onFailed: ((MutableList<VideoMarkerEntity>) -> 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<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
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<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
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()
}
/**

View File

@@ -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<MarkerOptions>()
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<MarkerOptions>()
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<PolylineOptions>) {
Log.d(TAG, "realDrawGlobalTrajectory")
if (globalPolylineList.isNotEmpty() && globalPolylineList.size != polylineOptionsList.size) {
@@ -1570,6 +1564,9 @@ class TravelRealityView @JvmOverloads constructor(
}
}
/**
* 绘制智慧道路范围(和全局轨迹匹配过的)
*/
private fun realDrawRoadTrajectory(polylineOptionsList: ArrayList<PolylineOptions>) {
Log.d(TAG, "realDrawRoadTrajectory")
if (trajectoryPolylineList.isNotEmpty() && trajectoryPolylineList.size != polylineOptionsList.size) {