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

View File

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

View File

@@ -108,4 +108,10 @@
android:textSize="30sp"
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>

View File

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