[6.4.4]
[bus乘客屏 登录逻辑使用通用模块]
This commit is contained in:
@@ -5,13 +5,8 @@ import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioFocusRequest
|
||||
import android.media.AudioManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
|
||||
@@ -28,10 +23,6 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.mogo.och.bus.passenger.bean.BusPassengerOperationStatusResponse
|
||||
import com.mogo.och.bus.passenger.bean.PM2RoutesResponse
|
||||
import com.mogo.och.bus.passenger.callback.IAutopilotStatusCallback
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassegerDriverStatusCallback
|
||||
@@ -39,6 +30,11 @@ import com.mogo.och.bus.passenger.callback.IDrivingInfoCallback
|
||||
import com.mogo.och.bus.passenger.callback.ISpeedCallback
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager
|
||||
import com.mogo.och.common.module.biz.lansocket.LoginLanPassengerSocket
|
||||
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.OpenOrderStatusEnum
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.IOchAutopilotStatusListener
|
||||
import com.mogo.och.common.module.manager.autopilot.autopilot.OchAutoPilotStatusListenerManager
|
||||
@@ -64,17 +60,14 @@ import com.mogo.och.data.bean.BusTransferData
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object OrderModel {
|
||||
|
||||
private val TAGA = OrderModel::class.java.simpleName
|
||||
private val TAG = OrderModel::class.java.simpleName
|
||||
|
||||
val TAG_LOOP_QUERY_BIND_LINE = "${TAGA}_TAG_LOOP_QUERY_BIND_LINE"
|
||||
val TAG_LOOP_QUERY_BIND_LINE = "${TAG}_TAG_LOOP_QUERY_BIND_LINE"
|
||||
|
||||
var mContext: Context? = null
|
||||
private var mContext: Context? = null
|
||||
|
||||
var operationStatus: BusPassengerOperationStatusResponse.Result? = null
|
||||
var routesResult: BusRoutesResult? = null
|
||||
var mNextStationIndex = 0 // A-B要到达站的index
|
||||
|
||||
private val MSG_QUERY_BUS_P_STATION = 1001
|
||||
private var routesResult: BusRoutesResult? = null
|
||||
private var mNextStationIndex = 0 // A-B要到达站的index
|
||||
|
||||
|
||||
var mDrivingInfoCallback: IDrivingInfoCallback? = null //行程信息
|
||||
@@ -82,15 +75,6 @@ object OrderModel {
|
||||
var mSpeedCallback: ISpeedCallback? = null //行程信息
|
||||
var mDriverStatusCallback: IBusPassegerDriverStatusCallback? = null //出车收车状态
|
||||
|
||||
val handler = Handler(Looper.getMainLooper(), Handler.Callback { msg ->
|
||||
if (msg.what == MSG_QUERY_BUS_P_STATION) {
|
||||
queryDriverOperationStatus()
|
||||
return@Callback true
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
|
||||
fun init(context: Context){
|
||||
mContext = context
|
||||
initListeners()
|
||||
@@ -102,41 +86,33 @@ object OrderModel {
|
||||
)
|
||||
}
|
||||
|
||||
open fun initListeners() {
|
||||
private fun initListeners() {
|
||||
//自动驾驶状态监听
|
||||
OchAutoPilotStatusListenerManager.addListener(TAGA, mGoAutopilotStatusListener)
|
||||
OchAutoPilotStatusListenerManager.addListener(TAG, mGoAutopilotStatusListener)
|
||||
// 定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAGA, 3, mMapLocationListener)
|
||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 3, mMapLocationListener)
|
||||
// 距离终点站距离监听
|
||||
TrajectoryAndDistanceManager.addDistanceListener(TAGA, trajectoryListener)
|
||||
TrajectoryAndDistanceManager.addDistanceListener(TAG, trajectoryListener)
|
||||
AbnormalFactorsLoopManager.startLoopAbnormalFactors(mContext!!)
|
||||
//司乘屏通信监听
|
||||
CallerTelematicListenerManager.addListener(TAGA, mReceivedMsgListener)
|
||||
IntentManager.getInstance()
|
||||
.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
CallerTelematicListenerManager.addListener(TAG, mReceivedMsgListener)
|
||||
|
||||
}
|
||||
|
||||
fun releaseListeners(){
|
||||
//自动驾驶状态监听
|
||||
OchAutoPilotStatusListenerManager.removeListener(mGoAutopilotStatusListener)
|
||||
// 注销定位监听
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAGA)
|
||||
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
|
||||
// 距离终点站距离监听
|
||||
TrajectoryAndDistanceManager.removeListener(TAGA)
|
||||
TrajectoryAndDistanceManager.removeListener(TAG)
|
||||
|
||||
AbnormalFactorsLoopManager.stopLoopAbnormalFactors()
|
||||
CallerTelematicListenerManager.removeListener(TAGA)
|
||||
CallerTelematicListenerManager.removeListener(TAG)
|
||||
BizLoopManager.removeLoopFunction(TAG_LOOP_QUERY_BIND_LINE)
|
||||
cleanStation("release")
|
||||
}
|
||||
|
||||
fun queryDriverOperationDelay() {
|
||||
handler.sendEmptyMessageDelayed(
|
||||
MSG_QUERY_BUS_P_STATION,
|
||||
BusPassengerConst.QUERY_BUS_P_STATION_DELAY
|
||||
)
|
||||
}
|
||||
|
||||
fun setDrivingInfoCallback(drivingInfoCallback: IDrivingInfoCallback?) {
|
||||
mDrivingInfoCallback = drivingInfoCallback
|
||||
}
|
||||
@@ -153,7 +129,7 @@ object OrderModel {
|
||||
mDriverStatusCallback = callback
|
||||
}
|
||||
|
||||
val mGoAutopilotStatusListener: IOchAutopilotStatusListener =
|
||||
private val mGoAutopilotStatusListener: IOchAutopilotStatusListener =
|
||||
object : IOchAutopilotStatusListener {
|
||||
override fun onAutopilotStatusResponse(state: Int) {
|
||||
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING != state) {
|
||||
@@ -170,7 +146,7 @@ object OrderModel {
|
||||
}
|
||||
}
|
||||
|
||||
val mMapLocationListener: IMoGoChassisLocationGCJ02Listener =
|
||||
private val mMapLocationListener: IMoGoChassisLocationGCJ02Listener =
|
||||
object : IMoGoChassisLocationGCJ02Listener {
|
||||
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
|
||||
if (null == mogoLocation) return
|
||||
@@ -180,11 +156,11 @@ object OrderModel {
|
||||
}
|
||||
}
|
||||
|
||||
val trajectoryListener: IDistanceListener = object : IDistanceListener {
|
||||
private val trajectoryListener: IDistanceListener = object : IDistanceListener {
|
||||
override fun distanceCallback(distance: Float) {
|
||||
val lastTime = distance / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 //秒
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"轨迹排查==lastSumLength = $distance"
|
||||
)
|
||||
if (routesResult != null) {
|
||||
@@ -201,7 +177,7 @@ object OrderModel {
|
||||
private val mReceivedMsgListener: IReceivedMsgListener = object : IReceivedMsgListener {
|
||||
override fun onReceivedServerSn(sn: String?) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"onReceivedServerSn = $sn"
|
||||
)
|
||||
mDriverStatusCallback?.updateDriverSn(sn)
|
||||
@@ -211,7 +187,7 @@ object OrderModel {
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"onReceivedMsg = " + GsonUtils.toJson(baseMsg)
|
||||
)
|
||||
|
||||
@@ -231,7 +207,7 @@ object OrderModel {
|
||||
}
|
||||
}else if (baseMsg != null && baseMsg.type == DPMsgType.TYPE_TASK_DETAILS.type){
|
||||
val msg = GsonUtils.fromJson(String(byteArray), TaskDetailsMsg::class.java)
|
||||
Logger.d(SceneConstant.M_BUS_P + TAGA, "onReceivedMsg = " + GsonUtils.toJson(msg))
|
||||
Logger.d(SceneConstant.M_BUS_P + TAG, "onReceivedMsg = " + GsonUtils.toJson(msg))
|
||||
|
||||
if (msg == null || msg.msg?.isEmpty() == true){
|
||||
clearLocalRouteResult()
|
||||
@@ -254,21 +230,6 @@ object OrderModel {
|
||||
}
|
||||
}
|
||||
|
||||
//监听网络变化,避免启动机器时无网导致无法更新订单信息
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, intent ->
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"onIntentReceived = %s",
|
||||
intentStr
|
||||
)
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
|
||||
if (NetworkUtils.isConnected(mContext)) {
|
||||
queryDriverOperationStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun queryDriverByLocalDriver() {
|
||||
//本地去请求司机端
|
||||
@@ -277,50 +238,40 @@ object OrderModel {
|
||||
}
|
||||
|
||||
|
||||
fun queryDriverOperationStatus() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverOperationStatus(
|
||||
it, object : OchCommonServiceCallback<BusPassengerOperationStatusResponse> {
|
||||
override fun onSuccess(data: BusPassengerOperationStatusResponse?) {
|
||||
if (data?.data == null) return
|
||||
if (mDriverStatusCallback != null) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverOperationStatus = %s",
|
||||
data.data.plateNumber
|
||||
)
|
||||
operationStatus = data.data as BusPassengerOperationStatusResponse.Result
|
||||
mDrivingInfoCallback?.changeOperationStatus(data.data.driverStatus == 1)
|
||||
private fun queryDriverOperationStatus() {
|
||||
LoginStatusManager.addListener(TAG,object: ILoginCallback{
|
||||
override fun onStatusChange(currentStatus: LoginStatusEnum?) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
queryDriverByLocalDriver()
|
||||
queryDriverOperationDelay()
|
||||
override fun onOpenOrderStatusEnumChange(businessEnum: OpenOrderStatusEnum?) {
|
||||
when (businessEnum) {
|
||||
OpenOrderStatusEnum.Ordering -> {
|
||||
mDrivingInfoCallback?.changeOperationStatus(true)
|
||||
}
|
||||
else -> {
|
||||
mDrivingInfoCallback?.changeOperationStatus(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
//延迟3s再次查询
|
||||
queryDriverOperationDelay()
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun onLoginErrorInfo(code: Int, msg: String?) {
|
||||
super.onLoginErrorInfo(code, msg)
|
||||
if(code==-10012){// 网络错误
|
||||
queryDriverByLocalDriver()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun queryDriverSiteByCoordinate() {
|
||||
private fun queryDriverSiteByCoordinate() {
|
||||
mContext?.let {
|
||||
BusPassengerServiceManager.queryDriverSiteByCoordinate(it,
|
||||
object : OchCommonServiceCallback<PM2RoutesResponse> {
|
||||
override fun onSuccess(data: PM2RoutesResponse?) {
|
||||
if (data == null || data.result == null) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"order = queryDriverSiteByCoordinate = null"
|
||||
)
|
||||
clearLocalRouteResult()
|
||||
@@ -330,7 +281,7 @@ object OrderModel {
|
||||
routesResult
|
||||
)) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"order = queryDriverSiteByCoordinate = not update"
|
||||
)
|
||||
return
|
||||
@@ -350,22 +301,22 @@ object OrderModel {
|
||||
}
|
||||
override fun onError() {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate = onError = sn = " + BusPassengerServiceManager.driverAppSn
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"queryDriverSiteByCoordinate = onError = sn = " + LoginLanPassengerSocket.driverSn
|
||||
)
|
||||
queryDriverByLocalDriver()
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate = $msg sn = ${BusPassengerServiceManager.driverAppSn}"
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"queryDriverSiteByCoordinate = $msg sn = ${LoginLanPassengerSocket.driverSn}"
|
||||
)
|
||||
if (code == 1003) {
|
||||
queryDriverOperationDelay()
|
||||
LoginStatusManager.queryLoginStatusByNet()
|
||||
cleanStation("queryDriverSiteByCoordinate 1003")
|
||||
}
|
||||
if (BusPassengerServiceManager.driverAppSn.isEmpty()) {
|
||||
if (LoginLanPassengerSocket.driverSn.isEmpty()) {
|
||||
//此处拦截是为了防止过程中乘客屏和司机端断连,拿不到司机端sn, 造成请求失败去刷新了界面
|
||||
return
|
||||
}
|
||||
@@ -379,7 +330,7 @@ object OrderModel {
|
||||
}
|
||||
}
|
||||
|
||||
fun setTrajectoryStation(
|
||||
private fun setTrajectoryStation(
|
||||
startStationInfo: BusStationBean,
|
||||
endStationInfo: BusStationBean,
|
||||
lineId: Int
|
||||
@@ -394,7 +345,7 @@ object OrderModel {
|
||||
}
|
||||
|
||||
fun cleanStation(type: String) {
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAGA, "清理站点 $type")
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "清理站点 $type")
|
||||
TrajectoryAndDistanceManager.setStationPoint(null, null, -1L)
|
||||
}
|
||||
|
||||
@@ -405,22 +356,16 @@ object OrderModel {
|
||||
mDrivingInfoCallback?.showNoTaskView()
|
||||
}
|
||||
|
||||
fun updateAutopilotControlParameters(
|
||||
private fun updateAutopilotControlParameters(
|
||||
busRoutesResult: BusRoutesResult,
|
||||
leaveIndex: Int
|
||||
) {
|
||||
val parameters = initAutopilotControlParameters(busRoutesResult, leaveIndex)
|
||||
if (null == parameters) {
|
||||
CallerLogger.e(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"AutopilotControlParameters is empty."
|
||||
)
|
||||
CallerLogger.e(SceneConstant.M_BUS_P + TAG, "AutopilotControlParameters is empty.")
|
||||
return
|
||||
}
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"AutopilotControlParameters is update."
|
||||
)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "AutopilotControlParameters is update.")
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(parameters)
|
||||
}
|
||||
|
||||
@@ -433,7 +378,7 @@ object OrderModel {
|
||||
}
|
||||
val stations = busRoutesResult.sites
|
||||
if (leaveIndex + 1 > stations.size - 1) {
|
||||
CallerLogger.e(SceneConstant.M_BUS_P + TAGA, "行程日志-mismatch condition1.")
|
||||
CallerLogger.e(SceneConstant.M_BUS_P + TAG, "行程日志-mismatch condition1.")
|
||||
return null
|
||||
}
|
||||
val currentStation = stations[leaveIndex]
|
||||
@@ -463,8 +408,8 @@ object OrderModel {
|
||||
}
|
||||
|
||||
|
||||
fun clearAutopilotControlParameters() {
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAGA, "AutopilotControlParameters is clear.")
|
||||
private fun clearAutopilotControlParameters() {
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "AutopilotControlParameters is clear.")
|
||||
CallerAutoPilotStatusListenerManager.updateAutopilotControlParameters(null)
|
||||
}
|
||||
|
||||
@@ -474,16 +419,10 @@ object OrderModel {
|
||||
return
|
||||
}
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"queryDriverSiteByCoordinate= update"
|
||||
)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "queryDriverSiteByCoordinate= update")
|
||||
routesResult = result
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = BusPassengerRoutesResult= " + GsonUtil.jsonFromObject(result)
|
||||
)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "order = BusPassengerRoutesResult= " + GsonUtil.jsonFromObject(result))
|
||||
mDrivingInfoCallback?.updateLine(result.name, result.runningDur)
|
||||
if (result.sites != null) {
|
||||
mDrivingInfoCallback?.hideNoTaskView()
|
||||
@@ -493,16 +432,16 @@ object OrderModel {
|
||||
val station = stations[i]
|
||||
if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && station.isLeaving && i + 1 < stations.size) { //离站
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"order = station= leave"
|
||||
)
|
||||
mDrivingInfoCallback?.updateStationsInfo(stations, i + 1, false)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"och-rotting--mNextStationIndex = $mNextStationIndex , i = $i"
|
||||
)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"och-rotting--start "
|
||||
)
|
||||
mNextStationIndex = i + 1
|
||||
@@ -513,23 +452,17 @@ object OrderModel {
|
||||
return
|
||||
} else if (station.drivingStatus == BusPassengerConst.STATION_STATUS_STOPPED && !station.isLeaving) { //到站
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
SceneConstant.M_BUS_P + TAG,
|
||||
"och-rotting--mNextStationIndex = $mNextStationIndex , i = $i"
|
||||
)
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"och-rotting--arrived "
|
||||
)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "och-rotting--arrived ")
|
||||
if (i == stations.size - 1) {
|
||||
cleanStation("updatePassengerRouteInfo最后一个站点")
|
||||
}
|
||||
|
||||
TrajectoryAndDistanceManager.suspendCalculate()
|
||||
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_BUS_P + TAGA,
|
||||
"order = station= arrive"
|
||||
)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "order = station= arrive")
|
||||
|
||||
mDrivingInfoCallback?.updateStationsInfo(stations, i, true)
|
||||
clearAutopilotControlParameters()
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mogo.och.bus.passenger.bean.BusPassengerQueryLineRequest
|
||||
import com.mogo.och.bus.passenger.bean.BusPassengerOperationStatusResponse
|
||||
import com.mogo.eagle.core.network.MoGoRetrofitFactory
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.och.common.module.biz.lansocket.LoginLanPassengerSocket
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.network.OchCommonSubscribeImpl
|
||||
@@ -19,27 +20,12 @@ import com.mogo.och.common.module.network.interceptor.transformTry
|
||||
*/
|
||||
object BusPassengerServiceManager {
|
||||
|
||||
private var driverSnCache = ""
|
||||
|
||||
private var mBusPassengerSaasServiceApi =
|
||||
MoGoRetrofitFactory.getInstance(OchCommonConst.getBaseUrl()).create(PassengerSAASServiceApi::class.java)
|
||||
|
||||
private var mBusPassengerServiceApi =
|
||||
MoGoRetrofitFactory.getInstance(OchCommonConst.getBaseUrl()).create(PassengerServiceApi::class.java)
|
||||
|
||||
/**
|
||||
* 获取Bus司机端的sn
|
||||
* @return
|
||||
*/
|
||||
public val driverAppSn: String
|
||||
get() {
|
||||
val serverToken = getServerToken()
|
||||
if (serverToken != driverSnCache && serverToken.isNotEmpty()) {
|
||||
driverSnCache = serverToken
|
||||
}
|
||||
return driverSnCache
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询绑定行驶的小巴车路线
|
||||
* @param context
|
||||
@@ -53,48 +39,17 @@ object BusPassengerServiceManager {
|
||||
mBusPassengerSaasServiceApi.queryDriverSiteByCoordinate(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
SharedPrefsMgr.getInstance().token,
|
||||
driverAppSn
|
||||
LoginLanPassengerSocket.driverSn
|
||||
).transformTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverSiteByCoordinate"))
|
||||
}else{
|
||||
mBusPassengerServiceApi.queryDriverSiteByCoordinate(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
SharedPrefsMgr.getInstance().token,
|
||||
BusPassengerQueryLineRequest(
|
||||
driverAppSn
|
||||
)
|
||||
BusPassengerQueryLineRequest(LoginLanPassengerSocket.driverSn)
|
||||
).transformTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverSiteByCoordinate"))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询司机端出车收车状态,以及车牌号
|
||||
* @param context
|
||||
* @param callback
|
||||
*/
|
||||
@JvmStatic
|
||||
fun queryDriverOperationStatus(
|
||||
context: Context,
|
||||
callback: OchCommonServiceCallback<BusPassengerOperationStatusResponse>?
|
||||
) {
|
||||
|
||||
if (DebugConfig.getProjectFlavor().contains("saas")){
|
||||
mBusPassengerSaasServiceApi.queryDriverOperationStatus(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
SharedPrefsMgr.getInstance().token,
|
||||
driverAppSn
|
||||
)
|
||||
.transformTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverOperationStatus"))
|
||||
}else{
|
||||
mBusPassengerServiceApi.queryDriverOperationStatus(
|
||||
MoGoAiCloudClientConfig.getInstance().serviceAppId,
|
||||
SharedPrefsMgr.getInstance().token,
|
||||
driverAppSn
|
||||
)
|
||||
.transformTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverOperationStatus"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,4 @@ public interface PassengerSAASServiceApi {
|
||||
@GET( "/och-bus-cabin/api/business/v1/driver/bus/lineDataWithDriver/query" )
|
||||
Observable<PM2RoutesResponse> queryDriverSiteByCoordinate(@Header("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
/**
|
||||
* 查询司机端的登陆状态
|
||||
* @param sn
|
||||
* @return
|
||||
*/
|
||||
@Headers({"Content-type:application/json;charset=UTF-8"})
|
||||
@GET("/och-bus-cabin/api/business/v1/loginStatus")
|
||||
Observable<BusPassengerOperationStatusResponse> queryDriverOperationStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,14 +26,4 @@ public interface PassengerServiceApi {
|
||||
@POST( "/autopilot-car-hailing/line/v2/driver/bus/passenger/lineDataWithDriver/query" )
|
||||
Observable<PM2RoutesResponse> queryDriverSiteByCoordinate(@Header("appId") String appId, @Header("ticket") String ticket, @Body BusPassengerQueryLineRequest request);
|
||||
|
||||
/**
|
||||
* 查询司机端的登陆状态
|
||||
* @param sn
|
||||
* @return
|
||||
*/
|
||||
@Headers({"Content-type:application/json;charset=UTF-8"})
|
||||
@GET("/autopilot-car-hailing/operation/v1/driver/bus/passenger/loginStatus")
|
||||
Observable<BusPassengerOperationStatusResponse> queryDriverOperationStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.mogo.och.biz.login.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
||||
@@ -45,13 +48,24 @@ import java.util.concurrent.TimeUnit
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object LoginModel {
|
||||
|
||||
private val TAG = "TaxiLoginModel"
|
||||
private const val TAG = "TaxiLoginModel"
|
||||
private var mContext: Context? = null
|
||||
var iTaxiLoginCallback: ITaxiLoginCallback? = null
|
||||
private var subscribe: Disposable? = null
|
||||
|
||||
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, _ ->
|
||||
d(TAG, "onIntentReceived = %s", intentStr)
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
|
||||
if (NetworkUtils.isConnected(mContext)) {
|
||||
queryCarStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
mContext = AbsMogoApplication.getApp()
|
||||
IntentManager.getInstance()
|
||||
.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener)
|
||||
}
|
||||
|
||||
fun init(context: Context) {
|
||||
@@ -59,10 +73,7 @@ object LoginModel {
|
||||
}
|
||||
|
||||
fun hasInit(): Boolean {
|
||||
if (iTaxiLoginCallback == null) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return iTaxiLoginCallback != null
|
||||
}
|
||||
|
||||
fun getiTaxiLoginCallback(): ITaxiLoginCallback? {
|
||||
@@ -159,7 +170,7 @@ object LoginModel {
|
||||
fun queryCarStatus() {
|
||||
mContext?.let {
|
||||
queryDriverServiceStatus(it, object : OchCommonServiceCallback<DriverStatusQueryRespBean> {
|
||||
override fun onSuccess(data: DriverStatusQueryRespBean) {
|
||||
override fun onSuccess(data: DriverStatusQueryRespBean?) {
|
||||
if (null != data && 0 == data.code) {
|
||||
// 不用登录也可以获得支持的业务模式
|
||||
LoginStatusManager.setBusinessType(data.data.businessType)
|
||||
@@ -188,18 +199,21 @@ object LoginModel {
|
||||
} else {
|
||||
ToastCharterUtils.showToastShort(mContext!!.getString(R.string.request_error_tip))
|
||||
}
|
||||
LoginStatusManager.setLoginError(-10012,"网络错误")
|
||||
subscribe = Observable.timer(5, TimeUnit.SECONDS)
|
||||
.subscribe { aLong: Long? -> queryCarStatus() }
|
||||
.subscribe { _: Long? -> queryCarStatus() }
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String) {
|
||||
LoginStatusManager.setLoginError(code,"msg:${msg}")
|
||||
ToastUtilsOch.showWithCodeMessage(code, msg)
|
||||
if (code == OchCommonConst.WAIT_TAKEN) {
|
||||
subscribe = Observable.timer(3, TimeUnit.SECONDS)
|
||||
.subscribe { aLong: Long? -> queryCarStatus() }
|
||||
} else {
|
||||
subscribe = Observable.timer(3, TimeUnit.SECONDS)
|
||||
.subscribe { _: Long? -> queryCarStatus() }
|
||||
// if (code == OchCommonConst.WAIT_TAKEN) {
|
||||
//
|
||||
// } else {
|
||||
loginFail(LoginStatusManager.isLogin())
|
||||
}
|
||||
// }
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -211,7 +225,7 @@ object LoginModel {
|
||||
OchCommonServiceManager.logout(
|
||||
mContext!!, location4Login,
|
||||
object : OchCommonServiceCallback<BaseData> {
|
||||
override fun onSuccess(data: BaseData) {
|
||||
override fun onSuccess(data: BaseData?) {
|
||||
if (null != data && 0 == data.code) {
|
||||
loginFail(false)
|
||||
queryCarStatus()
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.och.biz.login.bean.TaxiLoginRespBean
|
||||
import com.mogo.och.biz.login.bean.TaxiLoginSmsReqBean
|
||||
import com.mogo.och.biz.login.bean.TaxiLogoutReqBean
|
||||
import com.mogo.och.common.module.biz.lansocket.LoginLanPassengerSocket
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.network.OchCommonSubscribeImpl
|
||||
@@ -36,20 +37,6 @@ object OchCommonServiceManager {
|
||||
)
|
||||
}
|
||||
|
||||
private var draiverSnCacher = ""
|
||||
/**
|
||||
* 获取Bus司机端的sn
|
||||
* @return
|
||||
*/
|
||||
val draiverSn: String
|
||||
get(){
|
||||
val serverToken = CallerTelematicManager.getServerToken()
|
||||
if (serverToken != draiverSnCacher && serverToken.isNotEmpty()) {
|
||||
draiverSnCacher = serverToken
|
||||
}
|
||||
return draiverSnCacher
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机验证码
|
||||
* @param context
|
||||
@@ -153,7 +140,11 @@ object OchCommonServiceManager {
|
||||
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) {
|
||||
SharedPrefsMgr.getInstance().sn
|
||||
} else{
|
||||
draiverSn
|
||||
LoginLanPassengerSocket.driverSn
|
||||
}
|
||||
if(sn.isNullOrEmpty()){
|
||||
CallerLogger.d(TAG, "queryDriverServiceStatus:查询登录状态 没有有效的sn");
|
||||
return
|
||||
}
|
||||
if (ProjectUtils.isMogo()) {
|
||||
ochLoginServiceMogo.queryDriverServiceStatusAndLoginStatus(
|
||||
|
||||
@@ -10,4 +10,6 @@ public interface ILoginCallback {
|
||||
|
||||
default void onBusinessChangeDebug(BusinessEnum businessEnum){}
|
||||
|
||||
default void onLoginErrorInfo(int code,String msg){}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BusinessType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.EnvType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.ProjectType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.TaskDetailsMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.VehicleType
|
||||
import com.mogo.och.common.module.utils.CallerBase
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
@@ -120,7 +121,7 @@ object LoginStatusManager : CallerBase<ILoginCallback>() {
|
||||
|
||||
fun invokeLoginStatusChange(currentStatus: LoginStatusEnum) {
|
||||
if(currentStatus==LoginStatusEnum.Login){
|
||||
BizLoopManager.setLoopFunction(TAGLoopStatus, LoopInfo(60*10, ::queryLoginStatusByNet, scheduler = Schedulers.io()))
|
||||
BizLoopManager.setLoopFunction(TAGLoopStatus, LoopInfo(60*2, ::queryLoginStatusByNet,immediately = true, scheduler = Schedulers.io()))
|
||||
}else{
|
||||
BizLoopManager.removeLoopFunction(TAGLoopStatus)
|
||||
}
|
||||
@@ -183,5 +184,12 @@ object LoginStatusManager : CallerBase<ILoginCallback>() {
|
||||
listener.onOpenOrderStatusEnumChange(getOpenOrderType())
|
||||
}
|
||||
|
||||
fun setLoginError(code: Int, msg: String) {
|
||||
M_LISTENERS.forEach {
|
||||
val listener = it.value
|
||||
listener.onLoginErrorInfo(code,msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user