[getActivity 改为UiThread]
This commit is contained in:
yangyakun
2024-04-19 17:18:22 +08:00
parent d4bf056b95
commit 37a9c29b32
7 changed files with 142 additions and 107 deletions

View File

@@ -324,10 +324,13 @@ public abstract class BaseShuttleTabFragment<V extends IView, P extends Presente
* @param text 指定的文字
*/
public void showSlidePanel(String text) {
getActivity().runOnUiThread(() -> {
slidePanelView.setText(text);
slidePanelView.setVisibility(View.VISIBLE);
});
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
slidePanelView.setText(text);
slidePanelView.setVisibility(View.VISIBLE);
}
}, UiThreadHandler.MODE.QUEUE);
setArrivedClikable(false);
}
@@ -337,23 +340,29 @@ public abstract class BaseShuttleTabFragment<V extends IView, P extends Presente
* @param isClickable
*/
public void setArrivedClikable(boolean isClickable) {
getActivity().runOnUiThread(() -> {
tvArrived.setEnabled(isClickable);
if (isClickable) {
tvArrived.setTextColor(getResources().getColor(R.color.bus_white));
} else {
tvArrived.setTextColor(getResources().getColor(R.color.bus_arrived_btn_un_clickable_color));
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
tvArrived.setEnabled(isClickable);
if (isClickable) {
tvArrived.setTextColor(getResources().getColor(R.color.bus_white));
} else {
tvArrived.setTextColor(getResources().getColor(R.color.bus_arrived_btn_un_clickable_color));
}
}
});
}, UiThreadHandler.MODE.QUEUE);
}
/**
* 隐藏滑动按钮
*/
public void hideSlidePanel() {
getActivity().runOnUiThread(() -> {
slidePanelView.setVisibility(View.GONE);
});
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
slidePanelView.setVisibility(View.GONE);
}
}, UiThreadHandler.MODE.QUEUE);
}
public void playDI() {
@@ -366,9 +375,12 @@ public abstract class BaseShuttleTabFragment<V extends IView, P extends Presente
* @param autopilotStatus 0:不可用 1:可用状态 2:自动驾驶中
*/
public void onAutopilotStatusChanged(int autopilotStatus) {
getActivity().runOnUiThread(() -> {
changeAutopilotBtnView(autopilotStatus, isAnimateRunning);
});
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
changeAutopilotBtnView(autopilotStatus, isAnimateRunning);
}
}, UiThreadHandler.MODE.QUEUE);
}
public void setAutopilotBtnStatus(int autopilotStatus) {
@@ -450,19 +462,12 @@ public abstract class BaseShuttleTabFragment<V extends IView, P extends Presente
* 隐藏【自动驾驶】按钮
*/
public void hideAutopilotBiz() {
getActivity().runOnUiThread(() -> {
// ctvAutopilotStatus.setVisibility(View.GONE);
// slidePanelView.setVisibility(View.GONE);
});
}
/**
* 展示【自动驾驶】按钮
*/
public void showAutopilotBiz() {
// getActivity().runOnUiThread(() -> {
// ctvAutopilotStatus.setVisibility(View.VISIBLE);
// });
}
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() {

View File

@@ -25,6 +25,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant;
import com.mogo.eagle.core.utilcode.util.ActivityUtils;
import com.mogo.eagle.core.utilcode.util.ToastUtils;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.map.overlay.IMoGoOverlayManager;
import com.mogo.map.overlay.core.Level;
import com.mogo.map.overlay.point.Point;
@@ -198,20 +199,23 @@ public class ShuttleFragment extends BaseShuttleTabFragment<ShuttleFragment, Bus
return;
}
getActivity().runOnUiThread(() -> {
if (stationList == null) {
// 获取小巴数据失败
return;
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
if (stationList == null) {
// 获取小巴数据失败
return;
}
showStationsPanel();
showOrHideSwitchLineBtn(false);
mLineName.setText(lineName);
mTaskTime.setText(getString(R.string.bus_line_time_tag)+ lineTime);
// 渲染小巴路线数据
updateBusStationStatus(stationList,arrivingOrArrivedIndex,isArrived);
}
showStationsPanel();
showOrHideSwitchLineBtn(false);
mLineName.setText(lineName);
mTaskTime.setText(getString(R.string.bus_line_time_tag)+ lineTime);
// 渲染小巴路线数据
updateBusStationStatus(stationList,arrivingOrArrivedIndex,isArrived);
});
},UiThreadHandler.MODE.QUEUE);
}
private void updateBusStationStatus(List<BusStationBean> stationList,