[bugfix]
[到站后停止路距计算、结束UI回写]
This commit is contained in:
@@ -190,7 +190,7 @@ public class BusPassengerModel {
|
||||
mNextStationIndex = 0;
|
||||
}
|
||||
|
||||
startOrStopCalculateRouteInfo(false);
|
||||
cleanStation();
|
||||
|
||||
if (mRouteLineInfoCallback != null) {
|
||||
mRouteLineInfoCallback.showNoTaskView();
|
||||
@@ -221,7 +221,7 @@ public class BusPassengerModel {
|
||||
}
|
||||
if (code == 1003) {
|
||||
routesResult = null;
|
||||
startOrStopCalculateRouteInfo(false);
|
||||
cleanStation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -242,22 +242,18 @@ public class BusPassengerModel {
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations, i + 1, false);
|
||||
if (mNextStationIndex != i + 1) {
|
||||
mTwoStationsRouts.clear();
|
||||
startRemainRouteInfo();
|
||||
BusPassengerStation startStation = mStations.get(i);
|
||||
BusPassengerStation endStation = mStations.get(i+1);
|
||||
setTrajectoryStation(startStation,endStation,result.getLineId());
|
||||
}
|
||||
mNextStationIndex = i + 1;
|
||||
|
||||
BusPassengerStation startStation = mStations.get(i);
|
||||
BusPassengerStation endStation = mStations.get(mNextStationIndex);
|
||||
|
||||
setTrajectoryStation(startStation,endStation,result.getLineId());
|
||||
|
||||
updateAutopilotControlParameters(result, i);
|
||||
return;
|
||||
} else if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()) { //到站
|
||||
if(i==stations.size()-1){
|
||||
cleanStation();
|
||||
}
|
||||
startOrStopCalculateRouteInfo(false);
|
||||
TrajectoryAndDistanceManager.INSTANCE.suspendCalculate();
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations, i, true);
|
||||
clearAutopilotControlParameters();
|
||||
return;
|
||||
@@ -324,7 +320,7 @@ public class BusPassengerModel {
|
||||
|
||||
public void release() {
|
||||
releaseListeners();
|
||||
startOrStopCalculateRouteInfo(false);
|
||||
cleanStation();
|
||||
startOrStopOrderLoop(false);
|
||||
}
|
||||
|
||||
@@ -390,6 +386,13 @@ public class BusPassengerModel {
|
||||
private final IDistanceListener distanceListener = distance -> {
|
||||
double lastTime = distance / getAverageSpeed() * 3.6; //秒
|
||||
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = " + distance);
|
||||
|
||||
for (BusPassengerStation site : routesResult.getSites()) {
|
||||
if (site.getDrivingStatus() == STATION_STATUS_STOPPED && !site.isLeaving()){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mAutopilotPlanningCallback != null) {
|
||||
mAutopilotPlanningCallback.routePlanningToNextStationChanged((long) distance, (long) lastTime);
|
||||
}
|
||||
@@ -592,111 +595,10 @@ public class BusPassengerModel {
|
||||
}
|
||||
}
|
||||
|
||||
public void dynamicCalculateRouteInfo() {
|
||||
// //计算当前位置和下一站的剩余点集合
|
||||
// //计算剩余点总里程和时间
|
||||
// if (mTwoStationsRouts.size() == 0) {
|
||||
// calculateTwoStationsRoute();
|
||||
// }
|
||||
// if (mTwoStationsRouts.size() > 0 && mLocation != null) {
|
||||
// Map<Integer, List<MogoLocation>> lastPointsMap = CoordinateCalculateRouteUtil
|
||||
// .getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation);
|
||||
// if(lastPointsMap==null){
|
||||
// return;
|
||||
// }
|
||||
// for (int index : lastPointsMap.keySet()) {
|
||||
// mPreRouteIndex = index;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// for (List<MogoLocation> lastPoints : lastPointsMap.values()) {
|
||||
// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastPoints.size() = " + lastPoints.size());
|
||||
// float lastSumLength = 0;
|
||||
// if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离
|
||||
// if (mNextStationIndex <= mStations.size() - 1 && mNextStationIndex >= 0) {
|
||||
// BusPassengerStation stationNext = mStations.get(mNextStationIndex);
|
||||
// lastSumLength = CoordinateUtils.calculateLineDistance(
|
||||
// stationNext.getGcjLon(), stationNext.getGcjLat(),
|
||||
// mLocation.getLongitude(), mLocation.getLatitude());
|
||||
// } else {
|
||||
// lastSumLength = CoordinateUtils.calculateLineDistance(
|
||||
// lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(),
|
||||
// mLocation.getLongitude(), mLocation.getLatitude());
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
|
||||
// }
|
||||
//
|
||||
// double lastTime = lastSumLength / getAverageSpeed() * 3.6; //秒
|
||||
// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = " + lastSumLength);
|
||||
// if (mAutopilotPlanningCallback != null) {
|
||||
// mAutopilotPlanningCallback.routePlanningToNextStationChanged((long) lastSumLength, (long) lastTime);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public int getAverageSpeed() {
|
||||
return BusPassengerConst.BUS_AVERAGE_SPEED;
|
||||
}
|
||||
|
||||
public void startRemainRouteInfo() {
|
||||
//开启实时计算剩余距离,剩余时间,预计时间
|
||||
startOrStopCalculateRouteInfo(true);
|
||||
}
|
||||
|
||||
// public void startToRouteAndWipe() {
|
||||
// startOrStopRouteAndWipe(true);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 实时轨迹擦除
|
||||
*
|
||||
// * @param isStart
|
||||
*/
|
||||
// public void startOrStopRouteAndWipe(boolean isStart) {
|
||||
// if (isStart) {
|
||||
// BusPassengerModelLoopManager.getInstance().startOrStopRouteAndWipe();
|
||||
// } else {
|
||||
// mWipePreIndex = 0;
|
||||
// BusPassengerModelLoopManager.getInstance().stopOrStopRouteAndWipe();
|
||||
// }
|
||||
// }
|
||||
|
||||
public void loopRouteAndWipe() {
|
||||
// if (mRoutePoints != null && mRoutePoints.size() > 0 && mLocation != null) {
|
||||
// int haveArrivedIndex = CoordinateCalculateRouteUtil
|
||||
// .getArrivedPointIndexNew(mWipePreIndex,
|
||||
// mRoutePoints,
|
||||
// mLocation);
|
||||
//
|
||||
// mWipePreIndex = haveArrivedIndex;
|
||||
//
|
||||
// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "thread = " + Thread.currentThread().getName() + " haveArrivedIndex== " + haveArrivedIndex);
|
||||
// if (mAutopilotPlanningCallback != null) {
|
||||
// List<LatLng> routePoints = CoordinateCalculateRouteUtil
|
||||
// .coordinateConverterLocationToLatLng(mContext, mRoutePoints);
|
||||
// mAutopilotPlanningCallback.routeResult(routePoints, haveArrivedIndex);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始轮询计算剩余里程和时间
|
||||
*
|
||||
* @param isStart
|
||||
*/
|
||||
public void startOrStopCalculateRouteInfo(boolean isStart) {
|
||||
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "startOrStopCalculateRouteInfo() " + isStart);
|
||||
if (isStart) {
|
||||
BusPassengerModelLoopManager.getInstance().startCalculateRouteInfoLoop();
|
||||
} else {
|
||||
mTwoStationsRouts.clear();
|
||||
BusPassengerModelLoopManager.getInstance().stopCalculateRouteInfLoop();
|
||||
}
|
||||
}
|
||||
|
||||
private void startOrStopOrderLoop(boolean start) {
|
||||
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "startOrStopOrderLoop() " + start);
|
||||
if (start) {
|
||||
|
||||
@@ -37,45 +37,6 @@ public class BusPassengerModelLoopManager {
|
||||
}
|
||||
|
||||
private Disposable mQueryLineDisposable; //心跳轮询
|
||||
private CompositeDisposable mRouteWipeDisposable;
|
||||
private CompositeDisposable mCalculateRouteDisposable; //每隔2s计算一次剩余里程和时间
|
||||
|
||||
public void startOrStopRouteAndWipe() {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startOrStopRouteWipe()");
|
||||
if (mRouteWipeDisposable != null) return;
|
||||
if (mRouteWipeDisposable == null){
|
||||
mRouteWipeDisposable = new CompositeDisposable();
|
||||
}
|
||||
Disposable disposable = startLoopRouteAndWipe()
|
||||
.doOnSubscribe(new Consumer<Disposable>() {
|
||||
@Override
|
||||
public void accept(Disposable disposable) throws Exception {
|
||||
}
|
||||
})
|
||||
.doOnError(new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
}
|
||||
})
|
||||
.delay(LOOP_LINE_1S, TimeUnit.MILLISECONDS, true) // 设置delayError为true,表示出现错误的时候也需要延迟5s进行通知,达到无论是请求正常还是请求失败,都是5s后重新订阅,即重新请求。
|
||||
.subscribeOn(Schedulers.io())
|
||||
.repeat() // repeat保证请求成功后能够重新订阅。
|
||||
.retry() // retry保证请求失败后能重新订阅
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer integer) throws Exception {
|
||||
}
|
||||
});
|
||||
mRouteWipeDisposable.add(disposable);
|
||||
}
|
||||
|
||||
public void stopOrStopRouteAndWipe() {
|
||||
if (mRouteWipeDisposable != null) {
|
||||
mRouteWipeDisposable.dispose();
|
||||
mRouteWipeDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startQueryDriverLineLoop() {
|
||||
if (mQueryLineDisposable != null && !mQueryLineDisposable.isDisposed()) {
|
||||
@@ -98,63 +59,4 @@ public class BusPassengerModelLoopManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void startCalculateRouteInfoLoop() {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startCalculateRouteInfoLoop()");
|
||||
if (mCalculateRouteDisposable != null) return;
|
||||
if (mCalculateRouteDisposable == null){
|
||||
mCalculateRouteDisposable = new CompositeDisposable();
|
||||
}
|
||||
Disposable disposable = startLoopCalculateRouteInfo()
|
||||
.doOnSubscribe(new Consumer<Disposable>() {
|
||||
@Override
|
||||
public void accept(Disposable disposable) throws Exception {
|
||||
}
|
||||
})
|
||||
.doOnError(new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
}
|
||||
})
|
||||
.delay(LOOP_LINE_2S, TimeUnit.MILLISECONDS, true) // 设置delayError为true,表示出现错误的时候也需要延迟5s进行通知,达到无论是请求正常还是请求失败,都是5s后重新订阅,即重新请求。
|
||||
.subscribeOn(Schedulers.io())
|
||||
.repeat() // repeat保证请求成功后能够重新订阅。
|
||||
.retry() // retry保证请求失败后能重新订阅
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer integer) throws Exception {
|
||||
}
|
||||
});
|
||||
mCalculateRouteDisposable.add(disposable);
|
||||
}
|
||||
|
||||
public void stopCalculateRouteInfLoop() {
|
||||
if (mCalculateRouteDisposable != null) {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "stopCalculateRouteInfLoop()");
|
||||
mCalculateRouteDisposable.dispose();
|
||||
mCalculateRouteDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Observable<Integer> startLoopRouteAndWipe(){
|
||||
return Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
|
||||
if (emitter.isDisposed()) return;
|
||||
BusPassengerModel.getInstance().loopRouteAndWipe();
|
||||
emitter.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Observable<Integer> startLoopCalculateRouteInfo(){
|
||||
return Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
|
||||
if (emitter.isDisposed()) return;
|
||||
BusPassengerModel.getInstance().dynamicCalculateRouteInfo();
|
||||
emitter.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ public class BPRouteDataTestUtils {
|
||||
list.add(builder.build());
|
||||
}
|
||||
BusPassengerModel.getInstance().updateRoutePoints(list);
|
||||
BusPassengerModel.getInstance().startRemainRouteInfo();
|
||||
//BusPassengerModel.getInstance().startToRouteAndWipe();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -171,6 +171,17 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停路距计算
|
||||
*/
|
||||
fun suspendCalculate(){
|
||||
endCalculateDistanceLoop()
|
||||
}
|
||||
|
||||
fun reStartCalculate(){
|
||||
startCalculateDistanceLoop()
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动路距计算
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user