[主线程判空]
This commit is contained in:
yangyakun
2024-04-28 19:24:57 +08:00
parent a702fed625
commit eed570c859

View File

@@ -67,17 +67,6 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
BusPassengerModel.getInstance().setMoGoAutopilotPlanningListener(null);
}
private void runOnUIThread( Runnable executor ) {
if ( executor == null ) {
return;
}
if ( Looper.myLooper() != Looper.getMainLooper() ) {
UiThreadHandler.post( executor );
} else {
executor.run();
}
}
@Override
public void onAutopilotArriveEnd() {
@@ -87,24 +76,39 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
@Override
public void onAutopilotEnable() {
if(mView != null) {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void onAutopilotDisable() {
if(mView != null) {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void onAutopilotRunning() {
if(mView != null) {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@@ -116,14 +120,24 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
@Override
public void onCarLocationChanged(MogoLocation location) {
if (location != null && mView != null){
runOnUIThread(() -> mView.onCarLocationChanged(location));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.onCarLocationChanged(location);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void changeOperationStatus(boolean changeStatus) {
if(mView != null) {
runOnUIThread(() -> mView.changeOperationStatus(changeStatus));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.changeOperationStatus(changeStatus);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@@ -135,35 +149,60 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
@Override
public void updateLineInfo(String lineName) {
if(mView != null) {
runOnUIThread(() -> mView.updateLineInfo(lineName));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.updateLineInfo(lineName);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void updateStationsInfo(List<BusStationBean> stations, int currentStationIndex, boolean isArrived) {
if(mView != null) {
runOnUIThread(() -> mView.updateStationsInfo(stations, currentStationIndex, isArrived));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.updateStationsInfo(stations, currentStationIndex, isArrived);
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void showNoTaskView() {
if(mView != null) {
runOnUIThread(() -> mView.showNoTaskView());
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.showNoTaskView();
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void hideNoTaskView() {
if(mView != null) {
runOnUIThread(() -> mView.hideNoTaskView());
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.hideNoTaskView();
}
},UiThreadHandler.MODE.QUEUE);
}
}
@Override
public void routePlanningToNextStationChanged(long meters, long timeInSecond) {
if(mView != null) {
runOnUIThread(() -> mView.updateRoutePlanningToNextStation(meters, timeInSecond));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mView.updateRoutePlanningToNextStation(meters, timeInSecond);
}
},UiThreadHandler.MODE.QUEUE);
}
}