[Fix]解决lineId未赋值时不进行请求的问题

This commit is contained in:
chenfufeng
2022-12-28 13:56:40 +08:00
parent 609afa2c14
commit d5cdbed9fb
2 changed files with 33 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ package com.mogo.eagle.core.function.overview.vm
import androidx.lifecycle.*
import com.mogo.commons.constants.HostConst
import com.mogo.eagle.core.data.map.Infrastructure
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo
import com.mogo.eagle.core.function.overview.OverviewDao
import com.mogo.eagle.core.function.overview.remote.OverViewServiceApi
import com.mogo.eagle.core.function.overview.remote.V2XEvent
@@ -74,23 +75,29 @@ class OverViewModel(
}
}
fun getAllV2XEventsByLineId(lineId: String, sn: String) {
fun getAllV2XEventsByLineId(sn: String) {
if (disposable != null && !disposable!!.isDisposed) {
disposable!!.dispose()
}
// 1分钟查询一次
disposable = Observable.interval(0, 60000, TimeUnit.MILLISECONDS)
disposable = Observable.interval(2000, 60000, TimeUnit.MILLISECONDS)
.flatMap {
MoGoRetrofitFactory.getInstance(HostConst.getHost())
.create(OverViewServiceApi::class.java)
.queryAllV2XEventsByLineId(lineId, sn)
.map {
if (it.code == 200 || it.code == 0) {
return@map it.result?.v2XEventList
} else {
return@map null
val lineId = getLineId()
if (lineId > 0) {
MoGoRetrofitFactory.getInstance(HostConst.getHost())
.create(OverViewServiceApi::class.java)
.queryAllV2XEventsByLineId(lineId.toString(), sn)
.map {
if (it.code == 200 || it.code == 0) {
return@map it.result?.v2XEventList
} else {
return@map ArrayList()
}
}
}
} else {
Observable.just(ArrayList())
}
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@@ -106,4 +113,16 @@ class OverViewModel(
fun stopQueryV2XEvents() {
disposable?.dispose()
}
private fun getLineId(): Long {
var lineId: Long = -1
val parameter = getAutoPilotStatusInfo()
.autopilotControlParameters
if (parameter != null) {
if (parameter.autoPilotLine != null) {
lineId = parameter.autoPilotLine!!.lineId
}
}
return lineId
}
}

View File

@@ -2,7 +2,6 @@ package com.mogo.eagle.core.function.smp;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import androidx.annotation.Nullable;
@@ -21,7 +20,6 @@ import com.mogo.eagle.core.function.map.R;
import com.mogo.eagle.core.function.overview.InfStructureManager;
import com.mogo.eagle.core.function.overview.ViewModelExtKt;
import com.mogo.eagle.core.function.overview.vm.OverViewModel;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import java.util.List;
@@ -81,9 +79,8 @@ public class OverviewMapFragment extends BaseFragment
@Override
public void startQueryV2XEvents() {
if (isAdded()) {
long lineId = getLineId();
if (lineId > 0 && mViewModel != null) {
mViewModel.getAllV2XEventsByLineId("" + lineId, MoGoAiCloudClientConfig.getInstance().getSn());
if (mViewModel != null) {
mViewModel.getAllV2XEventsByLineId(MoGoAiCloudClientConfig.getInstance().getSn());
}
}
}
@@ -130,11 +127,7 @@ public class OverviewMapFragment extends BaseFragment
mViewModel.getV2XEventLiveData().observe(this.getViewLifecycleOwner(), v2XEvents -> {
mAMapCustomView.showV2XEventMarkers(v2XEvents);
});
long lineId = getLineId();
if (lineId > 0) {
mViewModel.getAllV2XEventsByLineId("" + lineId, MoGoAiCloudClientConfig.getInstance().getSn());
}
mViewModel.getAllV2XEventsByLineId(MoGoAiCloudClientConfig.getInstance().getSn());
}
/**