diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/ResourcesUtils.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/ResourcesUtils.kt index a0b95be62d..491022c562 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/ResourcesUtils.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/ResourcesUtils.kt @@ -17,4 +17,9 @@ object ResourcesUtils { return AbsMogoApplication.getApp().getString(id) } + @JvmStatic + fun getString(@StringRes id: Int, vararg formatArgs:String): String { + return AbsMogoApplication.getApp().getString(id,formatArgs) + } + } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/SlidePanelView.java b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/SlidePanelView.java similarity index 98% rename from OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/SlidePanelView.java rename to OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/SlidePanelView.java index a665ba8b78..e635ef9eab 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/SlidePanelView.java +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/SlidePanelView.java @@ -1,4 +1,4 @@ -package com.mogo.och.weaknet.view; +package com.mogo.och.common.module.wigets; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; @@ -25,8 +25,8 @@ import com.mogo.commons.AbsMogoApplication; import com.mogo.eagle.core.utilcode.util.ConvertUtils; import com.mogo.eagle.core.utilcode.util.ThreadUtils; import com.mogo.eagle.core.utilcode.util.UiThreadHandler; +import com.mogo.och.common.module.R; import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager; -import com.mogo.och.shuttle.weaknet.R; import me.jessyan.autosize.AutoSizeConfig; import me.jessyan.autosize.utils.AutoSizeUtils; @@ -139,7 +139,7 @@ public class SlidePanelView extends View { int size = AutoSizeUtils.dp2px(getContext(), 120); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inDensity = (int) AutoSizeConfig.getInstance().getInitDensity(); - bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.bus_base_slide_block,opts); + bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.common_wiget_slide_block,opts); bmBlock = Bitmap.createScaledBitmap(bmBlock, size, size, true); blockWidth = bmBlock.getWidth(); UiThreadHandler.post(this::requestLayout,UiThreadHandler.MODE.QUEUE); diff --git a/OCH/common/common/src/main/res/drawable-nodpi/common_wiget_slide_block.png b/OCH/common/common/src/main/res/drawable-nodpi/common_wiget_slide_block.png new file mode 100644 index 0000000000..ed7b293b90 Binary files /dev/null and b/OCH/common/common/src/main/res/drawable-nodpi/common_wiget_slide_block.png differ diff --git a/OCH/common/common/src/main/res/values/attrs.xml b/OCH/common/common/src/main/res/values/attrs.xml index 88181d340e..13b47cc9ee 100644 --- a/OCH/common/common/src/main/res/values/attrs.xml +++ b/OCH/common/common/src/main/res/values/attrs.xml @@ -88,4 +88,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/callback/IBusControllerStatusCallback.java b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/callback/IBusControllerStatusCallback.java index c9e0acf8ac..045ddc1be9 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/callback/IBusControllerStatusCallback.java +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/callback/IBusControllerStatusCallback.java @@ -8,8 +8,6 @@ import com.mogo.eagle.core.data.map.MogoLocation; * Model->Presenter回调:状态控制器监听(accOn、adas ui show、voice ui show、push ui show、v2x ui show等等) */ public interface IBusControllerStatusCallback { - // 自车定位 - void onCarLocationChanged(MogoLocation location); //开始开启自动驾驶 void startOpenAutopilot(); } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/BaseShuttleTabFragment.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/BaseShuttleTabFragment.kt index c5b451171e..5080a5ea84 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/BaseShuttleTabFragment.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/BaseShuttleTabFragment.kt @@ -1,257 +1,248 @@ -package com.mogo.och.weaknet.fragment; +package com.mogo.och.weaknet.fragment -import static com.mogo.och.weaknet.constant.BusConst.TIMER_START_AUTOPILOT_INTERVAL; +import android.animation.ObjectAnimator +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.LinearInterpolator +import android.widget.FrameLayout +import android.widget.ImageView +import android.widget.RelativeLayout +import android.widget.TextView +import androidx.constraintlayout.widget.Group +import androidx.core.content.ContextCompat +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.mvp.IView +import com.mogo.commons.mvp.MvpFragment +import com.mogo.commons.mvp.Presenter +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.config.HdMapBuildConfig +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.isCanStartAutopilot +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getState +import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotRecordListenerManager +import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager.attachAutopilotBeforeLaunchView +import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager.getMapUIController +import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxBubbleView +import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxButtonView +import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxListView +import com.mogo.eagle.core.function.smp.view.SmallMapView +import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils.isB1 +import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils.isB2 +import com.mogo.eagle.core.utilcode.mogo.view.OnPreventFastClickListener +import com.mogo.eagle.core.utilcode.util.ToastUtils +import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import com.mogo.map.MogoMap +import com.mogo.och.common.module.utils.ResourcesUtils +import com.mogo.och.common.module.utils.ResourcesUtils.getColor +import com.mogo.och.common.module.utils.SoundPoolHelper +import com.mogo.och.common.module.wigets.SlidePanelView +import com.mogo.och.shuttle.weaknet.R +import com.mogo.och.weaknet.constant.BusConst +import com.mogo.och.weaknet.model.OrderModel.busRoutesResult +import com.mogo.och.weaknet.view.BizMapView +import org.greenrobot.eventbus.EventBus -import android.animation.ObjectAnimator; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.LinearInterpolator; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.Group; -import androidx.core.content.ContextCompat; - -import com.mogo.commons.AbsMogoApplication; -import com.mogo.commons.mvp.IView; -import com.mogo.commons.mvp.MvpFragment; -import com.mogo.commons.mvp.Presenter; -import com.mogo.eagle.core.data.config.FunctionBuildConfig; -import com.mogo.eagle.core.data.config.HdMapBuildConfig; -import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; -import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotRecordListenerManager; -import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager; -import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager; -import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxBubbleView; -import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxButtonView; -import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxListView; -import com.mogo.eagle.core.function.smp.view.SmallMapView; -import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils; -import com.mogo.eagle.core.utilcode.mogo.view.OnPreventFastClickListener; -import com.mogo.eagle.core.utilcode.util.ToastUtils; -import com.mogo.eagle.core.utilcode.util.UiThreadHandler; -import com.mogo.map.MogoMap; -import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.och.common.module.utils.ResourcesUtils; -import com.mogo.och.weaknet.model.OrderModel; -import com.mogo.och.weaknet.view.BizMapView; -import com.mogo.och.data.bean.BusRoutesResult; -import com.mogo.och.weaknet.view.SlidePanelView; -import com.mogo.och.common.module.utils.SoundPoolHelper; -import com.mogo.och.shuttle.weaknet.R; - -import org.greenrobot.eventbus.EventBus; /** * 网约车基础Fragment,主要负责布局通用界面,处理站点面板和通话面板互斥情况 - *

+ * + * * 部分业务放在了此处处理 * * @author tongchenfei */ -public abstract class BaseShuttleTabFragment> extends MvpFragment { +abstract class BaseShuttleTabFragment?> : MvpFragment() { + protected var slidePanelView: SlidePanelView? = null + private var ctvAutopilotStatus: RelativeLayout? = null + private var ctvAutopilotStatusIv: ImageView? = null + private var ctvAutopilotStatusTv: TextView? = null + protected var tvArrived: TextView? = null + private var flStationPanelContainer: FrameLayout? = null + private var mapBizView: BizMapView? = null + private var groupTestPanel: Group? = null - private static final String TAG = "BaseBusTabFragment"; - - protected SlidePanelView slidePanelView; - private RelativeLayout ctvAutopilotStatus; - private ImageView ctvAutopilotStatusIv; - private TextView ctvAutopilotStatusTv; - protected TextView tvArrived; - private FrameLayout flStationPanelContainer; - private BizMapView mapBizView; - private Group groupTestPanel; - - protected SmallMapView smallMapView; + protected var smallMapView: SmallMapView? = null //消息盒子 - private DriverMsgBoxButtonView viewDriverMsgBoxButton; - private DriverMsgBoxListView viewDriverMsgBoxList; - private DriverMsgBoxBubbleView viewDriverMsgBoxBubble; + private var viewDriverMsgBoxButton: DriverMsgBoxButtonView? = null + private var viewDriverMsgBoxList: DriverMsgBoxListView? = null + private var viewDriverMsgBoxBubble: DriverMsgBoxBubbleView? = null - private ObjectAnimator autopilotLoadingAnimator; + private var autopilotLoadingAnimator: ObjectAnimator? = null - public boolean isAnimateRunning = false; + var isAnimateRunning: Boolean = false /** * 滑动按钮触发的事件 */ - private final SlidePanelView.OnSlidePanelMoveToEndListener onSlideToEndListener = () -> { + private val onSlideToEndListener = SlidePanelView.OnSlidePanelMoveToEndListener { // 此处做一个代理,处理一下共有情况 - if (getSlidePanelOnEndListener() != null) { - getSlidePanelOnEndListener().moveToEnd(); + if (slidePanelOnEndListener() != null) { + slidePanelOnEndListener()!!.moveToEnd() } - }; - - @Override - protected int getLayoutId() { - return R.layout.shuttle_weak_base_fragment; } - @Override - protected void initViews() { - mapBizView = findViewById(R.id.mapBizView); - groupTestPanel = findViewById(R.id.groupTestPanel); - slidePanelView = findViewById(R.id.module_mogo_och_slide_panel); - ctvAutopilotStatus = findViewById(R.id.module_mogo_och_autopilot_status); - ctvAutopilotStatusIv = findViewById(R.id.bus_autopilot_btn_iv); - ctvAutopilotStatusTv = findViewById(R.id.bus_autopolot_btn_tv); - flStationPanelContainer = findViewById(R.id.module_mogo_och_station_panel_container); + override fun getLayoutId(): Int { + return R.layout.shuttle_weak_base_fragment + } - tvArrived = findViewById(R.id.module_mogo_och_arrived_tv); + override fun initViews() { + mapBizView = findViewById(R.id.mapBizView) + groupTestPanel = findViewById(R.id.groupTestPanel) + slidePanelView = findViewById(R.id.module_mogo_och_slide_panel) + ctvAutopilotStatus = findViewById(R.id.module_mogo_och_autopilot_status) + ctvAutopilotStatusIv = findViewById(R.id.bus_autopilot_btn_iv) + ctvAutopilotStatusTv = findViewById(R.id.bus_autopolot_btn_tv) + flStationPanelContainer = findViewById(R.id.module_mogo_och_station_panel_container) - FrameLayout flSpeed = findViewById(R.id.fl_speed); + tvArrived = findViewById(R.id.module_mogo_och_arrived_tv) + + val flSpeed = findViewById(R.id.fl_speed) if (flSpeed != null) { - CallerDevaToolsManager.INSTANCE.attachAutopilotBeforeLaunchView(flSpeed.getContext(), flSpeed); + attachAutopilotBeforeLaunchView(flSpeed.context, flSpeed) } - LayoutInflater.from(getContext()).inflate(getStationPanelViewId(), flStationPanelContainer); - slidePanelView.setOnSlidePanelMoveToEndListener(onSlideToEndListener); + LayoutInflater.from(context).inflate(stationPanelViewId(), flStationPanelContainer) + slidePanelView!!.setOnSlidePanelMoveToEndListener(onSlideToEndListener) - updateSwitchMapIcon(); + updateSwitchMapIcon() - initListener(); - setAutopilotBtnStatus(CallerAutoPilotStatusListenerManager.INSTANCE.getState(), - CallerAutoPilotControlManager.INSTANCE.isCanStartAutopilot(false, 0)); - ctvAutopilotStatus.setOnClickListener(new OnPreventFastClickListener() { - - @Override - public void onClickImpl(View v) { - restartAutopilot(); + initListener() + setAutopilotBtnStatus( + getState(), + isCanStartAutopilot(false, 0) + ) + ctvAutopilotStatus!!.setOnClickListener(object : OnPreventFastClickListener() { + override fun onClickImpl(v: View) { + restartAutopilot() } - }); + }) // 模拟 不可自动驾驶,目前场景是刚开机,adas还未和工控机连接 - findViewById(R.id.btnAutopilotDisable).setOnClickListener(view -> - debugAutoPilotStatus(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) - ); + findViewById(R.id.btnAutopilotDisable)!!.setOnClickListener { view: View? -> + debugAutoPilotStatus( + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE + ) + } // 模拟 可自动驾驶,工控机连接正常,且处于人工干预状态 - findViewById(R.id.btnAutopilotEnable).setOnClickListener(view -> - debugAutoPilotStatus(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) - ); + findViewById(R.id.btnAutopilotEnable)!!.setOnClickListener { view: View? -> + debugAutoPilotStatus( + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE + ) + } // 模拟 自动驾驶能力,自动驾驶中,可能是停车,可能是行进,但是是机器在处理车的前进后退,不是人 - findViewById(R.id.btnAutopilotRunning).setOnClickListener(view -> - debugAutoPilotStatus(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) - ); + findViewById(R.id.btnAutopilotRunning)!!.setOnClickListener { view: View? -> + debugAutoPilotStatus( + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + ) + } - findViewById(R.id.btnAutopilotPingxing).setOnClickListener(view -> - debugAutoPilotStatus(IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING) - ); + findViewById(R.id.btnAutopilotPingxing)!!.setOnClickListener { view: View? -> + debugAutoPilotStatus( + IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING + ) + } // 模拟 自动驾驶网约车回调数据 - findViewById(R.id.btnAutopilotArrive).setOnClickListener(view -> - debugArrivedStation() - ); + findViewById(R.id.btnAutopilotArrive)!!.setOnClickListener { view: View? -> debugArrivedStation() } - tvArrived.setOnClickListener(view -> { - ToastUtils.showLong("weak_net"); - onArriveStation(); - }); + tvArrived!!.setOnClickListener { view: View? -> + ToastUtils.showLong("weak_net") + onArriveStation() + } //消息盒子 - viewDriverMsgBoxButton = findViewById(R.id.viewDriverMsgBoxButton); - viewDriverMsgBoxList = findViewById(R.id.viewDriverMsgBoxList); - viewDriverMsgBoxBubble = findViewById(R.id.viewDriverMsgBoxBubble); - viewDriverMsgBoxButton.setClickListener(show -> { - if(show){ - viewDriverMsgBoxList.setVisibility(View.VISIBLE); - viewDriverMsgBoxList.notifyData(); - viewDriverMsgBoxBubble.setVisibility(View.GONE); - viewDriverMsgBoxBubble.isShowData(false); - }else{ - viewDriverMsgBoxList.setVisibility(View.GONE); - viewDriverMsgBoxBubble.setVisibility(View.VISIBLE); - viewDriverMsgBoxBubble.isShowData(true); + viewDriverMsgBoxButton = findViewById(R.id.viewDriverMsgBoxButton) + viewDriverMsgBoxList = findViewById(R.id.viewDriverMsgBoxList) + viewDriverMsgBoxBubble = findViewById(R.id.viewDriverMsgBoxBubble) + viewDriverMsgBoxButton!!.setClickListener(object :DriverMsgBoxButtonView.ClickListener { + override fun showMsgBoxList(show: Boolean) { + if (show) { + viewDriverMsgBoxList!!.visibility = View.VISIBLE + viewDriverMsgBoxList!!.notifyData() + viewDriverMsgBoxBubble!!.visibility = View.GONE + viewDriverMsgBoxBubble!!.isShowData(false) + } else { + viewDriverMsgBoxList!!.visibility = View.GONE + viewDriverMsgBoxBubble!!.visibility = View.VISIBLE + viewDriverMsgBoxBubble!!.isShowData(true) + } } - }); + }) - smallMapView = findViewById(R.id.smallMapView); + smallMapView = findViewById(R.id.smallMapView) } - @Override - protected void initViews(Bundle savedInstanceState) { - super.initViews(savedInstanceState); - mapBizView.onCreate(savedInstanceState); - smallMapView.onCreateView(savedInstanceState); + override fun initViews(savedInstanceState: Bundle?) { + super.initViews(savedInstanceState) + mapBizView!!.onCreate(savedInstanceState) + smallMapView!!.onCreateView(savedInstanceState) } - @Override - public void onResume() { - super.onResume(); - mapBizView.onResume(); - smallMapView.onResume(); + override fun onResume() { + super.onResume() + mapBizView!!.onResume() + smallMapView!!.onResume() } - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container - , @Nullable Bundle savedInstanceState) { - EventBus.getDefault().register(this); - return super.onCreateView(inflater, container, savedInstanceState); + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + EventBus.getDefault().register(this) + return super.onCreateView(inflater, container, savedInstanceState) } - protected abstract void onArriveStation(); + protected abstract fun onArriveStation() - private void updateSwitchMapIcon() { - - IMogoMapUIController mapUIController = CallerMapUIServiceManager.INSTANCE.getMapUIController(MogoMap.DEFAULT); - if(mapUIController!=null){ - if (AppIdentityModeUtils.isB2(FunctionBuildConfig.appIdentityMode)) { - mapUIController.changeCurrentIcon(R.raw.m2); - HdMapBuildConfig.currentCarVrIconRes = R.raw.m2; - }else if (AppIdentityModeUtils.isB1(FunctionBuildConfig.appIdentityMode)) { - mapUIController.changeCurrentIcon(R.raw.xiaoba); - HdMapBuildConfig.currentCarVrIconRes = R.raw.xiaoba; + private fun updateSwitchMapIcon() { + val mapUIController = getMapUIController(MogoMap.DEFAULT) + if (mapUIController != null) { + if (isB2(FunctionBuildConfig.appIdentityMode)) { + mapUIController.changeCurrentIcon(R.raw.m2) + HdMapBuildConfig.currentCarVrIconRes = R.raw.m2 + } else if (isB1(FunctionBuildConfig.appIdentityMode)) { + mapUIController.changeCurrentIcon(R.raw.xiaoba) + HdMapBuildConfig.currentCarVrIconRes = R.raw.xiaoba } } } - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - mapBizView.onSaveInstanceState(outState); + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapBizView!!.onSaveInstanceState(outState) } - @Override - public void onLowMemory() { - super.onLowMemory(); - mapBizView.onLowMemory(); + override fun onLowMemory() { + super.onLowMemory() + mapBizView!!.onLowMemory() } - @Override - public void onPause() { - super.onPause(); - mapBizView.onPause(); - smallMapView.onPause(); + override fun onPause() { + super.onPause() + mapBizView!!.onPause() + smallMapView!!.onPause() } - @Override - public void onDestroyView() { - mapBizView.onDestroy(); - if(smallMapView != null){ - smallMapView.onDestroy(); + override fun onDestroyView() { + mapBizView!!.onDestroy() + if (smallMapView != null) { + smallMapView!!.onDestroy() } - super.onDestroyView(); - CallerAutopilotRecordListenerManager.INSTANCE.removeListener(TAG); - EventBus.getDefault().unregister(this); + super.onDestroyView() + CallerAutopilotRecordListenerManager.removeListener(TAG) + EventBus.getDefault().unregister(this) } /** * 测试到站 */ - protected abstract void debugArrivedStation(); - - private void initListener() { + protected abstract fun debugArrivedStation() + private fun initListener() { } /** @@ -259,15 +250,12 @@ public abstract class BaseShuttleTabFragment + * + * * START */ - private View busTestBar; - private TextView lineIdTV; - private TextView lineNameTV; - private TextView trajMd5TV; - private TextView stopMd5TV; - private TextView trajMd5DPQPTV; - private TextView stopMd5DPQPTV; + private var busTestBar: View? = null + private var lineIdTV: TextView? = null + private var lineNameTV: TextView? = null + private var trajMd5TV: TextView? = null + private var stopMd5TV: TextView? = null + private var trajMd5DPQPTV: TextView? = null + private var stopMd5DPQPTV: TextView? = null - public void showHideTestBar() { + fun showHideTestBar() { if (busTestBar == null) { - busTestBar = findViewById(R.id.module_mogo_och_bus_test_bar); - lineIdTV = findViewById(R.id.bus_test_bar_current_line_id); - lineNameTV = findViewById(R.id.bus_test_bar_current_line_name); - trajMd5TV = findViewById(R.id.bus_test_bar_current_traj_md5); - stopMd5TV = findViewById(R.id.bus_test_bar_current_stop_md5); - trajMd5DPQPTV = findViewById(R.id.bus_test_bar_current_traj_md5_dpqp); - stopMd5DPQPTV = findViewById(R.id.bus_test_bar_current_stop_md5_dpqp); + busTestBar = findViewById(R.id.module_mogo_och_bus_test_bar) + lineIdTV = findViewById(R.id.bus_test_bar_current_line_id) + lineNameTV = findViewById(R.id.bus_test_bar_current_line_name) + trajMd5TV = findViewById(R.id.bus_test_bar_current_traj_md5) + stopMd5TV = findViewById(R.id.bus_test_bar_current_stop_md5) + trajMd5DPQPTV = findViewById(R.id.bus_test_bar_current_traj_md5_dpqp) + stopMd5DPQPTV = findViewById(R.id.bus_test_bar_current_stop_md5_dpqp) } - if (busTestBar.getVisibility() == View.VISIBLE) { - busTestBar.setVisibility(View.GONE); + if (busTestBar!!.visibility == View.VISIBLE) { + busTestBar!!.visibility = View.GONE } else { - BusRoutesResult routesResult = OrderModel.getInstance().getBusRoutesResult(); - lineIdTV.setText("lineId:" + (routesResult == null ? "" : String.valueOf(routesResult.getLineId()))); - lineNameTV.setText("lineName:" + (routesResult == null ? "" : routesResult.getName())); - trajMd5TV.setText("TMd5:" + (routesResult == null ? "" : routesResult.csvFileMd5)); - stopMd5TV.setText("SMd5:" + (routesResult == null ? "" : routesResult.txtFileMd5)); - trajMd5DPQPTV.setText("TMd5DPQP:" + (routesResult == null ? "" : routesResult.csvFileMd5DPQP)); - stopMd5DPQPTV.setText("SMd5DPQP:" + (routesResult == null ? "" : routesResult.txtFileMd5DPQP)); - busTestBar.setVisibility(View.VISIBLE); + val routesResult = busRoutesResult + lineIdTV!!.text = + "lineId:" + (routesResult?.lineId?.toString() ?: "") + lineNameTV!!.text = + "lineName:" + (if (routesResult == null) "" else routesResult.name) + trajMd5TV!!.text = "TMd5:" + (if (routesResult == null) "" else routesResult.csvFileMd5) + stopMd5TV!!.text = + "SMd5:" + (if (routesResult == null) "" else routesResult.txtFileMd5) + trajMd5DPQPTV!!.text = + "TMd5DPQP:" + (if (routesResult == null) "" else routesResult.csvFileMd5DPQP) + stopMd5DPQPTV!!.text = + "SMd5DPQP:" + (if (routesResult == null) "" else routesResult.txtFileMd5DPQP) + busTestBar!!.visibility = View.VISIBLE } } - public void updateBusTestBarInfo() { - if (busTestBar != null && busTestBar.getVisibility() == View.VISIBLE) { - BusRoutesResult routesResult = OrderModel.getInstance().getBusRoutesResult(); - lineIdTV.setText("lineId:" + (routesResult == null ? "" : String.valueOf(routesResult.getLineId()))); - lineNameTV.setText("lineName:" + (routesResult == null ? "" : routesResult.getName())); - trajMd5TV.setText("TMd5:" + (routesResult == null ? "" : routesResult.csvFileMd5)); - stopMd5TV.setText("SMd5:" + (routesResult == null ? "" : routesResult.txtFileMd5)); - trajMd5DPQPTV.setText("TMd5DPQP:" + (routesResult == null ? "" : routesResult.csvFileMd5DPQP)); - stopMd5DPQPTV.setText("SMd5DPQP:" + (routesResult == null ? "" : routesResult.txtFileMd5DPQP)); + fun updateBusTestBarInfo() { + if (busTestBar != null && busTestBar!!.visibility == View.VISIBLE) { + val routesResult = busRoutesResult + lineIdTV!!.text = + "lineId:" + (routesResult?.lineId?.toString() ?: "") + lineNameTV!!.text = "lineName:" + (if (routesResult == null) "" else routesResult.name) + trajMd5TV!!.text = + "TMd5:" + (if (routesResult == null) "" else routesResult.csvFileMd5) + stopMd5TV!!.text = + "SMd5:" + (if (routesResult == null) "" else routesResult.txtFileMd5) + trajMd5DPQPTV!!.text = + "TMd5DPQP:" + (if (routesResult == null) "" else routesResult.csvFileMd5DPQP) + stopMd5DPQPTV!!.text = + "SMd5DPQP:" + (if (routesResult == null) "" else routesResult.txtFileMd5DPQP) } } + /** * END */ + companion object { + private const val TAG = "BaseBusTabFragment" + } } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/ShuttleFragment.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/ShuttleFragment.kt index b54aa7e480..788163ffd2 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/ShuttleFragment.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/fragment/ShuttleFragment.kt @@ -1,272 +1,260 @@ -package com.mogo.och.weaknet.fragment; - -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS; -import static com.mogo.map.MogoMap.DEFAULT; - -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.constraintlayout.widget.Group; -import androidx.annotation.Nullable; - -import com.mogo.commons.storage.SharedPrefsMgr; -import com.mogo.eagle.core.data.config.FunctionBuildConfig; -import com.mogo.eagle.core.data.temp.EventLogout; -import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; -import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager; -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; -import com.mogo.och.common.module.utils.ResourcesUtils; -import com.mogo.och.data.bean.BusStationBean; -import com.mogo.och.weaknet.constant.BusConst; -import com.mogo.och.weaknet.presenter.BusPresenter; -import com.mogo.och.weaknet.ui.BusStationCommonItem; -import com.mogo.och.weaknet.ui.BusSwitchLineActivity; -import com.mogo.och.weaknet.view.SlidePanelView; -import com.mogo.och.common.module.utils.BlinkAnimationUtil; -import com.mogo.och.common.module.utils.OCHThreadPoolManager; -import com.mogo.och.common.module.utils.QRUtilsKt; -import com.mogo.och.common.module.wigets.BindQRCodeDialog; -import com.mogo.och.common.module.wigets.MarqueeTextView; -import com.mogo.och.common.module.wigets.OCHCommitDialog; -import com.mogo.och.shuttle.weaknet.R; - -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.List; -import java.util.Objects; - -import me.jessyan.autosize.utils.AutoSizeUtils; +package com.mogo.och.weaknet.fragment +import android.content.Intent +import android.graphics.BitmapFactory +import android.os.Bundle +import android.view.View +import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.constraintlayout.widget.Group +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.storage.SharedPrefsMgr +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.temp.EventLogout +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getState +import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager.getOverlayManager +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d +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.MogoMap +import com.mogo.map.overlay.core.Level +import com.mogo.map.overlay.point.Point +import com.mogo.och.common.module.utils.BlinkAnimationUtil +import com.mogo.och.common.module.utils.OCHThreadPoolManager +import com.mogo.och.common.module.utils.ResourcesUtils +import com.mogo.och.common.module.utils.ResourcesUtils.getColor +import com.mogo.och.common.module.utils.createQRCodeWithPicture +import com.mogo.och.common.module.wigets.BindQRCodeDialog +import com.mogo.och.common.module.wigets.MarqueeTextView +import com.mogo.och.common.module.wigets.OCHCommitDialog +import com.mogo.och.common.module.wigets.SlidePanelView +import com.mogo.och.data.bean.BusStationBean +import com.mogo.och.shuttle.weaknet.R +import com.mogo.och.weaknet.constant.BusConst +import com.mogo.och.weaknet.presenter.BusPresenter +import com.mogo.och.weaknet.ui.BusStationCommonItem +import com.mogo.och.weaknet.ui.BusSwitchLineActivity +import me.jessyan.autosize.utils.AutoSizeUtils +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode +import java.util.Objects /** * 网约车小巴界面 * * @author tongchenfei */ -public class ShuttleFragment extends BaseShuttleTabFragment - implements SlidePanelView.OnSlidePanelMoveToEndListener, View.OnClickListener { - public static final String TAG = "BusFragment"; +class ShuttleFragment : BaseShuttleTabFragment(), + SlidePanelView.OnSlidePanelMoveToEndListener, View.OnClickListener { + private var mSwitchLine: TextView? = null //切换路线 + private var mLineName: MarqueeTextView? = null + private var mTaskTime: TextView? = null + private var groupStationsPanel: Group? = null + private var noDataView: ConstraintLayout? = null - private TextView mSwitchLine; //切换路线 - private MarqueeTextView mLineName; - private TextView mTaskTime; - private Group groupStationsPanel; - private ConstraintLayout noDataView; - - private BusStationBean startStation = null; - private BusStationBean endStation = null; - private BusStationCommonItem firstStationItem; - private BusStationCommonItem secondStationItem; - private BusStationCommonItem thirdStationItem; + private var startStation: BusStationBean? = null + private var endStation: BusStationBean? = null + private var firstStationItem: BusStationCommonItem? = null + private var secondStationItem: BusStationCommonItem? = null + private var thirdStationItem: BusStationCommonItem? = null - @Override - public String getTagName() { - return "BusFragment"; + override fun getTagName(): String { + return "BusFragment" } - @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) } - @Override - public void onDestroyView() { + + override fun onDestroyView() { if (mPresenter != null) { - mPresenter.onDestroy(this); + mPresenter!!.onDestroy(this) } - IMoGoOverlayManager overlayManager = CallerMapUIServiceManager.INSTANCE.getOverlayManager(); - if(overlayManager!=null) { - overlayManager.removeAllLines(); - overlayManager.removeAllPoints(); + val overlayManager = getOverlayManager() + if (overlayManager != null) { + overlayManager.removeAllLines() + overlayManager.removeAllPoints() } - super.onDestroyView(); + super.onDestroyView() } - @Override - protected void initViews() { - super.initViews(); + override fun initViews() { + super.initViews() - mSwitchLine = findViewById(R.id.switch_line_btn); - mSwitchLine.setTag(0); - mLineName = findViewById(R.id.module_och_bus_line_name); + mSwitchLine = findViewById(R.id.switch_line_btn) + mSwitchLine!!.tag = 0 + mLineName = findViewById(R.id.module_och_bus_line_name) - firstStationItem = findViewById(R.id.bus_panel_first_station); - secondStationItem = findViewById(R.id.bus_panel_second_station); - thirdStationItem = findViewById(R.id.bus_panel_third_station); - mTaskTime = findViewById(R.id.bus_task_time_tv); - groupStationsPanel = findViewById(R.id.group_stations_panel); - noDataView = findViewById(R.id.no_line_data_view); + firstStationItem = findViewById(R.id.bus_panel_first_station) + secondStationItem = findViewById(R.id.bus_panel_second_station) + thirdStationItem = findViewById(R.id.bus_panel_third_station) + mTaskTime = findViewById(R.id.bus_task_time_tv) + groupStationsPanel = findViewById(R.id.group_stations_panel) + noDataView = findViewById(R.id.no_line_data_view) - CallerLogger.d(M_BUS + TAG, "initView: " + CallerAutoPilotStatusListenerManager.INSTANCE.getState()); + d(SceneConstant.M_BUS + TAG, "initView: " + getState()) // 初始化的时候设置 UI 按钮状态 - showAutopilotBiz(); + showAutopilotBiz() - mSwitchLine.setOnClickListener(this); + mSwitchLine!!.setOnClickListener(this) - mLineName.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - showHideTestBar(); - return false; - } - }); + mLineName!!.setOnLongClickListener { + showHideTestBar() + false + } } @Subscribe(threadMode = ThreadMode.MAIN) - public void changeOverview(EventLogout eventLogout){ - if (eventLogout.getMessgae() == EventLogout.LOGOUT_TYPE){ - CallerLogger.d(M_BUS + TAG,"changeOverview Event消息去登出"); - mPresenter.logout(); - }else if (eventLogout.getMessgae() == EventLogout.SHOW_QR_TYPE){ //显示二维码 - CallerLogger.d(M_BUS + TAG,"changeOverview Event qrcode,sn = " - + SharedPrefsMgr.getInstance().getSn()); - String qrUrl = String.format(FunctionBuildConfig.urlJson.getBindDriverQRUrl(), - SharedPrefsMgr.getInstance().getSn()); - Bitmap bmQr = QRUtilsKt.createQRCodeWithPicture( - BitmapFactory.decodeResource(getResources(), R.drawable.icon_qr_center_logo) - ,qrUrl, AutoSizeUtils.dp2px(getContext(),340f), - AutoSizeUtils.dp2px(getContext(),340f),true); - if (bmQr != null){ - BindQRCodeDialog.Builder builder = new BindQRCodeDialog.Builder(); + fun changeOverview(eventLogout: EventLogout) { + if (eventLogout.messgae == EventLogout.LOGOUT_TYPE) { + d(SceneConstant.M_BUS + TAG, "changeOverview Event消息去登出") + mPresenter!!.logout() + } else if (eventLogout.messgae == EventLogout.SHOW_QR_TYPE) { //显示二维码 + d( + SceneConstant.M_BUS + TAG, "changeOverview Event qrcode,sn = " + + SharedPrefsMgr.getInstance().sn + ) + val qrUrl = String.format( + FunctionBuildConfig.urlJson.bindDriverQRUrl, + SharedPrefsMgr.getInstance().sn + ) + val bmQr = createQRCodeWithPicture( + BitmapFactory.decodeResource(resources, R.drawable.icon_qr_center_logo), + qrUrl, AutoSizeUtils.dp2px(context, 340f), + AutoSizeUtils.dp2px(context, 340f), true + ) + if (bmQr != null) { + val builder = BindQRCodeDialog.Builder() builder.title(getString(R.string.bind_driver_qr_title)) - .cancelStr(getString(R.string.qr_cancel)) - .qrBm(bmQr).build(getContext()).show(); - }else { - CallerLogger.d(M_BUS + TAG,"bmQr = null "); + .cancelStr(getString(R.string.qr_cancel)) + .qrBm(bmQr).build(AbsMogoApplication.getApp())!!.show() + } else { + d(SceneConstant.M_BUS + TAG, "bmQr = null ") } } } - @Override - protected void onArriveStation() { - mPresenter.onAutopilotArriveAtStation(null); - mPresenter.arriveStation(null,"点击进站触发进站操作"); + override fun onArriveStation() { + mPresenter!!.onAutopilotArriveAtStation(null) + mPresenter!!.arriveStation(null, "点击进站触发进站操作") } - @Override - protected void debugArrivedStation() { - mPresenter.onAutopilotArriveAtStation(null); - mPresenter.arriveStation(null,"点击debug进站按钮触发进站操作"); + override fun debugArrivedStation() { + mPresenter!!.onAutopilotArriveAtStation(null) + mPresenter!!.arriveStation(null, "点击debug进站按钮触发进站操作") } - @NonNull - @Override - protected BusPresenter createPresenter() { - return new BusPresenter(this); + override fun createPresenter(): BusPresenter { + return BusPresenter(this) } - @Override - public void onResume() { - super.onResume(); + override fun onResume() { + super.onResume() } - public void hideStationsPanel(){ - groupStationsPanel.setVisibility(View.GONE); - noDataView.setVisibility(View.VISIBLE); + fun hideStationsPanel() { + groupStationsPanel!!.visibility = View.GONE + noDataView!!.visibility = View.VISIBLE } - public void showStationsPanel(){ - groupStationsPanel.setVisibility(View.VISIBLE); - noDataView.setVisibility(View.GONE); + fun showStationsPanel() { + groupStationsPanel!!.visibility = View.VISIBLE + noDataView!!.visibility = View.GONE } - public void updateLineEmptyUI(){ - setArrivedClikable(false); - showOrHideSwitchLineBtn(true); - hideStationsPanel(); - hideSlidePanel(); - resetStationBlinkAnim(); + fun updateLineEmptyUI() { + setArrivedClikable(false) + showOrHideSwitchLineBtn(true) + hideStationsPanel() + hideSlidePanel() + resetStationBlinkAnim() } - private void resetStationBlinkAnim() { - BlinkAnimationUtil.clearAnimation(firstStationItem.getCircleImageView()); - BlinkAnimationUtil.clearAnimation(secondStationItem.getCircleImageView()); - BlinkAnimationUtil.clearAnimation(thirdStationItem.getCircleImageView()); + private fun resetStationBlinkAnim() { + BlinkAnimationUtil.clearAnimation(firstStationItem!!.getCircleImageView()) + BlinkAnimationUtil.clearAnimation(secondStationItem!!.getCircleImageView()) + BlinkAnimationUtil.clearAnimation(thirdStationItem!!.getCircleImageView()) } - public void updateBusTaskStatus(String lineName, String lineTime, - List stationList, - int arrivingOrArrivedIndex, - boolean isArrived){ - - if (getActivity() == null) { - return; + fun updateBusTaskStatus( + lineName: String?, lineTime: String, + stationList: List?, + arrivingOrArrivedIndex: Int, + isArrived: Boolean + ) { + if (activity == 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); + UiThreadHandler.post(Runnable { + if (stationList == null) { + // 获取小巴数据失败 + return@Runnable } - },UiThreadHandler.MODE.QUEUE); + showStationsPanel() + showOrHideSwitchLineBtn(false) + + mLineName!!.text = lineName + mTaskTime!!.text = getString(R.string.bus_line_time_tag) + lineTime + // 渲染小巴路线数据 + updateBusStationStatus(stationList, arrivingOrArrivedIndex, isArrived) + }, UiThreadHandler.MODE.QUEUE) } - private void updateBusStationStatus(List stationList, - int arrivingOrArrivedIndex, - boolean isArrived) { + private fun updateBusStationStatus( + stationList: List, + arrivingOrArrivedIndex: Int, + isArrived: Boolean + ) { + startStation = stationList[0] + endStation = stationList[stationList.size - 1] - startStation = stationList.get(0); - endStation = stationList.get(stationList.size() - 1); - - if (arrivingOrArrivedIndex == stationList.size() - 1 && isArrived){ + if (arrivingOrArrivedIndex == stationList.size - 1 && isArrived) { //切换路线和结束路线按钮切换 - showSlidePanel("单程结束"); + showSlidePanel("单程结束") - setOrRemoveMapMaker(false, BusConst.BUS_END_MAP_MAKER, endStation.getLat() - , endStation.getLon(),R.raw.end_marker); - }else if (arrivingOrArrivedIndex == 0 && isArrived){ + setOrRemoveMapMaker( + false, BusConst.BUS_END_MAP_MAKER, endStation!!.lat, + endStation!!.lon, R.raw.end_marker + ) + } else if (arrivingOrArrivedIndex == 0 && isArrived) { + showSlidePanel("滑动出发") - showSlidePanel("滑动出发"); - - setOrRemoveMapMaker(true, BusConst.BUS_START_MAP_MAKER, - startStation.getLat(), startStation.getLon(),R.raw.star_marker); - setOrRemoveMapMaker(true, BusConst.BUS_END_MAP_MAKER, - endStation.getLat(), endStation.getLon(),R.raw.end_marker); - }else{ - if (isArrived){ + setOrRemoveMapMaker( + true, BusConst.BUS_START_MAP_MAKER, + startStation!!.lat, startStation!!.lon, R.raw.star_marker + ) + setOrRemoveMapMaker( + true, BusConst.BUS_END_MAP_MAKER, + endStation!!.lat, endStation!!.lon, R.raw.end_marker + ) + } else { + if (isArrived) { // 重置滑动按钮文字 - showSlidePanel("滑动出发"); + showSlidePanel("滑动出发") } - setOrRemoveMapMaker(false, BusConst.BUS_START_MAP_MAKER, startStation.getLat() - , startStation.getLon(),R.raw.star_marker); - setOrRemoveMapMaker(true, BusConst.BUS_END_MAP_MAKER, endStation.getLat() - , endStation.getLon(),R.raw.end_marker); + setOrRemoveMapMaker( + false, BusConst.BUS_START_MAP_MAKER, startStation!!.lat, + startStation!!.lon, R.raw.star_marker + ) + setOrRemoveMapMaker( + true, BusConst.BUS_END_MAP_MAKER, endStation!!.lat, + endStation!!.lon, R.raw.end_marker + ) } - if (stationList.size() > 2){ //只有两个站点 - updateMoreThanTwoStationsUI(stationList,arrivingOrArrivedIndex,isArrived); - }else { - updateTwoStationsUI(stationList,arrivingOrArrivedIndex,isArrived); + if (stationList.size > 2) { //只有两个站点 + updateMoreThanTwoStationsUI(stationList, arrivingOrArrivedIndex, isArrived) + } else { + updateTwoStationsUI(stationList, arrivingOrArrivedIndex, isArrived) } - updateBusTestBarInfo(); + updateBusTestBarInfo() } /** @@ -275,87 +263,84 @@ public class ShuttleFragment extends BaseShuttleTabFragment stationList, - int arrivingOrArrivedIndex, - boolean isArrived) { - secondStationItem.setStationTag(""); - secondStationItem.showOrHideStationArrowBg(true); - thirdStationItem.setStationTag(""); - secondStationItem.setVisibility(View.VISIBLE); - thirdStationItem.showOrHideStationArrowBg(false); + private fun updateMoreThanTwoStationsUI( + stationList: List, + arrivingOrArrivedIndex: Int, + isArrived: Boolean + ) { + secondStationItem!!.setStationTag("") + secondStationItem!!.showOrHideStationArrowBg(true) + thirdStationItem!!.setStationTag("") + secondStationItem!!.visibility = View.VISIBLE + thirdStationItem!!.showOrHideStationArrowBg(false) - if (arrivingOrArrivedIndex == 0 || arrivingOrArrivedIndex -1 == 0 - || (arrivingOrArrivedIndex -2 == 0 && stationList.size() == 3)){ - firstStationItem.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_start)); - }else { - firstStationItem.setStationTag(""); + if (arrivingOrArrivedIndex == 0 || arrivingOrArrivedIndex - 1 == 0 || (arrivingOrArrivedIndex - 2 == 0 && stationList.size == 3)) { + firstStationItem!!.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_start)) + } else { + firstStationItem!!.setStationTag("") } - if (arrivingOrArrivedIndex + 1 == stationList.size() - 1 || arrivingOrArrivedIndex == stationList.size() - 1 - || (arrivingOrArrivedIndex == 0 && arrivingOrArrivedIndex + 2 == stationList.size() - 1)){ //确认是否显示 "终" - thirdStationItem.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_end)); - }else { - thirdStationItem.setStationTag(""); + if (arrivingOrArrivedIndex + 1 == stationList.size - 1 || arrivingOrArrivedIndex == stationList.size - 1 || (arrivingOrArrivedIndex == 0 && arrivingOrArrivedIndex + 2 == stationList.size - 1)) { //确认是否显示 "终" + thirdStationItem!!.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_end)) + } else { + thirdStationItem!!.setStationTag("") } //圆点: 0:灰色 过站 1:绿色 到站或者即将到站 2:蓝色:未到站 - if (arrivingOrArrivedIndex == 0 && isArrived){ - firstStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_line_station_color_selected)); - secondStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_arrived_station_name_text_color)); - thirdStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_arrived_station_name_text_color)); + if (arrivingOrArrivedIndex == 0 && isArrived) { + firstStationItem!!.setStationNameColor(getColor(R.color.bus_line_station_color_selected)) + secondStationItem!!.setStationNameColor(getColor(R.color.bus_arrived_station_name_text_color)) + thirdStationItem!!.setStationNameColor(getColor(R.color.bus_arrived_station_name_text_color)) - firstStationItem.setStationName(stationList.get(0).getName()); - secondStationItem.setStationName(stationList.get(1).getName()); - thirdStationItem.setStationName(stationList.get(2).getName()); + firstStationItem!!.setStationName(stationList[0].name) + secondStationItem!!.setStationName(stationList[1].name) + thirdStationItem!!.setStationName(stationList[2].name) - firstStationItem.setStationPointBg(1); - secondStationItem.setStationPointBg(2); - thirdStationItem.setStationPointBg(2); + firstStationItem!!.setStationPointBg(1) + secondStationItem!!.setStationPointBg(2) + thirdStationItem!!.setStationPointBg(2) - firstStationItem.setStationArrowBg(2); - secondStationItem.setStationArrowBg(2); + firstStationItem!!.setStationArrowBg(2) + secondStationItem!!.setStationArrowBg(2) + } else if (arrivingOrArrivedIndex == stationList.size - 1) { + firstStationItem!!.setStationNameColor(getColor(R.color.bus_station_tag_txt_un_color)) + secondStationItem!!.setStationNameColor(getColor(R.color.bus_station_tag_txt_un_color)) + thirdStationItem!!.setStationNameColor(getColor(R.color.bus_line_station_color_selected)) - }else if (arrivingOrArrivedIndex == stationList.size() - 1){ - firstStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_station_tag_txt_un_color)); - secondStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_station_tag_txt_un_color)); - thirdStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_line_station_color_selected)); + firstStationItem!!.setStationName(stationList[arrivingOrArrivedIndex - 2].name) + secondStationItem!!.setStationName(stationList[arrivingOrArrivedIndex - 1].name) + thirdStationItem!!.setStationName(stationList[arrivingOrArrivedIndex].name) - firstStationItem.setStationName(stationList.get(arrivingOrArrivedIndex -2).getName()); - secondStationItem.setStationName(stationList.get(arrivingOrArrivedIndex -1).getName()); - thirdStationItem.setStationName(stationList.get(arrivingOrArrivedIndex).getName()); + firstStationItem!!.setStationPointBg(0) + secondStationItem!!.setStationPointBg(0) + thirdStationItem!!.setStationPointBg(1) - firstStationItem.setStationPointBg(0); - secondStationItem.setStationPointBg(0); - thirdStationItem.setStationPointBg(1); - - firstStationItem.setStationArrowBg(0); - if (isArrived){ - secondStationItem.setStationArrowBg(0); - }else { - secondStationItem.setStationArrowBg(1); + firstStationItem!!.setStationArrowBg(0) + if (isArrived) { + secondStationItem!!.setStationArrowBg(0) + } else { + secondStationItem!!.setStationArrowBg(1) } + } else { + firstStationItem!!.setStationNameColor(getColor(R.color.bus_station_tag_txt_un_color)) + secondStationItem!!.setStationNameColor(getColor(R.color.bus_line_station_color_selected)) + thirdStationItem!!.setStationNameColor(getColor(R.color.bus_arrived_station_name_text_color)) - }else { - firstStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_station_tag_txt_un_color)); - secondStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_line_station_color_selected)); - thirdStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_arrived_station_name_text_color)); + firstStationItem!!.setStationName(stationList[arrivingOrArrivedIndex - 1].name) + secondStationItem!!.setStationName(stationList[arrivingOrArrivedIndex].name) + thirdStationItem!!.setStationName(stationList[arrivingOrArrivedIndex + 1].name) - firstStationItem.setStationName(stationList.get(arrivingOrArrivedIndex -1).getName()); - secondStationItem.setStationName(stationList.get(arrivingOrArrivedIndex).getName()); - thirdStationItem.setStationName(stationList.get(arrivingOrArrivedIndex + 1).getName()); + firstStationItem!!.setStationPointBg(0) + secondStationItem!!.setStationPointBg(1) + thirdStationItem!!.setStationPointBg(2) - firstStationItem.setStationPointBg(0); - secondStationItem.setStationPointBg(1); - thirdStationItem.setStationPointBg(2); - - secondStationItem.setStationArrowBg(2); - if (isArrived){ - firstStationItem.setStationArrowBg(0); - }else { - firstStationItem.setStationArrowBg(1); + secondStationItem!!.setStationArrowBg(2) + if (isArrived) { + firstStationItem!!.setStationArrowBg(0) + } else { + firstStationItem!!.setStationArrowBg(1) } } - } /** @@ -364,109 +349,110 @@ public class ShuttleFragment extends BaseShuttleTabFragment stationList, - int arrivingOrArrivedIndex, - boolean isArrived) { + private fun updateTwoStationsUI( + stationList: List, + arrivingOrArrivedIndex: Int, + isArrived: Boolean + ) { + secondStationItem!!.visibility = View.GONE + secondStationItem!!.showOrHideStationArrowBg(false) + thirdStationItem!!.showOrHideStationArrowBg(false) - secondStationItem.setVisibility(View.GONE); - secondStationItem.showOrHideStationArrowBg(false); - thirdStationItem.showOrHideStationArrowBg(false); + firstStationItem!!.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_start)) + thirdStationItem!!.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_end)) - firstStationItem.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_start)); - thirdStationItem.setStationTag(ResourcesUtils.getString(R.string.bus_station_txt_tag_end)); - - firstStationItem.setStationName(stationList.get(0).getName()); - thirdStationItem.setStationName(stationList.get(1).getName()); + firstStationItem!!.setStationName(stationList[0].name) + thirdStationItem!!.setStationName(stationList[1].name) //圆点: 0:灰色 过站 1:绿色 到站或者即将到站 2:蓝色:未到站 - if (arrivingOrArrivedIndex == 0 && isArrived){//到站 - firstStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_line_station_color_selected)); - thirdStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_arrived_station_name_text_color)); - firstStationItem.setStationPointBg(1); - firstStationItem.setStationArrowBg(2); - thirdStationItem.setStationPointBg(0); - - }else { - firstStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_station_tag_txt_un_color)); - thirdStationItem.setStationNameColor(ResourcesUtils.getColor(R.color.bus_line_station_color_selected)); - if (isArrived){ //到终点 - firstStationItem.setStationPointBg(0); - firstStationItem.setStationArrowBg(0); - thirdStationItem.setStationPointBg(1); - - }else { //到终点途中 - firstStationItem.setStationPointBg(0); - firstStationItem.setStationArrowBg(1); - thirdStationItem.setStationPointBg(1); - } + if (arrivingOrArrivedIndex == 0 && isArrived) { //到站 + firstStationItem!!.setStationNameColor(getColor(R.color.bus_line_station_color_selected)) + thirdStationItem!!.setStationNameColor(getColor(R.color.bus_arrived_station_name_text_color)) + firstStationItem!!.setStationPointBg(1) + firstStationItem!!.setStationArrowBg(2) + thirdStationItem!!.setStationPointBg(0) + } else { + firstStationItem!!.setStationNameColor(getColor(R.color.bus_station_tag_txt_un_color)) + thirdStationItem!!.setStationNameColor(getColor(R.color.bus_line_station_color_selected)) + if (isArrived) { //到终点 + firstStationItem!!.setStationPointBg(0) + firstStationItem!!.setStationArrowBg(0) + thirdStationItem!!.setStationPointBg(1) + } else { //到终点途中 + firstStationItem!!.setStationPointBg(0) + firstStationItem!!.setStationArrowBg(1) + thirdStationItem!!.setStationPointBg(1) + } } } - private void showOrHideSwitchLineBtn(boolean isShow) { - if (isShow){//显示切换路线 - mSwitchLine.setTag(0); - mSwitchLine.setText(ResourcesUtils.getString(R.string.bus_switch_line_btn)); - }else {//显示结束路线 - mSwitchLine.setTag(1); - mSwitchLine.setText(ResourcesUtils.getString(R.string.bus_close_line_btn)); + private fun showOrHideSwitchLineBtn(isShow: Boolean) { + if (isShow) { //显示切换路线 + mSwitchLine!!.tag = 0 + mSwitchLine!!.text = + ResourcesUtils.getString(R.string.bus_switch_line_btn) + } else { //显示结束路线 + mSwitchLine!!.tag = 1 + mSwitchLine!!.text = + ResourcesUtils.getString(R.string.bus_close_line_btn) } } - public void hideOchBus() { + fun hideOchBus() { // tvNotice.setVisibility(View.GONE); } - @Override - public int getStationPanelViewId() { - return R.layout.shuttle_weak_fragment_och; + override fun stationPanelViewId(): Int { + return R.layout.shuttle_weak_fragment_och } - @Override - public void restartAutopilot() { + override fun restartAutopilot() { if (!isAnimateRunning) { - mPresenter.restartAutopilot(); + mPresenter!!.restartAutopilot() } } - @Override - public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() { - return this; + override fun slidePanelOnEndListener(): SlidePanelView.OnSlidePanelMoveToEndListener { + return this } - @Override - public void moveToEnd() { + override fun moveToEnd() { // 开启自动驾驶到下一站 - if (isAnimateRunning){ - stopAutopilotAnimation(); + if (isAnimateRunning) { + stopAutopilotAnimation() } - mPresenter.autoDriveToNextStation(); + mPresenter!!.autoDriveToNextStation() } /** * 设置自动驾驶可用状态 */ - public void onAutopilotEnableChange(boolean isEnable) { + fun onAutopilotEnableChange(isEnable: Boolean) { if (isEnable) { - showAutopilotBiz(); + showAutopilotBiz() } else { - hideAutopilotBiz(); + hideAutopilotBiz() } } - public void clearBusStationsMarkers(){ - CallerLogger.d(M_BUS + TAG,"clearBusStationsMarkers()"); + fun clearBusStationsMarkers() { + d(SceneConstant.M_BUS + TAG, "clearBusStationsMarkers()") if (null != startStation) { - setOrRemoveMapMaker(false, BusConst.BUS_START_MAP_MAKER, startStation.getLat() - , startStation.getLon(),R.raw.star_marker); + setOrRemoveMapMaker( + false, BusConst.BUS_START_MAP_MAKER, startStation!!.lat, + startStation!!.lon, R.raw.star_marker + ) } if (null != endStation) { - setOrRemoveMapMaker(false, BusConst.BUS_END_MAP_MAKER, endStation.getLat() - , endStation.getLon(),R.raw.end_marker); + setOrRemoveMapMaker( + false, BusConst.BUS_END_MAP_MAKER, endStation!!.lat, + endStation!!.lon, R.raw.end_marker + ) } //清除鹰眼右下角小地图轨迹 - CallerLogger.d(SceneConstant.M_BUS, "clearBusStationsMarkers --------->"); - smallMapView.clearPolyline(); + d(SceneConstant.M_BUS, "clearBusStationsMarkers --------->") + smallMapView?.clearPolyline() } /** @@ -475,13 +461,21 @@ public class ShuttleFragment extends BaseShuttleTabFragment { - CallerLogger.d(M_BUS + "setMapMaker= "+Thread.currentThread().getName(), - uuid + "=latitude=" + lat + ",longitude=" + longi); - - Point.Options.Builder builder = new Point.Options.Builder(BusConst.TYPE_MARKER_BUS_ORDER, Level.MAP_MARKER) + val setMapMarkerRunnable = Runnable { + d( + SceneConstant.M_BUS + "setMapMaker= " + Thread.currentThread().name, + "$uuid=latitude=$lat,longitude=$longi" + ) + val builder = + Point.Options.Builder(BusConst.TYPE_MARKER_BUS_ORDER, Level.MAP_MARKER) .setId(uuid) .anchor(0.5f, 0.5f) .set3DMode(true) @@ -489,63 +483,63 @@ public class ShuttleFragment extends BaseShuttleTabFragment { - CallerLogger.d(M_BUS + "RemoveMapMaker="+Thread.currentThread().getName(), - uuid+"=latitude="+lat+",longitude="+longi); - Objects.requireNonNull(CallerMapUIServiceManager.INSTANCE.getOverlayManager()).removePoint(uuid); - }; - OCHThreadPoolManager.getsInstance().execute(removeMapMarkerRunnable); + OCHThreadPoolManager.getsInstance().execute(setMapMarkerRunnable) + } else { + val removeMapMarkerRunnable = Runnable { + d( + SceneConstant.M_BUS + "RemoveMapMaker=" + Thread.currentThread().name, + "$uuid=latitude=$lat,longitude=$longi" + ) + getOverlayManager()?.removePoint(uuid) + } + OCHThreadPoolManager.getsInstance().execute(removeMapMarkerRunnable) } } - @Override - public void debugAutoPilotStatus(int status) { - mPresenter.debugAutoPilotStatus(status); + override fun debugAutoPilotStatus(status: Int) { + mPresenter!!.debugAutoPilotStatus(status) } - @Override - public void onClick(View v) { - if (v.getId() == R.id.switch_line_btn) {//切换路线条件: 自动驾驶过程中,点击则toast提示:自动驾驶中,不可切换路线 + override fun onClick(v: View) { + if (v.id == R.id.switch_line_btn) { //切换路线条件: 自动驾驶过程中,点击则toast提示:自动驾驶中,不可切换路线 //本次行程未结束,不支持切换路线。点击则toast提示:当前行程未完成,不可切换路线 - if (CallerAutoPilotStatusListenerManager.INSTANCE.getState() - == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) { - ToastUtils.showLong(ResourcesUtils.getString(R.string.bus_switch_line_btn_warning1)); - return; + if (getState() + == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + ) { + ToastUtils.showLong(ResourcesUtils.getString(R.string.bus_switch_line_btn_warning1)) + return } - if ((int)mSwitchLine.getTag() == 0){//切换路线 - Intent intent = new Intent(getContext(), BusSwitchLineActivity.class); - ActivityUtils.startActivity(intent); - }else {//结束任务 - OCHCommitDialog.Builder builder = new OCHCommitDialog.Builder(); - OCHCommitDialog closeLineConfirmDialog = builder - .title(getString(R.string.bus_dialog_title)) - .tips(getString(R.string.bus_dialog_tips)) - .confirmStr(getString(R.string.bus_dialog_confirm)) - .cancelStr(getString(R.string.bus_dialog_cancel)) - .build(getContext()); - closeLineConfirmDialog.setClickListener(new OCHCommitDialog.ClickListener() { - @Override - public void confirm() { - mPresenter.abortTask(); + if (mSwitchLine!!.tag as Int == 0) { //切换路线 + val intent = Intent(context, BusSwitchLineActivity::class.java) + ActivityUtils.startActivity(intent) + } else { //结束任务 + val builder = OCHCommitDialog.Builder() + val closeLineConfirmDialog = builder + .title(getString(R.string.bus_dialog_title)) + .tips(getString(R.string.bus_dialog_tips)) + .confirmStr(getString(R.string.bus_dialog_confirm)) + .cancelStr(getString(R.string.bus_dialog_cancel)) + .build(AbsMogoApplication.getApp()) + closeLineConfirmDialog!!.setClickListener(object : OCHCommitDialog.ClickListener { + override fun confirm() { + mPresenter!!.abortTask() } - @Override - public void cancel() { - closeLineConfirmDialog.dismiss(); + override fun cancel() { + closeLineConfirmDialog.dismiss() } - }); - closeLineConfirmDialog.show(); + }) + closeLineConfirmDialog.show() } } } + + companion object { + const val TAG: String = "BusFragment" + } } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt index 827bc95132..caeb2b97ec 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/OrderModel.kt @@ -1,437 +1,409 @@ -package com.mogo.och.weaknet.model; +package com.mogo.och.weaknet.model -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS; - -import android.content.Context; -import android.text.TextUtils; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.elegant.network.utils.GsonUtil; -import com.mogo.commons.AbsMogoApplication; -import com.mogo.eagle.core.data.BaseData; -import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters; -import com.mogo.eagle.core.data.config.FunctionBuildConfig; -import com.mogo.eagle.core.data.map.MogoLocation; -import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; -import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener; -import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; -import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager; -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.eagle.core.utilcode.util.CoordinateUtils; -import com.mogo.eagle.core.utilcode.util.GsonUtils; -import com.mogo.eagle.core.utilcode.util.NetworkUtils; -import com.mogo.eagle.core.utilcode.util.StringUtils; -import com.mogo.eagle.core.utilcode.util.ToastUtils; -import com.mogo.eagle.core.utilcode.util.UiThreadHandler; -import com.mogo.och.common.module.biz.login.LoginStatusManager; -import com.mogo.och.common.module.callback.OchAdasStartFailureCallback; -import com.mogo.och.common.module.constant.OchCommonConst; -import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager; -import com.mogo.och.common.module.manager.autopilot.autopilot.ArrivedStation; -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager; -import com.mogo.och.common.module.manager.autopilot.line.LineManager; -import com.mogo.och.common.module.manager.autopilot.location.OchLocationManager; -import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager; -import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager; -import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager; -import com.mogo.och.common.module.manager.socket.cloud.IOchOnMessageListener; -import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager; -import com.mogo.och.common.module.manager.socket.cloud.data.SystemMsg; -import com.mogo.och.common.module.manager.socket.lan.LanSocketManager; -import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg; -import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg; -import com.mogo.och.common.module.manager.socket.lan.bean.BusCacheKey; -import com.mogo.och.common.module.manager.socket.lan.bean.BusinessType; -import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType; -import com.mogo.och.common.module.manager.socket.lan.bean.LoginCacheStatus; -import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg; -import com.mogo.och.common.module.network.OchCommonServiceCallback; -import com.mogo.och.common.module.utils.DateTimeUtil; -import com.mogo.och.common.module.utils.MultiRequestLimitChecker; -import com.mogo.och.common.module.utils.NumberFormatUtil; -import com.mogo.och.common.module.utils.OCHThreadPoolManager; -import com.mogo.och.common.module.utils.PinYinUtil; -import com.mogo.och.common.module.voice.VoiceNotice; -import com.mogo.och.data.bean.BusRoutesResult; -import com.mogo.och.data.bean.BusStationBean; -import com.mogo.och.data.bean.BusTransferData; -import com.mogo.och.data.manager.cache.CacheDataManager; -import com.mogo.och.weaknet.constant.BusConst; -import com.mogo.och.weaknet.database.repository.SiteRepository; -import com.mogo.och.weaknet.net.OrderServiceManager; -import com.mogo.och.weaknet.util.BusSendTripInfoManager; -import com.mogo.och.weaknet.util.ShuttleVoiceManager; -import com.mogo.och.shuttle.weaknet.R; -import com.mogo.och.weaknet.bean.BusRoutesResponse; -import com.mogo.och.weaknet.callback.IBusADASStatusCallback; -import com.mogo.och.weaknet.callback.IBusControllerStatusCallback; -import com.mogo.och.weaknet.callback.IRefreshBusStationsCallback; -import com.mogo.och.weaknet.callback.ISlidePannelHideCallback; -import com.mogo.och.weaknet.util.BusAnalyticsManager; -import com.mogo.och.weaknet.util.BusTrajectoryManager; - -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import io.reactivex.exceptions.UndeliverableException; -import io.reactivex.functions.Consumer; -import io.reactivex.plugins.RxJavaPlugins; +import android.annotation.SuppressLint +import android.content.Context +import android.text.TextUtils +import com.elegant.network.utils.GsonUtil +import com.mogo.commons.AbsMogoApplication +import com.mogo.eagle.core.data.BaseData +import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters +import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine +import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLonLat +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener +import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.cancelAutoPilot +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.isCanStartAutopilot +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.setIPCDemoMode +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.setIgnoreConditionDraw +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getState +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters +import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.i +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant +import com.mogo.eagle.core.utilcode.util.CoordinateUtils +import com.mogo.eagle.core.utilcode.util.GsonUtils +import com.mogo.eagle.core.utilcode.util.NetworkUtils +import com.mogo.eagle.core.utilcode.util.StringUtils +import com.mogo.eagle.core.utilcode.util.ToastUtils +import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import com.mogo.och.common.module.biz.login.LoginStatusManager +import com.mogo.och.common.module.callback.OchAdasStartFailureCallback +import com.mogo.och.common.module.constant.OchCommonConst +import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager +import com.mogo.och.common.module.manager.autopilot.autopilot.ArrivedStation +import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.canStartAutoPilot +import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.canStartAutoPilotSSM +import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotManager.startAutoPilot +import com.mogo.och.common.module.manager.autopilot.line.LineManager.setLineId +import com.mogo.och.common.module.manager.autopilot.location.OchLocationManager.addGCJ02Listener +import com.mogo.och.common.module.manager.autopilot.location.OchLocationManager.removeGCJ02Listener +import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager +import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager.setStationPoint +import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager.writeChainLog +import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager +import com.mogo.och.common.module.manager.socket.cloud.AbnormalFactorsLoopManager.stopLoopAbnormalFactors +import com.mogo.och.common.module.manager.socket.cloud.IOchOnMessageListener +import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager +import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager.pushAppOperationalMsgBox +import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager.registerSocketMessageListener +import com.mogo.och.common.module.manager.socket.cloud.OCHSocketMessageManager.releaseSocketMessageListener +import com.mogo.och.common.module.manager.socket.cloud.data.SystemMsg +import com.mogo.och.common.module.manager.socket.lan.LanSocketManager.sendMsgToClient +import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg +import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg +import com.mogo.och.common.module.manager.socket.lan.bean.BusCacheKey +import com.mogo.och.common.module.manager.socket.lan.bean.BusinessType +import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType +import com.mogo.och.common.module.manager.socket.lan.bean.LoginCacheStatus +import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg +import com.mogo.och.common.module.network.OchCommonServiceCallback +import com.mogo.och.common.module.utils.DateTimeUtil +import com.mogo.och.common.module.utils.MultiRequestLimitChecker.Companion.generateRequestId +import com.mogo.och.common.module.utils.MultiRequestLimitChecker.Companion.getInstance +import com.mogo.och.common.module.utils.NumberFormatUtil +import com.mogo.och.common.module.utils.OCHThreadPoolManager +import com.mogo.och.common.module.utils.PinYinUtil +import com.mogo.och.common.module.utils.ResourcesUtils +import com.mogo.och.common.module.utils.RxUtils +import com.mogo.och.common.module.voice.VoiceNotice.showNotice +import com.mogo.och.data.bean.BusRoutesResult +import com.mogo.och.data.bean.BusStationBean +import com.mogo.och.data.bean.BusTransferData +import com.mogo.och.data.manager.cache.CacheDataManager +import com.mogo.och.shuttle.weaknet.R +import com.mogo.och.weaknet.bean.BusRoutesResponse +import com.mogo.och.weaknet.callback.IBusADASStatusCallback +import com.mogo.och.weaknet.callback.IBusControllerStatusCallback +import com.mogo.och.weaknet.callback.IRefreshBusStationsCallback +import com.mogo.och.weaknet.callback.ISlidePannelHideCallback +import com.mogo.och.weaknet.constant.BusConst +import com.mogo.och.weaknet.model.TicketModel.load +import com.mogo.och.weaknet.net.OrderServiceManager +import com.mogo.och.weaknet.net.OrderServiceManager.endTask +import com.mogo.och.weaknet.net.OrderServiceManager.leaveStation +import com.mogo.och.weaknet.util.BusAnalyticsManager +import com.mogo.och.weaknet.util.BusSendTripInfoManager +import com.mogo.och.weaknet.util.BusSendTripInfoManager.sendBusTripInfo +import com.mogo.och.weaknet.util.BusTrajectoryManager +import com.mogo.och.weaknet.util.ShuttleVoiceManager.arrivedStationBus +import com.mogo.och.weaknet.util.ShuttleVoiceManager.endOrderBus +import com.mogo.och.weaknet.util.ShuttleVoiceManager.leaveStationBus +import com.mogo.och.weaknet.util.ShuttleVoiceManager.showLeafTime /** * @author congtaowang * @since 2021/3/23 - *

+ * + * * 小巴订单管理 */ -public class OrderModel { - private final String TAG = OrderModel.class.getSimpleName(); - private int backgroundCurrentStationIndex = 0;//A->B 此处值是A站点索引 - private static volatile OrderModel sInstance; - private Context mContext; - private final List stationList = new ArrayList<>(); - private BusRoutesResult busRoutesResult = null; +@SuppressLint("StaticFieldLeak") +object OrderModel { + private val TAG: String = OrderModel::class.java.simpleName + + @JvmStatic + var currentStationIndex: Int = 0 //A->B 此处值是A站点索引 + private set + private var mContext: Context? = null + private val stationList: MutableList? = ArrayList() + @JvmStatic + var busRoutesResult: BusRoutesResult? = null + private set + /** * 用来表示是否正在开往下一站 */ - private boolean isGoingToNextStation = false; - // 运营类型 - private static final int VEHICLE_TYPE = 10; + @JvmStatic + var isGoingToNextStation: Boolean = false + private set + private var refreshBusStationsCallback: IRefreshBusStationsCallback? = null + private var slidePanelHideCallback: ISlidePannelHideCallback? = null + private var mControllerStatusCallback: IBusControllerStatusCallback? = + null //Model->Presenter:VR mode等 + private var mADASStatusCallback: IBusADASStatusCallback? = null - private IRefreshBusStationsCallback refreshBusStationsCallback; - private ISlidePannelHideCallback slidePanelHideCallback; - private IBusControllerStatusCallback mControllerStatusCallback; //Model->Presenter:VR mode等 - private IBusADASStatusCallback mADASStatusCallback; - - private volatile boolean isArrivedStation = false; + @Volatile + private var isArrivedStation = false //0: 代表没有启动过 1代表是启动第一次,当>=1 代表是重试 每次到站/路线结束清空置为0 - private volatile int firstStartAutopilot = 0; + @Volatile + private var firstStartAutopilot = 0 - public static OrderModel getInstance() { - if (sInstance == null) { - synchronized (OrderModel.class) { - if (sInstance == null) { - sInstance = new OrderModel(); - } - } - } - return sInstance; - } + private const val VEHICLE_TYPE: Int = 10 - private OrderModel() { - - } - - public void init() { - mContext = AbsMogoApplication.getApp(); + @JvmStatic + fun init() { + mContext = AbsMogoApplication.getApp() // 定位监听 - OchLocationManager.addGCJ02Listener(TAG,5,mMapLocationListener); + addGCJ02Listener(TAG, 5, mMapLocationListener) //开启自驾后 异常信息返回 - OCHAdasAbilityManager.getInstance().setAdasStartFailureCallback(mAdasStartFailureListener); + OCHAdasAbilityManager.getInstance().setAdasStartFailureCallback(mAdasStartFailureListener) - OCHSocketMessageManager.INSTANCE.registerSocketMessageListener(//监听运营消息 - OCHSocketMessageManager.msgMonitorType, - mMogoOnMessageListener); + registerSocketMessageListener( //监听运营消息 + OCHSocketMessageManager.msgMonitorType, + mMogoOnMessageListener + ) - TicketModel.INSTANCE.load(); + load() - AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext); + AbnormalFactorsLoopManager.startLoopAbnormalFactors(AbsMogoApplication.getApp()) //监听乘客屏发来的消息 - CallerTelematicListenerManager.INSTANCE.addListener(TAG,mReceivedMsgListener); + CallerTelematicListenerManager.addListener(TAG, mReceivedMsgListener) //2022.1.28 // 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃 // The exception could not be delivered to the consumer because it has already canceled/disposed // the flow or the excTeption has nowhere to go to begin with - RxJavaPlugins.setErrorHandler(new Consumer() { - @Override - public void accept(Throwable e) { - if (e instanceof UndeliverableException) { - e = e.getCause(); - CallerLogger.d(M_BUS + TAG, "UndeliverableException"); + RxUtils.errCatch() + } + + private val mReceivedMsgListener: IReceivedMsgListener = object : IReceivedMsgListener { + override fun onDemoMode(isDemoMode: Boolean) { + } + + override fun onReceivedServerSn(sn: String?) { + } + + override fun onReceivedMsg(type: Int, byteArray: ByteArray) { + if (OchCommonConst.BUSINESS_STRING == type) { + d(SceneConstant.M_BUS + BaseDPMsg.TAG, String(byteArray)) + val msg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java) + if (msg != null) { + if (msg.type == DPMsgType.TYPE_TASK_DETAILS.type) { + sendTaskDetailsToClients() + } } - if ((e instanceof IOException)) {// - // fine, irrelevant network problem or API that throws on cancellation - CallerLogger.d(M_BUS + TAG, "IOException"); - return; - } - if (e instanceof InterruptedException) { - // fine, some blocking code was interrupted by a dispose call - CallerLogger.d(M_BUS + TAG, "InterruptedException"); - return; - } - if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) { - // that's likely a bug in the application - CallerLogger.d(M_BUS + TAG, "NullPointerException or IllegalArgumentException"); - Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); - return; - } - if (e instanceof IllegalStateException) { - // that's a bug in RxJava or in a custom operator - CallerLogger.d(M_BUS + TAG, "IllegalStateException"); - Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); - return; - } - CallerLogger.d(M_BUS + TAG, "Undeliverable exception"); } - }); + } } - private final IReceivedMsgListener mReceivedMsgListener = - new IReceivedMsgListener() { - @Override - public void onDemoMode(boolean isDemoMode) { + private val mMogoOnMessageListener = object : IOchOnMessageListener { + override fun target(): Class { + return SystemMsg::class.java + } + override fun onMsgReceived(obj: SystemMsg?) { + if (obj == null) { + d(SceneConstant.M_BUS + TAG, "onMsgReceived = null") + return + } + i(SceneConstant.M_BUS + TAG, "onMsgReceived = " + obj.context) + val list: List = obj.screenList + i(SceneConstant.M_BUS + TAG, "onMsgReceived = " + GsonUtils.toJson(list)) + + if (list != null && list.contains(1)) { // 1司机端 + pushAppOperationalMsgBox( + DateTimeUtil.getCurrentTimeStamp(), + obj.context, OCHSocketMessageManager.OPERATION_SYSTEM + ) } - @Override - public void onReceivedServerSn(@Nullable String sn) { - + if (list != null && list.contains(2)) { //乘客屏 + val msg = AppConnectMsg(true, false, obj.context, -1) + sendMsgToClient(msg) } + } - @Override - public void onReceivedMsg(int type, @NonNull byte[] byteArray) { - if (OchCommonConst.BUSINESS_STRING == type){ - CallerLogger.d(M_BUS + BaseDPMsg.TAG,new String(byteArray)); - BaseDPMsg msg = GsonUtils.fromJson(new String(byteArray),BaseDPMsg.class); - if(msg!=null) { - if (msg.getType() == DPMsgType.TYPE_TASK_DETAILS.getType()) { - sendTaskDetailsToClients(); - } - } - } - } - }; - private final IOchOnMessageListener mMogoOnMessageListener = - new IOchOnMessageListener() { - @Override - public Class target() { - return SystemMsg.class; - } - - @Override - public void onMsgReceived(SystemMsg obj) { - if (obj == null){ - CallerLogger.d(M_BUS + TAG, "onMsgReceived = null"); - return; - } - CallerLogger.i(M_BUS + TAG,"onMsgReceived = "+obj.getContext()); - List list = obj.getScreenList(); - CallerLogger.i(M_BUS + TAG,"onMsgReceived = "+GsonUtils.toJson(list)); - - if (list != null && list.contains(1)){ // 1司机端 - OCHSocketMessageManager.INSTANCE.pushAppOperationalMsgBox(DateTimeUtil.getCurrentTimeStamp(), - obj.getContext(),OCHSocketMessageManager.OPERATION_SYSTEM); - } - - if (list != null && list.contains(2)){ //乘客屏 - AppConnectMsg msg = new AppConnectMsg(true,false,obj.getContext(),-1); - LanSocketManager.sendMsgToClient(msg); - } - - } - }; - - public void setAdasStatusCallback(IBusADASStatusCallback callback){ - this.mADASStatusCallback = callback; } - public void setRefreshBusStationsCallback(IRefreshBusStationsCallback callback){ - this.refreshBusStationsCallback = callback; + @JvmStatic + fun setAdasStatusCallback(callback: IBusADASStatusCallback?) { + this.mADASStatusCallback = callback } - public void setSlidePanelHideCallback(ISlidePannelHideCallback callback) { - this.slidePanelHideCallback = callback; + @JvmStatic + fun setRefreshBusStationsCallback(callback: IRefreshBusStationsCallback?) { + this.refreshBusStationsCallback = callback } - public void setControllerStatusCallback(IBusControllerStatusCallback callback) { - this.mControllerStatusCallback = callback; + @JvmStatic + fun setSlidePanelHideCallback(callback: ISlidePannelHideCallback?) { + this.slidePanelHideCallback = callback } - public void release() { + @JvmStatic + fun setControllerStatusCallback(callback: IBusControllerStatusCallback?) { + this.mControllerStatusCallback = callback + } + @JvmStatic + fun release() { // 注销定位监听 - OchLocationManager.removeGCJ02Listener(TAG); - OCHAdasAbilityManager.getInstance().setAdasStartFailureCallback(null); + removeGCJ02Listener(TAG) - OCHSocketMessageManager.INSTANCE.releaseSocketMessageListener( - OCHSocketMessageManager.msgMonitorType); - OCHSocketMessageManager.INSTANCE.releaseSocketMessageListener( - OCHSocketMessageManager.msgWriteOffPassengerType); + OCHAdasAbilityManager.getInstance().setAdasStartFailureCallback(null) - AbnormalFactorsLoopManager.INSTANCE.stopLoopAbnormalFactors(); + releaseSocketMessageListener( + OCHSocketMessageManager.msgMonitorType + ) + releaseSocketMessageListener( + OCHSocketMessageManager.msgWriteOffPassengerType + ) + + stopLoopAbnormalFactors() //监听乘客屏发来的消息 - CallerTelematicListenerManager.INSTANCE.removeListener(TAG); + CallerTelematicListenerManager.removeListener(TAG) } - private Object readResolve() { - // 阻止反序列化,必须实现 Serializable 接口 - return sInstance; - } + private val mAdasStartFailureListener: OchAdasStartFailureCallback = + object : OchAdasStartFailureCallback { + override fun brakeStatusChanged(isBrakeAvailable: Boolean) { + } - private final OchAdasStartFailureCallback mAdasStartFailureListener = new OchAdasStartFailureCallback() { - @Override - public void brakeStatusChanged(boolean isBrakeAvailable) { - - } - - @Override - public void onStartAutopilotFailure(@NotNull String startFailedCode, @NonNull String startFailedMessage) { - BusAnalyticsManager.getInstance().triggerStartAutopilotFailureEventByAdas(startFailedCode, startFailedMessage,System.currentTimeMillis()); - if (mADASStatusCallback != null && !FunctionBuildConfig.isDemoMode){ - CallerLogger.e( M_BUS + TAG, "mAdasStartFailureListener = "+startFailedMessage ); - mADASStatusCallback.onStartAdasFailure(); + override fun onStartAutopilotFailure( + startFailedCode: String, + startFailedMessage: String + ) { + BusAnalyticsManager.triggerStartAutopilotFailureEventByAdas( + startFailedCode, + startFailedMessage, + System.currentTimeMillis() + ) + if (mADASStatusCallback != null && !FunctionBuildConfig.isDemoMode) { + e(SceneConstant.M_BUS + TAG, "mAdasStartFailureListener = $startFailedMessage") + mADASStatusCallback!!.onStartAdasFailure() + } } } - }; // 自车定位 - private final IMoGoChassisLocationGCJ02Listener mMapLocationListener = new IMoGoChassisLocationGCJ02Listener() { + private val mMapLocationListener: IMoGoChassisLocationGCJ02Listener = + object : IMoGoChassisLocationGCJ02Listener { + override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { + if (null == mogoLocation) return - @Override - public void onChassisLocationGCJ02(@Nullable MogoLocation mogoLocation) { - if (null == mogoLocation) return; - if (mControllerStatusCallback != null) { - mControllerStatusCallback.onCarLocationChanged(mogoLocation); - } - - //是否到站的围栏判断 离站状态并且自动驾驶还未触发到站 - if (isGoingToNextStation && !isArrivedStation) { - OCHThreadPoolManager.getsInstance().locationExecute(new Runnable() { - @Override - public void run() { - judgeArrivedStation(mogoLocation); - } - }); + //是否到站的围栏判断 离站状态并且自动驾驶还未触发到站 + if (isGoingToNextStation && !isArrivedStation) { + OCHThreadPoolManager.getsInstance() + .locationExecute { judgeArrivedStation(mogoLocation) } + } } } - }; //根据围栏判断,是否到达站点 - private void judgeArrivedStation(MogoLocation location) { - - if (backgroundCurrentStationIndex + 1 > stationList.size() - 1) { - CallerLogger.e(M_BUS + TAG, "到站数组越界"); - return; + private fun judgeArrivedStation(location: MogoLocation) { + if (currentStationIndex + 1 > stationList!!.size - 1) { + e(SceneConstant.M_BUS + TAG, "到站数组越界") + return } - BusStationBean upcomingStation = stationList.get(backgroundCurrentStationIndex + 1); + val upcomingStation = stationList[currentStationIndex + 1] - double startLon = upcomingStation.getGcjLon(); - double startLat = upcomingStation.getGcjLat(); - double distance = CoordinateUtils.calculateLineDistance( - startLon, startLat, - location.getLongitude(), location.getLatitude()); + val startLon = upcomingStation.gcjLon + val startLat = upcomingStation.gcjLat + val distance = CoordinateUtils.calculateLineDistance( + startLon, startLat, + location.longitude, location.latitude + ).toDouble() if (distance <= BusConst.ARRIVE_AT_END_STATION_DISTANCE) { - CallerLogger.d(M_BUS + TAG, "行程日志-judgeArrivedStation() distance = " + distance - + " to " + upcomingStation.getName()); - onArriveAt(null,"兜底:根据定位计算到站"); + d( + SceneConstant.M_BUS + TAG, "行程日志-judgeArrivedStation() distance = " + distance + + " to " + upcomingStation.name + ) + onArriveAt(null, "兜底:根据定位计算到站") } } - public void queryBusCacheRoutes(){ + @JvmStatic + fun queryBusCacheRoutes() { + val loginStr = CacheDataManager.instance.getCacheData( + mContext!!, BusCacheKey.BUS_LOGIN_STATUS_CACHE + ) + if (!loginStr.isEmpty()) { + val status = GsonUtils.fromJson(loginStr, LoginCacheStatus::class.java) + LoginStatusManager.setLoginStatus(status.loginStatus) + if (status.updateTime > DateTimeUtil.getTodayStartTime() && + status.loginStatus == 1 + ) { //登陆 - String loginStr = CacheDataManager.Companion.getInstance().getCacheData( - mContext, BusCacheKey.BUS_LOGIN_STATUS_CACHE); - if (!loginStr.isEmpty()){ - LoginCacheStatus status = GsonUtils.fromJson(loginStr,LoginCacheStatus.class); - LoginStatusManager.setLoginStatus(status.getLoginStatus()); - if (status.getUpdateTime() > DateTimeUtil.getTodayStartTime() && - status.getLoginStatus() == 1){//登陆 + val cacheData = CacheDataManager.instance.getCacheData( + mContext!!, + BusCacheKey.BUS_LINE_CACHE + ) - String cacheData = CacheDataManager.Companion.getInstance().getCacheData(mContext, - BusCacheKey.BUS_LINE_CACHE); - - if (cacheData == null || cacheData.isEmpty()){ - queryBusRoutes(); - }else { - BusTransferData data = GsonUtils.fromJson(cacheData,BusTransferData.class); - getCacheRouteSuccess(data.getRoutesResult()); + if (cacheData == null || cacheData.isEmpty()) { + queryBusRoutes() + } else { + val data = GsonUtils.fromJson(cacheData, BusTransferData::class.java) + getCacheRouteSuccess(data.routesResult) } - }else{ // 未登陆 - CacheDataManager.Companion.getInstance().clearCacheData(mContext,BusCacheKey.BUS_LOGIN_STATUS_CACHE); - sendTaskDetailsToClients(); + } else { // 未登陆 + CacheDataManager.instance.clearCacheData( + mContext!!, + BusCacheKey.BUS_LOGIN_STATUS_CACHE + ) + sendTaskDetailsToClients() } } } - private void getCacheRouteSuccess(BusRoutesResult data){ - if (data == null || data.getSites() == null - || data.getSites().isEmpty() - || data.getWriteVersion() < DateTimeUtil.getTodayStartTime()) { - //当为空时,显示无绑定路线图 - queryBusRoutes(); - CacheDataManager.Companion.getInstance().clearCacheData(mContext, BusCacheKey.BUS_LINE_CACHE); - return; - } - CallerLogger.d(M_BUS + TAG, "获取到小巴路线数据: " + GsonUtils.toJson(data)); - updateBusStatus(data); + private fun getCacheRouteSuccess(data: BusRoutesResult?) { + if (data == null || data.sites == null || data.sites.isEmpty() || data.writeVersion < DateTimeUtil.getTodayStartTime()) { + //当为空时,显示无绑定路线图 + queryBusRoutes() + CacheDataManager.instance.clearCacheData(mContext!!, BusCacheKey.BUS_LINE_CACHE) + return + } + d(SceneConstant.M_BUS + TAG, "获取到小巴路线数据: " + GsonUtils.toJson(data)) + updateBusStatus(data) } /** * 查询小巴路线 */ - public void queryBusRoutes() { - CallerLogger.d(M_BUS + TAG, "查询小巴路线"); - OrderServiceManager.queryBusRoutes(mContext, new OchCommonServiceCallback() { - @Override - public void onSuccess(BusRoutesResponse data) { - if (data == null - || data.getResult() == null - || data.getResult().getSites() == null - || data.getResult().getSites().isEmpty()) { + @JvmStatic + fun queryBusRoutes() { + d(SceneConstant.M_BUS + TAG, "查询小巴路线") + OrderServiceManager.queryBusRoutes(mContext!!, object : OchCommonServiceCallback { + override fun onSuccess(data: BusRoutesResponse) { + if (data?.result == null || data.result.sites == null || data.result.sites.isEmpty()) { // //当为空时,显示无绑定路线图 - CallerLogger.d(M_BUS + TAG, "获取到小巴路线数据:空 "); + d(SceneConstant.M_BUS + TAG, "获取到小巴路线数据:空 ") if (refreshBusStationsCallback != null) { - refreshBusStationsCallback.updateEmptyUi(); + refreshBusStationsCallback!!.updateEmptyUi() } - updateBusStatus(null); - clearAutopilotControlParameters(); - closeBeautificationMode(); - clearStartAutopilotTag(); - removeTipRunnables(); - CacheDataManager.Companion.getInstance().clearCacheData(mContext,BusCacheKey.BUS_LINE_CACHE); - return; + updateBusStatus(null) + clearAutopilotControlParameters() + closeBeautificationMode() + clearStartAutopilotTag() + removeTipRunnables() + CacheDataManager.instance.clearCacheData(mContext!!, BusCacheKey.BUS_LINE_CACHE) + return } - if (busRoutesResult == null || busRoutesResult.getWriteVersion() < data.getResult().getWriteVersion()){ - CallerLogger.d(M_BUS + TAG, "更新小巴路线数据: " + data); - updateBusStatus(data.getResult()); - pushCacheTransferData(data.getResult()); + if (busRoutesResult == null || busRoutesResult!!.writeVersion < data.result.writeVersion) { + d(SceneConstant.M_BUS + TAG, "更新小巴路线数据: $data") + updateBusStatus(data.result) + pushCacheTransferData(data.result) } } - @Override - public void onError() { + override fun onError() { if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort(mContext.getString(R.string.network_error_tip)); + ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip)) } else { - ToastUtils.showShort(mContext.getString(R.string.request_error_tip)); + ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip)) } } - @Override - public void onFail(int code, String failMsg) { + override fun onFail(code: Int, failMsg: String) { if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort("网络异常,请稍后重试"); - }else { - ToastUtils.showShort(failMsg); + ToastUtils.showShort("网络异常,请稍后重试") + } else { + ToastUtils.showShort(failMsg) } } - }); - + }) } /** @@ -439,120 +411,125 @@ public class OrderModel { * * @param stations */ - private void updateBusTaskStatus(List stations) { + private fun updateBusTaskStatus(stations: List?) { + var arrivingOrArrivedStationIndex = 0 //已经到站或者即将到站的索引呢 - int arrivingOrArrivedStationIndex = 0;//已经到站或者即将到站的索引呢 - - for (int i = 0; i < stations.size(); i++) { - BusStationBean station = stations.get(i); + for (i in stations!!.indices) { + val station = stations[i] if (i == 0) { // 首发站 显示在最上面 - if (station.getDrivingStatus() == BusConst.STATION_STATUS_STOPPED - && !station.isLeaving()) { //到达第一站 - arrivingOrArrivedStationIndex = i; - break; + if (station.drivingStatus == BusConst.STATION_STATUS_STOPPED + && !station.isLeaving + ) { //到达第一站 + arrivingOrArrivedStationIndex = i + break } } else { - BusStationBean preStation = stations.get(i - 1); - if ((station.getDrivingStatus() == BusConst.STATION_STATUS_STOPPED && !station.isLeaving()) - || (station.getDrivingStatus() == BusConst.STATION_STATUS_ARRIVING - && preStation.isLeaving())) { + val preStation = stations[i - 1] + if ((station.drivingStatus == BusConst.STATION_STATUS_STOPPED && !station.isLeaving) + || (station.drivingStatus == BusConst.STATION_STATUS_ARRIVING + && preStation.isLeaving) + ) { //到站未离开 | 即将到站 显示在最中间 - arrivingOrArrivedStationIndex = i; - break; + arrivingOrArrivedStationIndex = i + break } } } - BusStationBean arrivingOrArrivedStation = stations.get(arrivingOrArrivedStationIndex); + val arrivingOrArrivedStation = stations[arrivingOrArrivedStationIndex] - String lineTime = DateTimeUtil.formatLongToString( - busRoutesResult.getTaskTime(), - DateTimeUtil.HH_mm); + val lineTime = DateTimeUtil.formatLongToString( + busRoutesResult!!.taskTime, + DateTimeUtil.HH_mm + ) - if (arrivingOrArrivedStationIndex == 0 || - arrivingOrArrivedStation.getDrivingStatus() == BusConst.STATION_STATUS_STOPPED - && !arrivingOrArrivedStation.isLeaving()) { + if (arrivingOrArrivedStationIndex == 0 || ( + arrivingOrArrivedStation.drivingStatus == BusConst.STATION_STATUS_STOPPED + && !arrivingOrArrivedStation.isLeaving) + ) { if (refreshBusStationsCallback != null) { - refreshBusStationsCallback.updateBusTaskStatus(busRoutesResult.getName(), lineTime, - stationList, arrivingOrArrivedStationIndex, true); + refreshBusStationsCallback!!.updateBusTaskStatus( + busRoutesResult!!.name, lineTime, + stationList, arrivingOrArrivedStationIndex, true + ) } - clearAutopilotControlParameters(); + clearAutopilotControlParameters() } else { if (refreshBusStationsCallback != null) { - refreshBusStationsCallback.updateBusTaskStatus(busRoutesResult.getName(), lineTime, - stationList, arrivingOrArrivedStationIndex, false); + refreshBusStationsCallback!!.updateBusTaskStatus( + busRoutesResult!!.name, lineTime, + stationList, arrivingOrArrivedStationIndex, false + ) } - updateAutopilotControlParameters(); + updateAutopilotControlParameters() } } /** * 重置路线站点状态--结束路线,当前路线恢复到始发站 */ - public void abortTask() { - CallerLogger.d(M_BUS + TAG, "结束当前路线abortTask"); - if(busRoutesResult==null){ - ToastUtils.showLong("数据异常、请稍后再试"); - return; + @JvmStatic + fun abortTask() { + d(SceneConstant.M_BUS + TAG, "结束当前路线abortTask") + if (busRoutesResult == null) { + ToastUtils.showLong("数据异常、请稍后再试") + return } - OrderServiceManager.abortTask(mContext, busRoutesResult.getTaskId() - , new OchCommonServiceCallback() { - @Override - public void onSuccess(BaseData o) { - CallerLogger.d(M_BUS + TAG, "abortTask success: " + o); - if (o.code == 0) { // 重置成功 - endOrAbortTaskSuccess(); - clearBusStationDatas(); - queryBusRoutes(); - removeTipRunnables(); - // 取消自驾 - CallerAutoPilotControlManager.INSTANCE.cancelAutoPilot(); - setTrajectoryStation(null,null,-1L); - } + OrderServiceManager.abortTask( + mContext!!, busRoutesResult!!.taskId, object : OchCommonServiceCallback { + override fun onSuccess(o: BaseData) { + d(SceneConstant.M_BUS + TAG, "abortTask success: $o") + if (o.code == 0) { // 重置成功 + endOrAbortTaskSuccess() + clearBusStationDatas() + queryBusRoutes() + removeTipRunnables() + // 取消自驾 + cancelAutoPilot() + setTrajectoryStation(null, null, -1L) } + } - @Override - public void onError() { - if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort(mContext.getString(R.string.network_error_tip)); - } else { - ToastUtils.showShort(mContext.getString(R.string.request_error_tip)); - } + override fun onError() { + if (!NetworkUtils.isConnected(mContext)) { + ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip)) + } else { + ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip)) } + } - @Override - public void onFail(int code, String failMsg) { - if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort("网络异常,请稍后重试"); - }else { - ToastUtils.showShort(failMsg); - } + override fun onFail(code: Int, failMsg: String) { + if (!NetworkUtils.isConnected(mContext)) { + ToastUtils.showShort("网络异常,请稍后重试") + } else { + ToastUtils.showShort(failMsg) } - }); - + } + }) } /** * 中断或者正常结束任务后的处理 */ - private void endOrAbortTaskSuccess() { - - isGoingToNextStation = false; - backgroundCurrentStationIndex = 0; + private fun endOrAbortTaskSuccess() { + isGoingToNextStation = false + currentStationIndex = 0 if (busRoutesResult != null) { - BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.END_TRIP - , busRoutesResult.getName() - , "" - , "" - , false); + sendBusTripInfo( + BusSendTripInfoManager.END_TRIP, + busRoutesResult!!.name, + "", + "", + false + ) } - CacheDataManager.Companion.getInstance().clearCacheData(mContext, BusCacheKey.BUS_LINE_CACHE); - busRoutesResult = null; + CacheDataManager.instance.clearCacheData(mContext!!, BusCacheKey.BUS_LINE_CACHE) + busRoutesResult = null - sendTaskDetailsToClients(); + sendTaskDetailsToClients() } /** @@ -560,63 +537,69 @@ public class OrderModel { * 服务端返回的OchBusRoutesResult逻辑, 离开站为当前站, 到达下一站后才会将下一站置为当前站, * 车机端展示是离开当前站,下一站设置为当前站, 所以服务端数据回来要做处理,不能直接渲染 */ - private void leaveStationSuccess(int leaveIndex, String leaveStation, - String nextStation,String nextStationKr, - long writeVersion) { + private fun leaveStationSuccess( + leaveIndex: Int, leaveStation: String, + nextStation: String, nextStationKr: String, + writeVersion: Long + ) { + onStartAutopilot(leaveIndex) - onStartAutopilot(leaveIndex); + leaveTTSTips(nextStation, nextStationKr) - leaveTTSTips(nextStation,nextStationKr); - - sendStartStationToClient(nextStation); + sendStartStationToClient(nextStation) if (busRoutesResult != null) { - boolean isLastStop = false; - if (leaveIndex + 1 == stationList.size() - 1) { - isLastStop = true; + var isLastStop = false + if (leaveIndex + 1 == stationList!!.size - 1) { + isLastStop = true } //给bus外屏发送 - BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.LEAVE_STATION - , busRoutesResult.getName() - , leaveStation - , nextStation - , isLastStop); + sendBusTripInfo( + BusSendTripInfoManager.LEAVE_STATION, + busRoutesResult!!.name, + leaveStation, + nextStation, + isLastStop + ) } - reBuildCacheRouteData(leaveIndex,BusConst.STATION_STATUS_STOPPED,true,writeVersion); + reBuildCacheRouteData(leaveIndex, BusConst.STATION_STATUS_STOPPED, true, writeVersion) } - private void reBuildCacheRouteData(int currentIndex, int currentDrivingStatus, boolean isLeaving - , long writeVersion) { - if (busRoutesResult != null){ - busRoutesResult.setWriteVersion(writeVersion); - List sites = busRoutesResult.getSites(); - BusStationBean bean = sites.get(currentIndex); - bean.setDrivingStatus(currentDrivingStatus); - bean.setLeaving(isLeaving); - sites.set(currentIndex,bean); - if (currentDrivingStatus == BusConst.STATION_STATUS_STOPPED && !isLeaving){ - BusStationBean beanPre = sites.get(currentIndex -1); - beanPre.setDrivingStatus(BusConst.STATION_STATUS_LEAVING); - beanPre.setLeaving(false); - sites.set(currentIndex -1,beanPre); - } - //busRoutesResult.setSite(sites); + private fun reBuildCacheRouteData( + currentIndex: Int, currentDrivingStatus: Int, isLeaving: Boolean, + writeVersion: Long + ) { + if (busRoutesResult != null) { + busRoutesResult!!.writeVersion = writeVersion + val sites = busRoutesResult!!.sites + val bean = sites[currentIndex] + bean.drivingStatus = currentDrivingStatus + bean.isLeaving = isLeaving + sites[currentIndex] = bean + if (currentDrivingStatus == BusConst.STATION_STATUS_STOPPED && !isLeaving) { + val beanPre = sites[currentIndex - 1] + beanPre.drivingStatus = BusConst.STATION_STATUS_LEAVING + beanPre.isLeaving = false + sites[currentIndex - 1] = beanPre + } - pushCacheTransferData(busRoutesResult); + //busRoutesResult.setSite(sites); + pushCacheTransferData(busRoutesResult!!) - updateBusStatus(busRoutesResult); - } + updateBusStatus(busRoutesResult) + } } - private void onStartAutopilot(int leaveIndex) { + private fun onStartAutopilot(leaveIndex: Int) { //开启自动驾驶 2.10.0: 如果自动驾驶状态下开启, 非自动驾驶状态下不开启,需手动点击自动驾驶按钮开启 - isGoingToNextStation = true; - if (CallerAutoPilotStatusListenerManager.INSTANCE.getState() - == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) { - startAutopilot(false, leaveIndex); + isGoingToNextStation = true + if (getState() + == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + ) { + startAutopilot(false, leaveIndex) } else { - firstStartAutopilot = 0; + firstStartAutopilot = 0 } } @@ -625,284 +608,306 @@ public class OrderModel { * * @param isRestart */ - private void startAutopilot(boolean isRestart, int leaveIndex) { - BusAnalyticsManager.getInstance().triggerClickStartAutopilotTime(System.currentTimeMillis()); + private fun startAutopilot(isRestart: Boolean, leaveIndex: Int) { + BusAnalyticsManager.triggerClickStartAutopilotTime(System.currentTimeMillis()) //1、判断轨迹url是否可用 - if(busRoutesResult!=null){ + if (busRoutesResult != null) { //根据开关和后台是否发布轨迹启动自驾 if (FunctionBuildConfig.isPassStartAutopilotCommand - && TextUtils.isEmpty(busRoutesResult.csvFileUrl) - && TextUtils.isEmpty(busRoutesResult.csvFileUrlDPQP) + && TextUtils.isEmpty(busRoutesResult!!.csvFileUrl) + && TextUtils.isEmpty(busRoutesResult!!.csvFileUrlDPQP) ) { - ToastUtils.showLong("无发布轨迹, 请发布后重试"); - CallerLogger.e( - TAG, "isPassStartAutopilotCommand = " + - FunctionBuildConfig.isPassStartAutopilotCommand - + "busRoutesResult.csvFileUrl = " + busRoutesResult.csvFileUrl - ); - return; + ToastUtils.showLong("无发布轨迹, 请发布后重试") + e( + TAG, "isPassStartAutopilotCommand = " + + FunctionBuildConfig.isPassStartAutopilotCommand + + "busRoutesResult.csvFileUrl = " + busRoutesResult!!.csvFileUrl + ) + return } } //2、6个条件判断 - if (!CallerAutoPilotControlManager.INSTANCE.isCanStartAutopilot(true,0)) { - return; + if (!isCanStartAutopilot(true, 0)) { + return } // 3、距离轨迹15m计算 //3、距离轨迹15m计算 - String resion = OchAutoPilotManager.canStartAutoPilot(busRoutesResult.getLineId()); - if(TrajectoryAndDistanceManager.errorTypeNoneLineId.equals(resion)){ - MogoLocation nextStationPoint = new MogoLocation(); - if (backgroundCurrentStationIndex < stationList.size() - 1) { - BusStationBean nextStation = stationList.get(backgroundCurrentStationIndex + 1); - nextStationPoint.setLongitude(nextStation.getGcjLon()); - nextStationPoint.setLatitude(nextStation.getGcjLat()); + var resion = canStartAutoPilot(busRoutesResult!!.lineId) + if (TrajectoryAndDistanceManager.errorTypeNoneLineId == resion) { + val nextStationPoint = MogoLocation() + if (currentStationIndex < stationList!!.size - 1) { + val nextStation = stationList[currentStationIndex + 1] + nextStationPoint.longitude = nextStation.gcjLon + nextStationPoint.latitude = nextStation.gcjLat } - BusStationBean busStationBean = stationList.get(backgroundCurrentStationIndex); - MogoLocation currentStationPoint = new MogoLocation(); - currentStationPoint.setLongitude(busStationBean.getGcjLon()); - currentStationPoint.setLatitude(busStationBean.getGcjLat()); - setTrajectoryStation(currentStationPoint,nextStationPoint, (long) busRoutesResult.getLineId()); - resion = OchAutoPilotManager.canStartAutoPilot(busRoutesResult.getLineId()); + val busStationBean = stationList[currentStationIndex] + val currentStationPoint = MogoLocation() + currentStationPoint.longitude = busStationBean.gcjLon + currentStationPoint.latitude = busStationBean.gcjLat + setTrajectoryStation( + currentStationPoint, + nextStationPoint, + busRoutesResult!!.lineId.toLong() + ) + resion = canStartAutoPilot(busRoutesResult!!.lineId) } - if(!StringUtils.isEmpty(resion)){ - ToastUtils.showShort(resion); - VoiceNotice.showNotice(resion); - return; + if (!StringUtils.isEmpty(resion)) { + ToastUtils.showShort(resion) + showNotice(resion) + return } //4、ssm 给出数据 - if (!OchAutoPilotManager.canStartAutoPilotSSM()) { - triggerUnableStartAPReasonEvent(); - return; + if (!canStartAutoPilotSSM()) { + triggerUnableStartAPReasonEvent() + return } - firstStartAutopilot++; + firstStartAutopilot++ - triggerStartServiceEvent(isRestart, false); + triggerStartServiceEvent(isRestart, false) - AutopilotControlParameters parameters = initAutopilotControlParameters(leaveIndex); + val parameters = initAutopilotControlParameters(leaveIndex) if (null == parameters) { - CallerLogger.e(M_BUS + TAG, "行程日志-AutopilotControlParameters is empty."); - return; + e(SceneConstant.M_BUS + TAG, "行程日志-AutopilotControlParameters is empty.") + return } - OchAutoPilotManager.startAutoPilot(parameters); + startAutoPilot(parameters) - CallerLogger.d(M_BUS + TAG, "行程日志-开启自动驾驶====" + GsonUtil.jsonFromObject(parameters) - + " startLatLon=" + parameters.startName + ",endLatLon=" + parameters.endName + - "isRestart = " + isRestart); + d( + SceneConstant.M_BUS + TAG, + "行程日志-开启自动驾驶====" + GsonUtil.jsonFromObject(parameters) + + " startLatLon=" + parameters.startName + ",endLatLon=" + parameters.endName + + "isRestart = " + isRestart + ) if (mControllerStatusCallback != null) { - mControllerStatusCallback.startOpenAutopilot(); + mControllerStatusCallback!!.startOpenAutopilot() } } /** * 到站后重置站点状态 */ - private void arriveSiteStation(String changeInfo) { - OchChainLogManager.writeChainLog("触发进站", changeInfo); - if ( backgroundCurrentStationIndex +1 > stationList.size() - 1 ) { //到站短时间内调用多次 - CallerLogger.e( M_BUS + TAG, "数组越界" ); - return; + private fun arriveSiteStation(changeInfo: String) { + writeChainLog("触发进站", changeInfo) + if (currentStationIndex + 1 > stationList!!.size - 1) { //到站短时间内调用多次 + e(SceneConstant.M_BUS + TAG, "数组越界") + return } - int arrivedStationIndex = backgroundCurrentStationIndex + 1; - String arriveStation = stationList.get(arrivedStationIndex).getName(); - String arriveStationKr = stationList.get(arrivedStationIndex).getNameKr(); - String departureStopName = stationList.get(backgroundCurrentStationIndex).getName(); - CallerLogger.d(M_BUS + TAG, "arriveSiteStation-currentStationIndex = " + arrivedStationIndex); + val arrivedStationIndex = currentStationIndex + 1 + val arriveStation = stationList[arrivedStationIndex].name + val arriveStationKr = stationList[arrivedStationIndex].nameKr + val departureStopName = stationList[currentStationIndex].name + d(SceneConstant.M_BUS + TAG, "arriveSiteStation-currentStationIndex = $arrivedStationIndex") - isArrivedStation = true; - isGoingToNextStation = false; + isArrivedStation = true + isGoingToNextStation = false - long writeVersion = DateTimeUtil.getCurrentTimeStamp(); - arriveStationSuccess(arrivedStationIndex, departureStopName, - arriveStation,arriveStationKr,writeVersion); + val writeVersion = DateTimeUtil.getCurrentTimeStamp() + arriveStationSuccess( + arrivedStationIndex, departureStopName, + arriveStation, arriveStationKr, writeVersion + ) - String requestId = MultiRequestLimitChecker.Companion.generateRequestId(TAG + "-arriveSiteStation" - , String.valueOf(stationList.get(arrivedStationIndex).getSiteId()) - , String.valueOf(busRoutesResult.getTaskId())); - if (!MultiRequestLimitChecker.Companion.getInstance().canMakeRequest(requestId, 5)) { - CallerLogger.d(M_BUS + TAG, "arriveSiteStation-MultiRequestLimitChecker: 超过最大请求数,本次请求return"); - return; + val requestId = generateRequestId( + "$TAG-arriveSiteStation", + stationList[arrivedStationIndex].siteId.toString(), + busRoutesResult!!.taskId.toString() + ) + if (!getInstance().canMakeRequest(requestId, 5)) { + d( + SceneConstant.M_BUS + TAG, + "arriveSiteStation-MultiRequestLimitChecker: 超过最大请求数,本次请求return" + ) + return } - OrderServiceManager.arriveSiteStation(mContext, - stationList.get(arrivedStationIndex).getSeq(), - stationList.get(arrivedStationIndex).getSiteId(), - busRoutesResult.getTaskId(),writeVersion, - new OchCommonServiceCallback() { - @Override - public void onSuccess(BaseData o) { - CallerLogger.d(M_BUS + TAG, "行程日志-arriveSiteStation success"); - MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId); - } + OrderServiceManager.arriveSiteStation( + mContext!!, + stationList[arrivedStationIndex].seq, + stationList[arrivedStationIndex].siteId, + busRoutesResult!!.taskId, writeVersion, + object : OchCommonServiceCallback { + override fun onSuccess(o: BaseData) { + d(SceneConstant.M_BUS + TAG, "行程日志-arriveSiteStation success") + getInstance().decreaseRequestCount(requestId) + } - @Override - public void onError() { - MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId); - } + override fun onError() { + getInstance().decreaseRequestCount(requestId) + } - @Override - public void onFail(int code, String failMsg) { - MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId); - } - }); + override fun onFail(code: Int, failMsg: String) { + getInstance().decreaseRequestCount(requestId) + } + }) } - private void arriveStationSuccess(int arrivedStationIndex, String departureStopName, - String arriveStation,String arriveStationKr, - long writeVersion) { + private fun arriveStationSuccess( + arrivedStationIndex: Int, departureStopName: String, + arriveStation: String, arriveStationKr: String, + writeVersion: Long + ) { if (busRoutesResult != null) { - boolean isLastStop = false; - if (arrivedStationIndex == busRoutesResult.getSites().size() - 1) { - isLastStop = true; + var isLastStop = false + if (arrivedStationIndex == busRoutesResult!!.sites.size - 1) { + isLastStop = true } //给bus外屏发送 - BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.ARRIVE_STATION - , busRoutesResult.getName() - , departureStopName - , arriveStation - , isLastStop); + sendBusTripInfo( + BusSendTripInfoManager.ARRIVE_STATION, + busRoutesResult!!.name, + departureStopName, + arriveStation, + isLastStop + ) } - ShuttleVoiceManager.INSTANCE.arrivedStationBus(arriveStation,arriveStationKr); + arrivedStationBus(arriveStation, arriveStationKr) - sendArrivedStationToClient(arriveStation); + sendArrivedStationToClient(arriveStation) - reBuildCacheRouteData(arrivedStationIndex, BusConst.STATION_STATUS_STOPPED,false,writeVersion); + reBuildCacheRouteData( + arrivedStationIndex, + BusConst.STATION_STATUS_STOPPED, + false, + writeVersion + ) } - private void sendTaskDetailsToClients() { - - BusTransferData data = new BusTransferData(LoginStatusManager.isLogin() ? 1:0,busRoutesResult); - TaskDetailsMsg msg = new TaskDetailsMsg(GsonUtils.toJson(data), BusinessType.shuttle); - CallerLogger.d(M_BUS + TAG, "sendTaskDetailsToClients = " + GsonUtils.toJson(msg)); - LanSocketManager.sendMsgToClient(msg); + private fun sendTaskDetailsToClients() { + val data = BusTransferData(if (LoginStatusManager.isLogin()) 1 else 0, busRoutesResult) + val msg = TaskDetailsMsg(GsonUtils.toJson(data), BusinessType.shuttle) + d(SceneConstant.M_BUS + TAG, "sendTaskDetailsToClients = " + GsonUtils.toJson(msg)) + sendMsgToClient(msg) } - private void pushCacheTransferData(BusRoutesResult result) { - BusTransferData data = new BusTransferData(LoginStatusManager.isLogin() ? 1:0,result); - CallerLogger.d(M_BUS + TAG, "pushCacheTransferData = " + GsonUtils.toJson(data)); - CacheDataManager.Companion.getInstance().putCacheData(mContext, - BusCacheKey.BUS_LINE_CACHE, - GsonUtils.toJson(data)); + private fun pushCacheTransferData(result: BusRoutesResult) { + val data = BusTransferData(if (LoginStatusManager.isLogin()) 1 else 0, result) + d(SceneConstant.M_BUS + TAG, "pushCacheTransferData = " + GsonUtils.toJson(data)) + CacheDataManager.instance.putCacheData( + mContext!!, + BusCacheKey.BUS_LINE_CACHE, + GsonUtils.toJson(data) + ) } - private void sendArrivedStationToClient(String arriveStation) { - AppConnectMsg arrivedMsg = new AppConnectMsg(false,true,String.format(mContext - .getString(R.string.bus_arrived_station_tip), - arriveStation),-1); - LanSocketManager.sendMsgToClient(arrivedMsg); + private fun sendArrivedStationToClient(arriveStation: String) { + val arrivedMsg = AppConnectMsg(false, true, ResourcesUtils.getString(R.string.bus_arrived_station_tip,arriveStation), -1) + sendMsgToClient(arrivedMsg) } - private void sendStartStationToClient(String nextStation) { - AppConnectMsg startMsg = new AppConnectMsg(false,true,String.format(mContext - .getString(R.string.bus_leave_station_tip), - nextStation),-1); - - UiThreadHandler.postDelayed(()-> LanSocketManager.sendMsgToClient(startMsg), BusConst.DELAY_10S); + private fun sendStartStationToClient(nextStation: String) { + val startMsg = AppConnectMsg(false, true, ResourcesUtils.getString(R.string.bus_leave_station_tip,nextStation), -1) + UiThreadHandler.postDelayed({ sendMsgToClient(startMsg) }, BusConst.DELAY_10S) } - private void sendEndTaskToClient() { - AppConnectMsg endMsg = new AppConnectMsg(false,true,mContext - .getString(R.string.bus_end_task_tip),-1); - LanSocketManager.sendMsgToClient(endMsg); + private fun sendEndTaskToClient() { + val endMsg = AppConnectMsg(false, true, ResourcesUtils.getString(R.string.bus_end_task_tip), -1) + sendMsgToClient(endMsg) } /** * 离站上报 */ - public void leaveStation() { - CallerLogger.d(M_BUS + TAG, "leaveStation-backgroundCurrentStationIndex = " + backgroundCurrentStationIndex); - if(busRoutesResult==null){ - ToastUtils.showLong("数据异常、请稍后再试"); - return; + fun leaveStation() { + d( + SceneConstant.M_BUS + TAG, + "leaveStation-backgroundCurrentStationIndex = " + currentStationIndex + ) + if (busRoutesResult == null) { + ToastUtils.showLong("数据异常、请稍后再试") + return } - String nextStationName = ""; - String nextStationNameKr = ""; - MogoLocation nextStationPoint = new MogoLocation(); - if (backgroundCurrentStationIndex < stationList.size() - 1) { - BusStationBean nextStation = stationList.get(backgroundCurrentStationIndex + 1); - nextStationName = nextStation.getName(); - nextStationNameKr = nextStation.getNameKr(); - nextStationPoint.setLongitude(nextStation.getGcjLon()); - nextStationPoint.setLatitude(nextStation.getGcjLat()); + var nextStationName = "" + var nextStationNameKr = "" + val nextStationPoint = MogoLocation() + if (currentStationIndex < stationList!!.size - 1) { + val nextStation = stationList[currentStationIndex + 1] + nextStationName = nextStation.name + nextStationNameKr = nextStation.nameKr + nextStationPoint.longitude = nextStation.gcjLon + nextStationPoint.latitude = nextStation.gcjLat } - final String currentStationName = stationList.get(backgroundCurrentStationIndex).getName(); - String finalNextStationName = nextStationName; - String finalNextStationNameKr = nextStationNameKr; + val currentStationName = stationList[currentStationIndex].name + val finalNextStationName = nextStationName + val finalNextStationNameKr = nextStationNameKr - isArrivedStation = false; - CallerLogger.d(M_BUS + TAG, "行程日志-离站成功开往下一站===="); + isArrivedStation = false + d(SceneConstant.M_BUS + TAG, "行程日志-离站成功开往下一站====") - long writeVersion = DateTimeUtil.getCurrentTimeStamp(); - leaveStationSuccess(backgroundCurrentStationIndex, currentStationName, - finalNextStationName,finalNextStationNameKr,writeVersion); + val writeVersion = DateTimeUtil.getCurrentTimeStamp() + leaveStationSuccess( + currentStationIndex, currentStationName, + finalNextStationName, finalNextStationNameKr, writeVersion + ) - BusStationBean busStationBean = stationList.get(backgroundCurrentStationIndex); - MogoLocation currentStationPoint = new MogoLocation(); - currentStationPoint.setLongitude(busStationBean.getGcjLon()); - currentStationPoint.setLatitude(busStationBean.getGcjLat()); - setTrajectoryStation(currentStationPoint,nextStationPoint, (long) busRoutesResult.getLineId()); + val busStationBean = stationList[currentStationIndex] + val currentStationPoint = MogoLocation() + currentStationPoint.longitude = busStationBean.gcjLon + currentStationPoint.latitude = busStationBean.gcjLat + setTrajectoryStation( + currentStationPoint, + nextStationPoint, + busRoutesResult!!.lineId.toLong() + ) - String changeInfo = "taskId:" + busRoutesResult.getTaskId() + "--lineId:" + busRoutesResult.getLineId() + - "--currentStationName:"+currentStationName+"--finalNextStationName:"+finalNextStationName; - OchChainLogManager.writeChainLog("滑动出发", changeInfo); - OrderServiceManager.leaveStation(mContext, - stationList.get(backgroundCurrentStationIndex).getSeq(), - stationList.get(backgroundCurrentStationIndex).getSiteId(), - busRoutesResult.getTaskId(),writeVersion, - new OchCommonServiceCallback() { - @Override - public void onSuccess(BaseData o) { - OchChainLogManager.writeChainLog("滑动出发成功", changeInfo); - } + val changeInfo = + "taskId:" + busRoutesResult!!.taskId + "--lineId:" + busRoutesResult!!.lineId + + "--currentStationName:" + currentStationName + "--finalNextStationName:" + finalNextStationName + writeChainLog("滑动出发", changeInfo) + leaveStation( + mContext!!, + stationList[currentStationIndex].seq, + stationList[currentStationIndex].siteId, + busRoutesResult!!.taskId, writeVersion, + object : OchCommonServiceCallback { + override fun onSuccess(o: BaseData) { + writeChainLog("滑动出发成功", changeInfo) + } - @Override - public void onError() { - } + override fun onError() { + } - @Override - public void onFail(int code, String failMsg) { - } - }); + override fun onFail(code: Int, failMsg: String) { + } + }) } //车站10s后播报 - private void leaveTTSTips(String nextStation,String nextStationKr) { - UiThreadHandler.postDelayed(new Runnable() { - @Override - public void run() {//延迟10s播报 - ShuttleVoiceManager.INSTANCE.leaveStationBus(nextStation,nextStationKr); - } - }, BusConst.DELAY_10S); - + private fun leaveTTSTips(nextStation: String, nextStationKr: String) { + UiThreadHandler.postDelayed({ //延迟10s播报 + leaveStationBus(nextStation, nextStationKr) + }, BusConst.DELAY_10S) } /** * 关闭美化模式 */ - public void closeBeautificationMode() { - if (FunctionBuildConfig.isDemoMode) {//收车结束美化 - FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData = false; //是否强制绘制引导线 - CallerAutoPilotControlManager.INSTANCE.setIgnoreConditionDraw(false);// 同步给乘客屏 - CallerAutoPilotControlManager.INSTANCE.setIPCDemoMode(false);//是否自动启动自驾 - CallerLogger.d(M_BUS + TAG, "美化模式-ignore:置为false"); + @JvmStatic + fun closeBeautificationMode() { + if (FunctionBuildConfig.isDemoMode) { //收车结束美化 + FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData = false //是否强制绘制引导线 + setIgnoreConditionDraw(false) // 同步给乘客屏 + setIPCDemoMode(false) //是否自动启动自驾 + d(SceneConstant.M_BUS + TAG, "美化模式-ignore:置为false") } } /** * 开启自动驾驶到下一站 */ - public void autoDriveToNextStation() { - if (backgroundCurrentStationIndex >= stationList.size() - 1) { + @JvmStatic + fun autoDriveToNextStation() { + if (currentStationIndex >= stationList!!.size - 1) { // 当前站是最后一站,结束当前行程 - travelOver(); - return; + travelOver() + return } - leaveStation(); + leaveStation() } /** @@ -912,231 +917,224 @@ public class OrderModel { * * @param result */ - private void updateBusStatus(BusRoutesResult result) { + private fun updateBusStatus(result: BusRoutesResult?) { if (result == null) { - LineManager.setLineId(-1); - return; + setLineId(-1) + return } - busRoutesResult = result; - LineManager.setLineId(busRoutesResult.getLineId()); - stationList.clear(); - stationList.addAll(result.getSites()); - for (int i = 0; i < stationList.size(); i++) { - BusStationBean s = stationList.get(i); + busRoutesResult = result + setLineId(busRoutesResult!!.lineId) + stationList!!.clear() + stationList.addAll(result.sites) + for (i in stationList.indices) { + val s = stationList[i] - CallerLogger.d(M_BUS + "updateBusStationsStatus--", - "Index=" + i + " ,name = " + s.getName() + " ," + s.isLeaving() + "," + s.getDrivingStatus()); + d( + SceneConstant.M_BUS + "updateBusStationsStatus--", + "Index=" + i + " ,name = " + s.name + " ," + s.isLeaving + "," + s.drivingStatus + ) // 是否正在开往下一站 - if (s.isLeaving()) { - isGoingToNextStation = true; + if (s.isLeaving) { + isGoingToNextStation = true } // 当前站点信息 - if (s.getDrivingStatus() == BusConst.STATION_STATUS_STOPPED) { - backgroundCurrentStationIndex = i; - break; + if (s.drivingStatus == BusConst.STATION_STATUS_STOPPED) { + currentStationIndex = i + break } } - if (backgroundCurrentStationIndex == 0 && - stationList.get(0).getDrivingStatus() == BusConst.STATION_STATUS_STOPPED - && !stationList.get(0).isLeaving()) { //默认是第一站到站查询 + if (currentStationIndex == 0 && stationList[0].drivingStatus == BusConst.STATION_STATUS_STOPPED && !stationList[0].isLeaving + ) { //默认是第一站到站查询 if (busRoutesResult != null) { // 第一站到站也是行程开始的时候 - BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.START_TRIP - , busRoutesResult.getName(), "", "", false); + sendBusTripInfo( + BusSendTripInfoManager.START_TRIP, + busRoutesResult!!.name, "", "", false + ) } //任务选择后首发前给司机提示任务 - if (busRoutesResult != null){ - beforeTaskTips(); + if (busRoutesResult != null) { + beforeTaskTips() } - }else { - removeTipRunnables(); + } else { + removeTipRunnables() } - BusStationBean currentStation = stationList.get(backgroundCurrentStationIndex); + val currentStation = stationList[currentStationIndex] - CallerLogger.d(M_BUS + TAG, - "行程日志-STATION_STATUS_STOPPED-backgroundCurrentStationIndex=" - + backgroundCurrentStationIndex - + " isLeaving()=" + currentStation.isLeaving()); + d( + SceneConstant.M_BUS + TAG, + "行程日志-STATION_STATUS_STOPPED-backgroundCurrentStationIndex=" + + currentStationIndex + + " isLeaving()=" + currentStation.isLeaving + ) // 美化是否开始 - if (FunctionBuildConfig.isDemoMode && (backgroundCurrentStationIndex >= 0 - && backgroundCurrentStationIndex <= stationList.size() - 1)) {//行驶过程中设置美化 - if (stationList.get(backgroundCurrentStationIndex).isLeaving()) { - startBeautificationMode(); - CallerLogger.d(M_BUS + TAG, "美化模式-ignore:置为true(每次滑动出发)"); - } else if (backgroundCurrentStationIndex > 0 && backgroundCurrentStationIndex < stationList.size() - 1) { + if (FunctionBuildConfig.isDemoMode && (currentStationIndex >= 0 + && currentStationIndex <= stationList.size - 1) + ) { //行驶过程中设置美化 + if (stationList[currentStationIndex].isLeaving) { + startBeautificationMode() + d(SceneConstant.M_BUS + TAG, "美化模式-ignore:置为true(每次滑动出发)") + } else if (currentStationIndex > 0 && currentStationIndex < stationList.size - 1) { //美化模式下 中间站点到站 引导线要一直绘制,所以此处不出强制绘制不传false - CallerAutoPilotControlManager.INSTANCE.setIPCDemoMode(false); - CallerLogger.d(M_BUS + TAG, "美化模式-ignore:false(到达中间站)"); - clearStartAutopilotTag(); + setIPCDemoMode(false) + d(SceneConstant.M_BUS + TAG, "美化模式-ignore:false(到达中间站)") + clearStartAutopilotTag() } else { - closeBeautificationMode(); - clearStartAutopilotTag(); + closeBeautificationMode() + clearStartAutopilotTag() } } - if (currentStation.isLeaving() && slidePanelHideCallback != null) { - slidePanelHideCallback.hideSlidePanel(); + if (currentStation.isLeaving && slidePanelHideCallback != null) { + slidePanelHideCallback!!.hideSlidePanel() } - sendTaskDetailsToClients(); + sendTaskDetailsToClients() //更新bus路线面板 - updateBusTaskStatus(stationList); + updateBusTaskStatus(stationList) //需放在currentStationIndex赋值之后 - BusTrajectoryManager.getInstance().syncTrajectoryInfo(); + BusTrajectoryManager.getInstance().syncTrajectoryInfo() } - private void beforeTaskTips() { - if (busRoutesResult == null) return; + private fun beforeTaskTips() { + if (busRoutesResult == null) return - removeTipRunnables(); + removeTipRunnables() - long taskTime = busRoutesResult.getTaskTime(); - long tip3Time = taskTime- 3*60*1000 - DateTimeUtil.getCurrentTimeStamp(); // 首站离开前3分钟提示 - long tip1Time = taskTime-60*1000 - DateTimeUtil.getCurrentTimeStamp(); // 首站离开前1分钟提示 + val taskTime = busRoutesResult!!.taskTime + val tip3Time = taskTime - 3 * 60 * 1000 - DateTimeUtil.getCurrentTimeStamp() // 首站离开前3分钟提示 + val tip1Time = taskTime - 60 * 1000 - DateTimeUtil.getCurrentTimeStamp() // 首站离开前1分钟提示 - if (tip3Time > 0){ - UiThreadHandler.postDelayed(tip3Runnable,tip3Time); + if (tip3Time > 0) { + UiThreadHandler.postDelayed(tip3Runnable, tip3Time) } - if (tip1Time > 0){ - UiThreadHandler.postDelayed(tip1Runnable,tip1Time); + if (tip1Time > 0) { + UiThreadHandler.postDelayed(tip1Runnable, tip1Time) } } - Runnable tip3Runnable = new Runnable() { - @Override - public void run() { - - if (backgroundCurrentStationIndex == 0 && stationList.get(0).getDrivingStatus() == BusConst.STATION_STATUS_STOPPED - && !stationList.get(0).isLeaving()){ - tipStartTask("3"); - }else { - removeTipRunnables(); - } + private var tip3Runnable = Runnable { + if (currentStationIndex == 0 && stationList!![0].drivingStatus == BusConst.STATION_STATUS_STOPPED && !stationList[0].isLeaving + ) { + tipStartTask("3") + } else { + removeTipRunnables() } - }; + } - private void tipStartTask(String s) { - String tips = String.format(mContext - .getString(R.string.bus_before_tips_s), s); + private fun tipStartTask(s: String) { + val tips = ResourcesUtils.getString(R.string.bus_before_tips_s,s) //展示在运营消息 - OCHSocketMessageManager.INSTANCE.pushAppOperationalMsgBox( - DateTimeUtil.getCurrentTimeStamp(), - tips,OCHSocketMessageManager.OPERATION_SYSTEM); - ShuttleVoiceManager.INSTANCE.showLeafTime(tips); + pushAppOperationalMsgBox( + DateTimeUtil.getCurrentTimeStamp(), + tips, OCHSocketMessageManager.OPERATION_SYSTEM + ) + showLeafTime(tips) } - Runnable tip1Runnable = new Runnable() { - @Override - public void run() { - if (backgroundCurrentStationIndex == 0 && stationList != null && - stationList.get(0).getDrivingStatus() == BusConst.STATION_STATUS_STOPPED - && !stationList.get(0).isLeaving()){ - tipStartTask("1"); - }else { - removeTipRunnables(); - } - } - }; - - public void removeTipRunnables(){ - if (tip3Runnable != null){ - UiThreadHandler.removeCallbacks(tip3Runnable); - } - if (tip1Runnable != null){ - UiThreadHandler.removeCallbacks(tip1Runnable); + private var tip1Runnable = Runnable { + if (currentStationIndex == 0 && stationList != null && stationList[0].drivingStatus == BusConst.STATION_STATUS_STOPPED && !stationList[0].isLeaving + ) { + tipStartTask("1") + } else { + removeTipRunnables() } } - private void clearStartAutopilotTag() { - firstStartAutopilot = 0; + fun removeTipRunnables() { + UiThreadHandler.removeCallbacks(tip3Runnable) + UiThreadHandler.removeCallbacks(tip1Runnable) } - private void startBeautificationMode() { - FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData = true; - CallerAutoPilotControlManager.INSTANCE.setIgnoreConditionDraw(true); - CallerAutoPilotControlManager.INSTANCE.setIPCDemoMode(true); + private fun clearStartAutopilotTag() { + firstStartAutopilot = 0 } - public void clearBusStationDatas() { + private fun startBeautificationMode() { + FunctionBuildConfig.isIgnoreConditionsDrawAutopilotTrajectoryData = true + setIgnoreConditionDraw(true) + setIPCDemoMode(true) + } + + @JvmStatic + fun clearBusStationDatas() { if (refreshBusStationsCallback != null) { - refreshBusStationsCallback.clearBusStationsMarkers(); + refreshBusStationsCallback!!.clearBusStationsMarkers() } } /** * 在踩刹车、控制方向盘等操作后,会停止自动驾驶,重启自动驾驶的话相当于重新设置自动驾驶目的地 */ - public void restartAutopilot() { - CallerLogger.d(M_BUS + TAG, "行程日志-重启自动驾驶===" + isGoingToNextStation); + @JvmStatic + fun restartAutopilot() { + d(SceneConstant.M_BUS + TAG, "行程日志-重启自动驾驶===$isGoingToNextStation") //只去启动自动驾驶,不再去上报离站 - startAutopilot(firstStartAutopilot >= 1, -1); + startAutopilot(firstStartAutopilot >= 1, -1) } - public boolean isRestartAutopilot() { - return firstStartAutopilot > 1; - } + @JvmStatic + val isRestartAutopilot: Boolean + get() = firstStartAutopilot > 1 /** * 行程结束 */ - private void travelOver() { - - if (backgroundCurrentStationIndex >= stationList.size()) { - CallerLogger.e(M_BUS + TAG, "travel over index out of station list"); - return; + private fun travelOver() { + if (currentStationIndex >= stationList!!.size) { + e(SceneConstant.M_BUS + TAG, "travel over index out of station list") + return } - CallerLogger.d(M_BUS + TAG, "单程结束===="); - CallerAutoPilotControlManager.INSTANCE.cancelAutoPilot(); - setTrajectoryStation(null,null,-1L); - endTask(); + d(SceneConstant.M_BUS + TAG, "单程结束====") + cancelAutoPilot() + setTrajectoryStation(null, null, -1L) + endTask() } /** * task正常结束 */ - private void endTask() { - CallerLogger.d(M_BUS + TAG, "任务正常走完endTask()"); - OrderServiceManager.endTask(mContext, busRoutesResult.getTaskId() - , new OchCommonServiceCallback() { - @Override - public void onSuccess(BaseData o) { - CallerLogger.d(M_BUS + TAG, "endTask success: " + o); - if (o.code == 0) { - endOrAbortTaskSuccess(); - clearBusStationDatas(); - queryBusRoutes();// 重新获取任务 - removeTipRunnables(); - ShuttleVoiceManager.INSTANCE.endOrderBus(); - sendEndTaskToClient(); - } + private fun endTask() { + d(SceneConstant.M_BUS + TAG, "任务正常走完endTask()") + endTask( + mContext!!, busRoutesResult!!.taskId, + object : OchCommonServiceCallback { + override fun onSuccess(o: BaseData) { + d(SceneConstant.M_BUS + TAG, "endTask success: $o") + if (o.code == 0) { + endOrAbortTaskSuccess() + clearBusStationDatas() + queryBusRoutes() // 重新获取任务 + removeTipRunnables() + endOrderBus() + sendEndTaskToClient() } + } - @Override - public void onError() { - if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort(mContext.getString(R.string.network_error_tip)); - } else { - ToastUtils.showShort(mContext.getString(R.string.request_error_tip)); - } + override fun onError() { + if (!NetworkUtils.isConnected(mContext)) { + ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip)) + } else { + ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip)) } + } - @Override - public void onFail(int code, String failMsg) { - if (!NetworkUtils.isConnected(mContext)) { - ToastUtils.showShort("网络异常,请稍后重试"); - }else { - ToastUtils.showShort(failMsg); - } + override fun onFail(code: Int, failMsg: String) { + if (!NetworkUtils.isConnected(mContext)) { + ToastUtils.showShort("网络异常,请稍后重试") + } else { + ToastUtils.showShort(failMsg) } - }); + } + }) } /** @@ -1144,149 +1142,151 @@ public class OrderModel { * * @param data */ - public void onArriveAt(ArrivedStation data,String type) { - if (backgroundCurrentStationIndex + 1 > stationList.size() - 1) { - CallerLogger.e(M_BUS + TAG, "行程日志-到站异常,取消后续操作结束"); - return; + @JvmStatic + fun onArriveAt(data: ArrivedStation?, type: String) { + if (currentStationIndex + 1 > stationList!!.size - 1) { + e(SceneConstant.M_BUS + TAG, "行程日志-到站异常,取消后续操作结束") + return } //MAP 280 每隔100ms左右返回一次到站, 导致在到达中间站后再次滑动出发后会有时间差,收到一次到站,出现问题 //此处比对 自驾告诉的到站站点坐标和本地应到站站点坐标, 一致时才能到站 - if (data != null && data.getEndLocation() != null) { + if (data != null && data.endLocation != null) { + val latitude = NumberFormatUtil.cutOutNumber(data.endLocation.latitude, 5) //wgs + val longitude = NumberFormatUtil.cutOutNumber(data.endLocation.longitude, 5) - String latitude = NumberFormatUtil.cutOutNumber(data.getEndLocation().getLatitude(), 5); //wgs - String longitude = NumberFormatUtil.cutOutNumber(data.getEndLocation().getLongitude(), 5); + val arrivedStationIndex = currentStationIndex + 1 + val arriveStation = stationList[arrivedStationIndex] + val arriveLat = NumberFormatUtil.cutOutNumber(arriveStation.lat, 5) + val arriveLon = NumberFormatUtil.cutOutNumber(arriveStation.lon, 5) - int arrivedStationIndex = backgroundCurrentStationIndex + 1; - BusStationBean arriveStation = stationList.get(arrivedStationIndex); - String arriveLat = NumberFormatUtil.cutOutNumber(arriveStation.getLat(), 5); - String arriveLon = NumberFormatUtil.cutOutNumber(arriveStation.getLon(), 5); - - if (!latitude.equals(arriveLat) || !longitude.equals(arriveLon)) { - CallerLogger.e(M_BUS + TAG, "行程日志-到站拦截,到站坐标不一致"); - return; + if (latitude != arriveLat || longitude != arriveLon) { + e(SceneConstant.M_BUS + TAG, "行程日志-到站拦截,到站坐标不一致") + return } } - if (isArrivedStation) return; + if (isArrivedStation) return - CallerLogger.d(M_BUS + TAG, "行程日志-当前==backgroundCurrentStationIndex=" - + backgroundCurrentStationIndex); + d( + SceneConstant.M_BUS + TAG, "行程日志-当前==backgroundCurrentStationIndex=" + + currentStationIndex + ) - arriveSiteStation(type); - } - - public boolean isGoingToNextStation() { - return isGoingToNextStation; + arriveSiteStation(type) } // 登出 - public void logout() { - LoginStatusManager.loginOut(); + @JvmStatic + fun logout() { + LoginStatusManager.loginOut() } - public void triggerStartServiceEvent(boolean isRestart, boolean send) { - if (stationList == null || backgroundCurrentStationIndex >= stationList.size() - 1) { - return; + @JvmStatic + fun triggerStartServiceEvent(isRestart: Boolean, send: Boolean) { + if (stationList == null || currentStationIndex >= stationList.size - 1) { + return } - BusStationBean currentStation = stationList.get(backgroundCurrentStationIndex); - BusStationBean nextStation = stationList.get(backgroundCurrentStationIndex + 1); - BusAnalyticsManager.getInstance().triggerStartAutopilotEvent(isRestart, send, - currentStation.getName(), nextStation.getName(), busRoutesResult.getLineId(),"",System.currentTimeMillis()); + val currentStation = stationList[currentStationIndex] + val nextStation = stationList[currentStationIndex + 1] + BusAnalyticsManager.triggerStartAutopilotEvent( + isRestart, + send, + currentStation.name, + nextStation.name, + busRoutesResult!!.lineId, + "", + System.currentTimeMillis() + ) } - public void triggerUnableStartAPReasonEvent() { - if (stationList == null || backgroundCurrentStationIndex >= stationList.size() - 1) { - return; + fun triggerUnableStartAPReasonEvent() { + if (stationList == null || currentStationIndex >= stationList.size - 1) { + return } - BusStationBean currentStation = stationList.get(backgroundCurrentStationIndex); - BusStationBean nextStation = stationList.get(backgroundCurrentStationIndex + 1); - BusAnalyticsManager.getInstance().triggerUnableStartAPReasonEvent( - currentStation.getName(), nextStation.getName(), String.valueOf(busRoutesResult.getLineId()),"", - OCHAdasAbilityManager.getInstance().getAutopilotUnAbilityReason()); + val currentStation = stationList[currentStationIndex] + val nextStation = stationList[currentStationIndex + 1] + BusAnalyticsManager.triggerUnableStartAPReasonEvent( + currentStation.name, nextStation.name, busRoutesResult!!.lineId.toString(), "", + OCHAdasAbilityManager.getInstance().autopilotUnAbilityReason + ) } - public BusRoutesResult getBusRoutesResult() { - return busRoutesResult; - } - - public BusStationBean getBusNextStation() { - // A->B 的过程中A站点的信息 - if (stationList == null || backgroundCurrentStationIndex >= stationList.size() - 1) { - return null; + val busNextStation: BusStationBean? + get() { + // A->B 的过程中A站点的信息 + if (stationList == null || currentStationIndex >= stationList.size - 1) { + return null + } + return stationList[currentStationIndex] } - return stationList.get(backgroundCurrentStationIndex); - } - - public int getCurrentStationIndex() { - return backgroundCurrentStationIndex; - } /** * 将业务订单信息保存,鹰眼可取用 */ - private void updateAutopilotControlParameters() { - - AutopilotControlParameters parameters = initAutopilotControlParameters(-1); + private fun updateAutopilotControlParameters() { + val parameters = initAutopilotControlParameters(-1) if (null == parameters) { - CallerLogger.e(M_BUS + TAG, "AutopilotControlParameters is empty."); - return; + e(SceneConstant.M_BUS + TAG, "AutopilotControlParameters is empty.") + return } - CallerLogger.d(M_BUS + TAG, "AutopilotControlParameters is update."); - CallerAutoPilotStatusListenerManager.INSTANCE.updateAutopilotControlParameters(parameters); + d(SceneConstant.M_BUS + TAG, "AutopilotControlParameters is update.") + updateAutopilotControlParameters(parameters) } - private void clearAutopilotControlParameters() { - CallerLogger.d(M_BUS + TAG, "AutopilotControlParameters is clear."); - CallerAutoPilotStatusListenerManager.INSTANCE.updateAutopilotControlParameters(null); + private fun clearAutopilotControlParameters() { + d(SceneConstant.M_BUS + TAG, "AutopilotControlParameters is clear.") + updateAutopilotControlParameters(null) } - private AutopilotControlParameters initAutopilotControlParameters(int leaveIndex) { - BusStationBean currentStation = null; - BusStationBean nextStation = null; + private fun initAutopilotControlParameters(leaveIndex: Int): AutopilotControlParameters? { + var currentStation: BusStationBean? = null + var nextStation: BusStationBean? = null if (leaveIndex < 0) { - if (backgroundCurrentStationIndex + 1 > stationList.size() - 1 || !isGoingToNextStation) { - CallerLogger.e(M_BUS + TAG, "行程日志-mismatch condition1."); - return null; + if (currentStationIndex + 1 > stationList!!.size - 1 || !isGoingToNextStation) { + e(SceneConstant.M_BUS + TAG, "行程日志-mismatch condition1.") + return null } - currentStation = stationList.get(backgroundCurrentStationIndex); - nextStation = stationList.get(backgroundCurrentStationIndex + 1); + currentStation = stationList[currentStationIndex] + nextStation = stationList[currentStationIndex + 1] } else { - if (leaveIndex + 1 > stationList.size() - 1 || !isGoingToNextStation) { - CallerLogger.e(M_BUS + TAG, "行程日志-mismatch condition2."); - return null; + if (leaveIndex + 1 > stationList!!.size - 1 || !isGoingToNextStation) { + e(SceneConstant.M_BUS + TAG, "行程日志-mismatch condition2.") + return null } - currentStation = stationList.get(leaveIndex); - nextStation = stationList.get(leaveIndex + 1); + currentStation = stationList[leaveIndex] + nextStation = stationList[leaveIndex + 1] } - AutopilotControlParameters parameters = new AutopilotControlParameters(); - parameters.routeID = busRoutesResult.getLineId(); - parameters.routeName = busRoutesResult.getName(); - parameters.startName = PinYinUtil.getPinYinHeadChar(currentStation.getName()); - parameters.endName = PinYinUtil.getPinYinHeadChar(nextStation.getName()); - parameters.startLatLon = new AutopilotControlParameters - .AutoPilotLonLat(currentStation.getLat(), currentStation.getLon()); - parameters.endLatLon = new AutopilotControlParameters - .AutoPilotLonLat(nextStation.getLat(), nextStation.getLon()); - parameters.vehicleType = VEHICLE_TYPE; + val parameters = AutopilotControlParameters() + parameters.routeID = busRoutesResult!!.lineId + parameters.routeName = busRoutesResult!!.name + parameters.startName = PinYinUtil.getPinYinHeadChar(currentStation.name) + parameters.endName = PinYinUtil.getPinYinHeadChar(nextStation.name) + parameters.startLatLon = AutoPilotLonLat(currentStation.lat, currentStation.lon) + parameters.endLatLon = AutoPilotLonLat(nextStation.lat, nextStation.lon) + parameters.vehicleType = VEHICLE_TYPE if (parameters.autoPilotLine == null) { - parameters.autoPilotLine = new AutopilotControlParameters.AutoPilotLine( - busRoutesResult.getLineId(), busRoutesResult.getName(), - busRoutesResult.csvFileUrl, busRoutesResult.csvFileMd5, - busRoutesResult.txtFileUrl, busRoutesResult.txtFileMd5, - busRoutesResult.contrailSaveTime, busRoutesResult.carModel, - busRoutesResult.csvFileUrlDPQP, busRoutesResult.csvFileMd5DPQP, - busRoutesResult.txtFileUrlDPQP, busRoutesResult.txtFileMd5DPQP, - busRoutesResult.contrailSaveTimeDPQP); + parameters.autoPilotLine = AutoPilotLine( + busRoutesResult!!.lineId.toLong(), busRoutesResult!!.name, + busRoutesResult!!.csvFileUrl, busRoutesResult!!.csvFileMd5, + busRoutesResult!!.txtFileUrl, busRoutesResult!!.txtFileMd5, + busRoutesResult!!.contrailSaveTime, busRoutesResult!!.carModel, + busRoutesResult!!.csvFileUrlDPQP, busRoutesResult!!.csvFileMd5DPQP, + busRoutesResult!!.txtFileUrlDPQP, busRoutesResult!!.txtFileMd5DPQP, + busRoutesResult!!.contrailSaveTimeDPQP + ) } - return parameters; + return parameters } - public void setTrajectoryStation(MogoLocation startStation,MogoLocation endStation,Long lineId){ - TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation,lineId); + fun setTrajectoryStation( + startStation: MogoLocation?, + endStation: MogoLocation?, + lineId: Long? + ) { + setStationPoint(startStation, endStation, lineId) } - } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/TicketModel.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/TicketModel.kt index 8073cefd21..c36b4acb7f 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/TicketModel.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/model/TicketModel.kt @@ -96,8 +96,8 @@ object TicketModel : IReceivedMsgListener, IOchOnMessageListener implements IBusLinesCallback { +class BusLinePresenter(view: BusSwitchLineView?) : Presenter(view), + IBusLinesCallback { + private var subscribe: Disposable? = null - private Disposable subscribe; - - public BusLinePresenter(BusSwitchLineView view) { - super(view); - BusLineModel.init(); - OrderModel.getInstance().init(); + init { + BusLineModel.init() + OrderModel.init() } - @Override - public void onCreate(@NonNull LifecycleOwner owner) { - super.onCreate(owner); - initListener(); + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + initListener() } - private void initListener() { - BusLineModel.setBusLinesCallback(this); + private fun initListener() { + setBusLinesCallback(this) } - @Override - public void onBusLinesChange(List data) { - if(mView!=null) { - mView.onBusLinesChange(data); + override fun onBusLinesChange(data: List) { + if (mView != null) { + mView!!.onBusLinesChange(data) } } - @Override - public void onChangeLineIdSuccess() { - OrderModel.getInstance().clearBusStationDatas(); - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.onChangeLineIdSuccess(); - } + override fun onChangeLineIdSuccess() { + clearBusStationDatas() + UiThreadHandler.post({ + if (mView != null) { + mView!!.onChangeLineIdSuccess() } - }, UiThreadHandler.MODE.QUEUE); + }, UiThreadHandler.MODE.QUEUE) } - public void queryBusLines(){ - BusLineModel.queryBusLines(); + fun queryBusLines() { + BusLineModel.queryBusLines() } - public void queryBusLineTasks(long lineId, int position,boolean close){ - if(subscribe!=null&&!subscribe.isDisposed()){ - subscribe.dispose(); + fun queryBusLineTasks(lineId: Long, position: Int, close: Boolean) { + if (subscribe != null && !subscribe!!.isDisposed) { + subscribe!!.dispose() } - if(close){ - return; + if (close) { + return + } + queryBusLineTasksById(lineId, position, false) + subscribe = Observable.interval(3, TimeUnit.MINUTES).subscribe { aLong: Long? -> + queryBusLineTasksById(lineId, position, true) } - BusLineModel.queryBusLineTasksById(lineId,position,false); - subscribe = Observable.interval(3, TimeUnit.MINUTES).subscribe(aLong -> { - BusLineModel.queryBusLineTasksById(lineId,position,true); - }); } - public void commitSwitchLineId(long taskId,long lineId){ - BusLineModel.commitSwitchLineId(taskId,lineId); + fun commitSwitchLineId(taskId: Long, lineId: Long) { + BusLineModel.commitSwitchLineId(taskId, lineId) } - public void removeListener(){ - BusLineModel.setBusLinesCallback(null); + fun removeListener() { + setBusLinesCallback(null) } - public void queryBusRoutes(){ - OrderModel.getInstance().queryBusRoutes(); + fun queryBusRoutes() { + OrderModel.queryBusRoutes() } - @Override - public void onDestroy(@NonNull LifecycleOwner owner) { - super.onDestroy(owner); - if(subscribe!=null&&!subscribe.isDisposed()){ - subscribe.dispose(); + override fun onDestroy(owner: LifecycleOwner) { + super.onDestroy(owner) + if (subscribe != null && !subscribe!!.isDisposed) { + subscribe!!.dispose() } } - @Override - public void onBusLineTasks(List o, int position, boolean autoRefresh) { - if(mView!=null) { - mView.onBusLineTasks(o,position,autoRefresh); + override fun onBusLineTasks( + o: List, + position: Int, + autoRefresh: Boolean + ) { + if (mView != null) { + mView!!.onBusLineTasks(o, position, autoRefresh) } } } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/presenter/BusPresenter.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/presenter/BusPresenter.kt index fcb83bcb9b..b57c19834f 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/presenter/BusPresenter.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/presenter/BusPresenter.kt @@ -1,325 +1,274 @@ -package com.mogo.och.weaknet.presenter; +package com.mogo.och.weaknet.presenter -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS; - -import android.os.Looper; - -import androidx.annotation.NonNull; -import androidx.lifecycle.LifecycleOwner; - -import com.mogo.commons.AbsMogoApplication; -import com.mogo.commons.mvp.Presenter; -import com.mogo.eagle.core.data.config.FunctionBuildConfig; -import com.mogo.eagle.core.data.map.MogoLocation; -import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.eagle.core.utilcode.util.UiThreadHandler; -import com.mogo.och.common.module.biz.login.LoginStatusEnum; -import com.mogo.och.common.module.manager.autopilot.autopilot.ArrivedStation; -import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener; -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager; -import com.mogo.och.data.bean.BusStationBean; -import com.mogo.och.common.module.biz.login.ILoginCallback; -import com.mogo.och.common.module.biz.login.LoginStatusManager; -import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager; -import com.mogo.och.weaknet.callback.IBusADASStatusCallback; -import com.mogo.och.weaknet.callback.IBusControllerStatusCallback; -import com.mogo.och.weaknet.callback.IRefreshBusStationsCallback; -import com.mogo.och.weaknet.callback.ISlidePannelHideCallback; -import com.mogo.och.weaknet.fragment.ShuttleFragment; -import com.mogo.och.weaknet.model.OrderModel; -import com.mogo.och.weaknet.util.BusTrajectoryManager; - - -import java.util.ArrayList; -import java.util.List; - -import mogo_msg.MogoReportMsg; +import androidx.lifecycle.LifecycleOwner +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.mvp.Presenter +import com.mogo.eagle.core.data.config.FunctionBuildConfig +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.isCanStartAutopilot +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getState +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant +import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import com.mogo.och.common.module.biz.login.ILoginCallback +import com.mogo.och.common.module.biz.login.LoginStatusEnum +import com.mogo.och.common.module.biz.login.LoginStatusManager +import com.mogo.och.common.module.biz.login.LoginStatusManager.isLogin +import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager +import com.mogo.och.common.module.manager.autopilot.autopilot.ArrivedStation +import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener +import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager +import com.mogo.och.data.bean.BusStationBean +import com.mogo.och.weaknet.callback.IBusADASStatusCallback +import com.mogo.och.weaknet.callback.IBusControllerStatusCallback +import com.mogo.och.weaknet.callback.IRefreshBusStationsCallback +import com.mogo.och.weaknet.callback.ISlidePannelHideCallback +import com.mogo.och.weaknet.fragment.ShuttleFragment +import com.mogo.och.weaknet.model.OrderModel +import com.mogo.och.weaknet.model.OrderModel.closeBeautificationMode +import com.mogo.och.weaknet.model.OrderModel.init +import com.mogo.och.weaknet.model.OrderModel.isGoingToNextStation +import com.mogo.och.weaknet.model.OrderModel.isRestartAutopilot +import com.mogo.och.weaknet.model.OrderModel.onArriveAt +import com.mogo.och.weaknet.model.OrderModel.queryBusCacheRoutes +import com.mogo.och.weaknet.model.OrderModel.release +import com.mogo.och.weaknet.model.OrderModel.setAdasStatusCallback +import com.mogo.och.weaknet.model.OrderModel.setControllerStatusCallback +import com.mogo.och.weaknet.model.OrderModel.setRefreshBusStationsCallback +import com.mogo.och.weaknet.model.OrderModel.setSlidePanelHideCallback +import com.mogo.och.weaknet.model.OrderModel.triggerStartServiceEvent +import com.mogo.och.weaknet.util.BusTrajectoryManager +import mogo_msg.MogoReportMsg.MogoReportMessage /** * 网约车小巴 * * @author tongchenfei */ -public class BusPresenter extends Presenter - implements IRefreshBusStationsCallback, ISlidePannelHideCallback - , IOchAutopilotStatusListener, IBusControllerStatusCallback, ILoginCallback, IBusADASStatusCallback { +class BusPresenter(view: ShuttleFragment?) : Presenter(view), + IRefreshBusStationsCallback, ISlidePannelHideCallback, IOchAutopilotStatusListener, + IBusControllerStatusCallback, ILoginCallback, IBusADASStatusCallback { + private val mStationList: MutableList = ArrayList() + private var mCurrentStation = 0 - private static final String TAG = "BusPresenter"; - - private final List mStationList = new ArrayList<>(); - private int mCurrentStation = 0; - - public BusPresenter(ShuttleFragment view) { - super(view); + init { //2021.11.1 鹰眼架构整合,由IMoGoAutopilotStatusListener逐步替代IMogoAdasOCHCallback接口 - OrderModel.getInstance().init(); - OCHAdasAbilityManager.getInstance().init(AbsMogoApplication.getApp()); - + init() + OCHAdasAbilityManager.getInstance().init(AbsMogoApplication.getApp()) } - @Override - public void onCreate(@NonNull LifecycleOwner owner) { - super.onCreate(owner); - initModelListener(); + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + initModelListener() - OrderModel.getInstance().queryBusCacheRoutes(); + queryBusCacheRoutes() } - @Override - public void onDestroy(@NonNull LifecycleOwner owner) { - super.onDestroy(owner); - OrderModel.getInstance().release(); - releaseListener(); + override fun onDestroy(owner: LifecycleOwner) { + super.onDestroy(owner) + release() + releaseListener() } - public void initModelListener() { - OrderModel.getInstance().setRefreshBusStationsCallback(this); - OrderModel.getInstance().setSlidePanelHideCallback(this); - OrderModel.getInstance().setControllerStatusCallback(this); - OrderModel.getInstance().setAdasStatusCallback(this); - OchAutoPilotStatusListenerManager.INSTANCE.addListener(TAG,this); - LoginStatusManager.INSTANCE.addListener(TAG,this); + fun initModelListener() { + setRefreshBusStationsCallback(this) + setSlidePanelHideCallback(this) + setControllerStatusCallback(this) + setAdasStatusCallback(this) + OchAutoPilotStatusListenerManager.addListener(TAG, this) + LoginStatusManager.addListener(TAG, this) } - public void releaseListener() { - OrderModel.getInstance().setRefreshBusStationsCallback(null); - OrderModel.getInstance().setSlidePanelHideCallback(null); - OrderModel.getInstance().setControllerStatusCallback(null); - OrderModel.getInstance().setAdasStatusCallback(null); - OCHAdasAbilityManager.getInstance().release(); - OchAutoPilotStatusListenerManager.INSTANCE.removeListener(TAG); - LoginStatusManager.INSTANCE.removeListener(TAG); + fun releaseListener() { + setRefreshBusStationsCallback(null) + setSlidePanelHideCallback(null) + setControllerStatusCallback(null) + setAdasStatusCallback(null) + OCHAdasAbilityManager.getInstance().release() + OchAutoPilotStatusListenerManager.removeListener(TAG) + LoginStatusManager.removeListener(TAG) } - public void abortTask() { - OrderModel.getInstance().abortTask(); + fun abortTask() { + OrderModel.abortTask() } - public void autoDriveToNextStation() { - OrderModel.getInstance().autoDriveToNextStation(); + fun autoDriveToNextStation() { + OrderModel.autoDriveToNextStation() } - public void restartAutopilot() { - if (OrderModel.getInstance().isGoingToNextStation()){ - OrderModel.getInstance().restartAutopilot(); + fun restartAutopilot() { + if (isGoingToNextStation) { + OrderModel.restartAutopilot() } } // 登出 - public void logout() { - OrderModel.getInstance().logout(); + fun logout() { + OrderModel.logout() } - @Override - public void updateBusTaskStatus(String lineName,String lineTime, - List stationList, - int arrivingOrArrivedIndex, - boolean isArrived) { - mStationList.clear(); - mStationList.addAll(stationList); - if (arrivingOrArrivedIndex == 0 || isArrived){ - mCurrentStation = arrivingOrArrivedIndex; - }else { - mCurrentStation = arrivingOrArrivedIndex -1; + override fun updateBusTaskStatus( + lineName: String, lineTime: String, + stationList: List, + arrivingOrArrivedIndex: Int, + isArrived: Boolean + ) { + mStationList.clear() + mStationList.addAll(stationList) + mCurrentStation = if (arrivingOrArrivedIndex == 0 || isArrived) { + arrivingOrArrivedIndex + } else { + arrivingOrArrivedIndex - 1 } - CallerLogger.d(M_BUS + "BusOrderModel =", " mCurrentStation =" + mCurrentStation); + d(SceneConstant.M_BUS + "BusOrderModel =", " mCurrentStation =$mCurrentStation") - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.updateBusTaskStatus(lineName,lineTime, - stationList, arrivingOrArrivedIndex, isArrived); - } - } - }, UiThreadHandler.MODE.QUEUE); - } - - @Override - public void updateEmptyUi() { - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.updateLineEmptyUI(); - } - } - }, UiThreadHandler.MODE.QUEUE); - } - - @Override - public void clearBusStationsMarkers() { - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.clearBusStationsMarkers(); - } - } - }, UiThreadHandler.MODE.QUEUE); - } - - @Override - public void hideSlidePanel() { - if (mView != null) { - mView.hideSlidePanel(); - mView.setArrivedClikable(true); - } - } - - @Override - public void onAutopilotArriveAtStation(ArrivedStation arrivedStation) { - CallerLogger.e( M_BUS + TAG, "行程日志-onAutopilotArriveAtStation arrive"); - arriveStation(arrivedStation,"底盘触发进站"); - } - - public void arriveStation(ArrivedStation arrivedStation,String type){ - OrderModel.getInstance().onArriveAt(arrivedStation,type); - } - - @Override - public void onAutopilotStatusResponse(int state) { - switch (state) { - case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE: - case IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING: - case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE: - if (FunctionBuildConfig.isDemoMode - && ( - (mCurrentStation >= 0 && mCurrentStation <= mStationList.size() - 1) - && OrderModel.getInstance().isGoingToNextStation() + UiThreadHandler.post({ + if (mView != null) { + mView!!.updateBusTaskStatus( + lineName, lineTime, + stationList, arrivingOrArrivedIndex, isArrived ) - ) { - CallerLogger.d(M_BUS + "BusOrderModel=", "有美化功能"); - return; - } - // 改变UI自动驾驶状态 - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.onAutopilotStatusChanged(state, CallerAutoPilotControlManager.INSTANCE.isCanStartAutopilot(false,0)); - } - } - }, UiThreadHandler.MODE.QUEUE); - break; - case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING: - OrderModel.getInstance().triggerStartServiceEvent( - OrderModel.getInstance().isRestartAutopilot(), true); - // 改变UI自动驾驶状态 - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.onAutopilotStatusChanged(state, CallerAutoPilotControlManager.INSTANCE.isCanStartAutopilot(false,0)); - } - } - }, UiThreadHandler.MODE.QUEUE); - break; - default: - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.onAutopilotEnableChange(false); - } - } - }, UiThreadHandler.MODE.QUEUE); - break; + } + }, UiThreadHandler.MODE.QUEUE) + } + + override fun updateEmptyUi() { + UiThreadHandler.post({ + if (mView != null) { + mView!!.updateLineEmptyUI() + } + }, UiThreadHandler.MODE.QUEUE) + } + + override fun clearBusStationsMarkers() { + UiThreadHandler.post({ + if (mView != null) { + mView!!.clearBusStationsMarkers() + } + }, UiThreadHandler.MODE.QUEUE) + } + + override fun hideSlidePanel() { + if (mView != null) { + mView!!.hideSlidePanel() + mView!!.setArrivedClikable(true) } } - @Override - public void onCarLocationChanged(MogoLocation location) { -// if (null != location) { -// runOnUIThread(() -> mView.updateSpeedView(location.getGnssSpeed())); -// } + override fun onAutopilotArriveAtStation(arrivedStation: ArrivedStation?) { + e(SceneConstant.M_BUS + TAG, "行程日志-onAutopilotArriveAtStation arrive") + arriveStation(arrivedStation, "底盘触发进站") } - @Override - public void startOpenAutopilot() { - //非美化模式下启动动画 - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.startAutopilotAnimation(); + fun arriveStation(arrivedStation: ArrivedStation?, type: String?) { + onArriveAt(arrivedStation, type!!) + } + + override fun onAutopilotStatusResponse(state: Int) { + when (state) { + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE, IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING, IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE -> { + if (FunctionBuildConfig.isDemoMode + && ((mCurrentStation >= 0 && mCurrentStation <= mStationList.size - 1) + && isGoingToNextStation + ) + ) { + d(SceneConstant.M_BUS + "BusOrderModel=", "有美化功能") + return } + // 改变UI自动驾驶状态 + UiThreadHandler.post({ + if (mView != null) { + mView!!.onAutopilotStatusChanged(state, isCanStartAutopilot(false, 0)) + } + }, UiThreadHandler.MODE.QUEUE) } - }, UiThreadHandler.MODE.QUEUE); + + IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING -> { + triggerStartServiceEvent( + isRestartAutopilot, true + ) + // 改变UI自动驾驶状态 + UiThreadHandler.post({ + if (mView != null) { + mView!!.onAutopilotStatusChanged(state, isCanStartAutopilot(false, 0)) + } + }, UiThreadHandler.MODE.QUEUE) + } + + else -> UiThreadHandler.post({ + if (mView != null) { + mView!!.onAutopilotEnableChange(false) + } + }, UiThreadHandler.MODE.QUEUE) + } + } + + override fun startOpenAutopilot() { + //非美化模式下启动动画 + UiThreadHandler.post({ + if (mView != null) { + mView!!.startAutopilotAnimation() + } + }, UiThreadHandler.MODE.QUEUE) //中间站点再次开启自驾时, 自动驾驶状态是2未改变, 此次鹰眼底层不再返给业务,需优化按钮动画显示 if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING - == CallerAutoPilotStatusListenerManager.INSTANCE.getState()&&mView!=null){ - mView.onAutopilotStatusChanged(CallerAutoPilotStatusListenerManager.INSTANCE.getState(), - CallerAutoPilotControlManager.INSTANCE.isCanStartAutopilot(false,0)); - } - } - - private void runOnUIThread(Runnable executor) { - if (executor == null) { - return; - } - if (Looper.myLooper() != Looper.getMainLooper()) { - UiThreadHandler.post(executor); - } else { - executor.run(); + == getState() && mView != null + ) { + mView!!.onAutopilotStatusChanged( + getState(), + isCanStartAutopilot(false, 0) + ) } } /** * 测试使用 */ - public void debugAutoPilotStatus(int status) { - onAutopilotStatusResponse(status); + fun debugAutoPilotStatus(status: Int) { + onAutopilotStatusResponse(status) } - @Override - public void onAutopilotGuardian(MogoReportMsg.MogoReportMessage guardianInfo, long lineId) { - BusTrajectoryManager.getInstance().onAutopilotGuardian(guardianInfo,lineId); + override fun onAutopilotGuardian(guardianInfo: MogoReportMessage, lineId: Long) { + BusTrajectoryManager.getInstance().onAutopilotGuardian(guardianInfo, lineId) } - @Override - public void onStatusChange(LoginStatusEnum currentStatus) { - CallerLogger.d(M_BUS + TAG, " loginStatus =" + LoginStatusManager.isLogin()); - if(LoginStatusManager.isLogin()){ -// OrderModel.getInstance().queryBusRoutes(); - OrderModel.getInstance().queryBusCacheRoutes(); - }else { - BusTrajectoryManager.getInstance().stopTrajReqLoop(); - BusTrajectoryManager.getInstance().stopTrajReqLoop(); - clearBusStationsMarkers(); - if(mView!=null) { - mView.hideSlidePanel(); + override fun onStatusChange(currentStatus: LoginStatusEnum) { + d(SceneConstant.M_BUS + TAG, " loginStatus =" + isLogin()) + if (isLogin()) { + queryBusCacheRoutes() + } else { + BusTrajectoryManager.getInstance().stopTrajReqLoop() + BusTrajectoryManager.getInstance().stopTrajReqLoop() + clearBusStationsMarkers() + if (mView != null) { + mView!!.hideSlidePanel() } - OrderModel.getInstance().closeBeautificationMode(); + closeBeautificationMode() } } - @Override - public void onStartAdasFailure() { - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.stopAnimAndUpdateBtnStatus(); - } + override fun onStartAdasFailure() { + UiThreadHandler.post({ + if (mView != null) { + mView!!.stopAnimAndUpdateBtnStatus() } - }, UiThreadHandler.MODE.QUEUE); + }, UiThreadHandler.MODE.QUEUE) } - @Override - public void canStartAutopilot(boolean canStart) { - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - if(mView!=null) { - mView.onAutopilotStatusChanged(CallerAutoPilotStatusListenerManager.INSTANCE.getState(),canStart); - } + override fun canStartAutopilot(canStart: Boolean) { + UiThreadHandler.post({ + if (mView != null) { + mView!!.onAutopilotStatusChanged(getState(), canStart) } - }, UiThreadHandler.MODE.QUEUE); + }, UiThreadHandler.MODE.QUEUE) + } + + companion object { + private const val TAG = "BusPresenter" } } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusAnalyticsManager.kt b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusAnalyticsManager.kt index 93f5c13045..683f94cd14 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusAnalyticsManager.kt +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusAnalyticsManager.kt @@ -1,56 +1,42 @@ -package com.mogo.och.weaknet.util; +package com.mogo.och.weaknet.util +import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutopilotAnalytics -import androidx.annotation.NonNull; - -import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutopilotAnalytics; /** * OCH Bus埋点工具 - *

+ * + * * Created on 2022/3/24 */ -public class BusAnalyticsManager extends OchAutopilotAnalytics { +object BusAnalyticsManager : OchAutopilotAnalytics() { // 埋点key:开启自动驾驶前已识别的异常,会导致无法开启自驾 - private static final String EVENT_KEY_AP_UNABLE_START_REASON = "event_key_och_bus_ap_unable_start_reason"; + private const val EVENT_KEY_AP_UNABLE_START_REASON = + "event_key_och_bus_ap_unable_start_reason" + // 埋点key:接管后点击'自动驾驶'按钮启动 - private static final String EVENT_KEY_RESTART_AUTOPILOT = "event_key_och_bus_restart_autopilot"; + private const val EVENT_KEY_RESTART_AUTOPILOT = "event_key_och_bus_restart_autopilot" + // 埋点key:开始服务开启自动驾驶(成功/失败) - private static final String EVENT_KEY_START_SERVICE = "event_key_och_bus_start_service"; + private const val EVENT_KEY_START_SERVICE = "event_key_och_bus_start_service" + // 埋点key:点击启动自驾 - private static final String EVENT_KEY_CLICK_START_AUTOPILOT = "event_key_och_shuttle_click_start_autopilot"; + private const val EVENT_KEY_CLICK_START_AUTOPILOT = "event_key_och_shuttle_click_start_autopilot" - private static final class SingletonHolder { - private static final BusAnalyticsManager INSTANCE = new BusAnalyticsManager(); + override fun getEventKeyStartService(): String { + return EVENT_KEY_START_SERVICE } - public static BusAnalyticsManager getInstance() { - return SingletonHolder.INSTANCE; + override fun getEventKeyRestartService(): String { + return EVENT_KEY_RESTART_AUTOPILOT } - @NonNull - @Override - public String getEventKeyStartService() { - return EVENT_KEY_START_SERVICE; + override fun getEventKeyApUnableStartReason(): String { + return EVENT_KEY_AP_UNABLE_START_REASON } - @NonNull - @Override - public String getEventKeyRestartService() { - return EVENT_KEY_RESTART_AUTOPILOT; + override fun getEventKeyClickStartAutopilot(): String { + return EVENT_KEY_CLICK_START_AUTOPILOT } - - @NonNull - @Override - public String getEventKeyApUnableStartReason() { - return EVENT_KEY_AP_UNABLE_START_REASON; - } - - @NonNull - @Override - public String getEventKeyClickStartAutopilot() { - return EVENT_KEY_CLICK_START_AUTOPILOT; - } - } diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusTrajectoryManager.java b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusTrajectoryManager.java index 94d17edf10..a853c277a6 100644 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusTrajectoryManager.java +++ b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/util/BusTrajectoryManager.java @@ -50,10 +50,10 @@ public class BusTrajectoryManager { * 同步Bus路线信息 */ public void syncTrajectoryInfo() { - BusRoutesResult routesResult = OrderModel.getInstance().getBusRoutesResult(); + BusRoutesResult routesResult = OrderModel.getBusRoutesResult(); if (LoginStatusManager.isLogin() && routesResult != null - && OrderModel.getInstance().getCurrentStationIndex() == 0 - && !OrderModel.getInstance().isGoingToNextStation()) { + && OrderModel.getCurrentStationIndex() == 0 + && !OrderModel.isGoingToNextStation()) { CallerLogger.d(M_BUS + TAG, "syncTrajectoryInfo() start."); startTrajReqLoop(); } else { @@ -111,7 +111,7 @@ public class BusTrajectoryManager { } private void setupAutoPilotLine() { - BusRoutesResult routesResult = OrderModel.getInstance().getBusRoutesResult(); + BusRoutesResult routesResult = OrderModel.getBusRoutesResult(); if (routesResult == null) { CallerLogger.e(M_BUS + TAG, "setupAutoPilotLine(): routesResult is null."); diff --git a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/VerticalDashLineView.java b/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/VerticalDashLineView.java deleted file mode 100644 index abac3ca41b..0000000000 --- a/OCH/shuttle/driver_weaknet/src/main/java/com/mogo/och/weaknet/view/VerticalDashLineView.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.mogo.och.weaknet.view; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.graphics.LinearGradient; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Shader; -import android.util.AttributeSet; -import android.view.View; - -import androidx.annotation.Nullable; - -/** - * 垂直虚线 - * - * @author tongchenfei - */ -public class VerticalDashLineView extends View { - public VerticalDashLineView(Context context) { - this(context,null); - } - - public VerticalDashLineView(Context context, @Nullable AttributeSet attrs) { - this(context, attrs,0); - } - - public VerticalDashLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(); - } - - private final Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG); - private final Path dashPath = new Path(); - - private void init(){ - linePaint.setColor(Color.GREEN); - linePaint.setStyle(Paint.Style.STROKE); - linePaint.setStrokeWidth(2); - linePaint.setPathEffect(new DashPathEffect(new float[]{5, 5}, 0)); - } - - public void setGradient(int startColor, int endColor) { - LinearGradient linearGradient = new LinearGradient(0, 0, getWidth(), getHeight(), startColor, endColor, Shader.TileMode.CLAMP); - linePaint.setShader(linearGradient); - invalidate(); - } - - public void setColor(int color) { - linePaint.setShader(null); - linePaint.setColor(color); - invalidate(); - } - - @Override - protected void onDraw(Canvas canvas) { - dashPath.reset(); - dashPath.moveTo((float) getWidth()/2, 0); - dashPath.lineTo((float) getWidth()/2,getHeight()); - canvas.drawPath(dashPath,linePaint); - } -} diff --git a/OCH/shuttle/driver_weaknet/src/main/res/layout/shuttle_weak_base_fragment.xml b/OCH/shuttle/driver_weaknet/src/main/res/layout/shuttle_weak_base_fragment.xml index 3736800c39..c81adb63bf 100644 --- a/OCH/shuttle/driver_weaknet/src/main/res/layout/shuttle_weak_base_fragment.xml +++ b/OCH/shuttle/driver_weaknet/src/main/res/layout/shuttle_weak_base_fragment.xml @@ -276,7 +276,7 @@ android:layout_width="@dimen/dp_142" android:layout_height="@dimen/dp_142"/> - - - - - - - - - - \ No newline at end of file