This commit is contained in:
tongchenfei
2021-01-27 20:33:41 +08:00
parent ce1a5f9396
commit 0aee7e19fe
4 changed files with 100 additions and 66 deletions

View File

@@ -46,6 +46,12 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
private static final int VEHICAL_TYPE = 10; private static final int VEHICAL_TYPE = 10;
private static final int MSG_REQUERY_BUS_STATION = 1001; private static final int MSG_REQUERY_BUS_STATION = 1001;
private static final long REQUERY_BUS_STATION_DELAY = 5000; private static final long REQUERY_BUS_STATION_DELAY = 5000;
/**
* 用来表示是否正在开往下一站
*/
private boolean isGoingToNextStation = false;
public OchBusPresenter(OchBusFragment view) { public OchBusPresenter(OchBusFragment view) {
super(view); super(view);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasOCHCallback(this); MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasOCHCallback(this);
@@ -65,7 +71,7 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
lat = lastLocation.getLatitude(); lat = lastLocation.getLatitude();
lon = lastLocation.getLongitude(); lon = lastLocation.getLongitude();
} }
OchBusRoutesRequest request = new OchBusRoutesRequest(Utils.getSn(),lat, lon); OchBusRoutesRequest request = new OchBusRoutesRequest(Utils.getSn(), lat, lon);
RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request)); RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request));
MogoApisHandler.getInstance().getApis().getNetworkApi() MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN) .create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
@@ -117,14 +123,17 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
// } // }
} }
private void requeryBusStation(){ private void requeryBusStation() {
handler.sendEmptyMessageDelayed(MSG_REQUERY_BUS_STATION, REQUERY_BUS_STATION_DELAY); handler.sendEmptyMessageDelayed(MSG_REQUERY_BUS_STATION, REQUERY_BUS_STATION_DELAY);
} }
public void restartAutopilot(){ public void restartAutopilot() {
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(currentAutopilot); Logger.d(TAG, "重启自动驾驶===" + isGoingToNextStation);
if (isGoingToNextStation) {
autoDriveToNextStation();
}
} }
private RemoteControlAutoPilotParameters currentAutopilot;
public void autoDriveToNextStation() { public void autoDriveToNextStation() {
if (currentStationIndex >= stationList.size() - 1) { if (currentStationIndex >= stationList.size() - 1) {
// 当前站是最后一站,结束当前行程 // 当前站是最后一站,结束当前行程
@@ -135,10 +144,11 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
OchBusStation nextStation = stationList.get(currentStationIndex + 1); OchBusStation nextStation = stationList.get(currentStationIndex + 1);
currentStation.setIsCurrentSite(STATION_STATUS_LEAVING); currentStation.setIsCurrentSite(STATION_STATUS_LEAVING);
nextStation.setIsCurrentSite(STATION_STATUS_ARRIVING); nextStation.setIsCurrentSite(STATION_STATUS_ARRIVING);
currentAutopilot = new RemoteControlAutoPilotParameters(); RemoteControlAutoPilotParameters currentAutopilot = new RemoteControlAutoPilotParameters();
currentAutopilot.startLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(currentStation.getLat(), currentStation.getLon()); currentAutopilot.startLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(currentStation.getLat(), currentStation.getLon());
currentAutopilot.endLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(nextStation.getLat(), nextStation.getLon()); currentAutopilot.endLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(nextStation.getLat(), nextStation.getLon());
currentAutopilot.vehicleType = VEHICAL_TYPE; currentAutopilot.vehicleType = VEHICAL_TYPE;
Logger.d(TAG, "开启自动驾驶====" + currentAutopilot);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(currentAutopilot); MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(currentAutopilot);
} }
@@ -156,7 +166,9 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
@Override @Override
public void onArriveAt(AdasOCHData data) { public void onArriveAt(AdasOCHData data) {
Logger.d(TAG, "到站====");
// 当前站改为IDLE下一站改为STATION_STATUS_STOPEDcurrentStationIndex增加1 // 当前站改为IDLE下一站改为STATION_STATUS_STOPEDcurrentStationIndex增加1
isGoingToNextStation = false;
stationList.get(currentStationIndex++).setIsCurrentSite(STATION_STATUS_IDLE); stationList.get(currentStationIndex++).setIsCurrentSite(STATION_STATUS_IDLE);
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED); stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED);
if (mView != null) { if (mView != null) {
@@ -164,58 +176,69 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
} }
} }
private void travelOver(){ private void travelOver() {
if (currentStationIndex >= stationList.size()) { if (currentStationIndex >= stationList.size()) {
Logger.e(TAG, "index out of station list"); Logger.e(TAG, "travel over index out of station list");
return; return;
} }
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_IDLE); Logger.d(TAG, "单程结束====");
currentStationIndex = 0; RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), stationList.get(currentStationIndex).getSiteId())));
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED); MogoApisHandler.getInstance().getApis().getNetworkApi()
if (mView != null) { .create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
mView.refreshBusStations(stationList); .leaveStation(request).subscribeOn(Schedulers.io())
} .observeOn(AndroidSchedulers.mainThread())
// RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), stationList.get(currentStationIndex).getSiteId()))); .subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(getContext())) {
// MogoApisHandler.getInstance().getApis().getNetworkApi() @Override
// .create(IOchBusApiService.class, HostConst.OCH_DOMAIN) public void onSuccess(BaseData o) {
// .leaveStation(request).subscribeOn(Schedulers.io()) super.onSuccess(o);
// .observeOn(AndroidSchedulers.mainThread()) // 始发站改为Stoped其他站改为Idle
// .subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(getContext())) { Logger.d(TAG, "单程真的结束了====");
// @Override stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_IDLE);
// public void onSuccess(BaseData o) { currentStationIndex = 0;
// super.onSuccess(o); stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED);
// // 始发站改为Stoped其他站改为Idle if (mView != null) {
// stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_IDLE); mView.refreshBusStations(stationList);
// currentStationIndex = 0; }
// stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED); }
// if (mView != null) {
// mView.refreshBusStations(stationList); @Override
// } public void onError(String message, int code) {
// } super.onError(message, code);
// Logger.d(TAG, "leave station error: " + message);
// @Override }
// public void onError(String message, int code) {
// super.onError(message, code); @Override
// Logger.d(TAG, "leave station error: " + message); public void onError(Throwable e) {
// } super.onError(e);
// Logger.e(TAG, e, "leave station exception");
// @Override }
// public void onError(Throwable e) { });
// super.onError(e);
// Logger.e(TAG,e,"leave station exception");
// }
// });
} }
@Override @Override
public void onStateChanged(int state, String reason) { public void onStateChanged(int state, String reason) {
Logger.d(TAG,"onStateChange: "+state); Logger.d(TAG, "onStateChange: " + state);
switch (state) { switch (state) {
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE: case IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE:
mView.onAutopilotEnableChange(true); mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(false); mView.onAutopilotStatusChanged(false);
if (isGoingToNextStation) {
mView.hideSlidePanel();
}
break; break;
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING: case IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING:
mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(true);
mView.hideSlidePanel();
mView.hideNotice();
if (mView != null) {
mView.refreshBusStations(stationList);
}
if (isGoingToNextStation) {
// 为了避免恢复自动驾驶时重复的接口请求
return;
}
isGoingToNextStation = true;
RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), stationList.get(currentStationIndex).getSiteId()))); RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), stationList.get(currentStationIndex).getSiteId())));
MogoApisHandler.getInstance().getApis().getNetworkApi() MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN) .create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
@@ -225,13 +248,6 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
@Override @Override
public void onSuccess(BaseData o) { public void onSuccess(BaseData o) {
super.onSuccess(o); super.onSuccess(o);
mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(true);
mView.hideSlidePanel();
mView.hideNotice();
if (mView != null) {
mView.refreshBusStations(stationList);
}
} }
@Override @Override
@@ -243,12 +259,11 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
super.onError(e); super.onError(e);
Logger.e(TAG,e,"leave station exception"); Logger.e(TAG, e, "leave station exception");
} }
}); });
break; break;
default: default:
mView.onAutopilotEnableChange(false); mView.onAutopilotEnableChange(false);

View File

@@ -9,6 +9,7 @@ import android.widget.TextView;
import com.mogo.commons.mvp.IView; import com.mogo.commons.mvp.IView;
import com.mogo.commons.mvp.MvpFragment; import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.mvp.Presenter; import com.mogo.commons.mvp.Presenter;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.OnPreventFastClickListener; import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.och.view.FrameAnimImageView; import com.mogo.och.view.FrameAnimImageView;
@@ -60,9 +61,9 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
@Override @Override
public void onClickImpl(View v) { public void onClickImpl(View v) {
// 如果能自动驾驶,就自动驾驶,不能就提示 // 如果能自动驾驶,就自动驾驶,不能就提示
// if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() != IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) { if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE) {
// restartAutopilot(); restartAutopilot();
// } }
} }
}); });
@@ -71,9 +72,9 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
checkCallView(MogoApisHandler.getInstance().getApis().getStatusManagerApi().isCallViewShow()); checkCallView(MogoApisHandler.getInstance().getApis().getStatusManagerApi().isCallViewShow());
MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("Och", StatusDescriptor.CALL_VIEW, callViewListener); MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("Och", StatusDescriptor.CALL_VIEW, callViewListener);
findViewById(R.id.btnAutopilotDisable).setOnClickListener(view-> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE, "不能使用")); findViewById(R.id.btnAutopilotDisable).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE, "不能使用"));
findViewById(R.id.btnAutopilotEnable).setOnClickListener(view-> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE, "能使用")); findViewById(R.id.btnAutopilotEnable).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE, "能使用"));
findViewById(R.id.btnAutopilotRunning).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING, "Running")); findViewById(R.id.btnAutopilotRunning).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING, "Running"));
@@ -93,7 +94,7 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
} }
public void showSlidePanle(String text) { public void showSlidePanle(String text) {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
slidePanelView.setText(text); slidePanelView.setText(text);
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) { if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
return; return;
@@ -103,17 +104,18 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
} }
public void hideSlidePanel() { public void hideSlidePanel() {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
slidePanelView.setVisibility(View.GONE); slidePanelView.setVisibility(View.GONE);
}); });
} }
public void showNotice(String notice) { public void showNotice(String notice) {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
tvNotice.setText(notice); tvNotice.setText(notice);
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) { if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
return; return;
} }
AIAssist.getInstance(getContext()).speakTTSVoice(notice);
tvNotice.setVisibility(View.VISIBLE); tvNotice.setVisibility(View.VISIBLE);
fivNoticeHead.setVisibility(View.VISIBLE); fivNoticeHead.setVisibility(View.VISIBLE);
fivNoticeHead.startAnim(); fivNoticeHead.startAnim();
@@ -121,7 +123,7 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
} }
public void hideNotice() { public void hideNotice() {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
tvNotice.setVisibility(View.GONE); tvNotice.setVisibility(View.GONE);
fivNoticeHead.setVisibility(View.GONE); fivNoticeHead.setVisibility(View.GONE);
fivNoticeHead.stopAnim(); fivNoticeHead.stopAnim();
@@ -134,20 +136,20 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
* @param isInAutopilot true - 在自动驾驶中 false - 不在自动驾驶中 * @param isInAutopilot true - 在自动驾驶中 false - 不在自动驾驶中
*/ */
public void onAutopilotStatusChanged(boolean isInAutopilot) { public void onAutopilotStatusChanged(boolean isInAutopilot) {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
ctvAutopilotStatus.setChecked(isInAutopilot); ctvAutopilotStatus.setChecked(isInAutopilot);
}); });
} }
public void hideAutopilotBiz() { public void hideAutopilotBiz() {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
ctvAutopilotStatus.setVisibility(View.GONE); ctvAutopilotStatus.setVisibility(View.GONE);
slidePanelView.setVisibility(View.GONE); slidePanelView.setVisibility(View.GONE);
}); });
} }
public void showAutopilotBiz() { public void showAutopilotBiz() {
getActivity().runOnUiThread(()->{ getActivity().runOnUiThread(() -> {
ctvAutopilotStatus.setVisibility(View.VISIBLE); ctvAutopilotStatus.setVisibility(View.VISIBLE);
slidePanelView.setVisibility(View.VISIBLE); slidePanelView.setVisibility(View.VISIBLE);
}); });

View File

@@ -108,4 +108,10 @@
android:textSize="30sp" android:textSize="30sp"
android:background="#f00" /> android:background="#f00" />
<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="btnAutopilotArrive,btnAutopilotDisable,btnAutopilotEnable,btnAutopilotRunning"
android:visibility="gone" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -29,4 +29,15 @@ class RemoteControlAutoPilotParameters {
this.lon = lon; this.lon = lon;
} }
} }
@Override
public String toString() {
return "RemoteControlAutoPilotParameters{" +
"startLatLon=" + startLatLon +
", wayLatLons=" + wayLatLons +
", endLatLon=" + endLatLon +
", speedLimit=" + speedLimit +
", vehicleType=" + vehicleType +
'}';
}
} }